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:
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -921,6 +921,13 @@ public class CarpetEventServer
|
||||
}
|
||||
};
|
||||
|
||||
public static final Event PLAYER_COMMAND = new Event("player_command", 2, false) {
|
||||
@Override
|
||||
public boolean onPlayerMessage(ServerPlayer player, String message) {
|
||||
return handler.call( () -> Arrays.asList(new EntityValue(player), new StringValue(message)), player::createCommandSourceStack);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Event STATISTICS = new Event("statistic", 4, false)
|
||||
{
|
||||
private <T> ResourceLocation getStatId(Stat<T> stat)
|
||||
|
||||
Reference in new issue
Block a user