From 0db463378bfaa0ceb7ebc0e5b4c76df456b28836 Mon Sep 17 00:00:00 2001 From: Esophose Date: Mon, 15 Apr 2019 14:33:31 -0600 Subject: [PATCH] Hook stuff, event priority stuff --- .../hooks/CurrentJobsHook.java | 2 +- .../hooks/CurrentMcMMOHook.java | 9 ++++----- .../songoda/ultimatetimber/manager/HookManager.java | 12 ++++++++++-- .../manager/TreeDefinitionManager.java | 2 +- .../ultimatetimber/manager/TreeFallManager.java | 5 ++++- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentJobsHook.java b/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentJobsHook.java index f09f432..a2442a3 100644 --- a/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentJobsHook.java +++ b/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentJobsHook.java @@ -14,7 +14,7 @@ import org.bukkit.entity.Player; public class CurrentJobsHook implements TimberHook { @Override - public void apply(Player player, TreeBlockSet treeBlocks) throws Exception { + public void apply(Player player, TreeBlockSet treeBlocks) { if (player.getGameMode().equals(GameMode.CREATIVE)) return; diff --git a/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentMcMMOHook.java b/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentMcMMOHook.java index 5b55b41..dd0e526 100644 --- a/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentMcMMOHook.java +++ b/UltimateTimber-Adapter/Current/src/main/java/com.songoda.ultimatetimber.adapter.current/hooks/CurrentMcMMOHook.java @@ -16,7 +16,7 @@ public class CurrentMcMMOHook implements TimberHook { private Enum woodcuttingEnum; private Method getXpMethod; - + public CurrentMcMMOHook() throws NoSuchMethodException, SecurityException, ClassNotFoundException { try { // Try to find mcMMO Overhaul Class primarySkillTypeClass = Class.forName("com.gmail.nossr50.datatypes.skills.PrimarySkillType"); @@ -43,17 +43,16 @@ public class CurrentMcMMOHook implements TimberHook { @Override public void apply(Player player, TreeBlockSet treeBlocks) throws Exception { - if (player.getGameMode().equals(GameMode.CREATIVE)) + if (player.getGameMode().equals(GameMode.CREATIVE)) return; - + int xp = 0; for (ITreeBlock treeBlock : treeBlocks.getLogBlocks()) { Block block = treeBlock.getBlock(); Material material = block.getType(); - if (!material.name().endsWith("LOG")) continue; xp += (int) this.getXpMethod.invoke(ExperienceConfig.getInstance(), this.woodcuttingEnum, material); } - + ExperienceAPI.addXP(player, "woodcutting", xp, "pve"); } diff --git a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java index 9c1d916..6c6fa32 100644 --- a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java +++ b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/HookManager.java @@ -1,8 +1,11 @@ package com.songoda.ultimatetimber.manager; import com.songoda.ultimatetimber.UltimateTimber; +import com.songoda.ultimatetimber.adapter.VersionAdapterType; import com.songoda.ultimatetimber.adapter.current.hooks.CurrentJobsHook; import com.songoda.ultimatetimber.adapter.current.hooks.CurrentMcMMOHook; +import com.songoda.ultimatetimber.adapter.legacy.hooks.LegacyJobsHook; +import com.songoda.ultimatetimber.adapter.legacy.hooks.LegacyMcMMOHook; import com.songoda.ultimatetimber.hook.TimberHook; import com.songoda.ultimatetimber.tree.TreeBlockSet; import org.bukkit.Bukkit; @@ -25,8 +28,13 @@ public class HookManager extends Manager { public void reload() { this.hooks.clear(); - this.tryHook("mcMMO", CurrentMcMMOHook.class); - this.tryHook("Jobs", CurrentJobsHook.class); + if (this.ultimateTimber.getVersionAdapter().getVersionAdapterType().equals(VersionAdapterType.CURRENT)) { + this.tryHook("mcMMO", CurrentMcMMOHook.class); + this.tryHook("Jobs", CurrentJobsHook.class); + } else { + this.tryHook("mcMMO", LegacyMcMMOHook.class); + this.tryHook("Jobs", LegacyJobsHook.class); + } } @Override diff --git a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java index 1fca863..4f4eac9 100644 --- a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java +++ b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeDefinitionManager.java @@ -257,7 +257,7 @@ public class TreeDefinitionManager extends Manager { } // Add to inventory or drop on ground - if (addToInventory) { + if (addToInventory && player.getWorld().equals(treeBlock.getLocation().getWorld())) { Set extraItems = new HashSet<>(); for (ItemStack lootedItem : lootedItems) extraItems.addAll(player.getInventory().addItem(lootedItem).values()); diff --git a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeFallManager.java b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeFallManager.java index cd900d5..ea0d2a6 100644 --- a/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeFallManager.java +++ b/UltimateTimber/Plugin/src/main/java/com/songoda/ultimatetimber/manager/TreeFallManager.java @@ -32,8 +32,11 @@ public class TreeFallManager extends Manager implements Listener { } - @EventHandler(priority = EventPriority.LOW) + @EventHandler(priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { + if (event.isCancelled()) + return; + TreeDefinitionManager treeDefinitionManager = this.ultimateTimber.getTreeDefinitionManager(); TreeDetectionManager treeDetectionManager = this.ultimateTimber.getTreeDetectionManager(); TreeAnimationManager treeAnimationManager = this.ultimateTimber.getTreeAnimationManager();