From 78f2e0a06440f372d3ef8d2a0e6ebacf3a282b7f Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 24 Jul 2013 14:13:58 -0400 Subject: [PATCH] Check the range in a seperate function --- .../nossr50/skills/taming/TamingManager.java | 50 +++++++++++++------ 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 3ff333d87..cff2667e9 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -178,17 +178,13 @@ public class TamingManager extends SkillManager { return; } - double range = Config.getInstance().getTamingCOTWRange(); - if (range > 0) { - for (Entity entity : player.getNearbyEntities(range, range, range)) { - if (entity.getType() == type) { - player.sendMessage(Taming.getCallOfTheWildFailureMessage(type)); - return; - } - } + if (!rangeCheck(type)) { + return; } int amount = Config.getInstance().getTamingCOTWAmount(type); + + // TODO: Validate in config instead if (amount <= 0) { amount = 1; } @@ -199,16 +195,22 @@ public class TamingManager extends SkillManager { entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); ((Tameable) entity).setOwner(player); - if (type == EntityType.OCELOT) { - ((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Misc.getRandom().nextInt(3))); - } - else { - entity.setMaxHealth(20); - entity.setHealth(entity.getMaxHealth()); + switch (type) { + case OCELOT: + ((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Misc.getRandom().nextInt(3))); + break; + + case WOLF: + entity.setMaxHealth(20.0); + entity.setHealth(entity.getMaxHealth()); + break; + + default: + break; } if (Permissions.renamePets(player)) { - entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(entity.getType()))); + entity.setCustomName(LocaleLoader.getString("Taming.Summon.Name.Format", player.getName(), StringUtils.getPrettyEntityTypeString(type))); entity.setCustomNameVisible(true); } } @@ -216,4 +218,22 @@ public class TamingManager extends SkillManager { player.setItemInHand(new ItemStack(heldItem.getType(), heldItemAmount - summonAmount)); player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete")); } + + private boolean rangeCheck(EntityType type) { + double range = Config.getInstance().getTamingCOTWRange(); + Player player = getPlayer(); + + if (range == 0) { + return true; + } + + for (Entity entity : player.getNearbyEntities(range, range, range)) { + if (entity.getType() == type) { + player.sendMessage(Taming.getCallOfTheWildFailureMessage(type)); + return false; + } + } + + return true; + } }