Item Pickup blocking ALL items

Discussion in 'Plugin Development' started by ESSHD, Dec 24, 2015.

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

    ESSHD

    Hello,

    I'm making a plugin to stop players from picking up items that are not in a string list.

    I currently have this code, but it stops all item pickups.

    Code:
        @EventHandler
        public void onItemPickup(PlayerPickupItemEvent e) {
            if(!e.getPlayer().hasPermission("nyxfilter.use")) return;
            for(String s : ItemFilter.getInstance().getConfig().getStringList(e.getPlayer().getName() + ".ids")) {
                int item = Integer.parseInt(s);
                if(!(e.getItem().getEntityId() == item)) {
                    e.setCancelled(true);
                }else{
                    return;
                }
            }
        }
     
  2. Offline

    Javlin

    You only check the first entry of the list, instead of checking the entire list.
    This, and:
     
    Last edited: Dec 24, 2015
  3. Offline

    mcdorli

    What does the stringlist contains?
     
  4. Offline

    ESSHD

    Item IDs
     
  5. Offline

    mcdorli

    Entity id is not the same as typeId
     
  6. Offline

    ESSHD

    I've changed it, but it still stops all item pickups.
    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onItemPickup(PlayerPickupItemEvent e) {
            if(!e.getPlayer().hasPermission("nyxfilter.use")) return;
            for(String s : ItemFilter.getInstance().getConfig().getStringList(e.getPlayer().getName() + ".ids")) {
                int id = Integer.parseInt(s);
                if(id==e.getItem().getType().getTypeId()) {
                    return;
                }else{
                    e.setCancelled(true);
                }
            }
        }
     
  7. Offline

    mcdorli

    Show the config please, or do some debugging. BTW.: Errors?
     
  8. Offline

    ESSHD

    No errors. Config looks like this:
    Code:
    Tightan:
      toggle: true
      ids:
      - '264'
     
  9. Offline

    Javlin

    Did you try this?
     
  10. Offline

    ESSHD

    Is that what I'm doing or what I should do?
     
  11. Offline

    Javlin

    You are doing this, although you shouldn't be, because you won't be checking if the item the player is picking up is actually in the list.
     
  12. Offline

    Zombie_Striker

    Use the following:

    If(stringlist.contains(players name)){
    //do stuff
     
Thread Status:
Not open for further replies.

Share This Page