diff --git a/Changelog.txt b/Changelog.txt index e61407c9a..31c565986 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -57,9 +57,14 @@ Version 2.2.000 This power level command gives you a view of all your current masteries, it also provides a summary of your power level. Version 2.1.220 + (API) Added TreeFellerBlockBreakEvent class which extends FakeBlockBreakEvent (see notes), this is sent out during Tree Feller processing to allow other plugins to differentiate between Tree Feller and other fake block break events Config files update automatically again - Default configs are now copied to plugins/mcMMO/defaults for easy reference, these configs will always match the default values of the config in the JAR + Default configs are now copied to plugins/mcMMO/defaults for easy reference + Fixed child skills counting towards power level in /inspect (Thanks Wariorrrr) + NOTES: For a while configs were not updating automatically as a rewrite of how config files were loaded was partially done, this is now complete and configs will update automatically again. + Fake block break events have been sent out historically by mcMMO to check other plugins for a players permission to break or place a block, Tree Feller will now specify via inheritance its own event type for this so mcMMO plugins can handle Tree Feller fake block break events differently if they so choose. + You can now view the default configs more easily as they are now copied to plugins/mcMMO/defaults, these configs will be overwritten on start up to match the default values of the config in the JAR Version 2.1.219 Fixed Fishing exploit protection being triggered inappropriately by other plugins (Thanks smudgge) Fixed wiki url being incorrect in commands diff --git a/src/main/java/com/gmail/nossr50/api/FakeBlockBreakEventType.java b/src/main/java/com/gmail/nossr50/api/FakeBlockBreakEventType.java new file mode 100644 index 000000000..3476b294f --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/FakeBlockBreakEventType.java @@ -0,0 +1,6 @@ +package com.gmail.nossr50.api; + +public enum FakeBlockBreakEventType { + FAKE, + TREE_FELLER +} diff --git a/src/main/java/com/gmail/nossr50/api/TreeFellerBlockBreakEvent.java b/src/main/java/com/gmail/nossr50/api/TreeFellerBlockBreakEvent.java new file mode 100644 index 000000000..7f7db7bcf --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/TreeFellerBlockBreakEvent.java @@ -0,0 +1,14 @@ +package com.gmail.nossr50.api; + +import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; +import com.gmail.nossr50.events.fake.FakeEvent; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.jetbrains.annotations.NotNull; + +public class TreeFellerBlockBreakEvent extends FakeBlockBreakEvent { + public TreeFellerBlockBreakEvent(@NotNull Block theBlock, @NotNull Player player) { + super(theBlock, player); + } +} diff --git a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java index 816656b1f..ab1047387 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -9,6 +9,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager; +import com.gmail.nossr50.util.skills.SkillTools; import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -47,27 +48,26 @@ public class InspectCommand implements TabExecutor { sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", playerName)); - // Sum power level - int powerLevel = 0; - sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering")); for (PrimarySkillType skill : mcMMO.p.getSkillTools().GATHERING_SKILLS) { sender.sendMessage(CommandUtils.displaySkill(profile, skill)); - powerLevel += profile.getSkillLevel(skill); } sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat")); for (PrimarySkillType skill : mcMMO.p.getSkillTools().COMBAT_SKILLS) { sender.sendMessage(CommandUtils.displaySkill(profile, skill)); - powerLevel += profile.getSkillLevel(skill); } sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc")); for (PrimarySkillType skill : mcMMO.p.getSkillTools().MISC_SKILLS) { sender.sendMessage(CommandUtils.displaySkill(profile, skill)); - powerLevel += profile.getSkillLevel(skill); } + // Sum power level + int powerLevel = 0; + for (PrimarySkillType skill : SkillTools.NON_CHILD_SKILLS) + powerLevel += profile.getSkillLevel(skill); + sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", powerLevel)); } else { Player target = mcMMOPlayer.getPlayer(); diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index e7c4c86f8..8c22b1e62 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -558,7 +558,7 @@ public class BlockListener implements Listener { mcMMOPlayer.checkAbilityActivation(PrimarySkillType.UNARMED); if(mcMMOPlayer.getAbilityMode(SuperAbilityType.BERSERK)) { - if (SuperAbilityType.BERSERK.blockCheck(blockState) && EventUtils.simulateBlockBreak(blockState.getBlock(), player, true)) { + if (SuperAbilityType.BERSERK.blockCheck(blockState) && EventUtils.simulateBlockBreak(blockState.getBlock(), player)) { event.setInstaBreak(true); if(blockState.getType().getKey().getKey().contains("glass")) { @@ -633,11 +633,11 @@ public class BlockListener implements Listener { } else if (mcMMOPlayer.getAbilityMode(SuperAbilityType.BERSERK) && (heldItem.getType() == Material.AIR || mcMMO.p.getGeneralConfig().getUnarmedItemsAsUnarmed())) { if (mcMMOPlayer.getUnarmedManager().canUseBlockCracker() && BlockUtils.affectedByBlockCracker(blockState)) { - if (EventUtils.simulateBlockBreak(block, player, true) && mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) { + if (EventUtils.simulateBlockBreak(block, player) && mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) { blockState.update(); } } - else if (!event.getInstaBreak() && SuperAbilityType.BERSERK.blockCheck(blockState) && EventUtils.simulateBlockBreak(block, player, true)) { + else if (!event.getInstaBreak() && SuperAbilityType.BERSERK.blockCheck(blockState) && EventUtils.simulateBlockBreak(block, player)) { event.setInstaBreak(true); if(blockState.getType().getKey().getKey().contains("glass")) { @@ -647,7 +647,7 @@ public class BlockListener implements Listener { } } } - else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && BlockUtils.isNonWoodPartOfTree(blockState) && EventUtils.simulateBlockBreak(block, player, true)) { + else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && BlockUtils.isNonWoodPartOfTree(blockState) && EventUtils.simulateBlockBreak(block, player)) { event.setInstaBreak(true); SoundManager.sendSound(player, block.getLocation(), SoundType.POP); } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 3a3900dd4..8246ffd4f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -866,7 +866,7 @@ public class PlayerListener implements Listener { // Bukkit.getPluginManager().callEvent(fakeSwing); player.getInventory().getItemInMainHand().setAmount(heldItem.getAmount() - 1); player.updateInventory(); - if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) { + if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player)) { blockState.update(true); } } @@ -877,7 +877,7 @@ public class PlayerListener implements Listener { // Bukkit.getPluginManager().callEvent(fakeSwing); event.setCancelled(true); if (herbalismManager.processShroomThumb(blockState) - && EventUtils.simulateBlockBreak(block, player, false)) { + && EventUtils.simulateBlockBreak(block, player)) { blockState.update(true); } } diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java index fa668a6f1..d7295a31a 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -187,7 +187,7 @@ public class FishingManager extends SkillManager { return false; } - return EventUtils.simulateBlockBreak(block, player, false); + return EventUtils.simulateBlockBreak(block, player); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java index 69f15d024..7755a1fef 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -688,7 +688,7 @@ public class HerbalismManager extends SkillManager { for (HylianTreasure treasure : treasures) { if (skillLevel >= treasure.getDropLevel() && ProbabilityUtil.isStaticSkillRNGSuccessful(PrimarySkillType.HERBALISM, player, treasure.getDropChance())) { - if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, false)) { + if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player)) { return false; } blockState.setType(Material.AIR); diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 684139511..ee1cda951 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -139,7 +139,7 @@ public class MiningManager extends SkillManager { Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE); //Blast mining cooldown check needs to be first so the player can be messaged - if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !EventUtils.simulateBlockBreak(targetBlock, player, true)) { + if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !EventUtils.simulateBlockBreak(targetBlock, player)) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java index fe0ae14ce..403f23a97 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/WoodcuttingManager.java @@ -1,8 +1,10 @@ package com.gmail.nossr50.skills.woodcutting; +import com.gmail.nossr50.api.FakeBlockBreakEventType; import com.gmail.nossr50.api.ItemSpawnReason; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; +import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; @@ -302,7 +304,7 @@ public class WoodcuttingManager extends SkillManager { int beforeXP = xp; Block block = blockState.getBlock(); - if (!EventUtils.simulateBlockBreak(block, player, true)) { + if (!EventUtils.simulateBlockBreak(block, player, FakeBlockBreakEventType.TREE_FELLER)) { continue; } @@ -347,7 +349,7 @@ public class WoodcuttingManager extends SkillManager { processedLogCount = updateProcessedLogCount(xp, processedLogCount, beforeXP); } - applyXpGain(xp, XPGainReason.PVE); + applyXpGain(xp, XPGainReason.PVE, XPGainSource.SELF); } private int updateProcessedLogCount(int xp, int processedLogCount, int beforeXP) { diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index d03117ca3..49d9b4d76 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -1,5 +1,7 @@ package com.gmail.nossr50.util; +import com.gmail.nossr50.api.FakeBlockBreakEventType; +import com.gmail.nossr50.api.TreeFellerBlockBreakEvent; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.party.Party; @@ -43,6 +45,7 @@ import org.bukkit.entity.FishHook; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.Event; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; @@ -304,26 +307,50 @@ public final class EventUtils { /** * Simulate a block break event. * - * @param block The block to break - * @param player The player breaking the block - * @param shouldArmSwing true if an armswing event should be fired, false otherwise + * @param block The block to break + * @param player The player breaking the block + * @param shouldArmSwing ignored (here for API compatibility) * @return true if the event wasn't cancelled, false otherwise + * {@code @Deprecated} use {@link #simulateBlockBreak(Block, Player, FakeBlockBreakEventType)} instead */ public static boolean simulateBlockBreak(Block block, Player player, boolean shouldArmSwing) { - PluginManager pluginManager = mcMMO.p.getServer().getPluginManager(); + return simulateBlockBreak(block, player); + } - // Support for NoCheat - //if (shouldArmSwing) { - // callFakeArmSwingEvent(player); - //} + /** + * Simulate a block break event. + * + * @param block The block to break + * @param player The player breaking the block + * @return true if the event wasn't cancelled, false otherwise + * {@code @Deprecated} use {@link #simulateBlockBreak(Block, Player, FakeBlockBreakEventType)} instead + */ + public static boolean simulateBlockBreak(Block block, Player player) { + return simulateBlockBreak(block, player, FakeBlockBreakEventType.FAKE); + } + + /** + * Simulate a block break event. + * + * @param block The block to break + * @param player The player breaking the block + * @param eventType The type of event to signal to other plugins + * @return true if the event wasn't cancelled, false otherwise + */ + public static boolean simulateBlockBreak(Block block, Player player, FakeBlockBreakEventType eventType) { + PluginManager pluginManager = mcMMO.p.getServer().getPluginManager(); FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getInventory().getItemInMainHand(), true); pluginManager.callEvent(damageEvent); - FakeBlockBreakEvent breakEvent = new FakeBlockBreakEvent(block, player); - pluginManager.callEvent(breakEvent); + BlockBreakEvent fakeBlockBreakEvent = null; - return !damageEvent.isCancelled() && !breakEvent.isCancelled(); + switch (eventType) { + case FAKE -> fakeBlockBreakEvent = new FakeBlockBreakEvent(block, player); + case TREE_FELLER -> fakeBlockBreakEvent = new TreeFellerBlockBreakEvent(block, player); + } + pluginManager.callEvent(fakeBlockBreakEvent); + return !damageEvent.isCancelled() && !fakeBlockBreakEvent.isCancelled(); } public static void handlePartyTeleportEvent(Player teleportingPlayer, Player targetPlayer) {