Abnormal plugin type?

Discussion in 'General Help' started by bowlerguy66, Jun 8, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    bowlerguy66

    I just installed the 1.8 Java SE and put it in eclipse. It gave me this error:

    08.06 23:00:41 [Server] INFO ... 15 more 08.06
    23:00:41 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_72] 08.06 23:00:41 [Server] INFO Caused by: java.lang.InstantiationException: me.bowlerguy66.bprison.BPrison 08.06 23:00:41 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.Bukkit.reload(Bukkit.java:301) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:864) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:369) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:258) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:336) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:80) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 08.06 23:00:41 [Server] INFO org.bukkit.plugin.InvalidPluginException: Abnormal plugin type 08.06 23:00:41 [Server] ERROR Could not load 'plugins/BeefPrison.jar' in folder 'plugins'


    I use MC ProHosting. Can somebody tell me why this happens so I can fix it in the future?

    Code:
    package me.bowlerguy66.bprison;
    
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class BPrison extends JavaPlugin{
    
        public int number = 300;
        public int clock = 240;
        public final BukkitListener bl = new BukkitListener();
        public String error = new String(ChatColor.RED + "Incorrect usage! Do " + ChatColor.ITALIC + "" + ChatColor.RED + "/gco help");
        public static HashMap<String, Double> amount = new HashMap<>();
       
        @Override
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(bl, this);
            pm.addPermission(new Permissions().clearlag);
            this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "timer");
            new BPrison(this);
            loadBalances();
            Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
        }
       
        @Override
        public void onDisable() {
            getServer().getPluginManager().removePermission(new Permissions().clearlag);
            saveBalances();
        }
       
        private static BPrison plugin;
       
        public BPrison(BPrison instance) {
           
            plugin = instance;
           
        }
       
        public static BPrison getPlugin(){
           
            return plugin;
           
        }
       
        public static void setBalance(String player, Double amountD) {
           
            amount.put(player, amountD);
           
        }
       
        public static Double getBalance(String player) {
           
            return amount.get(player);
           
        }
       
        public static Double getSenderBalance(CommandSender sender) {
           
            return amount.get(sender);
           
        }
       
        public static boolean hasAccount(String player) {
           
            return amount.containsKey(player);
           
        }
       
        public static HashMap<String, Double> getBalanceMap() {
           
            return amount;
           
        }
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player player = (Player) sender;
           
            if(label.equalsIgnoreCase("clearlag") && sender instanceof Player) {
       
                if(player.hasPermission(new Permissions().clearlag) || player.isOp()) {
               
                    this.getServer().broadcastMessage(ChatColor.GRAY + "Clearing all ground items!");
               
                    this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "killall drops prison");
                   
                } else if(!player.hasPermission(new Permissions().clearlag)) {
                   
                    player.sendMessage(ChatColor.RED + "You do not have permission to use this command");
                   
                }
               
            if(label.equalsIgnoreCase("timer")) {
               
            number = 300;
            clock = 240;
               
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {       
                public void run() {
                    if(number !=-1) {
                        if(number != 0) {
                            number--;
                        } else {
                            Bukkit.broadcastMessage("Clearing all ground items!");
                            number--;
                        }
                    }
                }
               
            }, 0L, 20L);
           
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
               
                public void run() {
                    if(clock !=-1) {
                        if(clock != 0) {
                            clock--;
                        } else {
                            Bukkit.broadcastMessage(ChatColor.GRAY + "Ground items will be cleared in " + ChatColor.BOLD + "60" + ChatColor.GRAY + "seconds");
                            clock--;
                        }
                    }
                }
               
            }, 0L, 20L);
               
            }
               
                return true;
               
            }
           
            if(label.equalsIgnoreCase("gco")) {
               
                sender.sendMessage(ChatColor.GRAY + "Gem economy plugin by bowlerguy66");
               
                if(args.length != 3) {
                   
                    sender.sendMessage(error);
                   
                }
               
                if(!args[0].equalsIgnoreCase("give")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("take")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("set")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("balance")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("help")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
                if(args[0].equalsIgnoreCase("give")) {
                   
                    if(!hasAccount(args[1])) {
                       
                        sender.sendMessage(ChatColor.RED + "The player '" + args[2] + "' does not have an account!");
                        return true;
                       
                    }
                   
                    double amount = 0;
                   
                    try{
                        amount = Double.parseDouble(args[2]);
                    } catch(Exception e){
                        sender.sendMessage(error);
                        return true;
                    }
                   
                    setBalance(args[1], getBalance(args[1]) + amount);
                    sender.sendMessage(ChatColor.GREEN + "You added " + args[2] + " gem(s) to " + args[1] + "'s account. They now have " + getBalance(args[1]) + " gem(s).");
                   
                } else if(args[0].equalsIgnoreCase("take")) {
                   
                    if(!hasAccount(args[1])) {
                       
                        sender.sendMessage(ChatColor.RED + "The player '" + args[2] + "' does not have an account!");
                        return true;
                       
                    }
                   
                    double amount = 0;
                   
                    try{
                        amount = Double.parseDouble(args[2]);
                    } catch(Exception e){
                        sender.sendMessage(error);
                        return true;
                    }
                   
                    setBalance(args[1], getBalance(args[1]) - amount);
                    sender.sendMessage(ChatColor.GREEN + "You removed " + args[2] + " gem(s) from " + args[1] + "'s account. They now have " + getBalance(args[1]) + " gem(s).");
                   
                } else if(args[0].equalsIgnoreCase("set")) {
                   
                    if(!hasAccount(args[1])) {
                       
                        sender.sendMessage(ChatColor.RED + "The player '" + args[2] + "' does not have an account!");
                        return true;
                       
                    }
                   
                    double amount = 0;
                   
                    try{
                        amount = Double.parseDouble(args[2]);
                    } catch(Exception e){
                        sender.sendMessage(error);
                        return true;
                    }
                   
                    setBalance(args[1], amount);
                    sender.sendMessage(ChatColor.GREEN + "You set " + args[1] + "'s account to " + getBalance(args[1]) + " gem(s).");
                   
                } else if(args[0].equalsIgnoreCase("balance") && sender instanceof Player) {
                   
                    sender.sendMessage(ChatColor.GREEN + "You have " + getSenderBalance(sender) + " gem(s).");
                   
                } else if(args[0].equalsIgnoreCase("help")) {
                   
                    sender.sendMessage("Shhhhhhh this thing hasn't been added yet");
                   
                }
               
                return true;
               
            }
           
            return false;
           
        }
       
        public static void saveBalances() {
           
            for(String p: getBalanceMap().keySet()) {
                plugin.getConfig().set("balance." + p, BPrison.getBalanceMap().get(p));
            }
           
            plugin.saveConfig();
           
        }
       
        public static void loadBalances() {
           
            if(plugin.getConfig().contains("balance")) return;
           
            for(String s : plugin.getConfig().getConfigurationSection("balance").getKeys(false)) {
                setBalance(s, plugin.getConfig().getDouble("balance" + s));
            }
           
        }
       
    }
     
    Last edited: Jun 10, 2015
  2. Offline

    Boomer

    what is "it"
    There is no way that "java 1.8 SE in Eclipse" would be the 'it" giving that message... And not likely that you would have installed eclipse on mcprohosting...

    Explain your problem clearer please
     
  3. Offline

    bowlerguy66

    Ok "it" is the plugin I was working on using java 1.6 then I upgraded my plugin to java 1.8. The plugin was working fine in 1.6 but now the plugin gives me this error in the mcprohosting console.
     
  4. Offline

    Boomer

    Is the recompiling under 1.8 the ONLY change you made?
    Or did you do some rewriting as well?

    An InstantiationException error typically occurs by trying to ..instantiate something.. at a point where it cant be done. Like using a constructor argument for the main class, or trying to instanciate a new Something() class object in the main class definition stage, rather than in the onEnable()
     
  5. Offline

    bowlerguy66

    I added the /gco command and the hash map stuff. The clearlag command doesn't matter to my question
     
  6. Offline

    Boomer

    can you post your main class code
    Oh, you edited the question to include it..

    public BPrison(BPrison instance) {

    plugin = instance;

    }

    Get rid of that. Thats the typical constructor use that causes such error
    set the plugin value in the onEnable() instead

    ALso
    public final BukkitListener bl = new BukkitListener();
    Doesn't seem to be used here, and you create a new listener when registering anyways; You would just define it at this point, but initiate it in the onEnable() if you do want bl to be exposed.
    Createing a listener object here should also throw the error.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  7. Offline

    bowlerguy66

    Thanks! But, there is more errors. The plugin exists on the server now and I can run the commands a little. By little I mean I get this error every time I run a command that uses /gco.
    Here's the error and thanks so much for helping me with this

    Error (open)
    09.06 13:44:52 [Server] INFO ... 13 more 09.06 13:44:52 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at me.bowlerguy66.bprison.BPrison.onCommand(BPrison.java:144) ~[?:?] 09.06 13:44:52 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:880) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1043) [Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Spigot.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95] 09.06 13:44:52 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'gco' in plugin BeefPrison v1.0 09.06 13:44:52 [Server] ERROR null


    Here is the updated code:

    Code:
    [/I]
    package me.bowlerguy66.bprison;
    
    
    
    import java.util.HashMap;
    
    
    
    import org.bukkit.Bukkit;
    
    import org.bukkit.ChatColor;
    
    import org.bukkit.command.Command;
    
    import org.bukkit.command.CommandSender;
    
    import org.bukkit.entity.Player;
    
    import org.bukkit.plugin.PluginManager;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    
    public class BPrison extends JavaPlugin{
    
    
    
        public int number = 300;
    
        public int clock = 240;
    
        public final BukkitListener bl = new BukkitListener();
    
        public String error = new String(ChatColor.RED + "Incorrect usage! Do " + ChatColor.ITALIC + "" + ChatColor.RED + "/gco help");
    
        public static HashMap<String, Double> amount = new HashMap<>();
    
       
    
        @Override
    
        public void onEnable() {
    
            PluginManager pm = this.getServer().getPluginManager();
    
            pm.registerEvents(bl, this);
    
            pm.addPermission(new Permissions().clearlag);
    
            this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "timer");
    
            loadBalances();
    
            Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
    
            plugin = this;
    
        }
    
       
    
        @Override
    
        public void onDisable() {
    
            getServer().getPluginManager().removePermission(new Permissions().clearlag);
    
            saveBalances();
    
        }
    
       
    
        privatestatic BPrison plugin;
    
       
    
        public static BPrison getPlugin(){
    
           
    
            returnplugin;
    
           
    
        }
    
       
    
        public static void setBalance(String player, Double amountD) {
    
           
    
            amount.put(player, amountD);
    
           
    
        }
    
       
    
        public static Double getBalance(String player) {
    
           
    
            return amount.get(player);
    
           
    
        }
    
       
    
        public static Double getSenderBalance(CommandSender sender) {
    
           
    
            return amount.get(sender);
    
           
    
        }
    
       
    
        public static boolean hasAccount(String player) {
    
           
    
            return amount.containsKey(player);
    
           
    
        }
    
       
    
        public static HashMap<String, Double> getBalanceMap() {
    
           
    
            returnamount;
    
           
    
        }
    
       
    
        @SuppressWarnings("deprecation")
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
           
    
            Player player = (Player) sender;
    
           
    
            if(label.equalsIgnoreCase("clearlag") && sender instanceof Player) {
    
       
    
                if(player.hasPermission(new Permissions().clearlag) || player.isOp()) {
    
               
    
                    this.getServer().broadcastMessage(ChatColor.GRAY + "Clearing all ground items!");
    
               
    
                    this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "killall drops prison");
    
                   
    
                } else if(!player.hasPermission(new Permissions().clearlag)) {
    
                   
    
                    player.sendMessage(ChatColor.RED + "You do not have permission to use this command");
    
                   
    
                }
    
               
    
            if(label.equalsIgnoreCase("timer")) {
    
               
    
            number = 300;
    
            clock = 240;
    
               
    
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {       
    
                public void run() {
    
                    if(number !=-1) {
    
                        if(number != 0) {
    
                            number--;
    
                        } else {
    
                            Bukkit.broadcastMessage("Clearing all ground items!");
    
                            number--;
    
                        }
    
                    }
    
                }
    
               
    
            }, 0L, 20L);
    
           
    
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
    
               
    
                public void run() {
    
                    if(clock !=-1) {
    
                        if(clock != 0) {
    
                            clock--;
    
                        } else {
    
                            Bukkit.broadcastMessage(ChatColor.GRAY + "Ground items will be cleared in " + ChatColor.BOLD + "60" + ChatColor.GRAY + "seconds");
    
                            clock--;
    
                        }
    
                    }
    
                }
    
               
    
            }, 0L, 20L);
    
               
    
            }
    
               
    
                returntrue;
    
               
    
            }
    
           
    
            if(label.equalsIgnoreCase("gco")) {
    
               
    
                if(args.length != 3) {
    
                   
    
                    sender.sendMessage(error);
    
                   
    
                }
    
                if(!args[0].equalsIgnoreCase("give")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("take")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("set")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("balance")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(!args[0].equalsIgnoreCase("help")) {
    
                    sender.sendMessage(error);
    
                    returntrue;
    
                }
    
                if(args[0].equalsIgnoreCase("give")) {
    
                   
    
                    if(!hasAccount(args[1])) {
    
                       
    
                        sender.sendMessage(ChatColor.RED + "The player '" + args[1] + "' does not have an account!");
    
                        returntrue;
    
                       
    
                    }
    
                   
    
                    double amount = 0;
    
                   
    
                    try{
    
                        amount = Double.parseDouble(args[2]);
    
                    } catch(Exception e){
    
                        sender.sendMessage(error);
    
                        returntrue;
    
                    }
    
                   
    
                    setBalance(args[1], getBalance(args[1]) + amount);
    
                    sender.sendMessage(ChatColor.GREEN + "You added " + args[2] + " gem(s) to " + args[1] + "'s account. They now have " + getBalance(args[1]) + " gem(s).");
    
                   
    
                } else if(args[0].equalsIgnoreCase("take")) {
    
                   
    
                    if(!hasAccount(args[1])) {
    
                       
    
                        sender.sendMessage(ChatColor.RED + "The player '" + args[1] + "' does not have an account!");
    
                        returntrue;
    
                       
    
                    }
    
                   
    
                    double amount = 0;
    
                   
    
                    try{
    
                        amount = Double.parseDouble(args[2]);
    
                    } catch(Exception e){
    
                        sender.sendMessage(error);
    
                        returntrue;
    
                    }
    
                   
    
                    setBalance(args[1], getBalance(args[1]) - amount);
    
                    sender.sendMessage(ChatColor.GREEN + "You removed " + args[2] + " gem(s) from " + args[1] + "'s account. They now have " + getBalance(args[1]) + " gem(s).");
    
                   
    
                } else if(args[0].equalsIgnoreCase("set")) {
    
                   
    
                    if(!hasAccount(args[1])) {
    
                       
    
                        sender.sendMessage(ChatColor.RED + "The player '" + args[1] + "' does not have an account!");
    
                        returntrue;
    
                       
    
                    }
    
                   
    
                    double amount = 0;
    
                   
    
                    try{
    
                        amount = Double.parseDouble(args[2]);
    
                    } catch(Exception e){
    
                        sender.sendMessage(error);
    
                        returntrue;
    
                    }
    
                   
    
                    setBalance(args[1], amount);
    
                    sender.sendMessage(ChatColor.GREEN + "You set " + args[1] + "'s account to " + getBalance(args[1]) + " gem(s).");
    
                   
    
                } else if(args[0].equalsIgnoreCase("balance") && sender instanceof Player) {
    
                   
    
                    sender.sendMessage(ChatColor.GREEN + "You have " + getSenderBalance(sender) + " gem(s).");
    
                   
    
                } else if(args[0].equalsIgnoreCase("help")) {
    
                   
    
                    sender.sendMessage("Shhhhhhh this thing hasn't been added yet");
    
                   
    
                } else {
    
                   
    
                    sender.sendMessage(error);
    
                   
    
                }
    
               
    
                returntrue;
    
               
    
            }
    
           
    
            returnfalse;
    
           
    
        }
    
       
    
        public static void saveBalances() {
    
           
    
            for(String p: getBalanceMap().keySet()) {
    
                plugin.getConfig().set("balance." + p, BPrison.getBalanceMap().get(p));
    
            }
    
           
    
            plugin.saveConfig();
    
           
    
        }
    
       
    
        public static void loadBalances() {
    
           
    
            if(plugin.getConfig().contains("balance")) return;
    
           
    
            for(String s : plugin.getConfig().getConfigurationSection("balance").getKeys(false)) {
    
                setBalance(s, plugin.getConfig().getDouble("balance" + s));
    
            }
    
           
    
        }
    
       
    
    }
    [I]
     
    Last edited: Jun 10, 2015
  8. Offline

    Boomer

    Your line 144 in your code is where an array object is accessing an index that is bigger than the actual last index of the array object. Cant be sure if line 144 in the codebox above is the same line 144 as your program code or not...
    But, clearly it means you are triggering code with an index that doesn't exist. This line 144 is accessing args[1] which would mean, you had to use ONLY the /gco give without any additional parameters... or the numbering is off, and you just did /gco without give, having no arguments, and arg[0] cant be tested against 'give'... or the numbering is off and later it is args[2] not provided anything after a playername, etc...


    You provided a check to 'restrict' the code to exactly 3 arguments only, but lets see what that really is interpreted as in the code:

    if args.length !=3 send an error message...
    ...and then continue processing using those arguments as if it was correct
    ...and lets use arg[1] or arg[2] when you may not have even provided them since it jumped down into here anyways
    is what your code uses now.

    You want to return as soon as that length is not correct, so that only what continues after that IF will be things that do have the right number of arguments.

    dont forget to add
    plugin=this;

    into your onEnable() as well, since now plugin is not initialized anywhere to return in the function..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  9. Offline

    bowlerguy66

    I updated the code for the arguments but I don't really understand what you mean by "triggering and index that doesn't exist" please explain how I would go about fixing this. :D
     
  10. Offline

    Boomer

    triggering code with an index that doesn't exist:

    means that from faulty conditional-check structure, failure to check existance potential, forgetfulness, or assumptions that go unchecked....
    ... the execution point of a program passes into a point in the code where it tries to access Something[2] when there are only two elements - index 0, index 1 - in the Something[] array.

    The system tries to access an object via its index, Something , but, if there are not (i-1) or more elements already existing in that array/list (.length <(i-1) ) then the system is not able to access anything at index i since it doesn't exist - it is OUTSIDE of the UPPER BOUNDS of the array.

    Hence the error message Caused by: java.lang.ArrayIndexOutOfBoundsException:

    Imagine a sidewalk on a street, starting at your house, that has 10 slabs of concrete units before ending at the intersection-crosswalk. Number those slabs from 0 to 9, and you can refer to any particular slab of concrete by an index 0 to 9. But if you try to find slab index 10 - it doesn't exist, it would be where the cars are driving, you are trying to de-index a point beyond the index bounds (9) of the 10 slabs of concrete.

    [​IMG]


    You go about fixing it by, when seeing that error appear, identify what line is throwing it --- Something[2] -- and then look to say "What assumptions am I making, or have I done some tests to make sure there ARE 3 elements in the length of Something already, which may not be done correctly. HOW did my program execution point get to this line to call Something[2] when it doesn't exist. Oh, I see - I did a test in an IF, but then never broke out of the execution - I need to add a return so that nothing more is performed if the length is not 3, and only if the length is three will the point of execution now be able to get to the next line, into this conditional check, into this point here... etc

    Its one of the easiest bugs to debug, since its very clearly telling you where the bug is. You may need to backtrack a fair bit sometimes to figure out WHY it is saying out of bounds at that point, but the reason is 'that number index does not exist'

    Typically its from someone doing a loop from 1 to 10, instead of 0 to 9 for example, or thinking 'three arguments, arg[3] is my last argument', or as you had in your code - an if test that detected it wasn't 3 arguments, but.. only showed an error message to the user, before continuing to process the code anyways.

    I didn't notice earlier in the other code snip you posted, as i went to snap an example of code that can allow a failure past its checkpoint, that you also have a flawed thought process for command argument handling. To observe this, look at an execution-point flow diagram for three possible command lines you could type - one that doesnt have enough arguments and isnt even trying, and one of both 'legitimate' argument constructions:

    [​IMG]
    You catch the "not three arguments, something is wrong here" but dont stop executing.

    Bad flow design for your tests of the arguments though, look at how legitimate constructs will execute:
    For the give command, it fails the "is not give" test, and passes "is not take"
    For the take command, it passes the "is not give" test
    Two valid uses that both will send an error message.

    You should instead fish out positively with if / else if / else constructs

    If (arg0 is give) {
    .. stuff to do for give
    }
    else if (arg0 is take) {
    ... stuff to do for take
    } else if (arg0 is someothercriticalone) {
    ... stuff to do for someothercriticalone
    } else {
    //anything falling to this else is not one of the terms you want to act on
    }

    ---
    OR : Come up with some complex single-line logic that will catch all allowed possibilities, and act on the positive of that, or kick-out on the negative of that

    ie
    Code:
    if (arg0 is take  OR arg0 is give OR arg0 is otherthing){
      //now i know it is a valid parameter term to use, i can do things in common of all three first
     // then break into a series of
      if (arg0 is take){
        //stuff
          return;
      }   
      if (arg0 is give){
       // stuff
         return;
      }
    etc
    
    OR
    
    if ( !(arg0 is take OR arg0 is give OR arg0 is otherthing) ) {
       // its not one of the terms that is acceptable to use , no further processing
       // send error message
      return;
    }
    // now you still need to act on each term differentially, but only 'take, give, and otherthing' pass to here
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  11. Offline

    bowlerguy66

    Ok I started adding the checks but then I hit a wall, I have commands with different amounts of arguments. Here is my code:

    Code:
    package me.bowlerguy66.bprison;
    
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class BPrison extends JavaPlugin{
    
        public int number = 300;
        public int clock = 240;
        public final BukkitListener bl = new BukkitListener();
        public String error = new String(ChatColor.RED + "Incorrect usage! Do " + ChatColor.ITALIC + "" + ChatColor.RED + "/gco help");
        public static HashMap<String, Double> amount = new HashMap<>();
       
        @Override
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(bl, this);
            pm.addPermission(new Permissions().clearlag);
            this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "timer");
            loadBalances();
            Bukkit.getPluginManager().registerEvents(new BukkitListener(), this);
            plugin = this;
        }
       
        @Override
        public void onDisable() {
            getServer().getPluginManager().removePermission(new Permissions().clearlag);
            saveBalances();
        }
       
        private static BPrison plugin;
       
        public static BPrison getPlugin(){
           
            return plugin;
           
        }
       
        public static void setBalance(String player, Double amountD) {
           
            amount.put(player, amountD);
           
        }
       
        public static Double getBalance(String player) {
           
            return amount.get(player);
           
        }
       
        public static Double getSenderBalance(CommandSender sender) {
           
            return amount.get(sender);
           
        }
       
        public static boolean hasAccount(String player) {
           
            return amount.containsKey(player);
           
        }
       
        public static HashMap<String, Double> getBalanceMap() {
           
            return amount;
           
        }
       
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player player = (Player) sender;
           
            if(label.equalsIgnoreCase("clearlag") && sender instanceof Player) {
       
                if(player.hasPermission(new Permissions().clearlag) || player.isOp()) {
               
                    this.getServer().broadcastMessage(ChatColor.GRAY + "Clearing all ground items!");
               
                    this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "killall drops prison");
                   
                } else if(!player.hasPermission(new Permissions().clearlag)) {
                   
                    player.sendMessage(ChatColor.RED + "You do not have permission to use this command");
                   
                }
               
            if(label.equalsIgnoreCase("timer")) {
               
            number = 300;
            clock = 240;
               
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {       
                public void run() {
                    if(number !=-1) {
                        if(number != 0) {
                            number--;
                        } else {
                            Bukkit.broadcastMessage("Clearing all ground items!");
                            number--;
                        }
                    }
                }
               
            }, 0L, 20L);
           
            this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
               
                public void run() {
                    if(clock !=-1) {
                        if(clock != 0) {
                            clock--;
                        } else {
                            Bukkit.broadcastMessage(ChatColor.GRAY + "Ground items will be cleared in " + ChatColor.BOLD + "60" + ChatColor.GRAY + "seconds");
                            clock--;
                        }
                    }
                }
               
            }, 0L, 20L);
               
            }
               
                return true;
               
            }
           
            if(label.equalsIgnoreCase("gco")) {
               
                if(args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("take") || args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase("balance") || args[0].equalsIgnoreCase("help")) {
                   
                    if(args.length != 3) {
                       
                        sender.sendMessage(error);
                        return true;
                       
                    }
                   
                    if(args[0].equalsIgnoreCase("give")) {
                   
                        if(!hasAccount(args[1])) {
                       
                            sender.sendMessage(ChatColor.RED + "The player '" + args[1] + "' does not have an account!");
                            amount.put(args[1], 0D);
                            return true;
                       
                        }
                   
                        double amount = 0;
                   
                        try{
                            amount = Double.parseDouble(args[2]);
                        } catch(Exception e){
                            sender.sendMessage(error);
                            return true;
                        }
                   
                        setBalance(args[1], getBalance(args[1]) + amount);
                        sender.sendMessage(ChatColor.GREEN + "You added " + args[2] + " gem(s) to " + args[1] + "'s account. They now have " + getBalance(args[1]) + " gem(s).");
                   
                    } else if(args[0].equalsIgnoreCase("take")) {
                   
                        if(!hasAccount(args[1])) {
                       
                            sender.sendMessage(ChatColor.RED + "The player '" + args[1] + "' does not have an account!");
                            amount.put(args[1], 0D);
                            return true;
                       
                        }
                   
                        double amount = 0;
                   
                        try{
                            amount = Double.parseDouble(args[2]);
                        } catch(Exception e){
                            sender.sendMessage(error);
                            return true;
                        }
                   
                        setBalance(args[1], getBalance(args[1]) - amount);
                        sender.sendMessage(ChatColor.GREEN + "You removed " + args[2] + " gem(s) from " + args[1] + "'s account. They now have " + getBalance(args[1]) + " gem(s).");
                   
                    } else if(args[0].equalsIgnoreCase("set")) {
                   
                        if(!hasAccount(args[1])) {
                       
                            sender.sendMessage(ChatColor.RED + "The player '" + args[1] + "' does not have an account!");
                            amount.put(args[1], 0D);
                            return true;
                       
                        }
                   
                        double amount = 0;
                   
                        try{
                            amount = Double.parseDouble(args[2]);
                        } catch(Exception e){
                            sender.sendMessage(error);
                            return true;
                        }
                   
                        setBalance(args[1], amount);
                        sender.sendMessage(ChatColor.GREEN + "You set " + args[1] + "'s account to " + getBalance(args[1]) + " gem(s).");
                   
                    }
                } else {
                   
                    sender.sendMessage(error);
                   
                }       
                    if(args.length != 2) {   
                        sender.sendMessage(error);
                    }   
                        if(args[0].equalsIgnoreCase("balance") && sender instanceof Player) {
                   
                            sender.sendMessage(ChatColor.GREEN + "You have " + getBalance(args[1]) + " gem(s).");
                   
                        }
                    if(args.length != 1) {   
                        sender.sendMessage(error);
                    }   
                        if(args[0].equalsIgnoreCase("help")) {
                   
                            sender.sendMessage("Shhhhhhh this thing hasn't been added yet");
                   
                        } else {
                   
                        sender.sendMessage(error);
                   
                    }
               
                    return true;
                           
            } else {
               
                sender.sendMessage(error);
               
            }
            return false;
           
        }
       
        public static void saveBalances() {
           
            for(String p: getBalanceMap().keySet()) {
                plugin.getConfig().set("balance." + p, BPrison.getBalanceMap().get(p));
            }
           
            plugin.saveConfig();
           
        }
       
        public static void loadBalances() {
           
            if(plugin.getConfig().contains("balance")) return;
           
            for(String s : plugin.getConfig().getConfigurationSection("balance").getKeys(false)) {
                setBalance(s, plugin.getConfig().getDouble("balance" + s));
            }
           
        }
       
    }
     
  12. Offline

    Boomer

    many ways to deal with multiple-length arguments

    1) By command first, then sort out the legit from erroneous stuff
    or
    2) By argument count first, then hit commands out

    All that really matters is that you logically walk your way through to a given point and say "These are the types of arguments I will have for this command at this point.. now what" and start kicking out the errors: say you get to a point where no combination of arguments with a given command will work if there are more than 2 arguments -- throw an error. No arguments, is one needed? Throw an error, or throw the help code up, or return false; ..
    Then do a block where there is one argument, and execute the various things that only one argument can trigger. Then next do a block where there is two arguments, and execut the various tings that only two args can trigger.

    The only thing for sure is that you can NOT do code like this with these IF tests (and you still aren't escaping tests!)
    Code:
    A                if(args.length != 2) {  
                        sender.sendMessage(error);
                    }  
    B                    if(args[0].equalsIgnoreCase("balance") && sender instanceof Player) {               
                            sender.sendMessage(ChatColor.GREEN + "You have " + getBalance(args[1]) + " gem(s).");               
                        }
     C               if(args.length != 1) {  
                        sender.sendMessage(error);
                    }  
     D                   if(args[0].equalsIgnoreCase("help")) {               
                            sender.sendMessage("Shhhhhhh this thing hasn't been added yet");               
      E                  } else {               
                        sender.sendMessage(error);               
                    }
    
    DO NOT put IF's one after another that are testing for not equals this way. Reason:

    args length=2 Flow goes : A false, skip message, go to B. If its the balance command, send them the message AND KEEP GOING ON to C (Otherwise, if its not the balance command, just jump to C)... 2!=1 so now throw the error message, AND KEEP GOING ON to D. Lets say they used the help command - send that message, and skip E. Lets say they didn't use help command, they'd skip to E, and be shown the error message again.
    Thus the sender could see:
    You have 17 gem(s)
    (Error message)
    (Error message)
    or
    (Error message)
    Shhh this thing hasnt been added yet
    or
    (Error message)
    (Error message)

    Too many times the error message displayed, always displayed even when valid commands used.. because of the structure of your checks and failures to escape out.

    args length=1 Flow goes: A 1 is !2 so show the error, then continue to B, either show the balance or not, either way, keep going on to C: 1 is not !1 so skip C go to D, if it help, show that, otherwise show error.

    (error message)
    You have 17 gem(s)
    (error message)
    or
    (error message)
    Shh this thing hasn't been added yet

    or
    (error message)
    (error message)

    You need to format your code to make it easier to follow. Your indentation is all over the place.
    Aas you see, despite indentations, A B C D and E are all sequental. A is a complete test that terminates, then resumes at B, which is complete and terminates, and continues with C

    You can't do "If (something !=a) " on one point
    and "If (something!=b) " at a later point and
    "if (something !=c)" at a later point still with this type of expectation you have, because things will end up passing the test in multiple locations, or, will pass early, and get cancelled, when you really wanted it to move further down.

    Focus on the positives. Use negatives for absolute simple cut-tests ---
    if (!(sender instanceof Player)) { sender.sendMessage("Only for players to use!"); return true; }

    if (args.length>3) { sender.sendMessage("What you thinkin, boy? Aint no command takes more than 3 arguments!")); return true;}

    Things like that that draw a clean line in the sand - you're in or your out - then for everything else, fish out what matches, not what doesn't...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  13. Offline

    bowlerguy66

    I rewrote the code and now it works. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page