[Help] Instant-Soup

Discussion in 'Plugin Development' started by JollyGiant16, Feb 11, 2013.

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

    JollyGiant16

    Hello,

    I'm making a Kit-Pvp plugin and I was wondering how would I make a instant-soup that gives 3 hearts. - I DO NOT WANT TO GET A PLUGIN I WANNA ADD IT ONTO MY PLUGIN
     
  2. Offline

    ZeusAllMighty11

    interact listener, check if item in hand is soup, apply health accordingly
     
  3. Offline

    JollyGiant16

    @EventHandler
    public void onPlayerHand(PlayerHandEvent event){
    Player player = event.getPlayer()
    event.getPlayer().getInventory().getInHand();
    ?????? How would I check if he had soup
    event.getPlayer().setHeatlh(3);
     
  4. Offline

    Lonesface

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent event) {
    4. if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. Player player = event.getPlayer();
    6. if (player.getItemInHand().getType == Material.MUSHROOM_SOUP)
    7. player.setHealth(player.getHealth()+3);
    8. }
    9. }
    10.  


    You seem to be making quite a lot of help threads lately :confused:
     
  5. Offline

    JollyGiant16

    Lonesface

    Code:
    package me.anonymous350.AutoSoup;
     
    import java.util.logging.Logger;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
        public class AutoSoup extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static AutoSoup plugin;
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Has Been Disabled!");
           
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
           
        }
       
      @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Player player = event.getPlayer();
        if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP)
        player.setHealth(player.getHealth()+3);
        }
     
      }
    }
    Dosn't work...
     
  6. Offline

    Lonesface

  7. Offline

    JollyGiant16

    Lonesface

    Works but "When I right click with the soup I get 3 hearts but the soup doesn't dispear as in to a bowl."
     
  8. You must also change the item type in player's hand to Material.BOWL.
    I'm not sure if soup is stackable, if it is it would be a bit more complicated, would require to remove 1 amount from soup stack and add a bowl to user instead... all that if only player has more than 1 soup.
     
  9. Offline

    Lonesface

    Code:java
    1.  
    2. int a = player.getItemInHand().getAmount();
    3. if (a > 1) {
    4. player.getItemInHand().setAmount(a-1);
    5. if (player.getInventory().firstEmpty() > 0)
    6. player.getInventory().addItem(Material.BOWL,1);
    7. } else {
    8. player.getItemInHand().setType(Material.BOWL);
    9. }
    10.  

    I think you need to learn Java and the Bukkit API a bit before attempting to make a plugin like this. Every help thread you've made seems to point to a PvP plugin that goes back to 1.7- gameplay mechanics.
     
  10. Lonesface
    You forgot to add bowl when you subtract amount :p
     
  11. Offline

    JollyGiant16

    Lonesface

    Also Instead of making a new JavaPlugin can I just make a new class add that? Link it with the main class?
     
  12. Offline

    Tirelessly

    Yes, that's what you're supposed to do. Read the tutorial. You appear to be clueless.
     
  13. Offline

    Lonesface

    Aha, my music got the better of me. Fixed.
     
  14. Offline

    JollyGiant16

    Tirelessly, I'm sorry when I tried to link them It didn't work. You don't have to be like that.

    @ Lonesface

    I believe this should work?

    Code:
    public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Player player = event.getPlayer();
        if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP)
        player.setHealth(player.getHealth()+3);
        int a = player.getItemInHand().getAmount();
        if (a > 1) {
            player.getItemInHand().setAmount(a-1);
        } else {
            player.getItemInHand().setType(Material.BOWL);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  15. Offline

    Lonesface

  16. Offline

    JollyGiant16

    I seem to get an error with .addItem
     
  17. Offline

    Lonesface

    JollyGiant16 oops. Use player.getInventory().addItem(new ItemStack(Material.BOWL,1);
     
  18. Offline

    JollyGiant16

    Can you give me link or something on how to link different classes?
     
  19. Offline

    Lonesface

    JollyGiant16 I suggest you take some java tutorials, or take a look at other plugin's code (don't copy-paste it, but rather check through everything and try to understand what each thing does).
     
Thread Status:
Not open for further replies.

Share This Page