Trying to clean up duplicate checks & whatnot in our listeners.

This commit is contained in:
GJ 2013-01-24 20:10:50 -05:00
parent 7c59621c9e
commit 9cdfebda9a
22 changed files with 215 additions and 348 deletions

View File

@ -4,7 +4,6 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,18 +27,16 @@ import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.skills.Combat; import com.gmail.nossr50.skills.Combat;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.fishing.Fishing;
import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
@ -78,22 +75,22 @@ public class EntityListener implements Listener {
} }
/** /**
* Monitor EntityDamageByEntity events. * Handle EntityDamageByEntity events that involve modifying the event.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event instanceof FakeEntityDamageByEntityEvent) if (event instanceof FakeEntityDamageByEntityEvent || event.getDamage() <= 0)
return; return;
if (event.getDamage() <= 0)
return;
Entity attacker = event.getDamager();
Entity defender = event.getEntity(); Entity defender = event.getEntity();
if (attacker.hasMetadata("NPC") || defender.hasMetadata("NPC")) return; // Check if either players is are Citizens NPCs if (Misc.isNPCEntity(defender) || defender.isDead()) {
return;
}
Entity attacker = event.getDamager();
if (attacker instanceof Projectile) { if (attacker instanceof Projectile) {
attacker = ((Projectile) attacker).getShooter(); attacker = ((Projectile) attacker).getShooter();
@ -101,7 +98,7 @@ public class EntityListener implements Listener {
else if (attacker instanceof Tameable) { else if (attacker instanceof Tameable) {
AnimalTamer animalTamer = ((Tameable) attacker).getOwner(); AnimalTamer animalTamer = ((Tameable) attacker).getOwner();
if (animalTamer instanceof Entity) { if (animalTamer != null) {
attacker = (Entity) animalTamer; attacker = (Entity) animalTamer;
} }
} }
@ -113,11 +110,9 @@ public class EntityListener implements Listener {
return; return;
} }
if (attacker instanceof Player) { if (attacker instanceof Player && PartyManager.getInstance().inSameParty(defendingPlayer, (Player) attacker)) {
if (PartyManager.getInstance().inSameParty(defendingPlayer, (Player) attacker)) { event.setCancelled(true);
event.setCancelled(true); return;
return;
}
} }
} }
@ -126,35 +121,32 @@ public class EntityListener implements Listener {
LivingEntity livingDefender = (LivingEntity) defender; LivingEntity livingDefender = (LivingEntity) defender;
if (!Misc.isInvincible(livingDefender, event)) { if (!Misc.isInvincible(livingDefender, event)) {
Combat.combatChecks(event); Combat.combatChecks(event, attacker, livingDefender);
} }
} }
} }
/** /**
* Monitor EntityDamage events. * Handle EntityDamage events that involve modifying the event.
* *
* @param event The event to watch * @param event The event to modify
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof FakeEntityDamageEvent) { if (event instanceof FakeEntityDamageEvent || event.getDamage() <= 0) {
return; return;
} }
Entity entity = event.getEntity(); Entity entity = event.getEntity();
DamageCause cause = event.getCause();
if (entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
if (!(entity instanceof LivingEntity)) { if (!(entity instanceof LivingEntity)) {
return; return;
} }
LivingEntity lEntity = (LivingEntity) entity; DamageCause cause = event.getCause();
LivingEntity livingEntity = (LivingEntity) entity;
if (lEntity instanceof Player) { if (livingEntity instanceof Player) {
/* Check for invincibility */
Player player = (Player) entity; Player player = (Player) entity;
if (!player.isOnline()) { if (!player.isOnline()) {
@ -163,17 +155,18 @@ public class EntityListener implements Listener {
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) { if (Misc.isNPCPlayer(player, profile)) {
return; return;
} }
/* Check for invincibility */
if (profile.getGodMode()) { if (profile.getGodMode()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!Misc.isInvincible(player, event)) { if (!Misc.isInvincible(player, event)) {
if (cause == DamageCause.FALL && !player.isInsideVehicle() && !(player.getItemInHand().getType() == Material.ENDER_PEARL)) { if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) {
AcrobaticsManager acroManager = new AcrobaticsManager(player); AcrobaticsManager acroManager = new AcrobaticsManager(player);
acroManager.rollCheck(event); acroManager.rollCheck(event);
} }
@ -186,11 +179,12 @@ public class EntityListener implements Listener {
profile.actualizeRecentlyHurt(); profile.actualizeRecentlyHurt();
} }
} }
} else if (lEntity instanceof Tameable) { }
Tameable pet = (Tameable) lEntity; else if (livingEntity instanceof Tameable) {
Tameable pet = (Tameable) livingEntity;
AnimalTamer owner = pet.getOwner(); AnimalTamer owner = pet.getOwner();
if ((!Misc.isInvincible(lEntity, event)) && pet.isTamed() && (owner instanceof Player) && pet instanceof Wolf) { if ((!Misc.isInvincible(livingEntity, event)) && pet.isTamed() && owner instanceof Player && pet instanceof Wolf) {
TamingManager tamingManager = new TamingManager((Player) owner); TamingManager tamingManager = new TamingManager((Player) owner);
tamingManager.preventDamage(event); tamingManager.preventDamage(event);
} }
@ -277,11 +271,11 @@ public class EntityListener implements Listener {
} }
/** /**
* Monitor FoodLevelChange events. * Handle FoodLevelChange events that involve modifying the event.
* *
* @param event The event to watch * @param event The event to modify
*/ */
@EventHandler (priority = EventPriority.LOW) @EventHandler (priority = EventPriority.LOW, ignoreCancelled = true)
public void onFoodLevelChange(FoodLevelChangeEvent event) { public void onFoodLevelChange(FoodLevelChangeEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
@ -295,6 +289,7 @@ public class EntityListener implements Listener {
int currentFoodLevel = player.getFoodLevel(); int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel(); int newFoodLevel = event.getFoodLevel();
int foodChange = newFoodLevel - currentFoodLevel;
/* /*
* Some foods have 3 ranks * Some foods have 3 ranks
@ -302,127 +297,35 @@ public class EntityListener implements Listener {
* The number of ranks is based on how 'common' the item is * 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 * We can adjust this quite easily if we find something is giving too much of a bonus
*/ */
if (foodChange > 0) {
if (newFoodLevel > currentFoodLevel) { switch (player.getItemInHand().getType()) {
Material food = player.getItemInHand().getType(); case BAKED_POTATO: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM); case BREAD: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
int fishLevel = profile.getSkillLevel(SkillType.FISHING); case CARROT_ITEM: /* RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
int foodChange = newFoodLevel - currentFoodLevel; case GOLDEN_CARROT: /* RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
int rankChange = 0; case MUSHROOM_SOUP: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
boolean fish = false; case PUMPKIN_PIE: /* RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
boolean herb = false; Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel1, event);
int fishFoodRank1 = AdvancedConfig.getInstance().getFishermanDietRankChange();
int fishFoodRank2 = AdvancedConfig.getInstance().getFishermanDietRankChange() * 2;
int fishFoodRankMax = AdvancedConfig.getInstance().getFishermanDietRankChange() * 5;
switch (food) {
case BREAD:
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel1;
break; break;
case COOKIE: case COOKIE: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
/* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ case MELON: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
herb = true; case POISONOUS_POTATO: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
rankChange = Herbalism.farmersDietRankLevel2; case POTATO_ITEM: /* RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
Herbalism.farmersDiet(player, Herbalism.farmersDietRankLevel2, event);
break; break;
case MELON: case COOKED_FISH: /* RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
/* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ Fishing.fishermansDiet(player, Fishing.fishermansDietRankLevel1, event);
herb = true;
rankChange = Herbalism.farmersDietRankLevel2;
break; break;
case MUSHROOM_SOUP: case RAW_FISH: /* RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ Fishing.fishermansDiet(player, Fishing.fishermansDietRankLevel2, event);
herb = true;
rankChange = Herbalism.farmersDietRankLevel1;
break;
case CARROT_ITEM:
/* CARROT RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel1;
break;
case POTATO_ITEM:
/* POTATO RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel2;
break;
case BAKED_POTATO:
/* BAKED POTATO RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel1;
break;
case POISONOUS_POTATO:
/* POISONOUS POTATO RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel2;
break;
case GOLDEN_CARROT:
/* GOLDEN CARROT RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel1;
break;
case PUMPKIN_PIE:
/* PUMPKIN PIE RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
herb = true;
rankChange = Herbalism.farmersDietRankLevel1;
break;
case RAW_FISH:
/* RAW FISH RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
rankChange = fishFoodRank2;
fish = true;
break;
case COOKED_FISH:
/* COOKED FISH RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
rankChange = fishFoodRank1;
fish = true;
break; break;
default: default:
return; return;
} }
if (herb) {
if (!Permissions.farmersDiet(player)) {
return;
}
for (int i = Herbalism.farmersDietRankLevel1; i <= Herbalism.farmersDietMaxLevel; i += rankChange) {
if (herbLevel >= i) {
foodChange++;
}
}
}
else if (fish) {
if (!Permissions.fishermansDiet(player)) {
return;
}
for (int i = fishFoodRank1; i <= fishFoodRankMax; i += rankChange) {
if (fish && fishLevel >= i) {
foodChange++;
}
}
}
/* Make sure we don't go over the max value */
newFoodLevel = currentFoodLevel + foodChange;
if (newFoodLevel > 20) {
event.setFoodLevel(20);
}
else {
event.setFoodLevel(newFoodLevel);
}
} }
} }
} }
@ -432,31 +335,15 @@ public class EntityListener implements Listener {
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler (priority = EventPriority.MONITOR) @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityTame(EntityTameEvent event) { public void onEntityTame(EntityTameEvent event) {
Player player = (Player) event.getOwner(); Player player = (Player) event.getOwner();
if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC if (Misc.isNPCPlayer(player)) {
return;
if (Permissions.taming(player) && !mcMMO.placeStore.isSpawnedPet(event.getEntity())) {
PlayerProfile profile = Users.getProfile(player);
EntityType type = event.getEntityType();
int xp = 0;
switch (type) {
case WOLF:
xp = Config.getInstance().getTamingXPWolf();
break;
case OCELOT:
xp = Config.getInstance().getTamingXPOcelot();
break;
default:
break;
}
Skills.xpProcessing(player, profile, SkillType.TAMING, xp);
} }
TamingManager tamingManager = new TamingManager(player);
tamingManager.awardTamingXP(event);
} }
} }

View File

@ -28,11 +28,15 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.GainXp; import com.gmail.nossr50.runnables.GainXp;
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager; import com.gmail.nossr50.skills.axes.AxeManager;
import com.gmail.nossr50.skills.axes.Axes;
import com.gmail.nossr50.skills.swords.Swords; import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager; import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.ItemChecks;
@ -48,29 +52,28 @@ public class Combat {
* *
* @param event The event to run the combat checks on. * @param event The event to run the combat checks on.
*/ */
public static void combatChecks(EntityDamageByEntityEvent event) { public static void combatChecks(EntityDamageByEntityEvent event, Entity damager, LivingEntity target) {
if (event.getDamage() == 0 || event.getEntity().isDead()) {
return;
}
Entity damager = event.getDamager();
LivingEntity target = (LivingEntity) event.getEntity();
boolean targetIsPlayer = (target.getType() == EntityType.PLAYER); boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false; boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
switch (damager.getType()) { switch (damager.getType()) {
case PLAYER: case PLAYER:
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
ItemStack itemInHand = attacker.getItemInHand();
if (ItemChecks.isSword(itemInHand)) { if (Misc.isNPCPlayer(attacker)) {
return;
}
ItemStack heldItem = attacker.getItemInHand();
Material heldItemType = heldItem.getType();
if (ItemChecks.isSword(heldItem)) {
if (targetIsPlayer || targetIsTamedPet) { if (targetIsPlayer || targetIsTamedPet) {
if (!configInstance.getSwordsPVP()) { if (!Swords.pvpEnabled) {
return; return;
} }
} }
else if (!configInstance.getSwordsPVE()) { else if (!Swords.pveEnabled) {
return; return;
} }
@ -82,13 +85,13 @@ public class Combat {
startGainXp(attacker, swordsManager.getProfile(), target, SkillType.SWORDS); startGainXp(attacker, swordsManager.getProfile(), target, SkillType.SWORDS);
} }
else if (ItemChecks.isAxe(itemInHand) && Permissions.axes(attacker)) { else if (ItemChecks.isAxe(heldItem)) {
if (targetIsPlayer || targetIsTamedPet) { if (targetIsPlayer || targetIsTamedPet) {
if (!configInstance.getAxesPVP()) { if (!Axes.pvpEnabled) {
return; return;
} }
} }
else if (!configInstance.getAxesPVE()) { else if (!Axes.pveEnabled) {
return; return;
} }
@ -96,13 +99,13 @@ public class Combat {
AxeManager axeManager = new AxeManager(attacker); AxeManager axeManager = new AxeManager(attacker);
axeManager.bonusDamage(event); axeManager.bonusDamage(event);
axeManager.criticalHitCheck(event); axeManager.criticalHitCheck(event, target);
axeManager.impact(event); axeManager.impact(event, target);
axeManager.skullSplitter(event); axeManager.skullSplitter(target, event.getDamage());
startGainXp(attacker, axeManager.getProfile(), target, SkillType.AXES); startGainXp(attacker, axeManager.getProfile(), target, SkillType.AXES);
} }
else if (itemInHand.getType() == Material.AIR && Permissions.unarmed(attacker)) { else if (heldItemType == Material.AIR) {
if (targetIsPlayer || targetIsTamedPet) { if (targetIsPlayer || targetIsTamedPet) {
if (!configInstance.getUnarmedPVP()) { if (!configInstance.getUnarmedPVP()) {
return; return;
@ -115,20 +118,13 @@ public class Combat {
Skills.abilityCheck(attacker, SkillType.UNARMED); Skills.abilityCheck(attacker, SkillType.UNARMED);
UnarmedManager unarmedManager = new UnarmedManager(attacker); UnarmedManager unarmedManager = new UnarmedManager(attacker);
unarmedManager.bonusDamage(event); unarmedManager.bonusDamage(event);
unarmedManager.berserkDamage(event);
if (unarmedManager.getProfile().getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(attacker)) { unarmedManager.disarmCheck(target);
event.setDamage((int) (event.getDamage() * 1.5));
}
if (targetIsPlayer) {
unarmedManager.disarmCheck((Player) target);
}
startGainXp(attacker, unarmedManager.getProfile(), target, SkillType.UNARMED); startGainXp(attacker, unarmedManager.getProfile(), target, SkillType.UNARMED);
} }
else if (itemInHand.getType() == Material.BONE && target instanceof Tameable) { else if (heldItemType == Material.BONE && target instanceof Tameable) {
TamingManager tamingManager = new TamingManager(attacker); TamingManager tamingManager = new TamingManager(attacker);
tamingManager.beastLore(target); tamingManager.beastLore(target);
event.setCancelled(true); event.setCancelled(true);
@ -143,21 +139,20 @@ public class Combat {
Player master = (Player) wolf.getOwner(); Player master = (Player) wolf.getOwner();
if (targetIsPlayer || targetIsTamedPet) { if (targetIsPlayer || targetIsTamedPet) {
if (!configInstance.getTamingPVP()) { if (!Taming.pvpEnabled) {
return; return;
} }
} }
else if (!configInstance.getTamingPVE()) { else if (!Taming.pveEnabled) {
return; return;
} }
TamingManager tamingManager = new TamingManager(master); TamingManager tamingManager = new TamingManager(master);
tamingManager.fastFoodService(wolf, event.getDamage()); tamingManager.fastFoodService(wolf, event.getDamage());
tamingManager.sharpenedClaws(event); tamingManager.sharpenedClaws(event);
tamingManager.gore(event); tamingManager.gore(event);
startGainXp(master, Users.getProfile(master), target, SkillType.TAMING); startGainXp(master, tamingManager.getProfile(), target, SkillType.TAMING);
} }
break; break;
@ -165,16 +160,17 @@ public class Combat {
case ARROW: case ARROW:
LivingEntity shooter = ((Arrow) damager).getShooter(); LivingEntity shooter = ((Arrow) damager).getShooter();
//TODO: Is there a reason we're breaking here instead of returning?
if (shooter == null || shooter.getType() != EntityType.PLAYER) { if (shooter == null || shooter.getType() != EntityType.PLAYER) {
break; break;
} }
if (targetIsPlayer || targetIsTamedPet) { if (targetIsPlayer || targetIsTamedPet) {
if (!configInstance.getArcheryPVP()) { if (!Archery.pvpEnabled) {
return; return;
} }
} }
else if (!configInstance.getArcheryPVE()) { else if (!Archery.pveEnabled) {
return; return;
} }
@ -188,29 +184,29 @@ public class Combat {
if (targetIsPlayer) { if (targetIsPlayer) {
Player player = (Player) target; Player player = (Player) target;
AcrobaticsManager acroManager = new AcrobaticsManager(player); AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
SwordsManager swordsManager = new SwordsManager(player); SwordsManager swordsManager = new SwordsManager(player);
if (damager.getType() == EntityType.PLAYER) { if (damager instanceof Player) {
if (configInstance.getSwordsPVP()) { if (Swords.pvpEnabled) {
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
} }
if (configInstance.getAcrobaticsPVP()) { if (Acrobatics.pvpEnabled) {
acroManager.dodgeCheck(event); acrobaticsManager.dodgeCheck(event);
} }
} }
else { else {
if (configInstance.getSwordsPVE() && damager instanceof LivingEntity) { if (Swords.pveEnabled && damager instanceof LivingEntity) {
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
} }
if (configInstance.getAcrobaticsPVE()) { if (Acrobatics.pveEnabled) {
if (damager instanceof LightningStrike && configInstance.getDodgeLightningDisabled()) { if (damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) {
return; return;
} }
acroManager.dodgeCheck(event); acrobaticsManager.dodgeCheck(event);
} }
} }
} }

View File

@ -532,9 +532,6 @@ public class Skills {
* @param xp the amount of XP to gain * @param xp the amount of XP to gain
*/ */
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) { public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
if (player == null)
return;
if (type.getPermissions(player)) { if (type.getPermissions(player)) {
if (Users.getPlayer(player) == null) if (Users.getPlayer(player) == null)
return; return;

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.acrobatics; package com.gmail.nossr50.skills.acrobatics;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
public class Acrobatics { public class Acrobatics {
public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax(); public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax();
@ -9,9 +10,16 @@ public class Acrobatics {
public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax(); public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax();
public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel(); public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel();
public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax(); public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax();
public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel(); public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel();
public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier(); public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier();
public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier(); public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier();
public static boolean pvpEnabled = Config.getInstance().getAcrobaticsPVP();
public static boolean pveEnabled = Config.getInstance().getAcrobaticsPVE();
public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled();
public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled();
} }

View File

@ -3,7 +3,6 @@ package com.gmail.nossr50.skills.acrobatics;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -20,14 +19,6 @@ public class AcrobaticsManager extends SkillManager {
* @param event The event to check * @param event The event to check
*/ */
public void rollCheck(EntityDamageEvent event) { public void rollCheck(EntityDamageEvent event) {
if (Misc.isNPCPlayer(player) || !Permissions.roll(player)) {
return;
}
if (Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle()) {
return;
}
RollEventHandler eventHandler = new RollEventHandler(this, event); RollEventHandler eventHandler = new RollEventHandler(this, event);
double chance; double chance;

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
public class Archery { public class Archery {
@ -25,6 +26,9 @@ public class Archery {
public static double dazeMaxBonus = AdvancedConfig.getInstance().getDazeBonusMax(); public static double dazeMaxBonus = AdvancedConfig.getInstance().getDazeBonusMax();
public static int dazeModifier = AdvancedConfig.getInstance().getDazeModifier(); public static int dazeModifier = AdvancedConfig.getInstance().getDazeModifier();
public static boolean pvpEnabled = Config.getInstance().getArcheryPVP();
public static boolean pveEnabled = Config.getInstance().getArcheryPVE();
protected static void incrementTrackerValue(LivingEntity livingEntity) { protected static void incrementTrackerValue(LivingEntity livingEntity) {
for (TrackedEntity trackedEntity : trackedEntities) { for (TrackedEntity trackedEntity : trackedEntities) {
if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) { if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) {

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.axes; package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -21,7 +22,7 @@ public class AxeManager extends SkillManager {
* @param event The event to modify * @param event The event to modify
*/ */
public void bonusDamage(EntityDamageByEntityEvent event) { public void bonusDamage(EntityDamageByEntityEvent event) {
if (Misc.isNPCPlayer(player) || !Permissions.axeBonus(player)) { if (!Permissions.axeBonus(player)) {
return; return;
} }
@ -36,20 +37,16 @@ public class AxeManager extends SkillManager {
* *
* @param event The event to modify * @param event The event to modify
*/ */
public void criticalHitCheck(EntityDamageByEntityEvent event) { public void criticalHitCheck(EntityDamageByEntityEvent event, LivingEntity target) {
if (Misc.isNPCPlayer(player) || !Permissions.criticalHit(player)) { if (target.isDead() || (target instanceof Tameable && Misc.isFriendlyPet(player, (Tameable) target)) || !Permissions.criticalHit(player)) {
return; return;
} }
CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event); CriticalHitEventHandler eventHandler = new CriticalHitEventHandler(this, event, target);
if (eventHandler.defender instanceof Tameable && Misc.isFriendlyPet(player, (Tameable) eventHandler.defender)) {
return;
}
double chance = (Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * eventHandler.skillModifier; double chance = (Axes.criticalHitMaxChance / Axes.criticalHitMaxBonusLevel) * eventHandler.skillModifier;
if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.defender.isDead()) { if (chance > Misc.getRandom().nextInt(activationChance)) {
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
eventHandler.sendAbilityMessages(); eventHandler.sendAbilityMessages();
} }
@ -60,18 +57,14 @@ public class AxeManager extends SkillManager {
* *
* @param event The event to modify * @param event The event to modify
*/ */
public void impact(EntityDamageByEntityEvent event) { public void impact(EntityDamageByEntityEvent event, LivingEntity target) {
if (Misc.isNPCPlayer(player) || !Permissions.impact(player)) { if (target.isDead() || !Permissions.impact(player)) {
return; return;
} }
ImpactEventHandler eventHandler = new ImpactEventHandler(this, event); ImpactEventHandler eventHandler = new ImpactEventHandler(this, event, target);
if (eventHandler.livingDefender == null) { if (Misc.hasArmor(target)) {
return;
}
if (Misc.hasArmor(eventHandler.livingDefender)) {
eventHandler.damageArmor(); eventHandler.damageArmor();
} }
else { else {
@ -84,12 +77,12 @@ public class AxeManager extends SkillManager {
* *
* @param event The event to process * @param event The event to process
*/ */
public void skullSplitter(EntityDamageByEntityEvent event) { public void skullSplitter(LivingEntity target, int damage) {
if (Misc.isNPCPlayer(player) || !Permissions.skullSplitter(player) || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER)) { if (target.isDead() || !profile.getAbilityMode(AbilityType.SKULL_SPLIITER) || !Permissions.skullSplitter(player)) {
return; return;
} }
SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(this, event); SkullSplitterEventHandler eventHandler = new SkullSplitterEventHandler(player, damage, target);
eventHandler.applyAbilityEffects(); eventHandler.applyAbilityEffects();
} }
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.axes; package com.gmail.nossr50.skills.axes;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
public class Axes { public class Axes {
public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax(); public static int bonusDamageMaxBonus = AdvancedConfig.getInstance().getBonusDamageAxesBonusMax();
@ -19,4 +20,7 @@ public class Axes {
public static int greaterImpactBonusDamage = AdvancedConfig.getInstance().getGreaterImpactBonusDamage(); public static int greaterImpactBonusDamage = AdvancedConfig.getInstance().getGreaterImpactBonusDamage();
public static int skullSplitterModifier = AdvancedConfig.getInstance().getSkullSplitterModifier(); public static int skullSplitterModifier = AdvancedConfig.getInstance().getSkullSplitterModifier();
public static boolean pvpEnabled = Config.getInstance().getAxesPVP();
public static boolean pveEnabled = Config.getInstance().getAxesPVE();
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.skills.axes; package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -12,13 +12,13 @@ public class CriticalHitEventHandler {
private EntityDamageByEntityEvent event; private EntityDamageByEntityEvent event;
private int damage; private int damage;
protected Entity defender; protected LivingEntity defender;
protected int skillModifier; protected int skillModifier;
public CriticalHitEventHandler(AxeManager manager, EntityDamageByEntityEvent event) { public CriticalHitEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
this.manager = manager; this.manager = manager;
this.event = event; this.event = event;
this.defender = event.getEntity(); this.defender = defender;
this.damage = event.getDamage(); this.damage = event.getDamage();
calculateSkillModifier(); calculateSkillModifier();

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.skills.axes; package com.gmail.nossr50.skills.axes;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -20,20 +19,15 @@ public class ImpactEventHandler {
private EntityEquipment equipment; private EntityEquipment equipment;
private ItemStack[] armorContents; private ItemStack[] armorContents;
protected Entity defender; protected LivingEntity defender;
protected LivingEntity livingDefender;
public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event) { public ImpactEventHandler(AxeManager manager, EntityDamageByEntityEvent event, LivingEntity defender) {
this.manager = manager; this.manager = manager;
this.player = manager.getPlayer(); this.player = manager.getPlayer();
this.event = event; this.event = event;
this.defender = event.getEntity(); this.defender = defender;
this.equipment = defender.getEquipment();
if (defender instanceof LivingEntity) { this.armorContents = equipment.getArmorContents();
this.livingDefender = (LivingEntity) defender;
this.equipment = livingDefender.getEquipment();
this.armorContents = equipment.getArmorContents();
}
} }
protected void damageArmor() { protected void damageArmor() {
@ -70,14 +64,14 @@ public class ImpactEventHandler {
private void handleGreaterImpactEffect() { private void handleGreaterImpactEffect() {
event.setDamage(event.getDamage() + Axes.greaterImpactBonusDamage); event.setDamage(event.getDamage() + Axes.greaterImpactBonusDamage);
livingDefender.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier)); defender.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
} }
private void sendAbilityMessge() { private void sendAbilityMessge() {
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
if (livingDefender instanceof Player) { if (defender instanceof Player) {
((Player) livingDefender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck")); ((Player) defender).sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
} }
} }

View File

@ -2,7 +2,6 @@ package com.gmail.nossr50.skills.axes;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gmail.nossr50.skills.Combat; import com.gmail.nossr50.skills.Combat;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
@ -12,10 +11,10 @@ public class SkullSplitterEventHandler {
private LivingEntity target; private LivingEntity target;
private int damage; private int damage;
protected SkullSplitterEventHandler(AxeManager manager, EntityDamageByEntityEvent event) { protected SkullSplitterEventHandler(Player player, int damage, LivingEntity target) {
this.player = manager.getPlayer(); this.player = player;
this.target = (LivingEntity) event.getEntity(); this.target = target;
this.damage = event.getDamage(); this.damage = damage;
} }
protected void applyAbilityEffects() { protected void applyAbilityEffects() {

View File

@ -15,6 +15,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
import org.bukkit.entity.Skeleton; import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
@ -50,11 +51,20 @@ public class Fishing {
public static int shakeChanceLevel5 = AdvancedConfig.getInstance().getShakeChanceRank5(); public static int shakeChanceLevel5 = AdvancedConfig.getInstance().getShakeChanceRank5();
public static int shakeUnlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel(); public static int shakeUnlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel();
public static int fishermanDietRankChangeLevel = AdvancedConfig.getInstance().getFishermanDietRankChange(); public static int fishermansDietRankLevel1 = AdvancedConfig.getInstance().getFishermanDietRankChange();
public static int fishermanDietMaxLevel = fishermanDietRankChangeLevel * 5; public static int fishermansDietRankLevel2 = fishermansDietRankLevel1 * 2;
public static int fishermansDietMaxLevel = fishermansDietRankLevel1 * 5;
public static int magicHunterMultiplier = AdvancedConfig.getInstance().getFishingMagicMultiplier(); public static int magicHunterMultiplier = AdvancedConfig.getInstance().getFishingMagicMultiplier();
public static void fishermansDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
if (!Permissions.fishermansDiet(player)) {
return;
}
Skills.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange);
}
/** /**
* Get the player's current fishing loot tier. * Get the player's current fishing loot tier.
* *

View File

@ -49,7 +49,7 @@ public class FishingCommand extends SkillCommand {
shakeChanceLucky = shakeStrings[1]; shakeChanceLucky = shakeStrings[1];
//FISHERMAN'S DIET //FISHERMAN'S DIET
fishermansDietRank = calculateRank(Fishing.fishermanDietMaxLevel, Fishing.fishermanDietRankChangeLevel); fishermansDietRank = calculateRank(Fishing.fishermansDietMaxLevel, Fishing.fishermansDietRankLevel1);
} }
@Override @Override

View File

@ -83,10 +83,6 @@ public class MiningManager extends SkillManager{
* @param event Event whose explosion damage is being reduced * @param event Event whose explosion damage is being reduced
*/ */
public void demolitionsExpertise(EntityDamageEvent event) { public void demolitionsExpertise(EntityDamageEvent event) {
if (Misc.isNPCPlayer(player)) {
return;
}
DemoltionsExpertiseEventHandler eventHandler = new DemoltionsExpertiseEventHandler(this, event); DemoltionsExpertiseEventHandler eventHandler = new DemoltionsExpertiseEventHandler(this, event);
eventHandler.calculateDamageModifier(); eventHandler.calculateDamageModifier();

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.swords; package com.gmail.nossr50.skills.swords;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
public class Swords { public class Swords {
public static double bleedMaxChance = AdvancedConfig.getInstance().getBleedChanceMax(); public static double bleedMaxChance = AdvancedConfig.getInstance().getBleedChanceMax();
@ -14,4 +15,8 @@ public class Swords {
public static int serratedStrikesModifier = AdvancedConfig.getInstance().getSerratedStrikesModifier(); public static int serratedStrikesModifier = AdvancedConfig.getInstance().getSerratedStrikesModifier();
public static int serratedStrikesBleedTicks = AdvancedConfig.getInstance().getSerratedStrikesTicks(); public static int serratedStrikesBleedTicks = AdvancedConfig.getInstance().getSerratedStrikesTicks();
public static boolean pvpEnabled = Config.getInstance().getSwordsPVP();
public static boolean pveEnabled = Config.getInstance().getSwordsPVE();
} }

View File

@ -21,9 +21,6 @@ public class SwordsManager extends SkillManager {
* @param defender The defending entity * @param defender The defending entity
*/ */
public void bleedCheck(LivingEntity defender) { public void bleedCheck(LivingEntity defender) {
if (player == null)
return;
if (!Permissions.swordsBleed(player)) { if (!Permissions.swordsBleed(player)) {
return; return;
} }
@ -42,9 +39,6 @@ public class SwordsManager extends SkillManager {
} }
public void counterAttackChecks(LivingEntity attacker, int damage) { public void counterAttackChecks(LivingEntity attacker, int damage) {
if (player == null)
return;
if (!Permissions.counterAttack(player)) { if (!Permissions.counterAttack(player)) {
return; return;
} }
@ -65,7 +59,7 @@ public class SwordsManager extends SkillManager {
} }
public void serratedStrikes(LivingEntity target, int damage) { public void serratedStrikes(LivingEntity target, int damage) {
if (Misc.isNPCPlayer(player) || !Permissions.serratedStrikes(player) || !profile.getAbilityMode(AbilityType.SERRATED_STRIKES)) { if (!profile.getAbilityMode(AbilityType.SERRATED_STRIKES) || !Permissions.serratedStrikes(player)) {
return; return;
} }

View File

@ -18,9 +18,6 @@ public class EnvironmentallyAwareEventHandler {
} }
protected void teleportWolf() { protected void teleportWolf() {
if (player == null)
return;
if (event.getDamage() > wolf.getHealth()) { if (event.getDamage() > wolf.getHealth()) {
return; return;
} }
@ -29,9 +26,6 @@ public class EnvironmentallyAwareEventHandler {
} }
protected void sendAbilityMessage() { protected void sendAbilityMessage() {
if (player == null)
return;
player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf")); player.sendMessage(LocaleLoader.getString("Taming.Listener.Wolf"));
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.taming; package com.gmail.nossr50.skills.taming;
import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config;
public class Taming { public class Taming {
public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock(); public static int environmentallyAwareUnlockLevel = AdvancedConfig.getInstance().getEnviromentallyAwareUnlock();
@ -21,4 +22,10 @@ public class Taming {
public static int thickFurUnlockLevel = AdvancedConfig.getInstance().getThickFurUnlock(); public static int thickFurUnlockLevel = AdvancedConfig.getInstance().getThickFurUnlock();
public static int thickFurModifier = AdvancedConfig.getInstance().getThickFurModifier(); public static int thickFurModifier = AdvancedConfig.getInstance().getThickFurModifier();
public static int wolfXP = Config.getInstance().getTamingXPWolf();
public static int ocelotXP = Config.getInstance().getTamingXPOcelot();
public static boolean pvpEnabled = Config.getInstance().getTamingPVP();
public static boolean pveEnabled = Config.getInstance().getTamingPVE();
} }

View File

@ -6,11 +6,14 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
@ -22,6 +25,30 @@ public class TamingManager extends SkillManager {
this.configInstance = Config.getInstance(); this.configInstance = Config.getInstance();
} }
/**
* Award XP for taming.
*
* @param event The event to award XP for
*/
public void awardTamingXP(EntityTameEvent event) {
if (mcMMO.placeStore.isSpawnedMob(event.getEntity())) {
return;
}
switch (event.getEntityType()) {
case WOLF:
Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.wolfXP);
break;
case OCELOT:
Skills.xpProcessing(player, profile, SkillType.TAMING, Taming.ocelotXP);
break;
default:
break;
}
}
/** /**
* Apply the Fast Food Service ability. * Apply the Fast Food Service ability.
* *
@ -29,14 +56,7 @@ public class TamingManager extends SkillManager {
* @param damage The damage being absorbed by the wolf * @param damage The damage being absorbed by the wolf
*/ */
public void fastFoodService(Wolf wolf, int damage) { public void fastFoodService(Wolf wolf, int damage) {
if (player == null) if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(player)) {
return;
if (!Permissions.fastFoodService(player)) {
return;
}
if (skillLevel >= Taming.fastFoodServiceUnlockLevel) {
if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) { if (Misc.getRandom().nextInt(activationChance) < Taming.fastFoodServiceActivationChance) {
FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf); FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf);
@ -51,14 +71,7 @@ public class TamingManager extends SkillManager {
* @param event The event to modify * @param event The event to modify
*/ */
public void sharpenedClaws(EntityDamageEvent event) { public void sharpenedClaws(EntityDamageEvent event) {
if (player == null) if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(player)) {
return;
if (!Permissions.sharpenedClaws(player)) {
return;
}
if (skillLevel >= Taming.sharpenedClawsUnlockLevel) {
SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event); SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event);
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
@ -71,9 +84,6 @@ public class TamingManager extends SkillManager {
* @param event The event to modify * @param event The event to modify
*/ */
public void gore(EntityDamageEvent event) { public void gore(EntityDamageEvent event) {
if (player == null)
return;
if (!Permissions.gore(player)) { if (!Permissions.gore(player)) {
return; return;
} }
@ -143,15 +153,11 @@ public class TamingManager extends SkillManager {
* @param livingEntity The entity to examine * @param livingEntity The entity to examine
*/ */
public void beastLore(LivingEntity livingEntity) { public void beastLore(LivingEntity livingEntity) {
if (player == null)
return;
if (!Permissions.beastLore(player)) { if (!Permissions.beastLore(player)) {
return; return;
} }
BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity); BeastLoreEventHandler eventHandler = new BeastLoreEventHandler(player, livingEntity);
eventHandler.sendInspectMessage(); eventHandler.sendInspectMessage();
} }
@ -193,14 +199,7 @@ public class TamingManager extends SkillManager {
* @param cause The damage cause of the event * @param cause The damage cause of the event
*/ */
private void environmentallyAware(EntityDamageEvent event, DamageCause cause) { private void environmentallyAware(EntityDamageEvent event, DamageCause cause) {
if (player == null) if (skillLevel >= Taming.environmentallyAwareUnlockLevel && Permissions.environmentallyAware(player)) {
return;
if (!Permissions.environmentallyAware(player)) {
return;
}
if (skillLevel >= Taming.environmentallyAwareUnlockLevel) {
EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event); EnvironmentallyAwareEventHandler eventHandler = new EnvironmentallyAwareEventHandler(this, event);
switch (cause) { switch (cause) {
@ -228,16 +227,8 @@ public class TamingManager extends SkillManager {
* @param cause The damage cause of the event * @param cause The damage cause of the event
*/ */
private void thickFur(EntityDamageEvent event, DamageCause cause) { private void thickFur(EntityDamageEvent event, DamageCause cause) {
if (player == null) if (skillLevel >= Taming.thickFurUnlockLevel && Permissions.thickFur(player)) {
return;
if (!Permissions.thickFur(player)) {
return;
}
if (skillLevel >= Taming.thickFurUnlockLevel) {
ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause); ThickFurEventHandler eventHandler = new ThickFurEventHandler(event, cause);
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
} }
} }
@ -248,16 +239,8 @@ public class TamingManager extends SkillManager {
* @param event The event to modify * @param event The event to modify
*/ */
private void shockProof(EntityDamageEvent event) { private void shockProof(EntityDamageEvent event) {
if (player == null) if (skillLevel >= Taming.shockProofUnlockLevel && Permissions.shockProof(player)) {
return;
if (!Permissions.shockProof(player)) {
return;
}
if (skillLevel >= Taming.shockProofUnlockLevel) {
ShockProofEventHandler eventHandler = new ShockProofEventHandler(event); ShockProofEventHandler eventHandler = new ShockProofEventHandler(event);
eventHandler.modifyEventDamage(); eventHandler.modifyEventDamage();
} }
} }

View File

@ -14,4 +14,6 @@ public class Unarmed {
public static double ironGripMaxChance = AdvancedConfig.getInstance().getIronGripChanceMax(); public static double ironGripMaxChance = AdvancedConfig.getInstance().getIronGripChanceMax();
public static int ironGripMaxBonusLevel = AdvancedConfig.getInstance().getIronGripMaxBonusLevel(); public static int ironGripMaxBonusLevel = AdvancedConfig.getInstance().getIronGripMaxBonusLevel();
public static double berserkDamageModifier = 1.5;
} }

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.skills.unarmed; package com.gmail.nossr50.skills.unarmed;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.skills.AbilityType;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -18,12 +20,13 @@ public class UnarmedManager extends SkillManager {
* *
* @param defender The defending player * @param defender The defending player
*/ */
public void disarmCheck(Player defender) { public void disarmCheck(LivingEntity defender) {
if (Misc.isNPCPlayer(player) || !Permissions.disarm(player)) { if (!(defender instanceof Player) || !Permissions.disarm(player)) {
return; return;
} }
DisarmEventHandler eventHandler = new DisarmEventHandler(this, defender); Player defendingPlayer = (Player) defender;
DisarmEventHandler eventHandler = new DisarmEventHandler(this, defendingPlayer);
if (eventHandler.isHoldingItem()) { if (eventHandler.isHoldingItem()) {
eventHandler.calculateSkillModifier(); eventHandler.calculateSkillModifier();
@ -32,7 +35,7 @@ public class UnarmedManager extends SkillManager {
if (chance > Unarmed.disarmMaxChance) chance = (float) Unarmed.disarmMaxChance; if (chance > Unarmed.disarmMaxChance) chance = (float) Unarmed.disarmMaxChance;
if (chance > Misc.getRandom().nextInt(activationChance)) { if (chance > Misc.getRandom().nextInt(activationChance)) {
if (!hasIronGrip(defender)) { if (!hasIronGrip(defendingPlayer)) {
eventHandler.handleDisarm(); eventHandler.handleDisarm();
} }
} }
@ -64,15 +67,18 @@ public class UnarmedManager extends SkillManager {
} }
} }
public void berserkDamage(EntityDamageEvent event) {
if (!profile.getAbilityMode(AbilityType.BERSERK) || !Permissions.berserk(player)) {
event.setDamage((int) (event.getDamage() * Unarmed.berserkDamageModifier));
}
}
/** /**
* Handle Unarmed bonus damage. * Handle Unarmed bonus damage.
* *
* @param event The event to modify. * @param event The event to modify.
*/ */
public void bonusDamage(EntityDamageEvent event) { public void bonusDamage(EntityDamageEvent event) {
if (player == null)
return;
if (!Permissions.unarmedBonus(player)) { if (!Permissions.unarmedBonus(player)) {
return; return;
} }
@ -90,10 +96,7 @@ public class UnarmedManager extends SkillManager {
* @return true if the defender was not disarmed, false otherwise * @return true if the defender was not disarmed, false otherwise
*/ */
private boolean hasIronGrip(Player defender) { private boolean hasIronGrip(Player defender) {
if (defender == null) if (Misc.isNPCEntity(defender) || !Permissions.ironGrip(defender)) {
return false;
if (!Permissions.ironGrip(defender)) {
return false; return false;
} }

View File

@ -173,7 +173,7 @@ Skills:
# SuperRepair_MaxBonusLevel: On this level, Super Repair chance will be SuperRepair_ChanceMax # SuperRepair_MaxBonusLevel: On this level, Super Repair chance will be SuperRepair_ChanceMax
SuperRepair_ChanceMax: 100.0 SuperRepair_ChanceMax: 100.0
SuperRepair_MaxBonusLevel: 1000 SuperRepair_MaxBonusLevel: 1000
Arcane_Forging: Arcane_Forging:
May_Lose_Enchants: true May_Lose_Enchants: true
Rank_Levels: Rank_Levels: