[DEV] Fix up porting patches and configs
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.hypherionmc.craterlib.mixin;
|
||||
|
||||
import com.hypherionmc.craterlib.client.mentions.MentionsController;
|
||||
import net.minecraft.client.gui.components.CommandSuggestions;
|
||||
import net.minecraft.client.gui.components.EditBox;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* Allow Users, Roles and Channels to be pingable from MC chat (Client Side)
|
||||
*/
|
||||
@Mixin(CommandSuggestions.class)
|
||||
public abstract class ChatInputSuggestorMixin {
|
||||
|
||||
@Shadow
|
||||
public abstract void showSuggestions(boolean p_93931_);
|
||||
|
||||
@Shadow @Final
|
||||
EditBox input;
|
||||
|
||||
@Shadow
|
||||
private static int getLastWordIndex(String p_93913_) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "updateCommandInfo",
|
||||
at = @At(
|
||||
value = "FIELD",
|
||||
target = "Lnet/minecraft/client/gui/components/CommandSuggestions;pendingSuggestions:Ljava/util/concurrent/CompletableFuture;",
|
||||
opcode = Opcodes.PUTFIELD,
|
||||
shift = At.Shift.AFTER,
|
||||
ordinal = 0
|
||||
),
|
||||
slice = @Slice(
|
||||
from = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/gui/components/CommandSuggestions;getLastWordIndex(Ljava/lang/String;)I"
|
||||
)
|
||||
)
|
||||
)
|
||||
private void injectSuggestions(CallbackInfo ci) {
|
||||
if (MentionsController.hasMentions() && MentionsController.isLastMentionConditional()) {
|
||||
this.showSuggestions(true);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("InvalidInjectorMethodSignature")
|
||||
@ModifyVariable(method = "updateCommandInfo", at = @At(value = "STORE"), ordinal = 0, name = "collection")
|
||||
private Collection<String> injectMentions(Collection<String> vanilla) {
|
||||
if (!MentionsController.hasMentions())
|
||||
return vanilla;
|
||||
|
||||
ArrayList<String> newSuggest = new ArrayList<>(vanilla);
|
||||
|
||||
String currentInput = this.input.getValue();
|
||||
int currentCursorPosition = this.input.getCursorPosition();
|
||||
|
||||
String textBeforeCursor = currentInput.substring(0, currentCursorPosition);
|
||||
int startOfCurrentWord = getLastWordIndex(textBeforeCursor);
|
||||
|
||||
String currentWord = textBeforeCursor.substring(startOfCurrentWord);
|
||||
String finalWord = currentWord.replace("[", "").replace("]", "");
|
||||
|
||||
Collection<String> mentions = MentionsController.getMentions(finalWord);
|
||||
|
||||
if (!mentions.isEmpty()) {
|
||||
mentions.forEach(m -> newSuggest.add("[" + m + "]"));
|
||||
}
|
||||
|
||||
return newSuggest;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterCommandEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Commands.class)
|
||||
public class CommandMixin {
|
||||
|
||||
@Inject(method = "performCommand",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/commands/Commands;finishParsing(Lcom/mojang/brigadier/ParseResults;Ljava/lang/String;Lnet/minecraft/commands/CommandSourceStack;)Lcom/mojang/brigadier/context/ContextChain;",
|
||||
shift = At.Shift.BEFORE
|
||||
), cancellable = true
|
||||
)
|
||||
private void injectCommandEvent(ParseResults<CommandSourceStack> stackParseResults, String command, CallbackInfo ci) {
|
||||
CraterCommandEvent commandEvent = CraterCommandEvent.of(stackParseResults, command);
|
||||
CraterEventBus.INSTANCE.postEvent(commandEvent);
|
||||
if (commandEvent.wasCancelled()) {
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (commandEvent.getException() != null) {
|
||||
Throwables.throwIfUnchecked(commandEvent.getException());
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterAdvancementEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.advancements.BridgedAdvancement;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.server.PlayerAdvancements;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PlayerAdvancements.class)
|
||||
public class PlayerAdvancementsMixin {
|
||||
|
||||
@Shadow
|
||||
private ServerPlayer player;
|
||||
|
||||
@Inject(method = "award", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", shift = At.Shift.AFTER))
|
||||
private void injectAdvancementEvent(AdvancementHolder advancementHolder, String string, CallbackInfoReturnable<Boolean> cir) {
|
||||
Advancement advancement = advancementHolder.value();
|
||||
|
||||
if (advancement.display().isPresent() && advancement.display().get().shouldAnnounceChat()) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterAdvancementEvent(BridgedPlayer.of(this.player), BridgedAdvancement.of(advancementHolder.value())));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.server.CraterPlayerEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.MessageBroadcastEvent;
|
||||
import com.hypherionmc.craterlib.api.events.server.PlayerPreLoginEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.authlib.BridgedGameProfile;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(PlayerList.class)
|
||||
public class PlayerListMixin {
|
||||
|
||||
@Inject(method = "broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Ljava/util/function/Function;Z)V", at = @At("HEAD"))
|
||||
private void injectBroadcastEvent(Component component, Function<ServerPlayer, Component> function, boolean bl, CallbackInfo ci) {
|
||||
String thread = Thread.currentThread().getStackTrace()[3].getClassName();
|
||||
MessageBroadcastEvent event = new MessageBroadcastEvent(ChatUtils.mojangToAdventure(component), (f) -> ChatUtils.mojangToAdventure(component), bl, thread);
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
}
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("TAIL"))
|
||||
private void injectPlayerLoginEvent(Connection connection, ServerPlayer serverPlayer, CommonListenerCookie commonListenerCookie, CallbackInfo ci) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer)));
|
||||
}
|
||||
|
||||
@Inject(method = "remove", at = @At("HEAD"))
|
||||
private void injectPlayerLogoutEvent(ServerPlayer player, CallbackInfo ci) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(player)));
|
||||
}
|
||||
|
||||
@Inject(method = "canPlayerLogin", at = @At("HEAD"), cancellable = true)
|
||||
private void injectPreLoginEvent(SocketAddress address, GameProfile gameProfile, CallbackInfoReturnable<Component> cir) {
|
||||
PlayerPreLoginEvent event = new PlayerPreLoginEvent(address, BridgedGameProfile.of(gameProfile));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
if (event.getMessage() != null) {
|
||||
cir.setReturnValue(ChatUtils.adventureToMojang(event.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Player.class)
|
||||
public class PlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerDeathEvent(BridgedPlayer.of(((Player) (Object) this)), damageSource));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.hypherionmc.craterlib.mixin.events;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.common.CraterPlayerDeathEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class ServerPlayerMixin {
|
||||
|
||||
@Inject(method = "die", at = @At("HEAD"))
|
||||
private void injectPlayerDeathEvent(DamageSource damageSource, CallbackInfo ci) {
|
||||
CraterEventBus.INSTANCE.postEvent(new CraterPlayerDeathEvent(BridgedPlayer.of(((ServerPlayer) (Object) this)), damageSource));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package com.hypherionmc.craterlib.mixin.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.client.CraterSinglePlayerEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ClientLevel.class)
|
||||
public class ClientLevelMixin {
|
||||
|
||||
@Inject(method = "addEntity", at = @At("HEAD"))
|
||||
private void injectSinglePlayerJoinEvent(Entity entity, CallbackInfo ci) {
|
||||
if (entity instanceof Player player) {
|
||||
CraterSinglePlayerEvent.PlayerLogin playerLogin = new CraterSinglePlayerEvent.PlayerLogin(BridgedPlayer.of(player));
|
||||
CraterEventBus.INSTANCE.postEvent(playerLogin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.hypherionmc.craterlib.mixin.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.client.ScreenEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.client.gui.BridgedScreen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public Screen screen;
|
||||
|
||||
@Inject(method = "setScreen", at = @At(value = "TAIL"))
|
||||
private void injectScreenOpeningEvent(Screen screen, CallbackInfo ci) {
|
||||
Screen old = this.screen;
|
||||
if (screen != null) {
|
||||
ScreenEvent.Opening opening = new ScreenEvent.Opening(BridgedScreen.of(old), BridgedScreen.of(screen));
|
||||
CraterEventBus.INSTANCE.postEvent(opening);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package com.hypherionmc.craterlib.mixin.events.client;
|
||||
|
||||
import com.hypherionmc.craterlib.api.events.client.PlayerJoinRealmEvent;
|
||||
import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
import com.hypherionmc.craterlib.nojang.realmsclient.dto.BridgedRealmsServer;
|
||||
import com.mojang.realmsclient.RealmsMainScreen;
|
||||
import com.mojang.realmsclient.dto.RealmsServer;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(RealmsMainScreen.class)
|
||||
public class RealmsMainScreenMixin {
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "play(Lcom/mojang/realmsclient/dto/RealmsServer;Lnet/minecraft/client/gui/screens/Screen;Z)V")
|
||||
private static void play(RealmsServer serverData, Screen arg2, boolean bl, CallbackInfo ci) {
|
||||
PlayerJoinRealmEvent playerJoinRealm = new PlayerJoinRealmEvent(BridgedRealmsServer.of(serverData));
|
||||
CraterEventBus.INSTANCE.postEvent(playerJoinRealm);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user