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:
replaceitemandgnembon authored and GitHub committed 2022-02-16 00:07:53 +01:00
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);
}
}
}