From 133a60c4bf813e6913cb03eef418635d23fc3e92 Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Sun, 23 Apr 2023 20:08:06 +0200 Subject: [PATCH 1/2] Fix child skills counting towards power level in /inspect (#4889) --- .../nossr50/commands/player/InspectCommand.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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(); From db01b613712473382996559d5f4dd3cd8cbf5dbc Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 13 May 2023 14:42:14 -0700 Subject: [PATCH 2/2] 2.1.220 --- Changelog.txt | 7 ++- pom.xml | 2 +- .../nossr50/api/FakeBlockBreakEventType.java | 6 +++ .../api/TreeFellerBlockBreakEvent.java | 14 ++++++ .../nossr50/listeners/BlockListener.java | 8 +-- .../nossr50/listeners/PlayerListener.java | 4 +- .../skills/fishing/FishingManager.java | 2 +- .../skills/herbalism/HerbalismManager.java | 2 +- .../nossr50/skills/mining/MiningManager.java | 2 +- .../woodcutting/WoodcuttingManager.java | 6 ++- .../com/gmail/nossr50/util/EventUtils.java | 49 ++++++++++++++----- 11 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/api/FakeBlockBreakEventType.java create mode 100644 src/main/java/com/gmail/nossr50/api/TreeFellerBlockBreakEvent.java diff --git a/Changelog.txt b/Changelog.txt index 574eea05b..2bae603ab 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,7 +1,12 @@ 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/pom.xml b/pom.xml index fb39a2584..57739f082 100755 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.gmail.nossr50.mcMMO mcMMO - 2.1.220-SNAPSHOT + 2.1.220 mcMMO https://github.com/mcMMO-Dev/mcMMO 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/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 4e36e5e5c..d17b4ad85 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 d4d147325..4b3a03432 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -185,7 +185,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 60bc758c5..611e69232 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/HerbalismManager.java @@ -690,7 +690,7 @@ public class HerbalismManager extends SkillManager { for (HylianTreasure treasure : treasures) { if (skillLevel >= treasure.getDropLevel() && RandomChanceUtil.checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(treasure.getDropChance(), getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK))) { - 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 f2e4e617f..31131316c 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -111,7 +111,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 891399070..c59a7e7ac 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; @@ -277,7 +279,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; } @@ -321,7 +323,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 3420f9f1a..5d8ed9035 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; @@ -305,26 +308,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) {