How to stack mushroom soup?

Discussion in 'Plugin Development' started by Techtony96, Aug 31, 2012.

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

    Techtony96

    I want to make a plugin that when a player types a command, all mushroomsoup in their inventory stacks to 64. What bukkit api would i use for this?
     
  2. Offline

    TheSmallBones

    Make a new item stack with mushroom soup with the amount set to the amount in their inventory, then add it to their inventory.
     
  3. Offline

    Techtony96

    @TheSmallBones
    How do i do that? I can't find anything in the bukkit documentation...
     
  4. Offline

    TheSmallBones

    Not sure about getting the amount of mushroom soups, but it is very simple besides that...
    p.getInventory().remove(Material.MUSHROOM_SOUP);
    p.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, amount, (short), 1));
     
  5. Offline

    Techtony96

    @TheSmallBones
    Thanks!

    Anyone else know how to get the number of an item in a players inventory?

    @skore87
    You said you would help people if they tagged you :D Well im asking...

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

    TheSmallBones

    Code:
    public static int getAmount(Player player, int id)
    {
            PlayerInventory inventory = player.getInventory();
            ItemStack[] items = inventory.getContents();
            int has = 0;
            for (ItemStack item : items)
            {
                if ((item != null) && (item.getTypeId() == id) && (item.getAmount() > 0))
                {
                    has += item.getAmount();
                }
            }
            return has;
        }
     
  7. Offline

    Techtony96

    @TheSmallBones
    I get an error in eclipse :/

    Picture: http://puu.sh/117fa

    Not sure what is wrong...



    Not sure why it didnt upload the entire window. here it is:

    http://puu.sh/117iB

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

    tommycake50

    remove public and static and see if that works.
     
  9. Techtony96
    I strongly suggest you read the Java syntax documentation because you don't seem to understand what you're doing there.

    You can't define a method inside another method unless it's a subclass... which is not in your case.

    So, please stop asking for codes which you don't know how to use and learn basic Java syntax.
     
    calebbfmv likes this.
  10. Offline

    Techtony96

  11. Offline

    Firefly

    That doesn't fix it. You have to use the original method you were given, but declare it outside onCommand(). Then call that method inside onCommand().
     
  12. Offline

    skore87

    I didn't even get the alert despite my preferences being set for it =\ But it looks like you've been given a solution anyway. XD
     
  13. Offline

    Techtony96

    Well you are here now! :D
    I have been working on the bukkitdev channel for some time now, and this is the code i have now

    Code:java
    1.  
    2. package me.Techtony96.Stacker;
    3.  
    4. import java.text.DateFormat.Field;
    5.  
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class Stacker extends JavaPlugin{
    9.  
    10. @Override
    11. public void onDisable(){
    12.  
    13. }
    14.  
    15. @Override
    16. public void onEnable(){
    17. Field field=net.minecraft.server.Item.class.getDeclaredField("maxStackSize");
    18. field.setAccessible(true);
    19. field.setInt(net.minecraft.server.Item.ENDER_PEARL, 64);
    20.  
    21. }
    22. }
    23.  


    Any ideas?
     
  14. Offline

    skore87

    Seems to work, though it's a little weird. Be sure to surround it in a try/catch as there are several exceptions that can be thrown (NoSuchFieldException, SecurityException,IllegalArgumentException,IllegalAccessException are what eclipse finds for me). And also, it doesn't seem to work for anyone who joins after it is ran, so putting it in the join event might be better.

    Also when the player is given the item, it will continue to stack to the normal 64 max instead of making a new stack after you reach the number you give it. So it seems 64 is still the hardcap unless you manually change that specific stack to a higher number.
     
  15. Offline

    Techtony96

    @skore87

    Never could get that to work. Trying a different approach...
     
  16. Offline

    skore87

    Notice where I wrote that it works?
     
    calebbfmv likes this.
  17. Offline

    Techtony96

    skore87

    I cant get it to work, but yes i did see that. Could you send me your plugin that works? :D
     
  18. Offline

    calebbfmv

    Um might I say something?
    THE CODE WORKS!
    Thanks you.
     
  19. Offline

    skore87

    Code:java
    1.  
    2. @Override
    3. public void onEnable(){
    4. Field field=net.minecraft.server.Item.class.getDeclaredField("maxStackSize");
    5. field.setAccessible(true);
    6. field.setInt(net.minecraft.server.Item.ENDER_PEARL, 64);
    7. }
    8.  


    ^that, but with the required try/catch statements.
     
    calebbfmv likes this.
  20. Offline

    Techtony96

    That is exactly what i did! But when i try to add the try/catch statements i get tons of errors which i don't know how to fix.

    Also, could i put that in:
    Code:
    if(player.hasPermission("some.pointless.permission")) {
       //Do something
    }else{
       //Do something else
    }
    
    To only let certain people use it?
     
  21. Offline

    skore87

  22. Offline

    calebbfmv

    Yes, if you want NOTHING to happen

    Because
    Code:
    if(player.hasPermission("some.pointless.permission")) {
       //Do something
    }else{
       //Do something else
    }
    
    Does nothing

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  23. Offline

    Techtony96

    Who is that zombie kid... LOL

    why do you hate him? he helped me! LIKED!

    EDIT: What? I don't have permission to like posts?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  24. Offline

    calebbfmv

    Did you get the code?
     
  25. Offline

    Techtony96

    I found that on the bukkit tutorial. Is this out of date?
     
  26. Offline

    calebbfmv

    No just it does nothing -_-
     
  27. Offline

    Techtony96

    Yes i did. I'm going to test it now.

    OK then... I will research how to do it.

    wait. am i blind or did you delete the code...

    EDIT: why would you do that? I didnt copy it yet...

    @skore87
    Thats just not cool man. Come on. Im begging.

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

    TheSmallBones

    First of all... I gave you code which worked a long time ago... And now you're wasting your time asking him why he removed his code. Second of all, save your self some time and simply go back and look what I said. I use the same method in one of my plugins and it works.

    If it doesn't work, please make sure you actually use this code that I'm literally *giving* to you correctly before you think it is wrong.
     
  29. Offline

    skore87

    If you don't try to help yourself, people are prone to ignore you because of the disrespect. I didn't expect you to see the post I was doing, as it was just between me and another on skype joking around. Had you actually tried either the first solution or even the one you posted you would have found that they work. The second would work, but for fine tuning would require similar use of the first. You just had to pay attention to what your IDE was telling you to do.
     
    Icyene, XbannisherX and TheSmallBones like this.
  30. Offline

    calebbfmv

    -_-
    Peace
     
Thread Status:
Not open for further replies.

Share This Page