Solved AsyncPlayerChatEvent (Help)

Discussion in 'Plugin Development' started by Zettos, Sep 11, 2020.

  1. Offline

    Zettos

    My Problem is that when i tip "#ban" in the chat. There arrives a big error message.
    I want that when i tip this, that i get a Message in the chat, like "Usage: #ban <PlayerName>" .

    Code::

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
       
        public void onBanCMD(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            String[] args = e.getMessage().split(" ");
            Player t = Bukkit.getPlayer(args[1]);
           
                if(args[0].equalsIgnoreCase("#ban")) {
                    e.setCancelled(true);     
                   
                   
                   
                    if(t != null) {
                        p.sendMessage(pr+"§9"+args[1]+" §awurde gebannt!");
                        t.kickPlayer("§c§lDu wurdest gebannt!");
                        t.setBanned(true);
                    }else {
                        p.sendMessage(pr+"§9"+args[1]+" §cist nicht Online!");
                    }
                   
               
                }
           
            }
    Error Message::
    Code:
    [17:50:44 ERROR]: Could not pass event AsyncPlayerChatEvent to Ploit v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:483) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.java:1031) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:980) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:115) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.NetworkManager.channelRead0(NetworkManager.java:312) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.NetworkManager.channelRead0(NetworkManager.java:1) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:150) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [craftbukkit.jar:git-Bukkit-18fbb24]
            at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) [craftbukkit.jar:git-Bukkit-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at de.ploit.events.CMDS.onBanCMD(CMDS.java:105) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_251]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            ... 36 more
    [17:50:44 INFO]: <Zettos> #ban
    Thanks for Reading this. I Hope you can help me out
     
  2. Offline

    timtower Moderator Moderator

    @Zettos You are using the args without checking if they exist.
     
  3. Offline

    Kars

    Why would you not use commands for this?
    But if you must do it this way, you can surround the whole thing in a try-catch block.
     
  4. Offline

    Zettos

    ok thanks i got it
     

Share This Page