Cancel drop/place item in the armor slots

Discussion in 'Plugin Development' started by Kingzuck, Jun 20, 2014.

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

    Kingzuck

    I tryied to cancel the InventoryClickEvent if a Player try to place a item in the armor slot.
    I tried some Codes but nothing work, my last try was this :
    Code:
    if(e.getAction() == InventoryAction.PLACE_ALL){}
    this work, but i cant get the placed item ._.

    Sorry for my bad english...
     
  2. Offline

    THEREDBARON24

    Use this to check the slot "if(event.getSlotType() == SlotType.ARMOR){" You may also want to check for InventoryAction.PLACE_ONE or PLACE_SOME. There are a lot of actions to check for unfortunately.
     
  3. Offline

    Kingzuck

    But i cant get the Item that was placed in the armor slot :/
     
  4. Offline

    THEREDBARON24

    I am sure there is a method like event.getItem() or something like this that returns the ItemStack
     
  5. Offline

    Kingzuck

    Yes, getItem() and getRawItem() but both return null....
     
  6. Offline

    THEREDBARON24

    That is because the event is canceled. Try and get the item on the cursor.
     
  7. Offline

    Kingzuck

    No i cancel the Event after the if(...).
    When i get the Item on the cursor it works, but if i drop the item and move quickly the cursor its null too...

    no one :( ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Offline

    THEREDBARON24

    Can you paste in your code?
     
  9. Offline

    Kingzuck

    I tried many codes...But in no one i get the Item ! :(
    I try to cancel the InventoryClickEvent if the Slot a Armor Slot and if it is a Iron Armor(as example)
     
  10. Offline

    THEREDBARON24

    No, like paste them into pastebin or use the code option here in this message box?
     
  11. Offline

    Kingzuck

    What paste..?
    I have no special Code, i tried a many things but nothing work!
    (sorry for my bad english)
     
  12. Offline

    THEREDBARON24

    It's alright, but I mean can you copy and paste the code that you have created?
     
  13. Offline

    Kingzuck


    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e) {
    3. Player p = (Player) e.getWhoClicked();
    4. if(e.getAction() == InventoryAction.PLACE_ALL){
    5. if(e.getSlot() == 36||e.getSlot() == 37||e.getSlot() == 38||e.getSlot() == 39){
    6. ItemStack item = e.getCurrentItem();
    7. if(item != null){
    8. ItemMeta itemmeta = item.getItemMeta();
    9. int Levelp = (int) plugin.getConfig().get(p.getName() + ".Level");
    10. if(itemmeta.getLore() != null){
    11. List<String> lore = new ArrayList<String>(itemmeta.getLore());
    12. if(!(LordJused.permission.getPrimaryGroup(p).contains(lore.get(0)))){
    13. e.setCancelled(true);
    14. p.updateInventory();
    15. }else if(Levelp < Integer.parseInt(lore.get(1))){
    16. e.setCancelled(true);
    17. p.updateInventory();
    18. }
    19. }
    20. }
    21. }
    22. }
    23. }


    or i used
    Code:java
    1. ItemMeta itemmeta = e.getInventory().getItem(e.getRawSlot());

    or
    Code:java
    1. ItemMeta itemmeta = e.getInventory().getItem(e.getSlot());

    and some other..
     
  14. Offline

    THEREDBARON24

    Code:java
    1. @EventHandler
    2. public void onClick(InventoryClickEvent event){
    3. if(event.getSlotType().equals(SlotType.ARMOR)){
    4. ItemStack item = event.getCursor();
    5. //do whatever else here.
    6.  
    7. }
    8. }

    e.getCurrentItem is a method that gets the item that is currently in the slot which will most likely be null. event.getCursor() is a method which gets the items on the cursor. I would recommend that you use the code above for your first checks on the event. You can modify that ItemStack from there, cancel if necessary, etc. Hope this helps!
     
  15. Offline

    Kingzuck

    Thanks for your Code, but if i use getCursor() ( I tried it :p), the user can bug.
    If you put the Item in the Armor slot and move the Cursor fast it return null :/
     
  16. Offline

    THEREDBARON24

    Specific Bugs? Does it have an error?
     
  17. Offline

    Kingzuck

    no Bugs...its returns only null
     
Thread Status:
Not open for further replies.

Share This Page