Instant Soup Plugin Help

Discussion in 'Plugin Development' started by w84u2cy, Sep 17, 2013.

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

    w84u2cy

    Hi,
    Can someone help me with making a instant soup healer plugin?
    Thanks
    Ben
     
  2. Offline

    mollekake

    Have you started it? Have you any prior experience? Where are you stuck?
    We don't make plugins for you, we help you learn.
     
  3. Offline

    w84u2cy

    Hi,
    Thanks for the reply.
    I'm mostly stuck on the "Gethealth is now ambiguous for the type Player."
    I've read that bukkit changed something but i don't really get what they mean.
    Thanks.

    P.S. I'm new to coding, if you could supply some code that would be awesome. I learn by just reading over the code :)
     
  4. Offline

    CryKiller3

    w84u2cy here you go
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent e) {
    4. Player p = e.getPlayer();
    5. if(p.getItemInHand().getTypeId() == 282 && (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_AIR))) {// check right click and item in hand is soup
    6. e.setCancelled(true);// cancel the drinking
    7. if(p.getHealth() <= 20.0 - 6.0) {//check his health wont be above max when finish drinking
    8. p.setHealth(p.getHealth() + 6.0);// add health - 6.0 means 3 hearts, u have to put .0 beacuse of the update
    9. ItemStack is = new ItemStack(0); //create itemstack
    10. is.setTypeId(281); //make the itemstack empty bowl
    11. if(p.getItemInHand().getAmount() > 1) {// check if there is a stack of soups
    12. p.getInventory().addItem(is);//add the empty bowl to inventory
    13. is.setTypeId(282);//change the empty bowl to soup to lower the current soups amount
    14. is.setAmount(p.getItemInHand().getAmount() - 1);//set the soup's amount to the soups in hand amount -1
    15. p.setItemInHand(is);// set item in hand to new soup stack
    16. } else// if he has only 1 soup in hand
    17. p.setItemInHand(is);//replace item in hand to empty bowl
    18. }
    19. }
    20. }
     
  5. Offline

    Garris0n

    Use materials not item ids. It's deprecated for a reason.
     
  6. Offline

    The_Doctor_123

    Why is it deprecated?
     
  7. Offline

    Garris0n

    The same reason mojang is implementing the item id-less system for commands: item ids won't be around forever and could change. Say you have a plugin that gives players dirt every hour, and it relies on the item id of dirt(3). After publishing this plugin you give up on bukkit and go to college. A few months later, Mojang changes the item id of diamond blocks to 3. Now your plugin gives out free diamond blocks every hour and the servers that use it can't fix it. They have to abandon the plugin and now their server has lost a feature its users probably relied on. Obviously this scenario is not likely but something could go wrong on a larger scale (what if worldedit used block ids and they all got changed around, but sk89q quit).
     
  8. Offline

    The_Doctor_123

    Oh, that's such baloney.. Item IDs will stay around forever because that's how data is stored! If you used names, save files would be so huge and take forever to load.

    If Mojang changed item IDs, that would require ID conversions. Not going to happen.
     
  9. Offline

    Garris0n

    No they most likely won't STORE the items as strings(though the method of storage could change at any time, another reason to get rid of the magic numbers) however they could change the id of something. The issue is mostly with having magic numbers in the bukkit API. If everybody uses the enum as an interface it doesn't matter what mojang does to the item storage, bukkit can update the API and all old plugins will still function just fine. And about the "not going to happen", mojang themselves are changing the interface (in things like /give) to take something like "/give Notch minecraft:stone" instead of "/give Notch 1". Say what you want about it happening, but I'm not just speculating, they said they were doing that for this reason.
     
  10. Offline

    The_Doctor_123

    Garris0n
    Mojang WILL NOT change the item IDs, as that would force them to convert save files. That's way too much trouble for something extremely worthless.
     
  11. Offline

    w84u2cy

    How do I use materials?
    BTW. It still says getHealth() is ambiguous for the type player.

    I get getHealth() is ambiguous for type player
    :(

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

    CryKiller3

  13. Offline

    CeramicTitan Retired Staff

  14. Offline

    The_Doctor_123

    CeramicTitan
    Looks to me that they're starting to use enums for everything rather than IDs for easier to read code. They DID NOT say that Mojang was ever going to change any IDs other than them saying "Compatibility for future versions of Minecraft." You people must think about this, HOW could Mojang change IDs? Look at this scenario:

    Mojang changes the IDs in one update and in the next they change them again. What if you never loaded a world in that period of time? Your world will corrupt with diamond blocks and lava everywhere?
     
  15. Offline

    SkillSam

    w84u2cy
    Here is my code for instant soup.

    Code:
    Code:java
    1. @EventHandler
    2. public void SoupAbility (PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (p.getHealth() == p.getMaxHealth()) return;
    5. if (p.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
    6. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    7. p.setHealth(p.getHealth() + 7 > p.getMaxHealth() ? p.getMaxHealth() : p.getHealth() + 7);
    8. p.getItemInHand().setType(Material.BOWL);
    9. return;
    10. }
    11. }
    12. }
     
  16. Offline

    CryKiller3

    SkillSam if there is a stack then they will all be consumed
     
  17. Offline

    SkillSam

    CryKiller3
    Oh...I originally thought that the Mushroom Soup would just be one item in a stack. Sorry.

    EDIT:
    Why would there would be a stack of mushroom soup? Isn't this for PVP?
     
  18. Offline

    CryKiller3

  19. Offline

    w84u2cy

    Thanks!
    That fixed it.
    I new something about bukkit.jar but i didn't get it.
     
  20. Offline

    CeramicTitan Retired Staff

    I never said they would, I wasn't quite sure why it was deprecated, I sent you the link to inform you not to prove you wrong. I probably quoted the wrong post
     
  21. Offline

    w84u2cy

    Hi,
    Do you know how i'd spread the soup over the inventory?
     
  22. Offline

    CeramicTitan Retired Staff

    You can use this method. The slot number is based on this: http://media-mcw.cursecdn.com/8/8c/Items_slot_number.JPG
    Code:java
    1. public void addSoup(int startslot, int finalslot){
    2. for(int x=startslot; x<=finalslot; x++){
    3. p.getInventory().addItem(x, Material.SOUP);
    4. }
    5. }


    so an example; if you wanted to fill every slot
    Code:java
    1. addSoup(0, 35); // Will fill every slot
     
  23. Offline

    w84u2cy

    Thanks
    I get an error when i try and replace Material.SOUP); with Material.MUSHROOM_SOUP);
    on addItem.
    also where should i put this?
     
Thread Status:
Not open for further replies.

Share This Page