Solved setDamage()

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

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


  2. 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?

      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)){
              if(a.getHealth() == 20 && a.getInventory().getItemInHand().equals(Material.IRON_SWORD)){
              if(a.getHealth() == 20 && a.getInventory().getItemInHand().equals(Material.STONE_SWORD)){
  3. 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.
    Cirno and mastermustard like this.
  4. Offline


    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

    I dont get why it doesnt work, Is it possiable?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
  5. Well you are only applying this damage if the person getting hit has full hp..
  6. Offline


    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?
  7. Oh yeah you're right, I misread that.
  8. Offline


    Haha... So Any idea why it isnt doing that damage? They are pretty much that same damage with each sword.
  9. 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?
  10. 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
  11. Offline


    What do you mean by debug messages?

    And here is my OnEnable.

    public void onEnable() {
    Bukkit.getPluginManager().registerEvents(this, this);
  12. Is the event in the same class as the onEnable? Also, in the beginning of the command use like p.sendMessage("Ran event")
  13. Offline


    Yea Its in the same class. Let me go test the message

    Ok its send message when i just hit the player.

    Got it working thanks travja for the help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page