I have a plugin a made, and at the start of the class, it has a boolean set to true. This is what I'm using to regulate whether it's enabled or disabled. Well, without the extra "toggle" at the end of the core command, it gives me the "Internal error" message. Here's the code for the command ( /glassbreaker ) and with the toggle. Note the when it says "toggle == true", "toggle" is the boolean at the beginning of the code. Code (Text): public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[]args){ if (sender.isOp()){ if (args[0].length() == 0){ sender.sendMessage(ChatColor.GREEN + "GlassBreaker: Break glass in survival mode to get it's drop!"); } else if (args[0] == "toggle"){ if (toggle == true){ sender.sendMessage(ChatColor.YELLOW + "GlassBreaker disabled!"); toggle = false; } else if (toggle == false){ sender.sendMessage(ChatColor.YELLOW + "GlassBreaker enabled!"); toggle = true; } } I don't know what I'm doing wrong here. The original command doesn't work anymore, and the toggle feature doesn't do anything.
Ah, I forgot that works as well. It still doesn't fix the problem though. That same Internal Error message is still coming up.
Condense this into 2 lines (8 -> 2) Code (Java): toggle = !toggle; sender.sendMessage(ChatColor.YELLOW + "GlassBreaker " + (toggle ? "enabled!" : "disabled!"));
Wait wait wait... Anything about this line? args[0].length()? 1. No check for length of arguments (I assume that's what you were attempting to do). Could be no arguments (NullPointerException) 2. You're checking the length of the first index of "args", not the args array itself 3. That should use .equalsIgnoreCase(), and not ==. Use .equals() to compare strings
Wow.Okay, so what would I do for the args[0] if I wanted to detect if I put "toggle" after the command /GlassBreaker ?
You need to check the length of the argument array, and not the length of the first (potential non-existant; ArrayIndexOutOfBoundsException) index. Code (Java): args.length == 0 That will check if there are no arguments. As for checking what the first argument is (Assuming there is an argument); Code (Java): args[0].equalsIgnoreCase("toggle")