diff --git a/src/main/java/xyz/nucleoid/stimuli/EventSource.java b/src/main/java/xyz/nucleoid/stimuli/EventSource.java index 6523eeb..0ba1c0f 100644 --- a/src/main/java/xyz/nucleoid/stimuli/EventSource.java +++ b/src/main/java/xyz/nucleoid/stimuli/EventSource.java @@ -2,6 +2,7 @@ import net.minecraft.entity.Entity; import net.minecraft.registry.RegistryKey; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -65,6 +66,10 @@ public static EventSource forEntityAt(Entity entity, BlockPos pos) { return acquire(entity.getWorld().getRegistryKey(), pos, entity); } + public static EventSource forCommandSource(ServerCommandSource source) { + return acquire(source.getWorld().getRegistryKey(), BlockPos.ofFloored(source.getPosition()), source.getEntity()); + } + static EventSource acquire(RegistryKey dimension, BlockPos pos, @Nullable Entity entity) { var source = POOL.acquire(); source.set(dimension, pos, entity); diff --git a/src/main/java/xyz/nucleoid/stimuli/StimuliInitializer.java b/src/main/java/xyz/nucleoid/stimuli/StimuliInitializer.java index 0cedd84..2d3056d 100644 --- a/src/main/java/xyz/nucleoid/stimuli/StimuliInitializer.java +++ b/src/main/java/xyz/nucleoid/stimuli/StimuliInitializer.java @@ -78,5 +78,16 @@ public void onInitialize() { return result != ActionResult.FAIL; } }); + + ServerMessageEvents.ALLOW_COMMAND_MESSAGE.register((message, source, params) -> { + var player = source.getPlayer(); + if (player == null) { + return true; + } + try (var invokers = Stimuli.select().forCommandSource(source)) { + var result = invokers.get(PlayerChatEvent.EVENT).onSendChatMessage(player, message, params); + return result != ActionResult.FAIL; + } + }); } } diff --git a/src/main/java/xyz/nucleoid/stimuli/StimuliSelector.java b/src/main/java/xyz/nucleoid/stimuli/StimuliSelector.java index b919f15..9f9e4e9 100644 --- a/src/main/java/xyz/nucleoid/stimuli/StimuliSelector.java +++ b/src/main/java/xyz/nucleoid/stimuli/StimuliSelector.java @@ -3,6 +3,7 @@ import com.google.common.collect.AbstractIterator; import net.minecraft.entity.Entity; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -31,6 +32,10 @@ public EventInvokers forEntityAt(Entity entity, BlockPos pos) { return this.acquireInvokers(entity.getServer(), EventSource.forEntityAt(entity, pos)); } + public EventInvokers forCommandSource(ServerCommandSource source) { + return this.acquireInvokers(source.getServer(), EventSource.forCommandSource(source)); + } + EventInvokers acquireInvokers(@Nullable MinecraftServer server, EventSource source) { if (server == null) { return NoOPSelectorEventInvokers.INSTANCE;