Solved DamageCause Fall

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

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

    DoggyCode™

    Btw, instead of using the dispatch command to do that stuff, just loop through all online players, check if they have a specific permission node, then send them a message. This way the helpop command wouldn't be NEEDED (if plugin which uses that command decides to remove/edit it).
     
  2. Offline

    Coolgamer54

    IF you wanna help me throught that go ahead, but i'm making this plugin for a certain server and i know what they have
     
  3. Offline

    DoggyCode™

    I still wouldn't rely on a command, here, do this:
    Code:
    for(Player players : Bukkit.getServer().getOnlinePlayers()){ //looping through all online players
    if(players.hasPermission("myplugin.mypermissions...") || players.isOp()){ //if online players do t have this permission, they will not receive the message
    players.sendMessage(ChatColor.GRAY+"ALERT:"+ChatColor.RESET+String); //the message that would have been sent in Helpop. I put Alert since that suits the Helpop better.
    getLogger().info(String); //this method doesn't log the message in console, so you would have to do it manually which this piece is for
    
    This way your plugin wouldn't depend on Helpop IF it were to change in the future, instead, the plugin handles that message.
     
  4. Offline

    boomboompower

    @DoggyCode™
    Or they could wait for the new SCA Version which has the option to change what the alert message looks like xD (This is a joke, even though this feature is real).
    --------------------------------------------------------------------------------------​
    @Coolgamer54 You should use DoggyCode's code. (The Irony). It should work. Just as long as you define what String is (If you haven't already).
     
  5. Code:
    Bukkit.broadcast(alter, permission);
    
     
    Konato_K likes this.
  6. Offline

    DoggyCode™

    I know, but in that case any Op wouldn't receive the message (which the Helpop does).
     
  7. If you have plugins like PermissionsEx you wouldn't.

    "Broadcasts the specified message to every user with the given permission name."
     
  8. Offline

    Coolgamer54

    Thanks for the code @DoggyCode™ however i am going to wait to add that in until i know the plugin is working, and currently, it doesn't seem to be working.
     
  9. Offline

    Scimiguy

    His code could be fixing a problem you're having with helpop.

    Try replacing your helpop dispatch with his direct loop and see if it's any different
     
  10. Offline

    Coolgamer54

    Still nope

    Code:
    package me.clumsyliars;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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) {
                for(Player players : Bukkit.getServer().getOnlinePlayers()){ //looping through all online players
                    if(players.hasPermission("clumsyliars.donegoofed") || players.isOp()){ //if online players do t have this permission, they will not receive the message
                        players.sendMessage(ChatColor.GRAY + "ALERT:" + ChatColor.RESET); //the message that would have been sent in Helpop. I put Alert since that suits the Helpop better.       
                    }
                }
            }
        }
    }
     
  11. Offline

    RoboticPlayer

    Why are you using LastDamageCause? Try doing
    Code:
    if (e.getDamgeCause == DamageCause.FALL) {
    }
    And personally, I like to use not checks, it makes the code cleaner. For example, instead of
    Code:
    if(e.getEntity instanceof Player) {
    // Your code
    }
    Do
    Code:
    if(!(e.getEntity instanceof Player)) return;
    I just prefer not to have all of my code within lots of methods.
    Also, since you are only calling a variable once, why bother declaring it? You are adding code that is unnecessary.
     
    boomboompower likes this.
  12. Offline

    Coolgamer54

    Code:
    package me.clumsyliars;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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 (e.getCause() == DamageCause.FALL) {
                if (e.getEntity() instanceof Player){
                    for(Player players : Bukkit.getServer().getOnlinePlayers()){ //looping through all online players
                        if(players.hasPermission("clumsyliars.donegoofed") || players.isOp()){ //if online players do t have this permission, they will not receive the message
                            players.sendMessage(ChatColor.GRAY + "ALERT:" + ChatColor.RESET); //the message that would have been sent in Helpop. I put Alert since that suits the Helpop better.       
                        }
                    }
                }
            }
        }
    }
    I cri evy tim.
    (its not workking)
     
  13. Offline

    Zombie_Striker

    A) Why is the plugin field static? Also, why is it never set to anything
    B) You have to variables that both have the same name. That can't be good.
    C) You commented out those fields in the onEntityDamageEvent. Remove them since they are not needed.
    D) Instead of using Bukkit.getServer(), you can use plugin.getServer()
     
  14. Offline

    Coolgamer54

    Would that really be the reason its not sending the message?
     
  15. Offline

    Zombie_Striker

    @Coolgamer54
    For Point :
    A), Yes. This effects point B because...
    B), Yes, If you have two fields that are named the same thing, the computer might not know which one you are referring to (Does plugin mean the one in the parameters or the static field?) If it confuses the parameter field with the static field, the static field is null and as such would throw a null pointer exception.
    C), No, This is just for the people reading your code.
    D), No, it doesn't make a difference. Just something I would do.

    [Edit] related:
     
    boomboompower likes this.
  16. Offline

    RoboticPlayer

    B is not exactly true. This line:
    Code:java
    1. public static ClumsyLiars plugin;

    is declaring a field. However, this method:
    Code:java
    1. public ClumsyListener(ClumsyLiars plugin) {
    2. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    3. }

    Is using a parameter called plugin. Since they are named the same thing, the plugin field is accessed by using
    Code:java
    1. this.plugin.(whatever)

    So technically, @Coolgamer54 You are never using the plugin field, so it is being uselessly declared. However, I find it very strange to register your events like that in the first place. Try registering your events in your onEnable and see if that changes anything.

    Also, what is CURRENTLY happening when a player takes fall damage with the plugin enabled? Does anything happen? Is there a stacktrace? Does the plugin not load? What happens as of now?[/code]
     
  17. Offline

    Coolgamer54

    Currently what is happening, When i, Being operator, therefore i have all permissions (unless something changed), Take fall damage. Nothing happens. The plugin enables properly, if i do /plugins it shows my plugin along the list of plugins. Just nothing happens at all when i take fall damage as if nothing was ment to happen other then me take damage in the first place.
     
  18. Offline

    RoboticPlayer

    @Coolgamer54 Tahg me next time. Can I see your most updated code?
     
  19. Offline

    Konato_K

    If your base class is still this then you're not making an instance of your Listener (then the constructor is never called).

     
  20. Offline

    Coolgamer54

    @henderry2019 Here you go

    Bass Class
    Code:
    package me.clumsyliars;
    
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ClumsyLiars extends JavaPlugin {
        public static ClumsyLiars plugin;
        public final ClumsyListener bl = new ClumsyListener(this);
       
        public void onEnable(){
            getLogger().info("The Clumsy Liars plugin, Created by Zac Dunn, Has been activated");
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(bl, this);
        }
       
    
    
       
       
        public void onDisable(){
            getLogger().info("The Clumsy Liars plugin, Created by Zac Dunn, Has been disabled");
        }
    }
    
    Listener
    Code:
    package me.clumsyliars;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    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 (e.getCause() == DamageCause.FALL) {
                if (e.getEntity() instanceof Player){
                    for(Player players : Bukkit.getServer().getOnlinePlayers()){ //looping through all online players
                        if(players.hasPermission("clumsyliars.donegoofed") || players.isOp()){ //if online players do t have this permission, they will not receive the message
                            players.sendMessage(ChatColor.GRAY + "ALERT:" + ChatColor.RESET); //the message that would have been sent in Helpop. I put Alert since that suits the Helpop better.     
                        }
                    }
                }
            }
        }
    }
     
  21. Offline

    RoboticPlayer

    Try registering your events the "normal" way and get back to me.
     
  22. Offline

    Coolgamer54

  23. Offline

    RoboticPlayer

    In your onEnable method, put this line:
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(new ClumsyListener(), this);

    Then in your ClumsyListener class, remove this:
    Code:Java
    1. public static ClumsyLiars plugin;
    2. public ClumsyListener(ClumsyLiars plugin) {
    3. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    4. }
     
    boomboompower likes this.
  24. Offline

    Coolgamer54

    Sorry for the late Response! School got ahead of me here.

    Before i put in what you said @henderry2019 Me and my testers realised there is an error in concole!


    [21:33:01] [Server thread/ERROR]: Could not load 'plugins\ClumsyLiars.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register me.clumsyliars.ClumsyListener@170b850 while not enabled
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugins(CraftServer.java:357) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at org.bukkit.craftbukkit.v1_7_R3.CraftServer.<init>(CraftServer.java:319) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at net.minecraft.server.v1_7_R3.PlayerList.<init>(PlayerList.java:68) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at net.minecraft.server.v1_7_R3.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    Caused by: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register me.clumsyliars.ClumsyListener@170b850 while not enabled
    at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginManager.java:523) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at me.clumsyliars.ClumsyListener.<init>(ClumsyListener.java:12) ~[?:?]
    at me.clumsyliars.ClumsyLiars.<init>(ClumsyLiars.java:8) ~[?:?]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_60]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_60]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_60]
    at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_60]
    at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_60]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-64-g3012211-b3076jnks]
    ... 9 more
    [21:33:02] [Server thread/INFO]: [NoMetarino] Loading NoMetarino vNoMeta
     
  25. Offline

    Scimiguy

  26. Offline

    Coolgamer54

  27. Offline

    Zombie_Striker

    @Coolgamer54
    Does this path mean anything to you?
     
  28. Offline

    Coolgamer54

  29. Offline

    Zombie_Striker

    @Coolgamer54
    Wow, didn't think this thread was still alive.

    It should:
    equaling me.clumsyliars.ClumsyListener

    You are registering that command BEFORE the plugin was enabled. Try delaying registering that listener .

    [EDIT]
    I think you got those two mixed up. It should be (this,bl);
     
  30. Offline

    Coolgamer54

    Its working now! Thank you everyone for your help
     
Thread Status:
Not open for further replies.

Share This Page