1 item per slot (No stacking) need help..

Discussion in 'Plugin Development' started by sooon_mitch, Feb 20, 2014.

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

    sooon_mitch

    I am trying to prevent any items from stacking inside the players inventory. I did try using .setMaxStackSize(1); But nothing happened and it did not work. How do I use .setMazStackSize for it to work? Where do I call it? Also how do I prevent the player from stacking the items once its in the players inventory. Like drag and drop items on top of each other and stacking. Any help would be thankful. This is kinda urgent.
     
  2. Offline

    Captain Dory

    Did you
    1. Register events
    2. Use an EventHandler
    ?
    If so, no idea :3
     
  3. Offline

    sooon_mitch

    Captain Dory, Yes, Can you give an example code on how to use it?
     
  4. Offline

    Captain Dory

    Try using .setMaxStackSize(0);
    Java starts counting at 0. Untested, but could work :3
     
  5. Offline

    HubbyO9

    Captain Dory Almost every programming language starts counting at 0 ;3
     
  6. Offline

    sooon_mitch

    But how would I implement this for instance on a PlayerPickupItemEvent. How would I go by add this in? Do I have to do it for each item thats picked up? Or just call the the setMaxStackSize(0) on the players inventory?
     
  7. Offline

    Captain Dory

    I've never used setMaxStackSize before :p This is what I would do:
    PHP:
    @EventHandler
    public void onPickup (PlayerPickupItemEvent e) {
     
    ItemStack i e.getItem();
    for (
    ItemStack gpi e.getPlayer().getInventory() {
     
      if (
    == gpi) {
     
      
    e.setCancelled(true);
      
    e.getPlayer().getInventory.addItem(i); 
     
      }
     
    }
     
    }
    Then add code to set item on ground to air.
    This should send it to a new slot
     
  8. Offline

    sooon_mitch

    Captain Dory Will this also help make it to where the player does not stack it in his inventory also? So if he moves the items and picks it up and places on the other?
     
  9. Offline

    Captain Dory

    Oh, it won't do that... Try using an InventoryClickEvent or InventoryInteractEvent, I don't know what it's called.
     
  10. Offline

    sooon_mitch

    @Captian Dory I tried your method and it did not work at all.. It also has a lot of errors so I tried correcting them but it may of screwed it up.. Idk..

    Bump

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

Share This Page