From 6b18cec7fb4a65aa6907d08f160f290e66ac7236 Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 6 Mar 2013 10:47:56 -0500 Subject: [PATCH] Combine our placedAnvil checks into one function. --- .../nossr50/datatypes/player/McMMOPlayer.java | 36 ++++++++------ .../nossr50/listeners/BlockListener.java | 6 ++- .../gmail/nossr50/skills/repair/Repair.java | 25 ++++++++++ .../nossr50/skills/repair/RepairManager.java | 49 ++++--------------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 55b367fc5..63d1e283c 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -28,7 +28,9 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.fishing.FishingManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; +import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.RepairManager; +import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.taming.TamingManager; @@ -66,7 +68,7 @@ public class McMMOPlayer { private boolean displaySkillNotifications = true; private boolean abilityUse = true; - private boolean placedAnvil; + private boolean placedRepairAnvil; private boolean placedSalvageAnvil; private boolean godMode; @@ -313,24 +315,26 @@ public class McMMOPlayer { * Repair Anvil Placement */ - public void togglePlacedAnvil() { - placedAnvil = !placedAnvil; + public boolean getPlacedAnvil(int anvilId) { + if (anvilId == Repair.anvilID) { + return placedRepairAnvil; + } + + if (anvilId == Salvage.anvilID) { + return placedSalvageAnvil; + } + + return true; } - public Boolean getPlacedAnvil() { - return placedAnvil; - } + public void togglePlacedAnvil(int anvilId) { + if (anvilId == Repair.anvilID) { + placedRepairAnvil = !placedRepairAnvil; + } - /* - * Salvage Anvil Placement - */ - - public void togglePlacedSalvageAnvil() { - placedSalvageAnvil = !placedSalvageAnvil; - } - - public Boolean getPlacedSalvageAnvil() { - return placedSalvageAnvil; + if (anvilId == Salvage.anvilID) { + placedSalvageAnvil = !placedSalvageAnvil; + } } /* diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 608dc2179..5913bc903 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -35,6 +35,7 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager; import com.gmail.nossr50.skills.herbalism.HerbalismManager; import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.repair.Repair; +import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.smelting.SmeltingManager; import com.gmail.nossr50.skills.unarmed.Unarmed; import com.gmail.nossr50.skills.woodcutting.Woodcutting; @@ -108,14 +109,15 @@ public class BlockListener implements Listener { } BlockState blockState = event.getBlock().getState(); + int blockId = blockState.getTypeId(); /* Check if the blocks placed should be monitored so they do not give out XP in the future */ if (BlockUtils.shouldBeWatched(blockState)) { mcMMO.placeStore.setTrue(blockState); } - if (Repair.anvilMessagesEnabled) { - UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockState.getTypeId()); + if (Repair.anvilMessagesEnabled && (blockId == Repair.anvilID || blockId == Salvage.anvilID)) { + UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockId); } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java index e2cd49f31..b56b92be4 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/Repair.java @@ -5,6 +5,7 @@ import org.bukkit.inventory.PlayerInventory; import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.locale.LocaleLoader; public class Repair { // The order of the values is extremely important, a few methods depend on it to work properly @@ -111,4 +112,28 @@ public class Repair { inventory.removeItem(item); } + + protected static String[] getSpoutAnvilMessages(int blockId) { + if (blockId == Repair.anvilID) { + return new String[] {LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2")}; + } + + if (blockId == Salvage.anvilID) { + return new String[] {"[mcMMO] Anvil Placed", "Right click to salvage!"}; + } + + return new String[] {"", ""}; + } + + protected static String getAnvilMessage(int blockId) { + if (blockId == Repair.anvilID) { + return LocaleLoader.getString("Repair.Listener.Anvil"); + } + + if (blockId == Salvage.anvilID) { + return LocaleLoader.getString("Repair.Listener.Anvil2"); + } + + return ""; + } } diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java index f3b07dc06..5f8004e5e 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java @@ -32,24 +32,15 @@ public class RepairManager extends SkillManager { super(mcMMOPlayer, SkillType.REPAIR); } - public void placedAnvilCheck(int anvilId) { - if (anvilId == Repair.anvilID) { - repairAnvilCheck(anvilId); - } - else if (anvilId == Salvage.anvilID) { - salvageAnvilCheck(anvilId); - } - } - /** * Handles notifications for placing an anvil. * * @param anvilID The item ID of the anvil block */ - public void repairAnvilCheck(int anvilID) { + public void placedAnvilCheck(int anvilId) { Player player = getPlayer(); - if (mcMMOPlayer.getPlacedAnvil()) { + if (mcMMOPlayer.getPlacedAnvil(anvilId)) { return; } @@ -57,41 +48,19 @@ public class RepairManager extends SkillManager { SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); if (spoutPlayer.isSpoutCraftEnabled()) { - spoutPlayer.sendNotification(LocaleLoader.getString("Repair.AnvilPlaced.Spout1"), LocaleLoader.getString("Repair.AnvilPlaced.Spout2"), Material.getMaterial(anvilID)); + String[] spoutMessages = Repair.getSpoutAnvilMessages(anvilId); + spoutPlayer.sendNotification(spoutMessages[0], spoutMessages[1], Material.getMaterial(anvilId)); + } + else { + player.sendMessage(Repair.getAnvilMessage(anvilId)); } } else { - player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil")); + player.sendMessage(Repair.getAnvilMessage(anvilId)); } player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); - mcMMOPlayer.togglePlacedAnvil(); - } - - /** - * Handles notifications for placing an anvil. - * - * @param player The player placing the anvil - * @param anvilID The item ID of the anvil block - */ - public void salvageAnvilCheck(int anvilID) { - Player player = getPlayer(); - - if (!mcMMOPlayer.getPlacedSalvageAnvil()) { - if (mcMMO.spoutEnabled) { - final SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player); - - if (spoutPlayer.isSpoutCraftEnabled()) { - spoutPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to salvage!", Material.getMaterial(anvilID)); - } - } - else { - player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil2")); - } - - player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH); - mcMMOPlayer.togglePlacedSalvageAnvil(); - } + mcMMOPlayer.togglePlacedAnvil(anvilId); } public void handleRepair(ItemStack item) {