Args in a command!

Discussion in 'BungeeCord Plugin Help' started by UtilsByteMedia, Jan 27, 2020.

  1. Hello, I am trying to make a bungeecord plugin with the command /L, so if you did /L it would send you to the Lobby server, and if you did /L skyblock it would send you to the skyblock server, I got the /L to work but I can get the args to work any help please! Error I get in console will be down the under the code.

    Code (Java):
    package best.ashton.bungee.Commands;

    import net.md_5.bungee.api.ChatColor;
    import net.md_5.bungee.api.CommandSender;
    import net.md_5.bungee.api.ProxyServer;
    import net.md_5.bungee.api.chat.TextComponent;
    import net.md_5.bungee.api.connection.ProxiedPlayer;
    import net.md_5.bungee.api.plugin.Command;

    import java.lang.reflect.Proxy;

    public class ServerCommand extends Command {
        public ServerCommand() {
            super("l", "dev.lobby");
        }

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (args.length == 0) {
                ProxiedPlayer p = (ProxiedPlayer) sender;
                p.connect(ProxyServer.getInstance().getServerInfo("Lobby"));
                return;
            } else if (args.length == 1) {
                if (args[1].equalsIgnoreCase("Skyblock")) {
                    ProxiedPlayer p = (ProxiedPlayer) sender;
                    p.connect(ProxyServer.getInstance().getServerInfo("Skyblock"));
                }
            }
        }
    }
    Code (Java):
    19:56:31 [WARNING] Error in dispatching command
    java.lang.ArrayIndexOutOfBoundsException: 1
        at best.ashton.Commands.ServerCommand.execute(ServerCommand.java:31)
        at net.md_5.bungee.api.plugin.PluginManager.dispatchCommand(PluginManager.java:192)
        at net.md_5.bungee.api.plugin.PluginManager.dispatchCommand(PluginManager.java:142)
        at net.md_5.bungee.connection.UpstreamBridge.handle(UpstreamBridge.java:148)
        at net.md_5.bungee.protocol.packet.Chat.handle(Chat.java:50)
        at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:104)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:321)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:295)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:355)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:377)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at java.lang.Thread.run(Unknown Source)
     
  2. Code (Text):
    } else if (args.length == 1) {
                if (args[1].equalsIgnoreCase("Skyblock")) {
    Array index starts from 0, so you should be checking args[0] if the length of the array is 1.
     
  3. So what do I do??
     
    • Optimistic Optimistic x 2
  4. SteelPhoenix

    Moderator

    He literally told you.
     
  5. He didn't tell me where to put it, and where arrays 0 is.
     
    • Optimistic Optimistic x 1
  6. He mean you have to do this:
    Code (Text):
    } else if(args.length == 1) {
        if(args[0].equalsIgnoreCase("Skyblock")) {
    An argument always start with 0 not with 1.
     
    • Like Like x 1
  7. SteelPhoenix

    Moderator