diff --git a/Changelog.txt b/Changelog.txt index a8875cb9b..3d433517b 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,6 +3,11 @@ Version 2.1.174 Updated hu_HU locale (thanks andris155) Updated ru locale (thanks imDaniX) Updated fr locale (thanks Elikill58) + (API) Added SubSkillBlockEvent for some SubSkill events that have a block (eg: Green Thumb Block events) + (API) Green Thumb (Block) now fires a SubSkillBlockEvent which is cancellable + (API) Shroom Thumb now fires a SubSkillBlockEvent which is cancellable + + NOTE: A lot of sub-skills without random chance elements are missing events, this will be cleaned up in the near future. If you need something specific added sooner than that, post a GitHub issue for it and I'll patch it in. Version 2.1.173 The experience orbs dropped by Knock on Wood rank 2 during Tree Feller are now much less frequent but provide more XP diff --git a/src/main/java/com/gmail/nossr50/events/skills/secondaryabilities/SubSkillBlockEvent.java b/src/main/java/com/gmail/nossr50/events/skills/secondaryabilities/SubSkillBlockEvent.java new file mode 100644 index 000000000..69b730af5 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/skills/secondaryabilities/SubSkillBlockEvent.java @@ -0,0 +1,23 @@ +package com.gmail.nossr50.events.skills.secondaryabilities; + +import com.gmail.nossr50.datatypes.skills.SubSkillType; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class SubSkillBlockEvent extends SubSkillEvent { + private final @NotNull Block block; + + public SubSkillBlockEvent(@NotNull Player player, @NotNull SubSkillType subSkillType, @NotNull Block block) { + super(player, subSkillType); + this.block = block; + } + + /** + * Get the block associated with this event + * @return the block associated with this event + */ + public @NotNull Block getBlock() { + return block; + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index d79256336..0261adabc 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -817,19 +817,24 @@ public class PlayerListener implements Listener { FakePlayerAnimationEvent fakeSwing = new FakePlayerAnimationEvent(event.getPlayer()); //PlayerAnimationEvent compat if (herbalismManager.canGreenThumbBlock(blockState)) { - Bukkit.getPluginManager().callEvent(fakeSwing); - player.getInventory().getItemInMainHand().setAmount(heldItem.getAmount() - 1); - player.updateInventory(); - if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { - blockState.update(true); + //call event for Green Thumb Block + if(!EventUtils.callSubSkillBlockEvent(player, SubSkillType.HERBALISM_GREEN_THUMB, block).isCancelled()) { + Bukkit.getPluginManager().callEvent(fakeSwing); + player.getInventory().getItemInMainHand().setAmount(heldItem.getAmount() - 1); + player.updateInventory(); + if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { + blockState.update(true); + } } } /* SHROOM THUMB CHECK */ else if (herbalismManager.canUseShroomThumb(blockState)) { - Bukkit.getPluginManager().callEvent(fakeSwing); - event.setCancelled(true); - if (herbalismManager.processShroomThumb(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { - blockState.update(true); + if(!EventUtils.callSubSkillBlockEvent(player, SubSkillType.HERBALISM_SHROOM_THUMB, block).isCancelled()) { + Bukkit.getPluginManager().callEvent(fakeSwing); + event.setCancelled(true); + if (herbalismManager.processShroomThumb(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { + blockState.update(true); + } } } break; diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index b1f99de72..e1f2d1b97 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -28,6 +28,7 @@ import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent; import com.gmail.nossr50.events.skills.fishing.McMMOPlayerMagicHunterEvent; import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.salvage.McMMOPlayerSalvageCheckEvent; +import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillBlockEvent; import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillEvent; import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent; import com.gmail.nossr50.locale.LocaleLoader; @@ -190,13 +191,28 @@ public final class EventUtils { * @return the event after it has been fired */ @Deprecated - public static SubSkillEvent callSubSkillEvent(Player player, SubSkillType subSkillType) { + public static @NotNull SubSkillEvent callSubSkillEvent(Player player, SubSkillType subSkillType) { SubSkillEvent event = new SubSkillEvent(player, subSkillType); mcMMO.p.getServer().getPluginManager().callEvent(event); return event; } + /** + * Calls a new SubSkillBlockEvent for this SubSkill and its related block and then returns it + * @param player target player + * @param subSkillType target subskill + * @param block associated block + * @return the event after it has been fired + */ + @Deprecated + public static @NotNull SubSkillBlockEvent callSubSkillBlockEvent(@NotNull Player player, @NotNull SubSkillType subSkillType, @NotNull Block block) { + SubSkillBlockEvent event = new SubSkillBlockEvent(player, subSkillType, block); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + return event; + } + /** * Calls a new SubSkillEvent for this SubSkill and then returns it * @param player target player