Solved DamageCause Fall

Discussion in 'Plugin Development' started by Coolgamer54, Sep 27, 2015.

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

    Coolgamer54

    I'm obviously doing something wrong. But i can't figure it out.

    Basically i want it to send a Message to Operators saying that someone has taken fall damage.
    I also want it to make a message in the logs saying somone has taken fall damage
    It would be best if the Command sender could be the Player taking damage.

    Code:
    package me.clumsyliars;
    
    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    
    public class ClumsyListener implements Listener {
       
        public static ClumsyLiars plugin;
       
        public ClumsyListener(ClumsyLiars instance) {
            plugin = instance;
        }
    
        @EventHandler
        public void onEntityDamageEvent(EntityDamageEvent.DamageCause Fall)  {
            if (DamageCause.FALL != null){
                Bukkit.dispatchCommand(null, "helpop [ClumsyLiars] A player has taken Fall Damage");
                getLogger().info("Oh no!" Someone has taken Fall damage! );
            }
           
        }
           
    
               
       
           
           
    }
       
    
     
  2. Offline

    RoboticPlayer

    Why are you checking if DamageCause.FALL != null? That doesn't even make sense. Actually check what the type of damage was by doing if(e.getDamageCause == DamageCause.FALL) //stuff. Also, make sure that the entity being damaged is a player.
     
    0ct0berBkkitPlgins likes this.
  3. Could you show me the plugin when it's done? It sounds really funny xD
     
  4. Offline

    Zombie_Striker

    Should be
    Code:
    if(DammageCause == DamageCause.FALL)
     
  5. Offline

    Coolgamer54

    Okay, Everything works... however its not sending the helpop.
     
  6. Offline

    Zombie_Striker

    So the sender of the command is null (Sender cannot be null. Try ConsoleSender) and you are sending a command called helpop (is this an actual command?).
     
  7. Offline

    blackpoiso

    Code:
    getServer().dispatchCommand(player.getName(), command);
    Edit: Add a Player player = Fall.getPlayer()
    then the code above?
     
  8. Offline

    Coolgamer54

    Yes, Its an Essentials Command. changing it to ConsoleSender does not work

    Can you elaborate more please?

    EDIT: We just realised we are gettign this error on server startup:

    ClumsyLiars] ClumsyLiars vLiar attempted to register an invalid EventHandler method signature "public void me.clumsyliars.ClumsyListener.onEntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent$DamageCause)" in class me.clumsyliars.ClumsyListener
     
  9. Offline

    Zombie_Striker

    This is why you're getting that error. It should be "EntityDamageEvent event".
     
    blackpoiso likes this.
  10. Offline

    Coolgamer54

    That doesn't seem to be helping.
     
  11. Offline

    Coolgamer54

  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    Mexicaantjes

    Code:
    getLogger().info("Oh no!" Someone has taken Fall damage! );
    needs to be
    Code:
    getLogger().info("Oh no! Someone has taken Fall damage!");
     
  14. Offline

    Coolgamer54

    Updated Code

    Code:
    package me.clumsyliars;
    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    public class ClumsyListener implements Listener {
      
        public static ClumsyLiars plugin;
      
        public ClumsyListener(ClumsyLiars instance) {
            plugin = instance;
        }
        @EventHandler
        public void onEntityDamageEvent(EntityDamageEvent.DamageCause Fall)  {
            if (Fall == DamageCause.FALL){
                Bukkit.dispatchCommand(null, "helpop [ClumsyLiars] A player has taken Fall Damage");
                getLogger().info("Oh no! Someone has taken Fall damage!" );
            }
          
        }
          
              
      
          
          
    }
      
    
     
  15. Offline

    timtower Administrator Administrator Moderator

    @Coolgamer54 Change this
    Code:
    public void onEntityDamageEvent(EntityDamageEvent.DamageCause Fall)
    into this:
    Code:
        public void onEntityDamageEvent(EntityDamageEvent fall)
    Then check the damagecause from in there.
     
    Coolgamer54 likes this.
  16. Offline

    DoggyCode™

    If you actually want to have the quotation marks inside the actual message, you can use "\" to notify Java that it's a special character (that Java uses) but you want it to be treated like a normal character. So:
    Code:
    getLogger().info("\"Oh no!\" Someone has taken Fall damage!");
    That should work!
     
  17. Offline

    Coolgamer54

    The issue is not the Logger. Its obviously not my main focus.

    Current issue is its not sending a message. Its meant to send to operators in the first place. Here is the updated code.
    Only One of the Two "then" statements need to work but i don't think getting helpop to work is possible.
    Code:
        @EventHandler
        public void onEntityDamageEvent(EntityDamageEvent Fall)  {
            if (Fall.getCause() == DamageCause.FALL){
                Bukkit.getOperators()).sendMessage("Fall damage sucks");
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "helpop [ClumsyLiars] A player has taken Fall Damage");
            }
        
        }
     
  18. Offline

    RoboticPlayer

    Is the event actually being fired? Check if it is by adding debug messages.
     
    dlange likes this.
  19. Offline

    dlange

    @Coolgamer54 Try this?
    Code:
    if (Fall.getEntity() instanceof Player) {
        Bukkit.dispatchCommand((Player) Fall.getEntity(), "helpop [ClumsyLiars] A player has taken Fall Damage");
    }
    Add the player check near the start, otherwise it will call it whenever an ENTITY takes fall damage, that includes zombies, skeletons etc
     
  20. Offline

    Coolgamer54

    Updated, Not sending the Message.
    LISTENER
    Code:
    package me.clumsyliars;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    
    public class ClumsyListener implements Listener {
        public static ClumsyLiars plugin;
        public ClumsyListener(ClumsyLiars instance) {
            plugin = instance;
        }
       
        @EventHandler
        public void onEntityDamageEvent(EntityDamageEvent Fall)  {
            if (Fall.getEntity() instanceof Player){
                if (Fall.getCause() == DamageCause.FALL){
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "helpop [ClumsyLiars] A player has taken Fall Damage");
                }
            }
        }
        
            
        
        
    }
    Base Class

    Code:
    package me.clumsyliars;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ClumsyLiars extends JavaPlugin {
        public static ClumsyLiars plugin;
       
        public void onEnable() {
            getLogger().info("The Clumsy Liars plugin, Created by Zac Dunn, Has been Activated");
        }
       
        public void onDisable() {
            getLogger().info("The Clumsy Liars plugin, Created by Zac Dunn, Has been Disabled");
        }
    
    }
    
     
  21. Offline

    RoboticPlayer

    A) Why are you adding a constructor to your Listener class when you aren't using it?
    B) No need for enable/disable messages, Bukkit already does this
    C) onEnable and onDisable can be overridden
    D) Here is your actual issue: You aren't registering your events
     
    Konato_K likes this.
  22. Offline

    Coolgamer54

    Base Class is the same, Updated listener.

    STILL not sending message

    Code:
    package me.clumsyliars;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    
    public class ClumsyListener implements Listener {
        public static ClumsyLiars plugin;
        public ClumsyListener(ClumsyLiars plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
        @EventHandler
        public void onEntityDamageEvent(EntityDamageEvent Fall)  {
            if (Fall.getEntity() instanceof Player){
                if (Fall.getCause() == DamageCause.FALL){
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "helpop [ClumsyLiars] A player has taken Fall Damage");
                }
            }
        }
        
            
        
        
    }
     
  23. Offline

    DeJay007

    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e) {
           
            Entity entity = e.getEntity();
            EntityDamageEvent ldc = entity.getLastDamageCause();
            DamageCause dc = ldc.getCause();
            String p = e.getEntity().getPlayer().getName();
        if (entity instanceof Player && dc == DamageCause.FALL) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "helpop [ClumsyLiars] A player has taken Fall Damage");
            }
            
     
  24. Offline

    boomboompower

    You do realise, you are using EntityDeathEvent. He wants the event to be fired when the player takes fall damage not from how they died xD
     
  25. Offline

    DeJay007

    It can always be edited :p
     
  26. Offline

    Coolgamer54

    New Listenenr. Still. Not. Sending. Message ;-;

    Code:
    package me.clumsyliars;
    
    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    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.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    
    public class ClumsyListener implements Listener {
        public static ClumsyLiars plugin;
        public ClumsyListener(ClumsyLiars plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
    
       
        @EventHandler
        public void onEntityDamageEvent(EntityDamageEvent e) {
          
            Entity entity = e.getEntity();
            EntityDamageEvent ldc = entity.getLastDamageCause();
            DamageCause dc = ldc.getCause();
        if (entity instanceof Player && dc == DamageCause.FALL) {
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "helpop [ClumsyLiars] A player has taken Fall Damage" + entity.getFallDistance());
            }
        }
    }
     
  27. Offline

    boomboompower

    @Coolgamer54 you put the
    Code:
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    in the onEnable method.
     
  28. Offline

    timtower Administrator Administrator Moderator

    @boomboompower It doesn't matter where it stands, as long as it gets called somewhere.
     
    Konato_K likes this.
  29. Offline

    RoboticPlayer

    Is it proper for him to define the plugin field as public static? Whenever I use a constructor like that I do something like this:
    Code:
    private ClumsyLiars plugin;
    public ClumsyListener(ClumsyLiars plugin) {
        this.plugin = plugin;
    }
    However, @Coolgamer54 why are you adding a constructor if you aren't using it?
     
  30. Offline

    timtower Administrator Administrator Moderator

    @henderry2019 He is using the constructor, he is calling the registerEvents from it.
    And static is a bad practice.
     
Thread Status:
Not open for further replies.

Share This Page