Add event for commands and make __on_player_message not trigger for them (#1525)

* Restoring old behaviour of __on_player_message

Fixes #1511

* Changed to PLAYER_COMMAND

* Updated docs

* Updated event_test.sc

* Updated editor keywords

* Fixed issue
This commit is contained in:
Ghoulboy authored and GitHub committed 2022-12-26 15:30:50 +01:00
1 parent b63dfa1b0a
commit 43bb84437f
6 files changed
+32 -2

No files matched your search

@@ -1,6 +1,6 @@
package carpet.mixins;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -27,6 +27,7 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_SWAPS_HANDS;
import static carpet.script.CarpetEventServer.Event.PLAYER_SWINGS_HAND;
import static carpet.script.CarpetEventServer.Event.PLAYER_SWITCHES_SLOT;
import static carpet.script.CarpetEventServer.Event.PLAYER_MESSAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_COMMAND;
import static carpet.script.CarpetEventServer.Event.PLAYER_USES_ITEM;
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
@@ -302,4 +303,14 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
if(PLAYER_MESSAGE.onPlayerMessage(player, serverboundChatPacket.message())) ci.cancel();
}
}
@Inject(method = "handleChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;)V",
at = @At(value = "HEAD")
)
private void onChatCommandMessage(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) {
if (PLAYER_COMMAND.isNeeded())
{
PLAYER_COMMAND.onPlayerMessage(player, serverboundChatCommandPacket.command());
}
}
}