Solved Got an issue at executing

Discussion in 'Plugin Help/Development/Requests' started by Sarcry, Aug 29, 2016.

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

    Sarcry

    Here's the code:
    Code:
    public class InstaDespawn extends JavaPlugin implements Listener{
    
    
        public void onEnable() {
            saveDefaultConfig();
            getServer().getPluginManager().registerEvents(this, this);
           
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("timedespawn")) {
                if (sender.hasPermission("timedespawn.set")) {
                    if (args.length == 0) {
                        sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "!" + ChatColor.GRAY + "]" + ChatColor.RED + "You must specify time!");
                        sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "!" + ChatColor.GRAY + "]" + ChatColor.RED + "Usage /timedespawn <time>");
                        }
                    if (args.length == 1) {
                        String time = args[1];
                          int timeamount = Integer.parseInt(time);
                          this.getConfig().set("Time",timeamount);
                          this.saveConfig();
                          sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "!" + ChatColor.GRAY + "]" + ChatColor.GREEN +"TimeDespawn delay has been changed to "+ timeamount);
                    }
                    if (args.length >= 2) {
                        sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "!" + ChatColor.GRAY + "]" + ChatColor.RED + "Invalid arguments!");
                        sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "!" + ChatColor.GRAY + "]" + ChatColor.RED + "Usage /timedespawn <time>");
                    }
                    return true;
                    }
                }
            return true;
           
        }
    
        @EventHandler
        public void onSceduleItemRemove(PlayerDropItemEvent event){
            final Item item = event.getItemDrop();
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    
                @Override
                public void run() {
                    if(item != null && !item.isDead() && item.isValid()){
                        item.remove();
                    }
                }
            }, this.getConfig().getInt("Time") * 20);
        }
    
    I'm getting error from the console when executing that cmd. Here's the error
    Code:
    [16:25:51] [Server thread/INFO]: Sarcry issued server command: /timedespawn 5
    [16:25:51] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'timedespawn' in plugin TimeDespawn v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:742) ~[Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
        at sar.despawn.InstaDespawn.onCommand(InstaDespawn.java:37) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[Craftbukkit.jar:git-Bukkit-1.7.9-R0.2-10-ge6cd8c0-b3096jnks]
        ... 13 more
    
    
    Already solved!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 29, 2016
Thread Status:
Not open for further replies.

Share This Page