Search in sources :

Example 1 with EventSendPacket

use of dev.hypnotic.event.events.EventSendPacket in project Hypnotic-Client by Hypnotic-Development.

the class ClientConnectionMixin method send.

@Inject(method = "send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true)
public void send(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> callback, CallbackInfo ci) {
    // Call commands if the prefix is sent
    if (packet instanceof ChatMessageC2SPacket && ((ChatMessageC2SPacket) packet).getChatMessage().startsWith(CommandManager.INSTANCE.getPrefix())) {
        try {
            CommandManager.INSTANCE.dispatch(((ChatMessageC2SPacket) packet).getChatMessage().substring(CommandManager.INSTANCE.getPrefix().length()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
            ChatUtils.tellPlayer(e.getMessage());
        }
        ci.cancel();
    }
    EventSendPacket event = new EventSendPacket(packet);
    event.call();
    if (event.isCancelled())
        ci.cancel();
}
Also used : ChatMessageC2SPacket(net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket) EventSendPacket(dev.hypnotic.event.events.EventSendPacket) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 EventSendPacket (dev.hypnotic.event.events.EventSendPacket)1 ChatMessageC2SPacket (net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1