How to set a Maximum stack Amount?

Discussion in 'Plugin Development' started by TECGaming360, May 10, 2014.

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

    TECGaming360

    I have a Stuck item but when i try to take item out it jumps back in because of Inventory click event, but it keeps on doubling the item, I want to know a coding maybe i could add to the playerItemDrop event???
    Please help!
    Code:
    @EventHandler
        public void onDropItem(PlayerDropItemEvent e) {
            Player player = e.getPlayer();
            if (e.getItemDrop().getItemStack().getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1").toUpperCase()))
            {
                e.setCancelled(true);
                player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + " " + KeepthatItem.plugin.getConfig().getString("Drop Message 1"));
            }
        }
     
  2. Offline

    minoneer

    Does the duplicate item stay after you relog?
     
  3. Offline

    TECGaming360

    yes. When I grab item and try to throw it it comes back then it shows 2 then throw it again gives me 4, So on. So it keeps multipling the item by 2. I want to set it so a player only get 1!
     
  4. Offline

    minoneer

    Hmmm, that is strange. That doesn't happen to me when I use the event...
     
  5. Offline

    coasterman10

    Are you using Craftbukkit? If so, what version?

    If you're not using CraftBukkit (e.g. Spigot), try running the plugin on Craftbukkit and see if the problem is fixed. If that fixes it, you should go ask for help on the appropriate forum for the alternate server build.
     
  6. Offline

    TECGaming360

    Im using CraftBukkit 1.7.2 But i take the item it holds it then it creates another compass!
    Heres my coding.
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e)
    3. {
    4. if(e.isCancelled())
    5. {
    6. e.setCancelled(true);
    7. return;
    8. }
    9. else
    10. {
    11. if(e.getCurrentItem() != null)
    12. {
    13. if(e.getCurrentItem().getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1").toUpperCase()))
    14. {
    15. {
    16. if(e.isShiftClick() || e.isLeftClick())
    17. {
    18. e.setCancelled(true);
    19. return;
    20. }
    21. }
    22. }
    23. }
    24. if(e.getRawSlot() < 0)
    25. return;
    26. try
    27. {
    28. if(e.getInventory().getItem(e.getRawSlot()) != null)
    29. {
    30. ItemStack item = e.getInventory().getItem(e.getRawSlot());
    31. if(item.getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1").toUpperCase()))
    32. {
    33. {
    34. if(e.isShiftClick() || e.isLeftClick())
    35. {
    36. e.setCancelled(true);
    37. return;
    38. }
    39. }
    40. }
    41. }
    42. }
    43. {
    44. //do nothing...
    45. }
    46. try
    47. {
    48. if(e.getInventory().getItem(e.getSlot()) != null)
    49. {
    50. ItemStack item = e.getInventory().getItem(e.getSlot());
    51. if(item.getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1")))
    52. {
    53. {
    54. if(e.isShiftClick() || e.isLeftClick())
    55. {
    56. e.setCancelled(true);
    57. return;
    58. }
    59. }
    60. }
    61. }
    62. }
    63. {
    64. //do nothing...
    65. }
     
  7. Offline

    minoneer

    Wait... didn't you just talk about the PlayerDropItemEvent? And now you are using the InventoryClickEvent?

    I have to say I'm a little confused...
     
  8. Offline

    coasterman10

    When you click an item, click it down into another hotbar slot, and then right click a block with both stacks. If one disappears, that is your client finally catching up with the server in that the item doesn't actually exist. If both items stay, then you may want to submit a bug report, though you should do that with the latest dev version (1.7.9 methinks) in case it has been fixed.
     
  9. Offline

    TECGaming360

    ok. i will use recent craft bukkit
    And for minoneer
    I am also using this
    Code:java
    1. @EventHandler
    2. public void onDropItem(PlayerDropItemEvent e) {
    3. Player player = e.getPlayer();
    4. if (e.getItemDrop().getItemStack().getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1").toUpperCase()))
    5. {
    6. e.setCancelled(true);
    7. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + " " + KeepthatItem.plugin.getConfig().getString("Drop Message 1"));
    8. }
    9. }


    Haha that was it thnks it was a old CraftBukkit

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page