Help With .removeItem

Discussion in 'Spigot Plugin Development' started by juthekiller, Jun 21, 2015.

  1. Ok Hey People =D
    I'm working on a new plugin called Gadget+ and my problem is quite simple...

    I got my gui here...

    Code (Text):
    public void openGUI(Player p){
            inv = Bukkit.createInventory(null, 27, ChatColor.GOLD + "Gadgets"); //format: null, size of inventory (must be divisible by 9), "GUI name"
            inv.setItem(0,
                    make(Material.GOLD_BARDING, 1, 0, ChatColor.GOLD + "Particle Gun" + ChatColor.DARK_GRAY + " - " + ChatColor.DARK_RED + "Click!",
                            Arrays.asList(ChatColor.AQUA + "Shoots Particles!", ChatColor.AQUA + "Made By xXRedstoneTekXx")));
            inv.setItem(26,
                    make(Material.BARRIER, 1, 0, ChatColor.RED + "Close Menu + Remove Gadget" + ChatColor.DARK_GRAY + " - " + ChatColor.BLUE + "Click!",
                            Arrays.asList(ChatColor.AQUA + "Closes GUI!", ChatColor.AQUA + "Made By xXRedstoneTekXx")));
            p.openInventory(inv);
    This Is My Code For My GUI...


    Here Is My Click Listener

    Code (Text):
    ArrayList<UUID> hasgadget = new ArrayList<UUID>();
        @EventHandler
        public void onInvClick(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
            ItemStack clicked = e.getCurrentItem();
            Inventory inventory = e.getInventory();
            UUID pUUID = player.getUniqueId();
            if (inventory.getName().equals(inv.getName())){
                if(clicked.getType() == Material.GOLD_BARDING) {
                    e.setCancelled(true);
                    player.closeInventory();
                    if(hasgadget.contains(pUUID)){
                        player.sendMessage(ChatColor.RED + "You Already Have A Gadget In Your Inventory!");
                    }else{
                        player.playSound(player.getLocation(), Sound.FIZZ, 1, 1);
                        hasgadget.add(pUUID);
                        player.getInventory().addItem(
                                make(Material.GOLD_BARDING, 1, 0, ChatColor.GOLD + "Particle Gun" + ChatColor.DARK_GRAY + " - " + ChatColor.DARK_RED + "Click!",
                                     Arrays.asList(ChatColor.AQUA + "Shoots Particles!", ChatColor.AQUA + "Made By xXRedstoneTekXx")));
                    }
                    }
                }
                if(clicked.getType() == Material.BARRIER) {//HERE IS WHAT I GOT AS A PROBLEM...
                    e.setCancelled(true);
                    player.closeInventory();
                    hasgadget.remove(pUUID);
                    //I Want A Way To Remove The Particle Gun... Check In The GUI For Reference...
                    }//HERE IS WHAT I GOT AS A PROBLEM...
                   
                   
                }
    Thank You For Helping...
    I Basically Want To Remove A Item With A Custom Lore And Custom Name From A Players Inventory...
     
  2. Creeoer

    Supporter

    First off you should've put this into Spigot Plugin Developement to get more replies.
    Anyway,it's very simple, you could loop through the inventory and check whether or not the item stack has item meta, if it does check the display name and if its equal to particle gun remove the item
     
  3. tried that
    didnt work :/
    give an example ?
     
  4. It would be better for you to give us an example of what you tried, and then we can tell you why it didnt work.
     
  5. Nvm i fixed this problem... now I ran into a new one... I'm working on a friend plugin... And I would like the each time that a player joins:

    It adds their UUID in the config file as a list:

    ExampleUUID: //This Would Be The UUID of the player...
    - Friend1
    - Friend2
    - Friend3

    Basically... I just need help into adding the lists
    like ExampleUUID:

    Thank you in advance
     
  6. Creeoer

    Supporter

    Should of created a new thread for this but anyway, set a new list in the config by using config.set("pathtolist", list); then to add to the list just use config.get("pathtolist"); that will return a list, add to that list.
     
  7. ok ill try that :) thanks
     
  8. I get an error on List

    getConfig().set(player.getUniqueId(), list);
    II
    Error here ---------------------------------->