An Internal Error?

Discussion in 'Spigot Plugin Development' started by BeachiePvP, May 28, 2016.

  1. So I made this plugin with arguments, when you do the command with 0 arguments theres an error.

    Error:

    Code (Text):
    [20:17:04] [Server thread/INFO]: BeachiePvP issued server command: /global
    [20:17:04] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'global' in plugin ProsperitySuite v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[asa.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[asa.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [asa.jar:git-Spigot-550ebac-7019900]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_91]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_91]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [asa.jar:git-Spigot-550ebac-7019900]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at me.suite.p.Main.onCommand(Main.java:72) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[asa.jar:git-Spigot-550ebac-7019900]
        ... 14 more
    [20:18:49] [Server thread/INFO]: BeachiePvP issued server command: /global
    [20:18:49] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'global' in plugin ProsperitySuite v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[asa.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[asa.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [asa.jar:git-Spigot-550ebac-7019900]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_91]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_91]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [asa.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [asa.jar:git-Spigot-550ebac-7019900]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at me.suite.p.Main.onCommand(Main.java:72) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[asa.jar:git-Spigot-550ebac-7019900]
        ... 14 more
     
    Main Class(class for everything in the whole thing):

    Code (Text):
    package me.suite.p;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.md_5.bungee.api.ChatColor;

    public class Main extends JavaPlugin implements Listener {

        public boolean frozen = false;
        public boolean mute = false;
        public boolean global = true;
        public boolean as = true;

        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            AntiSwearC AntiSwearC = new AntiSwearC(this);
            ClearChats CC = new ClearChats();
            getCommand("gcc").setExecutor(CC);
            getCommand("pcc").setExecutor(CC);
            getCommand("global").setExecutor(this);
            getCommand("antiswear").setExecutor(AntiSwearC);
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            int length = args.length;
            if (label.equalsIgnoreCase("global")) {
                if (sender.isOp()) {
                    if (length == 0) { //around here
                        sender.sendMessage(ChatColor.AQUA + "Global not enough args. Do /global help!");
                    }
                }

            }
            if (args.length == 1) {
                if (args[0].equalsIgnoreCase("help"))
                    if (sender instanceof Player) {
                        if (sender.isOp()) {
                            sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
                                    "&8[&4&lProsperity&6&lUHC&8] &bGlobal help!"));
                            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b/global toggle"));
                            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b/global freeze"));
                            sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b/global mute"));
                        }
                    }
            }
            if (args.length == 1) {
                if (args[0].equalsIgnoreCase("toggle")) {
                    if (sender.isOp()) {
                        if (global == false) {
                            global = true;
                            Bukkit.broadcastMessage(ChatColor.RED + "Global is now " + Boolean.toString(global));
                        } else {
                            global = false;
                            Bukkit.broadcastMessage(ChatColor.RED + "Global is now " + Boolean.toString(global));
                        }
                    }
                }
            }
            if (args[0].equalsIgnoreCase("freeze")) {
                if (global == true) {
                    if (sender instanceof Player) {
                        if (sender.isOp()) {
                            if (frozen == false) {
                                frozen = true;
                                Bukkit.broadcastMessage("All players are frozen!!");
                            } else {
                                frozen = false;
                                Bukkit.broadcastMessage("All players are unfrozen!");
                            }
                        } else {
                            sender.sendMessage("Console bruh only for players! :)");
                        }
                    }
                } else {
                    sender.sendMessage(ChatColor.DARK_RED + "Global is false!");
                }
            }
            if (args[0].equalsIgnoreCase("mute")) {
                if (global == true) {
                    if (sender instanceof Player) {
                        if (sender.isOp()) {
                            if (mute == false) {
                                mute = true;
                                Bukkit.broadcastMessage("All players are muted!");
                            } else {
                                mute = false;
                                Bukkit.broadcastMessage("All players are unmuted!");
                            }

                        }
                    }
                } else {
                    sender.sendMessage(ChatColor.DARK_RED + "Global is false!");
                }
            } else if (args[0].equalsIgnoreCase("all")) {
                if (global == true) {
                    if (frozen == false) {
                        frozen = true;
                    }
                    if (mute == false) {
                        mute = true;
                    }
                } else {
                    sender.sendMessage(ChatColor.DARK_RED + "Global is false!");
                }
            } else if (args[0].equalsIgnoreCase("antiswear")) {
                if (sender.isOp()) {
                    if (as == false) {
                        as = true;
                        Bukkit.broadcastMessage("AntiSwear is " + Boolean.toString(as) + "!");
                    } else {
                        as = false;
                        Bukkit.broadcastMessage("AntiSwear is " + Boolean.toString(as) + "!");
                    }
                }
            }

            return false;

        }

        @EventHandler
        public void moveEvent(PlayerMoveEvent e) {
            if (frozen == true) {
                Player player = e.getPlayer();
                player.teleport(player);
                player.sendMessage("You are frozen!");

            }
        }

        @EventHandler
        public void chatE(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            if (mute == true) {
                if (p.isOp()) {
                    return;
                } else {
                    p.sendMessage("You are muted!");
                    e.setCancelled(true);
                }

            }

        }

        @EventHandler
        public void onChat(AsyncPlayerChatEvent ev) {
            if (as == true) {
                ArrayList<String> words = new ArrayList<String>();
                words.add("cunt");
                words.add("dick");
                words.add("fuck");
                words.add("nigger");
                words.add("prick");
                words.add("faggot");
                words.add("queer");
                words.add("ass");
                words.add("shit");
                words.add("nigga");
                words.add("fag");
                String msg = ev.getMessage();
                Player p = (Player) ev.getPlayer();

                if (p.isOp()) {
                    return;
                }

                for (String x : words) {
                    if (msg.contains(x)) {
                        ev.setCancelled(true);
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&',
                                "&8[&c&lAnti&8-&c&lSwear&8] &r&4&lDon&8'&4&lt Swear&4&l&n!"));
                    }
                }
            }

        }
    }
     

    If anyone could possibly help me that would be nice thanks!
     
    • Funny Funny x 1
  2. Oh dear god my eyes..... Side note just return if the arguments length is not equal to 1
     
    • Agree Agree x 1
  3. @camden theres still that error in game and in console.
     
  4. Camdens answer should sort your issue out, but incase you were a bit confused on what he means:


    Code (Text):
    int length = args.length;
            if (label.equalsIgnoreCase("global")) {
            if (sender.isOp()) {
                if (length == 0) { // around here
                    sender.sendMessage(ChatColor.AQUA + "Global not enough args. Do /global help!");
                    return true; //This is the return statement
                }
                }

            }
     
    • Like Like x 1