From 77462888ff86149d602f366b50b616cb6e35811b Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 25 Mar 2012 16:26:40 -0400 Subject: [PATCH] Moved anvil placement handling into Repair.java --- .../nossr50/listeners/mcBlockListener.java | 28 ++++--------------- .../java/com/gmail/nossr50/skills/Repair.java | 27 ++++++++++++++++++ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index fb8d3826e..57b25f661 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -14,9 +14,11 @@ import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.skills.Excavation; import com.gmail.nossr50.skills.Herbalism; import com.gmail.nossr50.skills.Mining; +import com.gmail.nossr50.skills.Repair; import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.WoodCutting; import com.gmail.nossr50.spout.SpoutSounds; +import com.gmail.nossr50.events.FakeBlockBreakEvent; import org.bukkit.Bukkit; import org.bukkit.CropState; @@ -36,12 +38,9 @@ import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; -import org.getspout.spoutapi.SpoutManager; -import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.sound.SoundEffect; -import com.gmail.nossr50.locale.mcLocale; -import com.gmail.nossr50.events.FakeBlockBreakEvent; + public class mcBlockListener implements Listener { private final mcMMO plugin; @@ -109,7 +108,7 @@ public class mcBlockListener implements Listener { continue; } else { - Block newLocation = block.getRelative(0, y+1, 0); + Block newLocation = block.getRelative(0, y + 1, 0); newLocation.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true)); break; } @@ -122,22 +121,7 @@ public class mcBlockListener implements Listener { } if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) { - PlayerProfile PP = Users.getProfile(player); - - if (!PP.getPlacedAnvil()) { - if (LoadProperties.spoutEnabled) { - SpoutPlayer sPlayer = SpoutManager.getPlayer(player); - - if (sPlayer.isSpoutCraftEnabled()) { - sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(id)); - } - } - else { - event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil")); - } - - PP.togglePlacedAnvil(); - } + Repair.placedAnvilCheck(player, id); } } @@ -154,7 +138,7 @@ public class mcBlockListener implements Listener { Material mat = block.getType(); ItemStack inhand = player.getItemInHand(); - if(event instanceof FakeBlockBreakEvent) { + if (event instanceof FakeBlockBreakEvent) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index 2292db9f0..c3cf8ef67 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -9,6 +9,8 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import org.getspout.spoutapi.SpoutManager; +import org.getspout.spoutapi.player.SpoutPlayer; import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.Users; @@ -434,4 +436,29 @@ public class Repair { is.setDurability(getRepairAmount(is, player)); } + + /** + * Handles notifications for placing an anvil. + * + * @param player The player placing the anvil + * @param anvilID The item ID of the anvil block + */ + public static void placedAnvilCheck(Player player, int anvilID) { + PlayerProfile PP = Users.getProfile(player); + + if (!PP.getPlacedAnvil()) { + if (LoadProperties.spoutEnabled) { + SpoutPlayer sPlayer = SpoutManager.getPlayer(player); + + if (sPlayer.isSpoutCraftEnabled()) { + sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(anvilID)); //TODO: Use Locale + } + } + else { + player.sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil")); + } + + PP.togglePlacedAnvil(); + } + } }