I have a custom event in my bukkit/spigot plugin that extends PlayerInteractEvent which attempts to open chests in a nearby area around the player.
Currently the code uses this event to make sure that no other plugins (Grief prevention, for example) object to the player being able to open the chest. If the player can open the chest, my plugin will attempt to deposit items into the chest. I would like to ignore the setCancelled()
if it's called by a certain plugin (ideally) or class (as a work around)
From this question I can see that to get the class I can use
String callerClassName = new Exception().getStackTrace()[1].getClassName();
String calleeClassName = new Exception().getStackTrace()[0].getClassName();
To get the classnames. Alternatively I can use something around this call:
StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
However, all the comments on that question state that there is likely a better way to do it, other than what this is doing.
Does Bukkit have any better way of doing this?
For reference, this is the entirety of my custom player interact event:
public class FakePlayerInteractEvent extends PlayerInteractEvent {
public FakePlayerInteractEvent(Player player, Action rightClickBlock, ItemStack itemInHand, Block clickedBlock, BlockFace blockFace) {
super(player, rightClickBlock, itemInHand, clickedBlock, blockFace);
}
}
And the code surrounding the use of the event:
PlayerInteractEvent fakeEvent = AutomaticInventory.getInstance().new FakePlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, player.getInventory().getItemInMainHand(), block, BlockFace.UP);
Bukkit.getServer().getPluginManager().callEvent(fakeEvent);
if(!fakeEvent.isCancelled()){ ... do stuff }