From 41c9741b728a5232b21e2ac77f328eecd430a439 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 21 May 2012 23:41:11 -0400 Subject: [PATCH] Fixed exploit where you could gain tons of Acrobatics XP from spamming Ender Pearls --- Changelog.txt | 1 + .../gmail/nossr50/listeners/EntityListener.java | 2 +- .../gmail/nossr50/skills/gathering/Mining.java | 14 ++++++-------- .../gmail/nossr50/skills/misc/Acrobatics.java | 1 - .../java/com/gmail/nossr50/util/ModChecks.java | 16 ++++++++++++++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 4d7ef8a5c..b81123ef9 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -10,6 +10,7 @@ Key: Version 1.3.08 + Added new hidden.yml inside the jar for very sensitive config options for advanced users + Added option to disable Chunklets for servers which do not have doubledrops and do not care about xp farming + = Fixed exploit where you could gain tons of Acrobatics XP from spamming Ender Pearls ! Changed Mining to allow Silk Touch to work again since the dupe exploit has been fixed. Version 1.3.07 diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 92c373db5..5dfc47e67 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -123,7 +123,7 @@ public class EntityListener implements Listener { } if (!Misc.isInvincible(player, event)) { - if (cause == DamageCause.FALL && Permissions.getInstance().acrobatics(player) && !player.isInsideVehicle()) { + if (cause == DamageCause.FALL && Permissions.getInstance().acrobatics(player) && !player.isInsideVehicle() && !player.getItemInHand().getType().equals(Material.ENDER_PEARL)) { Acrobatics.acrobaticsCheck(player, event); } else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.getInstance().demolitionsExpertise(player)) { diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java index 575d86175..71d4d4bf0 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Mining.java @@ -19,13 +19,11 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.config.mods.CustomBlocksConfig; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; public class Mining { - private static Random random = new Random(); /** @@ -88,7 +86,7 @@ public class Mining { break; default: - if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + if (ModChecks.isCustomMiningBlock(block)) { Misc.dropItem(loc, item); } break; @@ -197,7 +195,7 @@ public class Mining { break; default: - if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + if (ModChecks.isCustomMiningBlock(block)) { item = ModChecks.getCustomBlock(block).getItemDrop(); Misc.dropItem(loc, item); } @@ -271,7 +269,7 @@ public class Mining { break; default: - if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + if (ModChecks.isCustomMiningBlock(block)) { xp += ModChecks.getCustomBlock(block).getXpGain(); } break; @@ -295,10 +293,10 @@ public class Mining { miningXP(player, block); final int MAX_BONUS_LEVEL = 1000; - int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING); + int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL); - if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && Permissions.getInstance().miningDoubleDrops(player)) { + if (random.nextInt(1000) <= skillCheck && Permissions.getInstance().miningDoubleDrops(player)) { if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) { silkTouchDrops(block); } @@ -320,7 +318,7 @@ public class Mining { int durabilityLoss = Config.getInstance().getAbilityToolDamage(); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); - if (Config.getInstance().getBlockModsEnabled() && CustomBlocksConfig.getInstance().customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + if (ModChecks.isCustomMiningBlock(block)) { if (ModChecks.getCustomBlock(block).getTier() < tier) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/misc/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/misc/Acrobatics.java index 59672ad39..b15952b6c 100644 --- a/src/main/java/com/gmail/nossr50/skills/misc/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/misc/Acrobatics.java @@ -16,7 +16,6 @@ import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; public class Acrobatics { - private static Random random = new Random(); /** diff --git a/src/main/java/com/gmail/nossr50/util/ModChecks.java b/src/main/java/com/gmail/nossr50/util/ModChecks.java index bfed23e2c..537a2bb3b 100644 --- a/src/main/java/com/gmail/nossr50/util/ModChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ModChecks.java @@ -15,6 +15,7 @@ public class ModChecks { private static Config configInstance = Config.getInstance(); private static boolean customToolsEnabled = configInstance.getToolModsEnabled(); private static boolean customArmorEnabled = configInstance.getArmorModsEnabled(); + private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled(); private static CustomToolsConfig toolInstance = CustomToolsConfig.getInstance(); private static CustomArmorConfig armorInstance = CustomArmorConfig.getInstance(); @@ -60,6 +61,21 @@ public class ModChecks { return null; } + /** + * Check if a custom block is a custom block. + * + * @param block The block to check + * @return true if the block is custom, false otherwise + */ + public static boolean isCustomMiningBlock(Block block) { + if (customBlocksEnabled && blocksInstance.customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) { + return true; + } + else { + return false; + } + } + /** * Check if a custom block is a leaf block. *