Straighten up the Taming classes in order to stop passing events around quite so much. Also reordered some checks in our EntityDamage listeners for readability & efficiency purposes.

This commit is contained in:
GJ 2013-03-01 15:49:24 -05:00
parent c0b7f8a323
commit cbe9cae4ea
10 changed files with 242 additions and 424 deletions

View File

@ -38,6 +38,7 @@ import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -59,18 +60,21 @@ public class EntityListener implements Listener {
public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
Entity entity = event.getEntity();
if (entity instanceof FallingBlock) {
Block block = event.getBlock();
if (!(entity instanceof FallingBlock)) {
return;
}
if (mcMMO.placeStore.isTrue(block) && !entity.hasMetadata(mcMMO.entityMetadataKey)) {
Block block = event.getBlock();
boolean isTracked = entity.hasMetadata(mcMMO.entityMetadataKey);
if (mcMMO.placeStore.isTrue(block) && !isTracked) {
mcMMO.placeStore.setFalse(block);
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
}
else if (entity.hasMetadata(mcMMO.entityMetadataKey)) {
else if (isTracked) {
mcMMO.placeStore.setTrue(block);
}
}
}
/**
* Handle EntityDamageByEntity events that involve modifying the event.
@ -85,11 +89,12 @@ public class EntityListener implements Listener {
Entity defender = event.getEntity();
if (Misc.isNPCEntity(defender) || defender.isDead()) {
if (Misc.isNPCEntity(defender) || !defender.isValid() || !(defender instanceof LivingEntity)) {
return;
}
Entity attacker = event.getDamager();
LivingEntity target = (LivingEntity) defender;
if (attacker instanceof Projectile) {
attacker = ((Projectile) attacker).getShooter();
@ -102,6 +107,10 @@ public class EntityListener implements Listener {
}
}
if (CombatUtils.isInvincible(target, event.getDamage())) {
return;
}
if (defender instanceof Player && attacker instanceof Player) {
Player defendingPlayer = (Player) defender;
Player attackingPlayer = (Player) attacker;
@ -110,22 +119,14 @@ public class EntityListener implements Listener {
if (defendingPlayer == attackingPlayer) {
return;
}
else if (PartyManager.inSameParty(defendingPlayer, attackingPlayer)) {
if (!(Permissions.friendlyFire(attackingPlayer) && Permissions.friendlyFire(defendingPlayer))) {
if (PartyManager.inSameParty(defendingPlayer, attackingPlayer) && !(Permissions.friendlyFire(attackingPlayer) && Permissions.friendlyFire(defendingPlayer))) {
event.setCancelled(true);
return;
}
}
}
/* Check for invincibility */
if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity) defender;
if (!CombatUtils.isInvincible(livingDefender, event.getDamage())) {
CombatUtils.combatChecks(event, attacker, livingDefender);
}
}
CombatUtils.combatChecks(event, attacker, target);
}
/**
@ -210,24 +211,26 @@ public class EntityListener implements Listener {
Player player = (Player) owner;
Wolf wolf = (Wolf) pet;
TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();
switch (cause) {
case CONTACT:
case FIRE:
case LAVA:
if (Taming.canUseEnvironmentallyAware(player)) {
Taming.processEnvironmentallyAware(player, wolf, event.getDamage());
if (tamingManager.canUseEnvironmentallyAware()) {
tamingManager.processEnvironmentallyAware(wolf, event.getDamage());
}
return;
case FALL:
if (Taming.canUseEnvironmentallyAware(player)) {
if (tamingManager.canUseEnvironmentallyAware()) {
event.setCancelled(true);
}
return;
case ENTITY_ATTACK:
case PROJECTILE:
if (Taming.canUseThickFur(player)) {
if (tamingManager.canUseThickFur()) {
event.setDamage(Taming.processThickFur(wolf, event.getDamage()));
if (event.getDamage() == 0) {
@ -237,7 +240,7 @@ public class EntityListener implements Listener {
return;
case FIRE_TICK:
if (Taming.canUseThickFur(player)) {
if (tamingManager.canUseThickFur()) {
Taming.processThickFurFire(wolf);
}
return;
@ -245,7 +248,7 @@ public class EntityListener implements Listener {
case MAGIC:
case POISON:
case WITHER:
if (Taming.canUseHolyHound(player)) {
if (tamingManager.canUseHolyHound()) {
Taming.processHolyHound(wolf, event.getDamage());
}
return;
@ -253,7 +256,7 @@ public class EntityListener implements Listener {
case BLOCK_EXPLOSION:
case ENTITY_EXPLOSION:
case LIGHTNING:
if (Taming.canUseShockProof(player)) {
if (tamingManager.canUseShockProof()) {
event.setDamage(Taming.processShockProof(wolf, event.getDamage()));
if (event.getDamage() == 0) {
@ -294,7 +297,7 @@ public class EntityListener implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (Misc.isSpawnerXPEnabled || event.getEntity() == null) {
if (Misc.isSpawnerXPEnabled) {
return;
}
@ -317,7 +320,9 @@ public class EntityListener implements Listener {
if (entity instanceof TNTPrimed) {
int id = entity.getEntityId();
if (plugin.tntIsTracked(id)) {
if (!plugin.tntIsTracked(id)) {
return;
}
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
@ -326,7 +331,6 @@ public class EntityListener implements Listener {
}
}
}
}
/**
* Handle EntityExplode events that involve modifying the event.
@ -340,7 +344,10 @@ public class EntityListener implements Listener {
if (entity instanceof TNTPrimed) {
int id = entity.getEntityId();
if (plugin.tntIsTracked(id)) {
if (!plugin.tntIsTracked(id)) {
return;
}
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
if (miningManager.canUseBlastMining()) {
@ -351,7 +358,6 @@ public class EntityListener implements Listener {
plugin.removeFromTNTTracker(id);
}
}
}
/**
* Handle FoodLevelChange events that involve modifying the event.
@ -373,13 +379,16 @@ public class EntityListener implements Listener {
int newFoodLevel = event.getFoodLevel();
int foodChange = newFoodLevel - currentFoodLevel;
if (foodChange <= 0) {
return;
}
/*
* Some foods have 3 ranks
* Some foods have 5 ranks
* The number of ranks is based on how 'common' the item is
* We can adjust this quite easily if we find something is giving too much of a bonus
*/
if (foodChange > 0) {
switch (player.getItemInHand().getType()) {
case BAKED_POTATO: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
@ -418,7 +427,6 @@ public class EntityListener implements Listener {
}
}
}
}
/**
* Monitor EntityTame events.
@ -428,34 +436,39 @@ public class EntityListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityTame(EntityTameEvent event) {
Player player = (Player) event.getOwner();
LivingEntity entity = event.getEntity();
if (Misc.isNPCEntity(player)) {
if (Misc.isNPCEntity(player) || Misc.isNPCEntity(entity) || entity.hasMetadata(mcMMO.entityMetadataKey)) {
return;
}
LivingEntity entity = event.getEntity();
if (entity != null && !entity.hasMetadata(mcMMO.entityMetadataKey)) {
UserManager.getPlayer(player).getTamingManager().awardTamingXP(entity);
}
}
/**
* Handle EntityTarget events.
*
* @param event The event to process
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityTarget(EntityTargetEvent event) {
if (event.getEntity() instanceof Tameable && event.getTarget() instanceof Player) {
Player player = (Player) event.getTarget();
Tameable tameable = (Tameable) event.getEntity();
Entity entity = event.getEntity();
Entity target = event.getTarget();
if (entity instanceof Tameable && target instanceof Player) {
Player player = (Player) target;
Tameable tameable = (Tameable) entity;
if (!CombatUtils.isFriendlyPet(player, tameable)) {
return;
}
if (CombatUtils.isFriendlyPet(player, tameable)) {
// isFriendlyPet ensures that the Tameable is: Tamed, owned by a player, and the owner is in the same party
// So we can make some assumptions here, about our casting and our check
Player owner = (Player) tameable.getOwner();
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire(owner))) {
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire((Player) tameable.getOwner()))) {
event.setCancelled(true);
return;
}
}
}
}
}

View File

@ -401,7 +401,7 @@ public class PlayerListener implements Listener {
case LEFT_CLICK_BLOCK:
/* CALL OF THE WILD CHECKS */
if (player.isSneaking()) {
if (player.isSneaking() && Permissions.callOfTheWild(player)) {
Material type = heldItem.getType();
TamingManager tamingManager = mcMMOPlayer.getTamingManager();

View File

@ -1,54 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import com.gmail.nossr50.locale.LocaleLoader;
public class BeastLoreEventHandler {
private Player player;
private LivingEntity livingEntity;
private Tameable beast;
protected BeastLoreEventHandler(Player player, LivingEntity livingEntity) {
this.player = player;
this.livingEntity = livingEntity;
this.beast = (Tameable) livingEntity;
}
protected void sendInspectMessage() {
if (player == null) {
return;
}
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
if (beast.isTamed()) {
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", getOwnerName()) + " ");
}
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", livingEntity.getHealth(), livingEntity.getMaxHealth()));
player.sendMessage(message);
}
/**
* Get the name of a tameable animal's owner.
*
* @return the name of the animal's owner
*/
private String getOwnerName() {
AnimalTamer tamer = beast.getOwner();
if (tamer instanceof Player) {
return ((Player) tamer).getName();
}
else if (tamer instanceof OfflinePlayer) {
return ((OfflinePlayer) tamer).getName();
}
return "Unknown Master";
}
}

View File

@ -1,108 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
public class CallOfTheWildEventHandler {
protected Player player;
protected ItemStack inHand;
protected EntityType type;
protected int summonAmount;
protected CallOfTheWildEventHandler(Player player, EntityType type, int summonAmount) {
this.player = player;
this.inHand = player.getItemInHand();
this.type = type;
this.summonAmount = summonAmount;
}
protected void sendInsufficientAmountMessage() {
if (player == null) {
return;
}
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(inHand.getTypeId())));
}
protected boolean nearbyEntityExists() {
if (player == null) {
return false;
}
boolean entityExists = false;
for (Entity entity : player.getNearbyEntities(40, 40, 40)) {
if (entity.getType() == type) {
entityExists = true;
break;
}
}
return entityExists;
}
protected void sendFailureMessage() {
if (player == null) {
return;
}
if (type == EntityType.OCELOT) {
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Ocelot"));
}
else {
player.sendMessage(LocaleLoader.getString("Taming.Summon.Fail.Wolf"));
}
}
protected void spawnCreature() {
if (player == null) {
return;
}
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
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.setHealth(entity.getMaxHealth());
}
}
protected void processResourceCost() {
if (player == null) {
return;
}
int newAmount = inHand.getAmount() - summonAmount;
if (newAmount == 0) {
player.setItemInHand(new ItemStack(Material.AIR));
}
else {
player.getItemInHand().setAmount(inHand.getAmount() - summonAmount);
}
}
protected void sendSuccessMessage() {
if (player == null) {
return;
}
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
}
}

View File

@ -1,27 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.entity.Wolf;
public class FastFoodServiceEventHandler {
private Wolf wolf;
public FastFoodServiceEventHandler(Wolf wolf) {
this.wolf = wolf;
}
protected void modifyHealth(int damage) {
int health = wolf.getHealth();
int maxHealth = wolf.getMaxHealth();
if (health < maxHealth) {
int newHealth = health + damage;
if (newHealth <= maxHealth) {
wolf.setHealth(newHealth);
}
else {
wolf.setHealth(maxHealth);
}
}
}
}

View File

@ -1,44 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.util.skills.SkillUtils;
public class GoreEventHandler {
private TamingManager manager;
private EntityDamageEvent event;
private Entity entity;
protected int skillModifier;
protected GoreEventHandler(TamingManager manager, EntityDamageEvent event) {
this.manager = manager;
this.event = event;
this.entity = event.getEntity();
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = SkillUtils.skillCheck(manager.getSkillLevel(), Taming.goreMaxBonusLevel);
}
protected void modifyEventDamage() {
event.setDamage(event.getDamage() * Taming.goreModifier);
}
protected void sendAbilityMessage() {
if (entity instanceof Player) {
((Player) entity).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
}
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore"));
}
protected void applyBleed() {
BleedTimerTask.add((LivingEntity) entity, Taming.goreBleedTicks);
}
}

View File

@ -1,15 +0,0 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.event.entity.EntityDamageEvent;
public class SharpenedClawsEventHandler {
private EntityDamageEvent event;
public SharpenedClawsEventHandler(EntityDamageEvent event) {
this.event = event;
}
protected void modifyEventDamage() {
event.setDamage(event.getDamage() + Taming.sharpenedClawsBonusDamage);
}
}

View File

@ -1,17 +1,16 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.EntityEffect;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.SkillUtils;
public class Taming {
public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock();
@ -41,22 +40,6 @@ public class Taming {
return pet.isTamed() && owner instanceof Player && pet instanceof Wolf;
}
public static boolean canUseThickFur(Player player) {
return SkillUtils.unlockLevelReached(player, SkillType.TAMING, thickFurUnlockLevel) && Permissions.thickFur(player);
}
public static boolean canUseEnvironmentallyAware(Player player) {
return SkillUtils.unlockLevelReached(player, SkillType.TAMING, environmentallyAwareUnlockLevel) && Permissions.environmentallyAware(player);
}
public static boolean canUseShockProof(Player player) {
return SkillUtils.unlockLevelReached(player, SkillType.TAMING, shockProofUnlockLevel) && Permissions.shockProof(player);
}
public static boolean canUseHolyHound(Player player) {
return SkillUtils.unlockLevelReached(player, SkillType.TAMING, holyHoundUnlockLevel) && Permissions.holyHound(player);
}
public static int processThickFur(Wolf wolf, int damage) {
wolf.playEffect(EntityEffect.WOLF_SHAKE);
return damage / thickFurModifier;
@ -67,24 +50,55 @@ public class Taming {
wolf.setFireTicks(0);
}
public static void processEnvironmentallyAware(Player player, Wolf wolf, int damage) {
if (damage > wolf.getHealth()) {
return;
}
wolf.teleport(player);
player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
}
public static int processShockProof(Wolf wolf, int damage) {
wolf.playEffect(EntityEffect.WOLF_SHAKE);
return damage / shockProofModifier;
}
/**
* Apply the Sharpened Claws ability.
*
* @param event The event to modify
*/
public static int sharpenedClaws(int damage) {
return damage + Taming.sharpenedClawsBonusDamage;
}
public static void processHolyHound(Wolf wolf, int damage) {
int modifiedHealth = Math.min(wolf.getHealth() + damage, wolf.getMaxHealth());
wolf.setHealth(modifiedHealth);
wolf.playEffect(EntityEffect.WOLF_HEARTS);
}
/**
* Get the name of a tameable animal's owner.
*
* @return the name of the animal's owner
*/
protected static String getOwnerName(Tameable beast) {
AnimalTamer tamer = beast.getOwner();
if (tamer instanceof Player) {
return ((Player) tamer).getName();
}
else if (tamer instanceof OfflinePlayer) {
return ((OfflinePlayer) tamer).getName();
}
return "Unknown Master";
}
protected static String getCallOfTheWildFailureMessage(EntityType type) {
switch (type) {
case OCELOT:
return LocaleLoader.getString("Taming.Summon.Fail.Ocelot");
case WOLF:
return LocaleLoader.getString("Taming.Summon.Fail.Wolf");
default:
return "";
}
}
}

View File

@ -1,17 +1,24 @@
package com.gmail.nossr50.skills.taming;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class TamingManager extends SkillManager {
@ -19,6 +26,22 @@ public class TamingManager extends SkillManager {
super(mcMMOPlayer, SkillType.TAMING);
}
public boolean canUseThickFur() {
return getSkillLevel() > Taming.thickFurUnlockLevel && Permissions.thickFur(getPlayer());
}
public boolean canUseEnvironmentallyAware() {
return getSkillLevel() > Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(getPlayer());
}
public boolean canUseShockProof() {
return getSkillLevel() > Taming.shockProofUnlockLevel && Permissions.shockProof(getPlayer());
}
public boolean canUseHolyHound() {
return getSkillLevel() > Taming.holyHoundUnlockLevel && Permissions.holyHound(getPlayer());
}
/**
* Award XP for taming.
*
@ -58,34 +81,26 @@ public class TamingManager extends SkillManager {
}
}
/**
* Apply the Sharpened Claws ability.
*
* @param event The event to modify
*/
public void sharpenedClaws(EntityDamageEvent event) {
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
eventHandler.modifyEventDamage();
}
/**
* Apply the Gore ability.
*
* @param event The event to modify
*/
public void gore(EntityDamageEvent event) {
GoreEventHandler eventHandler = new GoreEventHandler(this, event);
public int gore(LivingEntity target, int damage) {
Player owner = getPlayer();
float chance = (float) ((Taming.goreMaxChance / Taming.goreMaxBonusLevel) * getSkillLevel());
if (chance > Taming.goreMaxChance) {
chance = (float) Taming.goreMaxChance;
if (SkillUtils.activationSuccessful(owner, skill, Taming.goreMaxChance, Taming.goreMaxBonusLevel)) {
BleedTimerTask.add(target, Taming.goreBleedTicks);
if (target instanceof Player) {
((Player) target).sendMessage(LocaleLoader.getString("Combat.StruckByGore"));
}
if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.modifyEventDamage();
eventHandler.applyBleed();
eventHandler.sendAbilityMessage();
owner.sendMessage(LocaleLoader.getString("Combat.Gore"));
return damage * Taming.goreModifier;
}
return damage;
}
/**
@ -105,11 +120,31 @@ public class TamingManager extends SkillManager {
/**
* Handle the Beast Lore ability.
*
* @param livingEntity The entity to examine
* @param target The entity to examine
*/
public void beastLore(LivingEntity livingEntity) {
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(getPlayer(), livingEntity);
eventHandler.sendInspectMessage();
public void beastLore(LivingEntity target) {
Player player = getPlayer();
Tameable beast = (Tameable) target;
String message = LocaleLoader.getString("Combat.BeastLore") + " ";
if (beast.isTamed()) {
message = message.concat(LocaleLoader.getString("Combat.BeastLoreOwner", Taming.getOwnerName(beast)) + " ");
}
message = message.concat(LocaleLoader.getString("Combat.BeastLoreHealth", target.getHealth(), target.getMaxHealth()));
player.sendMessage(message);
}
public void processEnvironmentallyAware(Wolf wolf, int damage) {
if (damage > wolf.getHealth()) {
return;
}
Player owner = getPlayer();
wolf.teleport(owner);
owner.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
}
/**
@ -119,27 +154,36 @@ public class TamingManager extends SkillManager {
* @param summonAmount The amount of material needed to summon the entity
*/
private void callOfTheWild(EntityType type, int summonAmount) {
if (!Permissions.callOfTheWild(getPlayer())) {
Player player = getPlayer();
ItemStack heldItem = player.getItemInHand();
int heldItemAmount = heldItem.getAmount();
if (heldItemAmount < summonAmount) {
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(heldItem.getTypeId())));
return;
}
CallOfTheWildEventHandler eventHandler = new CallOfTheWildEventHandler(getPlayer(), type, summonAmount);
ItemStack inHand = eventHandler.inHand;
int inHandAmount = inHand.getAmount();
if (inHandAmount < summonAmount) {
eventHandler.sendInsufficientAmountMessage();
for (Entity entity : player.getNearbyEntities(40, 40, 40)) {
if (entity.getType() == type) {
player.sendMessage(Taming.getCallOfTheWildFailureMessage(type));
return;
}
}
if (eventHandler.nearbyEntityExists()) {
eventHandler.sendFailureMessage();
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
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 {
eventHandler.spawnCreature();
eventHandler.processResourceCost();
eventHandler.sendSuccessMessage();
}
entity.setHealth(entity.getMaxHealth());
}
player.setItemInHand(new ItemStack(heldItem.getType(), heldItemAmount - summonAmount));
player.sendMessage(LocaleLoader.getString("Taming.Summon.Complete"));
}
}

View File

@ -79,12 +79,7 @@ public final class CombatUtils {
}
if (ItemUtils.isSword(heldItem)) {
if (targetIsPlayer || targetIsTamedPet) {
if (!SkillType.SWORDS.getPVPEnabled()) {
return;
}
}
else if (!SkillType.SWORDS.getPVEEnabled()) {
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.SWORDS.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.SWORDS.getPVEEnabled())) {
return;
}
@ -212,11 +207,11 @@ public final class CombatUtils {
}
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(master)) {
tamingManager.sharpenedClaws(event);
event.setDamage(Taming.sharpenedClaws(event.getDamage()));
}
if (Permissions.gore(master)) {
tamingManager.gore(event);
event.setDamage(tamingManager.gore(target, event.getDamage()));
}
startGainXp(mcMMOPlayer, target, SkillType.TAMING);