java - Mute command with 2 arguments (ArrayIndexOutOfBoundsException) -



java - Mute command with 2 arguments (ArrayIndexOutOfBoundsException) -

for reason having arrayindexoutofboundsexception on line 41. have been trying @ to the lowest degree hr figure out what's wrong code. trying create mute command, command should be: /mute [player] [enable/disable].

your help much apprechiated.

package me.parat26.cmds; import me.parat26.admingui.messagemanager; import me.parat26.admingui.settingsmanager; import org.bukkit.bukkit; 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 mute implements commandexecutor { settingsmanager config = settingsmanager.getinstance(); messagemanager send = messagemanager.getinstance(); public static boolean chatdisabled = false; @suppresswarnings("deprecation") public boolean oncommand(commandsender sender, command cmd, string label, string[] args) { if ( sender.haspermission((string) config.getconfig().get("permissions.mute")) ) { if (args.length == 0) { send.message(sender, "error", "please provide plenty arguments."); } if (args.length == 1) { player offender = bukkit.getserver().getplayer(args[0]); string s = sender.getname(); if (offender == null) { send.message(sender, "error", "player " + chatcolor.yellow + args[0] + chatcolor.white + " not found."); homecoming true; } // line 41 if (args[0] != null && args[1] != null && offender != null && offender.isonline()) { if (args[1].equalsignorecase("enable")) { send.message(sender, "yes", "enabled..."); } else if (args[1].equalsignorecase("disabled")) { send.message(sender, "yes", "disabled..."); } } else { send.message(sender, "error", "please provide plenty arguments."); homecoming true; } } } homecoming true; } }

you have

if (args.length == 1) { /* ... */ if (args[0] != null && args[1] != null & // problem here ----^

if args.length 1, can't seek access args[1] because array doesn't have one. that's why exception.

either args.length == 1 test wrong, or need not utilize args[1] anywhere within if block.

java bukkit

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -