Solved Possible syntax error?

Discussion in 'Plugin Development' started by u_mad_bros, Jul 22, 2016.

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

    u_mad_bros

    It won't let me use || in this situation, and I couldn't resolve the issue with some google searching.
    Code:
    
    @EventHandler
        public void Something (PlayerPickupItemEvent e){
            if(plugin.enabledPlayers.contains(e.getPlayer().getUniqueId())){
            if (e.getItem().equals(Material.SEEDS || Material.ARROW || Material.DIRT || Material.COBBLESTONE || Material.BONE || Material.DEAD_BUSH || Material.EGG)){
                e.setCancelled(true);
            }
        }
        }
    
     
  2. Offline

    N00BHUN73R

    @u_mad_bros
    You have your parenthesis wrong.
    Should be like this,
    Code:
     if (e.getItem().equals(Material.SEEDS) || e.getItem().equals(Material.ARROW) || etc...
    
     
  3. Offline

    Zombie_Striker

    @u_mad_bros @N00BHUN73R
    Also, you should use '==' for comparing enums. It is more efficient than .equals. Only use .equals for objects that can either be null or where you need to compare if all the values are the same.
     
    N00BHUN73R likes this.
  4. Offline

    u_mad_bros

    @Zombie_Striker @N00BHUN73R Thanks guys, problem resolved. Working on a filter plugin for filtering out items on my SMP server. Thanks for the help guys.
     
Thread Status:
Not open for further replies.

Share This Page