title: How to see what class/plugin called setCancelled() in a bukkit plugin?
body: <p>I have a custom event in my bukkit/spigot plugin that extends <a href="https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerInteractEvent.html" rel="nofollow noreferrer">PlayerInteractEvent</a> which attempts to open chests in a nearby area around the player.</p>
  
  <p>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 <code>setCancelled()</code> if it's called by a certain plugin (ideally) or class (as a work around)</p>
  
  <p>From <a href="https://stackoverflow.com/questions/11306811/how-to-get-the-caller-class-in-java">this question</a> I can see that to get the class I can use</p>
  
  <pre><code>String callerClassName = new Exception().getStackTrace()[1].getClassName();
  String calleeClassName = new Exception().getStackTrace()[0].getClassName();
  </code></pre>
  
  <p>To get the classnames. Alternatively I can use something around this call:</p>
  
  <pre><code>StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
  </code></pre>
  
  <p>However, all the comments on that question state that there is likely a better way to do it, other than what this is doing.</p>
  
  <p>Does Bukkit have any better way of doing this?</p>
  
  <p>For reference, this is the entirety of my custom player interact event:</p>
  
  <pre><code>public class FakePlayerInteractEvent extends PlayerInteractEvent {
      public FakePlayerInteractEvent(Player player, Action rightClickBlock, ItemStack itemInHand, Block clickedBlock, BlockFace blockFace) {
          super(player, rightClickBlock, itemInHand, clickedBlock, blockFace);
      }
  }
  </code></pre>
  
  <p>And the code surrounding the use of the event:</p>
  
  <pre><code>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 }
  </code></pre>