From 671be424724f7c58246f5b99191d486ae95e8156 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 18 Feb 2013 10:32:29 -0500 Subject: [PATCH] SkillTools, not Misc --- .../nossr50/skills/herbalism/Herbalism.java | 2 +- .../nossr50/skills/mining/MiningManager.java | 3 +- .../gmail/nossr50/skills/unarmed/Unarmed.java | 4 +- .../nossr50/skills/utilities/SkillTools.java | 37 ++++++++++++++++++- .../skills/woodcutting/TreeFeller.java | 2 +- .../java/com/gmail/nossr50/util/Misc.java | 36 ------------------ 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index 03a64defa..06fb45b2d 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -90,7 +90,7 @@ public class Herbalism { } public static void greenTerraConvert(Player player, Block block) { - if (Misc.blockBreakSimulate(block, player, false)) { + if (SkillTools.blockBreakSimulate(block, player, false)) { Material type = block.getType(); switch (type) { 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 659be3816..7873f2c7d 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.skills.SkillManager; +import com.gmail.nossr50.skills.utilities.SkillTools; import com.gmail.nossr50.skills.utilities.SkillType; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; @@ -36,7 +37,7 @@ public class MiningManager extends SkillManager{ return; } - if (!Misc.blockBreakSimulate(eventHandler.getBlock(), mcMMOPlayer.getPlayer(), true)) { + if (!SkillTools.blockBreakSimulate(eventHandler.getBlock(), mcMMOPlayer.getPlayer(), true)) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java index c15aca309..307d3400c 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/Unarmed.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.skills.utilities.SkillTools; public class Unarmed { public static int ironArmMaxBonusDamage = AdvancedConfig.getInstance().getIronArmMaxBonus(); @@ -29,7 +29,7 @@ public class Unarmed { public static double berserkDamageModifier = 1.5; public static void blockCracker(Player player, Block block) { - if (Misc.blockBreakSimulate(block, player, false)) { + if (SkillTools.blockBreakSimulate(block, player, false)) { Material type = block.getType(); switch (type) { diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java index 55be50364..4eabef72c 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java @@ -11,6 +11,7 @@ import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.PluginManager; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.getspout.spoutapi.SpoutManager; @@ -22,6 +23,9 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.HiddenConfig; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; +import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; +import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; +import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mods.ModChecks; import com.gmail.nossr50.spout.SpoutConfig; @@ -479,7 +483,7 @@ public class SkillTools { break; } - if (!Misc.blockBreakSimulate(block, player, true)) { + if (!blockBreakSimulate(block, player, true)) { activate = false; break; } @@ -632,4 +636,35 @@ public class SkillTools { return item; } + + /** + * 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 + * @return true if the event wasn't cancelled, false otherwise + */ + public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) { + + //Support for NoCheat + if (shouldArmSwing) { + FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); + mcMMO.p.getServer().getPluginManager().callEvent(armswing); + } + + PluginManager pluginManger = mcMMO.p.getServer().getPluginManager(); + + FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true); + pluginManger.callEvent(damageEvent); + + FakeBlockBreakEvent breakEvent = new FakeBlockBreakEvent(block, player); + pluginManger.callEvent(breakEvent); + + if (!damageEvent.isCancelled() && !breakEvent.isCancelled()) { + return true; + } + + return false; + } } diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java index cdbc3a263..1d67500e9 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java @@ -171,7 +171,7 @@ public final class TreeFeller { int xp = 0; for (Block block : treeFellerBlocks) { - if (!Misc.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) { + if (!SkillTools.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) { break; // TODO: Shouldn't we use continue instead? } diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 5938912e6..21ef79886 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -4,18 +4,13 @@ import java.util.Random; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.PluginManager; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; -import com.gmail.nossr50.events.fake.FakeBlockDamageEvent; -import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.items.McMMOItemSpawnEvent; import com.gmail.nossr50.mods.ModChecks; @@ -51,37 +46,6 @@ public final class Misc { return false; } - /** - * 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 - * @return true if the event wasn't cancelled, false otherwise - */ - public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) { - - //Support for NoCheat - if (shouldArmSwing) { - FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); - mcMMO.p.getServer().getPluginManager().callEvent(armswing); - } - - PluginManager pluginManger = mcMMO.p.getServer().getPluginManager(); - - FakeBlockDamageEvent damageEvent = new FakeBlockDamageEvent(player, block, player.getItemInHand(), true); - pluginManger.callEvent(damageEvent); - - FakeBlockBreakEvent breakEvent = new FakeBlockBreakEvent(block, player); - pluginManger.callEvent(breakEvent); - - if (!damageEvent.isCancelled() && !breakEvent.isCancelled()) { - return true; - } - - return false; - } - /** * Get the upgrade tier of the item in hand. *