Solved setDamage()

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

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

    mrbill513

    fixed.
     
  2. Offline

    _Filip

    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

    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

    mrbill513

    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. Offline

    RealDope

    Well you are only applying this damage if the person getting hit has full hp..
     
  6. Offline

    mrbill513

    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. Offline

    RealDope

    Oh yeah you're right, I misread that.
     
  8. Offline

    mrbill513

    Haha... So Any idea why it isnt doing that damage? They are pretty much that same damage with each sword.
     
  9. Offline

    RealDope

    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. Offline

    travja

    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

    mrbill513

    What do you mean by debug messages?

    And here is my OnEnable.

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

    travja

    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

    mrbill513

    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