Solved onPlayerRespawn, go through player's inventory and remove items NOT on a whitelist.

Discussion in 'Plugin Development' started by triarry, Feb 8, 2013.

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


    Hey guys, I'm trying to do this using a list in my config. I can't think of a proper way to go through a player's items when he respawns and only pick out the ones THAT ARE NOT on that list. Can anyone steer me in the right direction? I'm probably overthinking this.
  2. Offline


    Go through player's inventory and if the item is not on the list, remove it.
  3. Offline


    I made a plugin similar to this once, and it's fairly difficult because you have to catch their Death event and handle the inventory stuff there, before they die and drop all the items. I'll dig up some code for you a bit later, kind of busy atm.
  4. Offline


    Okay, this is what I have so far. But it's giving me an NPE once everything is done. It does it flawlessly, but it spams my console.

        public void whitelistItems(Player p) {
            Boolean itemCheck = false;
            if (p.hasPermission("pvprestore.whitelist.drop") && plugin.getConfig().getBoolean("whitelist.enabled") == true) {
                for (ItemStack stackList : p.getInventory().getContents()) {
                    for (Integer itemList : plugin.getConfig().getIntegerList("whitelist.items")) {
                        if (stackList.getTypeId() == itemList){
                            itemCheck = true;
                    if (itemCheck != true) {
                        System.out.println("Removed item ID: " + stackList.getTypeId() + " from your inventory.");
                    itemCheck = false;
    I believe I need some null checks in here, but I'm not sure where.
  5. Offline


    And you can't read that stacktrace, can you ?
  6. Offline


    So you could do something like this:

    public void checkItems(PlayerRespawnEvent event){
    Player p = event.getPlayer();
    Inventory playerinv = p.getInventory();
    if (playerinv().contains(Material.whateveryouwant){ // or something that is in the config file
    playerinv.remove(Material.whateveryouwant); //
  7. Offline


    Got it, I read on how to read stacktraces and eliminated the error. Never knew they were really readable, I'm a native C++ coder just beginning to learn about Java :) Thanks for the help!

    EDIT: I added null checks before both of the if statements that check the ItemStack.
Thread Status:
Not open for further replies.

Share This Page