Solved Why does my for loop not work? :L

Discussion in 'Plugin Development' started by bennie3211, Jul 20, 2013.

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

    bennie3211

    Hi all, I was working on my disablecommand class, so players can add command that are not blocked in game. Now everything worken before with my plugin commands only, but when i loop throught my arraylist called 'allowed' it wont detect the allowed commands :L

    This is my onDisableCommand event:
    Code:
    @EventHandler()
        public void onDisableCommands(PlayerCommandPreprocessEvent event)
        {
            String[] split = event.getMessage().split(" ");
           
            if (!(plugin.InArena.contains(event.getPlayer().getName())))
            {
                return;
            }
           
            if (split[0].equalsIgnoreCase("/pvp") || split[0].equalsIgnoreCase("/kitpvp") || split[0].equalsIgnoreCase("/ppvp"))
            {
                return;
            }
           
            for (int i = 0; i < plugin.allowed.size(); i++)
            {
                if (split[0] == plugin.allowed.get(i))
                    {
                        return;
                    }
            }
           
            event.setCancelled(true);
            event.getPlayer().sendMessage(prefix + ChatColor.RED + "You cannott use commands while in a pvp arena!");
            event.getPlayer().sendMessage(prefix + ChatColor.GREEN + "Do /pvpkits leave to leave the pvp arena.");
        }
    this is the list in config.yml:

    And this is how i create my arraylist in onEnable() where i extend my class with JavaPlugin

    Code:
    #Outside my onEnable()
    List <String> allowed = new ArrayList<String>();
     
    #Inside my onEnable()
    allowed = getConfig().getStringList("AllowedCommands");
    It doesn't give errors, but when i want to do /butcher, or /mute, or /broadcast as command, it still blocks it :L Someone knows why?
     
  2. split[0] == plugin.allowed.get(i)

    nope.

    You do not check object equality like that

    split[0].equalsIgnoreCase(plugin.allowed.get(i))
     
    bennie3211 likes this.
  3. Offline

    CubieX

    Use "equalsIgnoreCase()" instead of == to compare the strings in your for-loop.
     
    bennie3211 likes this.
  4. Offline

    bennie3211

    Thnx, I thought it should act the same :p
     
Thread Status:
Not open for further replies.

Share This Page