Unhandled exception

Discussion in 'Plugin Development' started by IlBmdiquartiere, Sep 9, 2021.

  1. Offline

    IlBmdiquartiere

    If i write the 2 commands in my plugin with 0 args it works, but if i write the commands with 1 args then he go in error, this is the log when i write the commands with 1 args
    Code:
    [20:36:57] [Server thread/INFO]: IlBmdiquartiere issued server command: /unfreeze a
    [20:36:57] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'unfreeze' in plugin plugin v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1385) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1220) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        at java.lang.Thread.run(Thread.java:834) [?:?]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
        at me.unfreeze.onCommand(unfreeze.java:20) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.jar:git-Spigot-596221b-9a1fc1e]
        ... 15 more
    And this is the code

    (unfreeze)
    Code:
    package me;import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class unfreeze implements CommandExecutor {
    
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
    Player p = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("unfreeze")) {
    if (sender instanceof Player) {
    if (p.hasPermission("tools.unfreeze")) {
    if (args.length == 1) {
    if (args[1] != p.getName()) {
    
    Player target = Bukkit.getPlayer(args[1]);
    if (target != null) {
    target.setWalkSpeed(1);
    target.resetTitle();
    return true;
    } else; {
    
    p.sendMessage(ChatColor.RED + target.toString() + "è attualmente offline!");
    return true;
    }
    
    } else; {
    
    p.sendMessage("Usage: /unfreeze <Player>");
    return true;}
    
    
    } else; {
    
    p.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
    return true;
    }
    
    }
    return true;}
    else; {
    
    if (args.length == 1) {
    
    
    Player target = Bukkit.getPlayer(args[1]);
    if (target != null) {
    target.setWalkSpeed(1);target.resetTitle();
    return true;}
    else; {
    
    sender.sendMessage(ChatColor.RED + target.toString() + "è attualmente offline!");
    return true;
    }
    
    } else; {
    
    sender.sendMessage("Usage: /unfreeze <Player>");
    return true;}
    
    }
    }
    return true;}
    }
    
    
    (Freeze)
    Code:
    package me;
    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;import java.util.Timer;
    public class freeze implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
    Player p = (Player) sender; if (cmd.getName().equalsIgnoreCase("freeze")) {
    if (sender instanceof Player) {
    if (p.hasPermission("tools.freeze")) {
    if (args.length == 1) {
    if (args[1] != p.getName()) {
    Player target = Bukkit.getPlayer(args[1]);
    if (target != null) {
    target.setWalkSpeed(0);target.sendTitle(ChatColor.RED + "You got freezed", ChatColor.RED + "You got freezed");
    p.sendMessage("Ricorda di unfreezare il player quando finito il conotrollo!");
    return true;} else; {
    
    p.sendMessage(ChatColor.RED + target.toString() + "è attualmente offline!");
    return true;}
    
    } else; {
    
    p.sendMessage(ChatColor.RED + "You can't freeze yourself!");
    return true;}
    } else; {
    
    p.sendMessage("Usage: /freeze <Player>");
    return true;}
    } else; {
    
    p.sendMessage(ChatColor.RED + "You don't have the permission to do this!");
    return true;}
    
    
    } else; {
    
    if (args.length == 1) {
    Player target = Bukkit.getPlayer(args[1]);
    if (target != null) {
    target.setWalkSpeed(0);target.sendTitle(ChatColor.RED + "You got freezed", ChatColor.RED + "You got freezed");
    sender.sendMessage("Ricorda di unfreezare il player quando finito il conotrollo!");
    return true;}
    else; {
    
    sender.sendMessage(ChatColor.RED + target.toString() + "è attualmente offline!");
    return true;}
    
    } else; {
    
    sender.sendMessage("Usage: /freeze <Player>");
    return true;}
    
    
    }
    
    }
    return true;}
    }
     
    Last edited: Sep 9, 2021
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    IlBmdiquartiere

  4. Offline

    timtower Administrator Administrator Moderator

    @IlBmdiquartiere Then why are you checking if args.length==1 and using args[1] instead of args[0]
     
  5. Offline

    IlBmdiquartiere

    I have tried to check args 0 too but don't work
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    IlBmdiquartiere

    The error in the console Is in the First one, the code of the commands are the other codes
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    IlBmdiquartiere

    Im not at home now
     
  10. Offline

    timtower Administrator Administrator Moderator

Share This Page