Solved Hit and Knockback but no Damage

Discussion in 'Plugin Development' started by TheLexoPlexx, Nov 12, 2013.

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

    TheLexoPlexx

    Hey Guys TheLexoPlexx is here,

    I am currently working on a Little TNTTag-Plugin. As you might know. In TNTTag, you can hit Players, the Players get the Knockback, but no Damage. Heres my Code:
    Code:
    package de.thelexoplexx.TnTTagMain;
     
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
     
    public class HitPlayer implements Listener {
     
        private boolean tnt = false;
     
        @EventHandler
        public void onDamage(EntityDamageByEntityEvent e0) {
            Entity p0 = e0.getEntity();
            Entity p1 = e0.getDamager();
            if (p0 instanceof Player) {
                if (p1 instanceof Player) {
     
                }
            }
        }
    }
     
  2. Offline

    thepaperboy99

    Maybe just set there health back to 20 when they get hit by a player? And then you can kill them if they get hit by an explosion.
     
    TheLexoPlexx likes this.
  3. Offline

    CraftBang

    TheLexoPlexx maybe try e0.setDamage(0); ?
    that sets damage to null
     
  4. Offline

    MrSnare

    it sets the damage to 0, not null. setDamage(null) would set it to null which would cause an error
     
  5. Offline

    CraftBang

    MrSnare lol, my bad, typed it to quickly, but I said eo.setDamage(0) so it would be zero damage, and not null...
     
    MrSnare likes this.
  6. Offline

    user_90854156

    Can't you just give the players weakness effect? :p
     
  7. Offline

    McMhz

    If you want regular knockback then try something like this:
    Code:java
    1. public void onPlayerDamage(EntityDamageByEntityEvent e){
    2. if(e.getEntity() instanceof Player){
    3.  
    4. if(e.getDamager() instanceof Player) {
    5. //Maybe do a check if he's a spectator or whatever here.
    6. e.setDamage(0.00);
    7.  
    8. }
    9. }
    10. }
     
    TheLexoPlexx likes this.
  8. Offline

    MrSnare

    needs more zeros :p
     
  9. Offline

    McMhz

    Doubles.
     
  10. Offline

    MrSnare

    '0D' or '0.0' would do. It was a joke
     
    McMhz likes this.
  11. Offline

    TheLexoPlexx

    McMhz
    Thanks Bro, thats what I wanted ;D

    MrSnare
    It throws an Error if I just type in "0" thats why I asked in this Forum ;)

    @Everybody who helped
    Thanks for Your help, solved it.

    The Code, for everybody who wants to find a solution on this Thread:
    Code:
    package de.thelexoplexx.TnTTagMain;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
     
    public class HitPlayer implements Listener {
       
        @EventHandler
        public void onPlayerDamage(EntityDamageByEntityEvent e){
            if(e.getEntity() instanceof Player){
                if(e.getDamager() instanceof Player) {
                    e.setDamage(0.00);
                }
            }
        }
    }
    @thepaperboy99
    Good Idea, but I'm gonna kill them and make an p.playExplosion() or however this is called xD I saw it one time and im gonna use this.

    How the Hell Can I mark this thread as Solved :confused:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    McMhz likes this.
  12. Offline

    mattrick

    Thread Tools at the top of the page.
     
  13. Offline

    McMhz

    Glad to help, Just PM me if you need anything else.
     
  14. Offline

    TheLexoPlexx

    @mattrik16
    thx
    fount it :p
     
  15. Offline

    jusjus112

Thread Status:
Not open for further replies.

Share This Page