Solved How do you delete something on the cursor

Discussion in 'Spigot Plugin Development' started by kingmo100, Oct 12, 2019.

  1. So im trying to make a custom enchant plugin. Everything works except when I try to delete the item in the cursor it says i am but it doesnt. Im not sure if this is a bug or just my mistake.

    Code (Java):
        public void onBookApply(InventoryClickEvent e) {
            if(e.getWhoClicked() instanceof Player) {
            Player p = (Player) e.getWhoClicked();
            ItemStack ci = e.getCurrentItem();
            ItemStack cu = e.getCursor();
             List<String> nl = new ArrayList<>();
            if(ci == null || cu == null || ci.getType() == Material.AIR || cu.getType() == Material.AIR) return;
            if(!(cu.getType() == Material.BOOK)) return;
            for(EnchantType e2: getAllEnchantTypes()) {
                if((cu.getItemMeta().getDisplayName().contains(e2.getEnchantClass(e2).getBookName()) || cu.getItemMeta().getLore().equals(e2.getEnchantClass(e2).getLore()))){
                 Book b = e2.getEnchantClass(e2);
                for(Material m : b.getApplicableItems()) {
                     ItemStack nit = ci;
                     ItemMeta nim = ci.getItemMeta();
                     if(nim.getLore() != null) { for(String s : nim.getLore()) { if(s.contains(b.getAppliedBookName()))  return;}}
                     if(ci.getType() == m) {
                     nl.add(b.getAppliedBookName() + " " + cu.getItemMeta().getDisplayName().split(" ")[1]);
                     p.sendMessage(ci + "");
                     p.sendMessage(ci + "");
                     p.getInventory().setItem(e.getSlot(), e.getCurrentItem());
    If you need any help translating just ask
  2. Gadse

    Gadse Previously GummiBoat

  3. nope still doesnt work
    Also if i set the cursor to something like a block and i then click the original cursor down the block doesnt show up but I exit the inventory and it is thrown out
  4. Gadse

    Gadse Previously GummiBoat

    I just tested cu.setAmount(0); and e.getWhoClicked().setItemOnCursor(null); and both worked just fine.
    The issue is then definitely somewhere in your code. Try cleaning it up a little. You should note, that the InventoryClickEvent is a little weird if you're in creative mode since creative mode is mostly client sided. (It gets fired twice for example.)
  5. You got it. I was in creative mode tf. It works fine in survival