Added __on_player_message event (#1312)
* Added __on_player_sends_message event * Docs for chat message event * Rename to __on_player_message * Editor support * Added event to event_test app * Update docs/scarpet/api/Events.md Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com>
This commit is contained in:
1 parent
4da992dd22
commit
bf00051482
6 files changed
+34
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import net.minecraft.server.network.TextFilter;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -24,6 +25,7 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SPRINTING;
|
||||
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_USES_ITEM;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
|
||||
|
||||
@@ -42,6 +44,7 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
@@ -278,4 +281,15 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
||||
PLAYER_SWINGS_HAND.onHandAction(player, packet.getHand());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleChat(Lnet/minecraft/server/network/TextFilter$FilteredText;)V",
|
||||
at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z"),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void onChatMessage(TextFilter.FilteredText filteredText, CallbackInfo ci, String string) {
|
||||
if (PLAYER_MESSAGE.isNeeded())
|
||||
{
|
||||
PLAYER_MESSAGE.onPlayerMessage(player,string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -856,6 +856,14 @@ public class CarpetEventServer
|
||||
handler.call( () -> Arrays.asList(new EntityValue(player), new StringValue(message)), player::createCommandSourceStack);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Event PLAYER_MESSAGE = new Event("player_message", 2, false) {
|
||||
@Override
|
||||
public void onPlayerMessage(ServerPlayer player, String message) {
|
||||
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