Internal error if you dont finish your command

Discussion in 'Plugin Development' started by DedosThreat, Jul 2, 2018.

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

    DedosThreat

    ok so for my PotionEffectcmds, and one of my commands is /blind (user) (duration) but when i just do /blind or /blind (user) it gives me an internal error, can someone help me out?
     
  2. Offline

    timtower Moderator Moderator

    @DedosThreat Code please and mark the line that is giving the error, also post the error please.
     
  3. Offline

    DedosThreat

    this is for /invs DedosThreat
    Code:
    [12:34:11 ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'invs' in plugin PotionsEffectCmds v1.2     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1397) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1232) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_172]     at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_172]     at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at java.lang.Thread.run(Thread.java:748) [?:1.8.0_172] Caused by: java.lang.ArrayIndexOutOfBoundsException: 1     at me.DedosThreat.PluginMain.onCommand(PluginMain.java:44) ~[?:?]     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     ... 15 more
    
    
    this is for /invs
    Code:
    12:34:53 ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'invs' in plugin PotionsEffectCmds v1.2     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1397) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1232) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_172]     at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_172]     at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     at java.lang.Thread.run(Thread.java:748) [?:1.8.0_172] Caused by: java.lang.ArrayIndexOutOfBoundsException: 1     at me.DedosThreat.PluginMain.onCommand(PluginMain.java:44) ~[?:?]     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]     ... 15 more [12:34:55 INFO]: [BuycraftX] Updating coupon list...
    
    and this is my code
    Code:
    package me.DedosThreat;
    import java.util.Random;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.yaml.snakeyaml.events.Event.ID;
    public class PluginMain extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static PluginMain plugin;
        @Override
    public void onEnable() {
        getLogger().info(ChatColor.DARK_AQUA + "Plugin Successfully Enabled :)");
        PluginManager pm = getServer().getPluginManager();
      }
       @Override
    public void onDisable( ) {
      }
    @SuppressWarnings("deprecation")
    public boolean onCommand(CommandSender Sender, Command cmd, String lable, String[] args) {
    Player player = (Player) Sender;
    //int
    int s = Integer.parseInt(args[1]);
    //int
    //Potion effect list start
    PotionEffect blind = new PotionEffect(PotionEffectType.BLINDNESS, s * 20, 255);
    PotionEffect invs = new PotionEffect(PotionEffectType.INVISIBILITY, s * 20, 255);
    PotionEffect strength = new PotionEffect(PotionEffectType.INCREASE_DAMAGE, s * 20, 255);
    PotionEffect poison = new PotionEffect(PotionEffectType.POISON, s * 20, 255);
    PotionEffect glow = new PotionEffect(PotionEffectType.GLOWING, s * 20, 255);
    //Potion effect list end
    //Blind 
    if(cmd.getName().equalsIgnoreCase("Blind")&& Sender instanceof Player) {
        if(args.length==2) {
        Player user = player.getServer().getPlayer(args [0]);
        if(user==null) player.sendMessage(ChatColor.RED + "Invalid Player");
        user.addPotionEffect(blind);
        player.sendMessage(ChatColor.GREEN + "Blinded!");}
        else {
            player.sendMessage(ChatColor.DARK_RED + "Invalid usage!" + ChatColor.RED + "/Blind <player> <Duration>");       
        }
        return true;       
    }
    //Invs
    if(cmd.getName().equalsIgnoreCase("Invs")&& Sender instanceof Player) {
        if(args.length==2) {
        Player user = player.getServer().getPlayer(args [0]);
        if(user==null) player.sendMessage(ChatColor.RED + "Invalid Player");
        user.addPotionEffect(invs);
        player.sendMessage(ChatColor.GREEN + "Player has been become Invs");}
        else {
            player.sendMessage(ChatColor.DARK_RED + "Invalid usage!" + ChatColor.RED + "/Invs <player> <Duration>");       
        }
        return true;       
    }
    //Strong
    if(cmd.getName().equalsIgnoreCase("Strong")&& Sender instanceof Player) {
        if(args.length==2) {
        Player user = player.getServer().getPlayer(args [0]);
        if(user==null) player.sendMessage(ChatColor.RED + "Invalid Player");
      user.addPotionEffect(strength);
        player.sendMessage(ChatColor.GREEN + "Player has been Strengthened");}
        else {
        player.sendMessage(ChatColor.DARK_RED + "Invalid usage!" + ChatColor.RED + "/Strong <player> <Duration>");       
        }
        return true;       
    }
    //Poison
    if(cmd.getName().equalsIgnoreCase("Poison")&& Sender instanceof Player) {
        if(args.length==2) {
        Player user = player.getServer().getPlayer(args [0]);
        if(user==null) player.sendMessage(ChatColor.RED + "Invalid Player");
      user.addPotionEffect(poison);
        player.sendMessage(ChatColor.GREEN + "Player has been Poisoned");}
        else {
            player.sendMessage(ChatColor.DARK_RED + "Invalid usage!" + ChatColor.RED + "/Poison <player> <Duration>");       
        }
        return true;       
    }
    //Glow
    if(cmd.getName().equalsIgnoreCase("Glow")&& Sender instanceof Player) {
        if(args.length==2) {
        Player user = player.getServer().getPlayer(args [0]);
        if(user==null) player.sendMessage(ChatColor.RED + "Invalid Player");
      user.addPotionEffect(glow);
        player.sendMessage(ChatColor.GREEN + "Player has been Glowed");}
        else {
            player.sendMessage(ChatColor.DARK_RED + "Invalid usage!" + ChatColor.RED + "/Glow <player> <Duration>");       
        }
        return true;       
    }
    return false;
    } }
     
  4. Offline

    timtower Moderator Moderator

    @DedosThreat int s = Integer.parseInt(args[1]);
    That line is being used before all length checks are done.
     
  5. Offline

    DedosThreat

    meaning?
    ***im confused***
     
  6. Offline

    A5H73Y

    Meaning you are trying to get a numeric value of something that may not exist before doing a arguments length validation.
     
    SavageAvocado likes this.
  7. Offline

    DedosThreat

    sorry..... im still confused....
     
  8. Offline

    KarimAKL

    @DedosThreat You have to check if the arguments are set before using them.
     
Thread Status:
Not open for further replies.

Share This Page