Solved setDamage()

Discussion in 'Plugin Development' started by mrbill513, Feb 10, 2013.

  1. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    fixed.

    This post has been edited 2 times. It was last edited by mrbill513 Feb 11, 2013.
  2. Offline

    TheSpherret

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    First of all, when you do an if you have to put open and close brackets...
    Second, to cancel an event you have to issue e.setCancelled(true);
    Third, why would you want to only damage the other player if their health is 20?
    Fourth, why would you do a.getPlayer() when you already set a as a player type?


    Code:
    @EventHandler
      public void onEntityDamage(EntityDamageByEntityEvent e)
      {
          if(e.getEntity() instanceof Player && e.getDamager() instanceof Player){
              Player v = (Player)e.getEntity();
              Player a = (Player)e.getDamager();
         
              if(a.getHealth() == 20 && a.getInventory().getItemInHand().equals(Material.DIAMOND_SWORD)){
                  v.setHealth(16);
                  e.setCancelled(true);
              }
         
              if(a.getHealth() == 20 && a.getInventory().getItemInHand().equals(Material.IRON_SWORD)){
                  v.setHealth(13);
                  e.setCancelled(true);
                  return
              }
         
              if(a.getHealth() == 20 && a.getInventory().getItemInHand().equals(Material.STONE_SWORD)){
                      v.setHealth(8);
                      e.setCancelled(true)
                      return;
                     
               
              }
     
          }
      }    
  3. Offline

    RealDope

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Well that was a very condescending tone for a bunch of false answers:
    First: No, you don't have to add brackets. If there are no brackets, Java will assume that only the next line of code should be executed conditionally.
    Second: He wasn't trying to cancel the event, he was checking if it was cancelled.
    Third: He can do whatever he wants
    Fourth: Valid point.

    Learn your stuff before you try to be an ass to others.

    This post has been edited 1 time. It was last edited by RealDope Feb 10, 2013.
    Cirno and mastermustard like this.
  4. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @swampshark19 Everytime you would hit the person with lets say the stone it would set there health to like 3.5 hearts. If i think right it will just keep setting there health there so they wouldnt die?

    EDIT: I just tested it.. It seemed that hte highest it went was 5 hearts

    This post has been edited 1 time. It was last edited by mrbill513 Feb 10, 2013.
  5. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I dont get why it doesnt work, Is it possiable?
  6. Offline

    RealDope

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Well you are only applying this damage if the person getting hit has full hp..
  7. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I am? I thought it was if the damager has full hp.


    a is the damager and a.getHealth wouldnt that get the damgers health?

    This post has been edited 1 time. It was last edited by mrbill513 Feb 10, 2013.
  8. Offline

    RealDope

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Oh yeah you're right, I misread that.
  9. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Haha... So Any idea why it isnt doing that damage? They are pretty much that same damage with each sword.
  10. Offline

    RealDope

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Are you sure that the event is actually firing? Add debug messages within all conditional statements and right at the top of the event.
    Did you register your events?
  11. Offline

    travja

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Did you make sure your event is registered?
    EDIT: @RealDope darn, ninja'd.... Had it ready but was making sure no one already asked the question

    This post has been edited 1 time. It was last edited by travja Feb 10, 2013.
  12. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    What do you mean by debug messages?

    And here is my OnEnable.

    Code:
    public void onEnable() {
    Bukkit.getPluginManager().registerEvents(this, this);
    }

    This post has been edited 2 times. It was last edited by mrbill513 Feb 10, 2013.
  13. Offline

    travja

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Is the event in the same class as the onEnable? Also, in the beginning of the command use like p.sendMessage("Ran event")
  14. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yea Its in the same class. Let me go test the message
  15. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ok its send message when i just hit the player.

    This post has been edited 1 time. It was last edited by mrbill513 Feb 10, 2013.
  16. Offline

    mrbill513

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Got it working thanks @travja for the help!

Share This Page