Solved SetDamage..

Discussion in 'Plugin Development' started by xelatercero, Jun 13, 2016.

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

    xelatercero

    I have this move event where i want to check if the player have a pottion effect and if is true , set the damage to null, no damage

    Code:
    @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if(p.getActivePotionEffects() == PotionEffectType.JUMP) {
                //Code here...
            }
          
        }
     
  2. Offline

    Fhbgsdhkfbl

    @xelatercero
    Use EntityDamageEvent, check for the damagecause, check for the potioneffecttype, cancel it.

    Edit:
    Make sure to check the isntance of Player then the damagecause
     
  3. Offline

    xelatercero

    @Fhbgsdhkfbl but in this event i can check potioneffect type
     
  4. Offline

    Fhbgsdhkfbl

    @xelatercero

    yes I'm spoonfeeding, but you can check potioneffect in EntityDamageEvent

    Code:
    @EventHandler
        public void noFallDamage(EntityDamageEvent e) {
            if(e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL) { //Checks fall damage and if the entity is a player
                Player p = (Player) e.getEntity(); //Casting of a player
                if(p.getActivePotionEffects() == PotionEffectType.JUMP) { //gets if the player has the potioneffect type Jump
                    e.setCancelled(true); //Cancels the fall damage for the player
                }
            }
        }
     
  5. Offline

    mine-care

    @Fhbgsdhkfbl yeah better provide links to documentation or Pseudocode instead from now on...
    Yes the move event shouldn't be used unless it is absolutely needed in what case you need to make various checks for it!
     
  6. Offline

    xelatercero

    Last edited: Jun 14, 2016
  7. Offline

    mine-care

    @xelatercero That shouldnt be happening, are there any other damage listeners in your plugin or any other plugin on the server?
     
  8. Offline

    xelatercero

    @mine-care no is the unic damage listener and i only have my plugin
     
  9. Offline

    Fhbgsdhkfbl

  10. Offline

    xelatercero

    @Fhbgsdhkfbl i have registered all my events , playerinteractevent, consume event , entity damage event
     
  11. Offline

    Zombie_Striker

    @xelatercero
    You are comparing if a Collection of potions, is the same as a PotionEffectType. You need to loop through all the active potion effects, get their types, and test if the type is the same as JUMP. If so, then cancel the event.
     
    mine-care likes this.
  12. Offline

    xelatercero

    @Zombie_Striker @Fhbgsdhkfbl @mine-care This doesnt work:

    Code:
    @EventHandler
        public void noFallDamage(EntityDamageEvent e) {
            if(e.getEntity() instanceof Player && e.getCause() == DamageCause.FALL) {
                Player p = (Player) e.getEntity();
            
            Collection<PotionEffect> pot = p.getActivePotionEffects();
          
            for(PotionEffect n : pot) {
                if(n.getType() == PotionEffectType.JUMP) {
                    e.setCancelled(true);
                    break;
                }
            }
            }
        }
    
     
  13. Offline

    Lordloss

    did you try debugging? Make a message that prints out after every if-statement to see which parts of the code is reached.
     
  14. Offline

    xelatercero

    @Lordloss ok i have debuged and the code only reach to the first if the second doesnt work
     
  15. Offline

    Lordloss

    ok then, let print out what n.getType() delivers, to see why it doesnt matches PotionEffectType.JUMP
     
  16. Offline

    xelatercero

    @Lordloss i cant send a messassager , i mean p.sendMessage(n.getType()) or p.sendRawMessage(n.getType()) dont work, i have and error
     
  17. Offline

    timtower Administrator Administrator Moderator

  18. Offline

    xelatercero

    @timtower @Lordloss ok i used System print and the result is PotionEffectType[8, JUMP]

    @Lordloss @timtower I dont know what is wrong....

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Jun 16, 2016
  19. Offline

    xelatercero

    Repost Cause: Need help, anyone can help me
     
  20. Offline

    Zombie_Striker

    @xelatercero
    Check if the PotionEffectType "N"'s name is equal to JUMP's name. The method getName() returns a potioneffectType's name.
     
  21. Offline

    xelatercero

  22. Offline

    Lordloss

    Code:
     if(n.getType() == PotionEffectType.JUMP) {
    I tested it on my testserver. Replace the check with equals() and it works...
     
  23. Offline

    xelatercero

Thread Status:
Not open for further replies.

Share This Page