Plugin Issue

Discussion in 'Plugin Development' started by thegarfish, Aug 24, 2013.

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

    thegarfish

    Hey guys, I have spent the last few hours of my life by starting the coding of a KitPvP plugin. It took me awhile to sort out my souping issues but I have one final bug I can not squash.

    Whenever a player instantly eats the soup it should turn into an empty bowl, right?

    Well thats where my issue is.

    Code:
          @EventHandler
            public void onPlayerInteract(PlayerInteractEvent event1){
                if (event1.getAction() == Action.RIGHT_CLICK_AIR || event1.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    Player player = event1.getPlayer();
                    if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP);
                    player.setHealth(player.getHealth() + Math.min(3, player.getMaxHealth()-player.getHealth()));
                    ItemStack bowl = new ItemStack(Material.BOWL, 1);
                    player.getInventory().setItemInHand(bowl);
     
  2. Offline

    Deleted user

    thegarfish

    It's really weird...I have the same issue...It works with left click though :p
     
  3. Offline

    epicfacecreeper

    thegarfish What is the issue exactly? You should probably cancel the event.
     
  4. Offline

    kreashenz

    You need to cancel the event to make it stop drinking, and then you set it.
     
  5. Offline

    thegarfish

    How would I cancel the event?

    epicfacecreeper When the player drinks the soup the soup doesn't turn into a bowl, rather it keeps the soup.
     
  6. Offline

    Kjordo711

  7. Offline

    Rockett8855

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent event1){
    4. if (event1.getAction() == Action.RIGHT_CLICK_AIR || event1.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. Player player = event1.getPlayer();
    6. if (player.getItemInHand().getType() == Material.MUSHROOM_SOUP) {
    7. if (player.getHealth() == 20)
    8. return;
    9.  
    10.  
    11. event.setCancelled(true);
    12. player.setHealth(player.getHealth() > 14 ? 20 : player.getHealth() + 6);
    13. player.getItemInHand().setType(Material.BOWL);
    14. }
    15.  
    16.  


    That's my soup plugin, heals 3 hearts at a time.
     
Thread Status:
Not open for further replies.

Share This Page