How to get what plugin is cancelling an event?

Discussion in 'Plugin Development' started by joehot2000, May 12, 2013.

  1. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hi, how do i get which plugin has cancelled an event? (would obviously be using EventPriority.MONITOR)
  2. Offline

    CubieX

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I don't think that this is possible.
    You can un-cancel the event, if your listener has a higher priority than the listener of the plugin which cancelled it.
    But find out which plugin cancelled it in the first place.... idk.

    Why do you need this informaton?
  3. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I need to uncancel an event, but only if a certain plugin is cancelling it.
    It is the EntityDamageByEntity event, so i obviously cant be uncancelling it in faction safezone, etc
  4. Offline

    CubieX

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hm. Then you need to determine if your conditions are met within that plugin.
    Can you explain a bit, when exactly you need to cancel it and when not to?
    What are the conditions?
  5. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    What i want my plugin to do:

    1. Stop people from running in safezone.

    2. Fix an error where some unknown plugin is wrongly cancelling the event.

    To do this i want to:
    Uncancel the event if its not cancelled by factions.

    Add them to an array and add a delayed task to remove them from it.

    Make it so they can be damaged anywhere if they are in the array.

    So, i mainly need to know due to the damage glitch (Note that the EntityDamageByEntityEvent is called, but is cancelled, by some unknown plugin).
  6. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Problem then is, i also want to make it so people who are in the same faction dant damage each other also.
  7. Offline

    Comphenix

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    It is possible to determine this by hacking into the event's HandlerList (proxy each registered listener's EventExecutor), but I'd recommend against it ...

    In any case, here's how it works:
    Code:java
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. private CancellationDetector<BlockPlaceEvent> detector = new CancellationDetector<BlockPlaceEvent>(BlockPlaceEvent.class);
    3.  
    4. @Override
    5. public void onEnable() {
    6. getServer().getPluginManager().registerEvents(this, this);
    7.  
    8. detector.addListener(new CancelListener<BlockPlaceEvent>() {
    9. @Override
    10. public void onCancelled(Plugin plugin, BlockPlaceEvent event) {
    11. System.out.println(event + " cancelled by " + plugin);
    12. }
    13. });
    14. }
    15.  
    16. @Override
    17. public void onDisable() {
    18. // Incredibly important!
    19. detector.close();
    20. }
    21.  
    22. // For testing
    23. @EventHandler
    24. public void onBlockPlaceEvent(BlockPlaceEvent e) {
    25. e.setCancelled(true);
    26. }
    27. }

    CancellationDetector can be downloaded here (full gist).
    chasechocolate likes this.
  8. Offline

    CubieX

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    That was not what I meant...
    Do you know in which circumstances the damageEvent should be canceled for a player?
    Where does he need to be, or what must be happened to him, so you decide to uncancel it?

    You said: "Uncancel the event if its not cancelled by factions."
    And also: " i obviously cant be uncancelling it in faction safezone"

    I don't know a way to say which plugin cancels the event.
    And as long as nobody else comes up with a solution, your only chance is to check,
    if your conditions to un-cancel it are met from your own plugin.
    That's why I'm asking what the conditions for this are.

    So basicly, you need to know if a player is outside a factions safezone?
    If he is, you un-cancel the event, right?

    So you have to hook into the factions plugin (it has no real API though) to get those information.
    A little bit of using google gave me this.
    Seems to be exactly what you want.

    ---
    If you don't know how to hook to factions, a start could be this thread. Source.
    Here is some example how to use Faction methods, after you imported the path.

    Basicly you import the factions.jar, import the path "com.massivecraft.factions" or whatever sub-package is needed (ecplise should help you here, as soon as you use a faction method)
    and access the needed methods the same way you do it with bukkit.

    This post has been edited 1 time. It was last edited by CubieX May 12, 2013.
  9. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    :confused: Just awesome! Going to try it out now! Thanks!! :)
  10. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @CubieX I have found no way to get what faction a player is in :(
  11. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    The plugin ESSENTIALS was causing my damage glitch! Damn you essentials xD
  12. Offline

    Comphenix

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    No problem. Oh, and I forgot to mention - you can uncancel the event directly in onCancelled().

    But interacting with Factions directly might be a better method overall.
  13. Offline

    CubieX

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    The problem was not really the un-cancelling. Problem was to know when he has to un-cancel it. ;)
    But seems the problem has just vanished into thin air. :D
    Comphenix likes this.
  14. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I have fixed the damage glitch - this means that now i do not need to know when to uncancel it because the event will always occour - n0t cancelled. I can then add to the arrayList so they can be damaged in safezone normally :).

    Thanks for your help :D.
  15. Offline

    joehot2000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    The cancel code is causing a lot of plugins to error :confused:

    at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    12:26:30 [SEVERE] Could not pass event EntityDamageEvent to Factions v1.6.9.3
    java.lang.ClassCastException: org.bukkit.event.entity.EntityDamageEvent cannot be cast to org.bukkit.event.entity.EntityDamageByEntityEvent
    at com.gmail.joehot200.AntiHack.Main$2.onCancelled(Main.java:1)
    at com.gmail.joehot200.AntiHack.CancellationDetector.invokeCancelled(CancellationDetector.java:118)
    at com.gmail.joehot200.AntiHack.CancellationDetector.access$2(CancellationDetector.java:116)
    at com.gmail.joehot200.AntiHack.CancellationDetector$2.callEvent(CancellationDetector.java:107)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:479)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:464)
    at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:89)
    at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:377)
    at net.minecraft.server.v1_5_R3.EntityLiving.a(EntityLiving.java:963)
    at net.minecraft.server.v1_5_R3.EntityHuman.a(EntityHuman.java:1295)
    at net.minecraft.server.v1_5_R3.Entity.a(Entity.java:788)
    at net.minecraft.server.v1_5_R3.EntityLiving.a(EntityLiving.java:243)
    at net.minecraft.server.v1_5_R3.EntityPlayer.b(EntityPlayer.java:464)
    at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:424)
    at net.minecraft.server.v1_5_R3.Packet10Flying.handle(SourceFile:136)
    at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:186)
    at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:109)
    at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
    at org.spigotmc.MultiplexingServerConnection.b(MultiplexingServerConnection.java:72)
    at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:583)
    at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:472)
    at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:404)
    at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    12:26:30 [SEVERE] Could not pass event EntityDamageByEntityEvent to AntiHack v1.1

Share This Page