How to get what plugin is cancelling an event?

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

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


    Hi, how do i get which plugin has cancelled an event? (would obviously be using EventPriority.MONITOR)
  2. Offline


    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


    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


    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


    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).

    Problem then is, i also want to make it so people who are in the same faction dant damage each other also.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 1, 2016
  6. Offline


    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:
    1. public class ExampleMod extends JavaPlugin implements Listener {
    2. private CancellationDetector<BlockPlaceEvent> detector = new CancellationDetector<BlockPlaceEvent>(BlockPlaceEvent.class);
    4. @Override
    5. public void onEnable() {
    6. getServer().getPluginManager().registerEvents(this, this);
    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. }
    16. @Override
    17. public void onDisable() {
    18. // Incredibly important!
    19. detector.close();
    20. }
    22. // For testing
    23. @EventHandler
    24. public void onBlockPlaceEvent(BlockPlaceEvent e) {
    25. e.setCancelled(true);
    26. }
    27. }

    CancellationDetector can be downloaded here (full gist).
    cnaude and chasechocolate like this.
  7. Offline


    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.
  8. Offline


    :confused: Just awesome! Going to try it out now! Thanks!! :)

    CubieX I have found no way to get what faction a player is in :(

    The plugin ESSENTIALS was causing my damage glitch! Damn you essentials xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 1, 2016
  9. Offline


    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.
  10. Offline


    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.
  11. Offline


    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.

    The cancel code is causing a lot of plugins to error :confused:

    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 org.bukkit.plugin.SimplePluginManager.fireEvent(
    at org.bukkit.plugin.SimplePluginManager.callEvent(
    at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEvent(
    at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callEntityDamageEvent(
    at net.minecraft.server.v1_5_R3.EntityLiving.a(
    at net.minecraft.server.v1_5_R3.EntityHuman.a(
    at net.minecraft.server.v1_5_R3.Entity.a(
    at net.minecraft.server.v1_5_R3.EntityLiving.a(
    at net.minecraft.server.v1_5_R3.EntityPlayer.b(
    at net.minecraft.server.v1_5_R3.PlayerConnection.a(
    at net.minecraft.server.v1_5_R3.Packet10Flying.handle(SourceFile:136)
    at org.spigotmc.netty.NettyNetworkManager.b(
    at net.minecraft.server.v1_5_R3.PlayerConnection.d(
    at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
    at org.spigotmc.MultiplexingServerConnection.b(
    at net.minecraft.server.v1_5_R3.MinecraftServer.r(
    at net.minecraft.server.v1_5_R3.DedicatedServer.r(
    at net.minecraft.server.v1_5_R3.MinecraftServer.q(
    12:26:30 [SEVERE] Could not pass event EntityDamageByEntityEvent to AntiHack v1.1

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page