mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
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:
parent
c0b7f8a323
commit
cbe9cae4ea
@ -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,16 +60,19 @@ 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)) {
|
||||
mcMMO.placeStore.setFalse(block);
|
||||
entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue);
|
||||
}
|
||||
else if (entity.hasMetadata(mcMMO.entityMetadataKey)) {
|
||||
mcMMO.placeStore.setTrue(block);
|
||||
}
|
||||
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 (isTracked) {
|
||||
mcMMO.placeStore.setTrue(block);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
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,13 +320,14 @@ public class EntityListener implements Listener {
|
||||
if (entity instanceof TNTPrimed) {
|
||||
int id = entity.getEntityId();
|
||||
|
||||
if (plugin.tntIsTracked(id)) {
|
||||
|
||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
||||
if (!plugin.tntIsTracked(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (miningManager.canUseBiggerBombs()) {
|
||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||
}
|
||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBiggerBombs()) {
|
||||
event.setRadius(miningManager.biggerBombs(event.getRadius()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -340,16 +344,18 @@ public class EntityListener implements Listener {
|
||||
if (entity instanceof TNTPrimed) {
|
||||
int id = entity.getEntityId();
|
||||
|
||||
if (plugin.tntIsTracked(id)) {
|
||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBlastMining()) {
|
||||
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
||||
event.setYield(0);
|
||||
}
|
||||
|
||||
plugin.removeFromTNTTracker(id);
|
||||
if (!plugin.tntIsTracked(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MiningManager miningManager = UserManager.getPlayer(plugin.getTNTPlayer(id)).getMiningManager();
|
||||
|
||||
if (miningManager.canUseBlastMining()) {
|
||||
miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
|
||||
event.setYield(0);
|
||||
}
|
||||
|
||||
plugin.removeFromTNTTracker(id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,49 +379,51 @@ 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 */
|
||||
case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
|
||||
case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||
case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
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 */
|
||||
case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
|
||||
case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
|
||||
case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
|
||||
if (Permissions.farmersDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getHerbalismManager().farmersDiet(Herbalism.farmersDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel1, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
|
||||
if (Permissions.fishermansDiet(player)) {
|
||||
event.setFoodLevel(UserManager.getPlayer(player).getFishingManager().handleFishermanDiet(Fishing.fishermansDietRankLevel2, newFoodLevel));
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -428,33 +436,38 @@ 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);
|
||||
}
|
||||
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 (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 (entity instanceof Tameable && target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
Tameable tameable = (Tameable) entity;
|
||||
|
||||
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire(owner))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!CombatUtils.isFriendlyPet(player, tameable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
if (!(Permissions.friendlyFire(player) && Permissions.friendlyFire((Player) tameable.getOwner()))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,29 +1,28 @@
|
||||
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();
|
||||
public static int holyHoundUnlockLevel = AdvancedConfig.getInstance().getHolyHoundUnlock();
|
||||
|
||||
public static int fastFoodServiceUnlockLevel = AdvancedConfig.getInstance().getFastFoodUnlock();
|
||||
public static int fastFoodServiceUnlockLevel = AdvancedConfig.getInstance().getFastFoodUnlock();
|
||||
public static double fastFoodServiceActivationChance = AdvancedConfig.getInstance().getFastFoodChance();
|
||||
|
||||
public static int goreBleedTicks = AdvancedConfig.getInstance().getGoreBleedTicks();
|
||||
public static int goreBleedTicks = AdvancedConfig.getInstance().getGoreBleedTicks();
|
||||
public static int goreMaxBonusLevel = AdvancedConfig.getInstance().getGoreMaxBonusLevel();
|
||||
public static int goreModifier = AdvancedConfig.getInstance().getGoreModifier();
|
||||
public static double goreMaxChance = AdvancedConfig.getInstance().getGoreChanceMax();
|
||||
public static int goreModifier = AdvancedConfig.getInstance().getGoreModifier();
|
||||
public static double goreMaxChance = AdvancedConfig.getInstance().getGoreChanceMax();
|
||||
|
||||
public static int sharpenedClawsUnlockLevel = AdvancedConfig.getInstance().getSharpenedClawsUnlock();
|
||||
public static int sharpenedClawsBonusDamage = AdvancedConfig.getInstance().getSharpenedClawsBonus();
|
||||
@ -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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
|
||||
owner.sendMessage(LocaleLoader.getString("Combat.Gore"));
|
||||
return damage * Taming.goreModifier;
|
||||
}
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
eventHandler.modifyEventDamage();
|
||||
eventHandler.applyBleed();
|
||||
eventHandler.sendAbilityMessage();
|
||||
}
|
||||
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();
|
||||
return;
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user