我在我的bukkit/spigot插件中有一個自定義事件,它擴展了PlayerInteractEvent,它嘗試在玩家周圍的附近地區打開箱子。如何查看bukkit插件中名爲setCancelled()的類/插件?
當前代碼使用此事件來確保沒有其他插件(例如,悲傷預防)反對玩家能夠打開胸部。如果玩家可以打開胸部,我的插件會嘗試將物品放入胸部。我想忽略setCancelled()
如果它是由一定的插件(理想情況下)或者類中調用(作爲變通)
從this question我可以看到,獲得I類可以使用
String callerClassName = new Exception().getStackTrace()[1].getClassName();
String calleeClassName = new Exception().getStackTrace()[0].getClassName();
要獲取類名。或者我可以用的東西圍繞這一呼籲:對這個問題的狀態很可能有更好的方法來做到這一點比什麼,這是做其他
StackTraceElement[] stElements = Thread.currentThread().getStackTrace();
然而,所有的意見。
Bukkit有沒有更好的方法來做到這一點?
供參考,這是我的自定義播放器交互事件的全部:
public class FakePlayerInteractEvent extends PlayerInteractEvent {
public FakePlayerInteractEvent(Player player, Action rightClickBlock, ItemStack itemInHand, Block clickedBlock, BlockFace blockFace) {
super(player, rightClickBlock, itemInHand, clickedBlock, blockFace);
}
}
和周圍使用事件的代碼:
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 }
是的,有一個更好的解決方案。只要我檢查了一些事情,我會盡快發佈更多細節。 – Frelling