setMaxStackSize?

Discussion in 'Plugin Development' started by CaLxCyMru, Nov 8, 2013.

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

    CaLxCyMru

    Hello there; I am trying to set the max stack size so that I players can only have one of the item in each slot, Any ideas on how do do this?:)
     
  2. Offline

    sd5

  3. Offline

    CaLxCyMru

  4. Offline

    Assist

    CaLxCyMru
    Code:java
    1. public void modifyMaxStack(Item item, int amount) {
    2. try {
    3. Field f = Item.class.getDeclaredField("maxStackSize");
    4. f.setAccessible(true);
    5. f.setInt(item, amount);
    6. } catch (Exception e) {
    7. e.printStackTrace();
    8. return;
    9. }
    10. }

    This requires http://dl.bukkit.org/downloads/bukkit/, as it uses NMS Item. Usage:
    Code:java
    1. modifyMaxstack(Item.INK_SAC, 1); //or whatever the name of ink sac is in nms code.
     
  5. Offline

    CaLxCyMru

    Thanks; I will try this out now!:)

    Does any one know what the NMS name for Ink_Sack is ?

    -Thanks

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

    The_Doctor_123

    CaLxCyMru
    It may be something like "Black Dye" since it is a dye.
     
  7. Offline

    CaLxCyMru

    Will try it out now!

    Code:java
    1. modifyMaxstack(Item.BLACK_DYE, 1);
    2.  
    3. modifyMaxstack(Item.INK_SACK, 1);


    Both do not work :(

    Bump.

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

    Janmm14

    CaLxCyMru
    Write
    Item.
    then press ctrl + space and a list of possible values should show up in eclipse.
     
    Mathias Eklund likes this.
  9. Offline

    CaLxCyMru

    Nope, Did not work.
     
  10. Offline

    Janmm14

    CaLxCyMru
    And you are sure that you have craftbukkit as a dependency?
     
  11. Offline

    koesie10

  12. Offline

    CaLxCyMru

  13. Offline

    Janmm14

  14. Offline

    CookieGamer100

    OMG Best thread ever saved me tons of time :)
     
Thread Status:
Not open for further replies.

Share This Page