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
@@ -316,7 +316,10 @@ Triggered when the player has successfully logged in and was placed in the game.
|
||||
Triggered when a player sends a disconnect package or is forcefully disconnected from the server.
|
||||
|
||||
### `__on_player_message(player, message)`
|
||||
Triggered when a player sends a chat message or runs a command.
|
||||
Triggered when a player sends a chat message.
|
||||
|
||||
### `__on_player_command(player, command)`
|
||||
Triggered when a player runs a command. Command value is returned without the / in front.
|
||||
|
||||
This event can be cancelled by returning `'cancel'`, which prevents the message from being sent.
|
||||
|
||||
|
||||
@@ -46,5 +46,6 @@ __on_player_respawns(player) ->
|
||||
__on_player_disconnects(player, reason) ->
|
||||
__on_player_connects(player) ->
|
||||
__on_player_message(player, message) ->
|
||||
__on_player_command(player, command) ->
|
||||
__on_explosion(pos, power, source, causer, mode, fire) ->
|
||||
__on_explosion_outcome(pos, power, source, causer, mode, fire, blocks, entities) ->
|
||||
@@ -149,6 +149,7 @@
|
||||
__on_player_disconnects(player, reason) ->
|
||||
__on_player_connects(player) ->
|
||||
__on_player_message(player, message) ->
|
||||
__on_player_command(player, command) ->
|
||||
__on_explosion(pos, power, source, causer, mode, fire) ->
|
||||
__on_explosion_outcome(pos, power, source, causer, mode, fire, blocks, entities) ->
|
||||
</Keywords>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -272,6 +272,13 @@ __on_player_message(player, message) ->
|
||||
print('Player '+player+' sent message: '+message)
|
||||
);
|
||||
|
||||
__on_player_command(player, command) ->
|
||||
(
|
||||
print('');
|
||||
print('__on_player_command(player, command)');
|
||||
print('Player '+player+' sent command: '+command)
|
||||
);
|
||||
|
||||
__on_player_chooses_recipe(player, recipe, full_stack) ->
|
||||
(
|
||||
print('');
|
||||
|
||||
Reference in new issue
Block a user