Check the range in a seperate function

This commit is contained in:
GJ 2013-07-24 14:13:58 -04:00
parent df2defe969
commit 78f2e0a064

View File

@ -178,17 +178,13 @@ public class TamingManager extends SkillManager {
return; return;
} }
double range = Config.getInstance().getTamingCOTWRange(); if (!rangeCheck(type)) {
if (range > 0) { return;
for (Entity entity : player.getNearbyEntities(range, range, range)) {
if (entity.getType() == type) {
player.sendMessage(Taming.getCallOfTheWildFailureMessage(type));
return;
}
}
} }
int amount = Config.getInstance().getTamingCOTWAmount(type); int amount = Config.getInstance().getTamingCOTWAmount(type);
// TODO: Validate in config instead
if (amount <= 0) { if (amount <= 0) {
amount = 1; amount = 1;
} }
@ -199,16 +195,22 @@ public class TamingManager extends SkillManager {
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
((Tameable) entity).setOwner(player); ((Tameable) entity).setOwner(player);
if (type == EntityType.OCELOT) { switch (type) {
((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Misc.getRandom().nextInt(3))); case OCELOT:
} ((Ocelot) entity).setCatType(Ocelot.Type.getType(1 + Misc.getRandom().nextInt(3)));
else { break;
entity.setMaxHealth(20);
entity.setHealth(entity.getMaxHealth()); case WOLF:
entity.setMaxHealth(20.0);
entity.setHealth(entity.getMaxHealth());
break;
default:
break;
} }
if (Permissions.renamePets(player)) { 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); entity.setCustomNameVisible(true);
} }
} }
@ -216,4 +218,22 @@ public class TamingManager extends SkillManager {
player.setItemInHand(new ItemStack(heldItem.getType(), heldItemAmount - summonAmount)); player.setItemInHand(new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete")); 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;
}
} }