We were calling deflect twice. Also made individual functions for each

type of combat.
This commit is contained in:
GJ 2013-06-07 13:55:49 -04:00
parent 3f7b17961f
commit a1792fe125
4 changed files with 172 additions and 174 deletions

View File

@ -170,7 +170,7 @@ public class EntityListener implements Listener {
} }
} }
CombatUtils.combatChecks(event, attacker, target); CombatUtils.processCombatAttack(event, attacker, target);
} }
/** /**

View File

@ -261,7 +261,10 @@ public class mcMMO extends JavaPlugin {
} }
private void checkForUpdates() { private void checkForUpdates() {
if (Config.getInstance().getUpdateCheckEnabled()) { if (!Config.getInstance().getUpdateCheckEnabled()) {
return;
}
try { try {
updateAvailable = UpdateChecker.updateAvailable(); updateAvailable = UpdateChecker.updateAvailable();
} }
@ -274,11 +277,9 @@ public class mcMMO extends JavaPlugin {
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable")); getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
} }
} }
}
private void loadConfigFiles() { private void loadConfigFiles() {
// Force the loading of config files // Force the loading of config files
Config configInstance = Config.getInstance();
TreasureConfig.getInstance(); TreasureConfig.getInstance();
HiddenConfig.getInstance(); HiddenConfig.getInstance();
AdvancedConfig.getInstance(); AdvancedConfig.getInstance();
@ -286,19 +287,19 @@ public class mcMMO extends JavaPlugin {
List<Repairable> repairables = new ArrayList<Repairable>(); List<Repairable> repairables = new ArrayList<Repairable>();
if (configInstance.getToolModsEnabled()) { if (Config.getInstance().getToolModsEnabled()) {
repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables()); repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables());
} }
if (configInstance.getArmorModsEnabled()) { if (Config.getInstance().getArmorModsEnabled()) {
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables()); repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
} }
if (configInstance.getBlockModsEnabled()) { if (Config.getInstance().getBlockModsEnabled()) {
CustomBlockConfig.getInstance(); CustomBlockConfig.getInstance();
} }
if (configInstance.getEntityModsEnabled()) { if (Config.getInstance().getEntityModsEnabled()) {
CustomEntityConfig.getInstance(); CustomEntityConfig.getInstance();
} }
@ -309,14 +310,16 @@ public class mcMMO extends JavaPlugin {
repairableManager.registerRepairables(repairables); repairableManager.registerRepairables(repairables);
// Check if Repair Anvil and Salvage Anvil have different itemID's // Check if Repair Anvil and Salvage Anvil have different itemID's
if (configInstance.getSalvageAnvilId() == configInstance.getRepairAnvilId()) { if (Config.getInstance().getSalvageAnvilId() == Config.getInstance().getRepairAnvilId()) {
getLogger().warning("Can't use the same itemID for Repair/Salvage Anvils!"); getLogger().warning("Can't use the same itemID for Repair/Salvage Anvils!");
} }
} }
private void setupSpout() { private void setupSpout() {
// Check for Spout if (!getServer().getPluginManager().isPluginEnabled("Spout")) {
if (getServer().getPluginManager().isPluginEnabled("Spout")) { return;
}
spoutEnabled = true; spoutEnabled = true;
SpoutConfig.getInstance(); SpoutConfig.getInstance();
@ -324,7 +327,6 @@ public class mcMMO extends JavaPlugin {
SpoutUtils.preCacheFiles(); SpoutUtils.preCacheFiles();
SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload
} }
}
private void registerEvents() { private void registerEvents() {
PluginManager pluginManager = getServer().getPluginManager(); PluginManager pluginManager = getServer().getPluginManager();

View File

@ -46,46 +46,8 @@ import com.gmail.nossr50.util.player.UserManager;
public final class CombatUtils { public final class CombatUtils {
private CombatUtils() {} private CombatUtils() {}
/** private static void processSwordCombat(LivingEntity target, Player player, int damage) {
* Apply combat modifiers and process and XP gain.
*
* @param event The event to run the combat checks on.
*/
public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
Entity damager = event.getDamager();
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
Player player = (Player) attacker;
if (Misc.isNPCEntity(player)) {
return;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
ItemStack heldItem = player.getItemInHand();
if (target instanceof Tameable) {
if (heldItem.getType() == Material.BONE) {
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
if (tamingManager.canUseBeastLore()) {
tamingManager.beastLore(target);
event.setCancelled(true);
return;
}
}
if (isFriendlyPet(player, (Tameable) target)) {
return;
}
}
if (ItemUtils.isSword(heldItem)) {
if (!shouldProcessSkill(target, SkillType.SWORDS)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager(); SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
if (swordsManager.canActivateAbility()) { if (swordsManager.canActivateAbility()) {
@ -97,18 +59,14 @@ public final class CombatUtils {
} }
if (swordsManager.canUseSerratedStrike()) { if (swordsManager.canUseSerratedStrike()) {
swordsManager.serratedStrikes(target, event.getDamage()); swordsManager.serratedStrikes(target, damage);
} }
startGainXp(mcMMOPlayer, target, SkillType.SWORDS); startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
} }
}
else if (ItemUtils.isAxe(heldItem)) {
if (!shouldProcessSkill(target, SkillType.AXES)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.AXES)) { private static void processAxeCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AxesManager axesManager = mcMMOPlayer.getAxesManager(); AxesManager axesManager = mcMMOPlayer.getAxesManager();
if (axesManager.canActivateAbility()) { if (axesManager.canActivateAbility()) {
@ -136,13 +94,9 @@ public final class CombatUtils {
startGainXp(mcMMOPlayer, target, SkillType.AXES); startGainXp(mcMMOPlayer, target, SkillType.AXES);
} }
}
else if (heldItem.getType() == Material.AIR) {
if (!shouldProcessSkill(target, SkillType.UNARMED)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.UNARMED)) { private static void processUnarmedCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager(); UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
if (unarmedManager.canActivateAbility()) { if (unarmedManager.canActivateAbility()) {
@ -163,25 +117,8 @@ public final class CombatUtils {
startGainXp(mcMMOPlayer, target, SkillType.UNARMED); startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
} }
}
}
switch (damager.getType()) { private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) {
case WOLF:
Wolf wolf = (Wolf) damager;
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
Player master = (Player) wolf.getOwner();
if (Misc.isNPCEntity(master)) {
return;
}
if (!shouldProcessSkill(target, SkillType.TAMING)) {
return;
}
if (Permissions.skillEnabled(master, SkillType.TAMING)) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
TamingManager tamingManager = mcMMOPlayer.getTamingManager(); TamingManager tamingManager = mcMMOPlayer.getTamingManager();
@ -199,29 +136,8 @@ public final class CombatUtils {
startGainXp(mcMMOPlayer, target, SkillType.TAMING); startGainXp(mcMMOPlayer, target, SkillType.TAMING);
} }
}
break; private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) {
case ARROW:
LivingEntity shooter = ((Arrow) damager).getShooter();
/* Break instead of return due to Dodge/Counter/Deflect abilities */
if (shooter == null || !(shooter instanceof Player)) {
break;
}
if (!shouldProcessSkill(target, SkillType.ARCHERY)) {
break;
}
Player player = (Player) shooter;
if (Misc.isNPCEntity(player)) {
break;
}
if (Permissions.skillEnabled(player, SkillType.ARCHERY)) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager(); ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
@ -245,15 +161,114 @@ public final class CombatUtils {
event.setDamage(archeryManager.dazeCheck((Player) target, event.getDamage())); event.setDamage(archeryManager.dazeCheck((Player) target, event.getDamage()));
} }
if (!damager.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) { if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) {
archeryManager.trackArrows(target); archeryManager.trackArrows(target);
} }
archeryManager.distanceXpBonus(target, damager); archeryManager.distanceXpBonus(target, arrow);
startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, damager.getMetadata(mcMMO.bowForceKey).get(0).asDouble()); startGainXp(mcMMOPlayer, target, SkillType.ARCHERY, arrow.getMetadata(mcMMO.bowForceKey).get(0).asDouble());
} }
/**
* Apply combat modifiers and process and XP gain.
*
* @param event The event to run the combat checks on.
*/
public static void processCombatAttack(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
Entity damager = event.getDamager();
if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
Player player = (Player) attacker;
if (Misc.isNPCEntity(player)) {
return;
}
ItemStack heldItem = player.getItemInHand();
if (target instanceof Tameable) {
if (heldItem.getType() == Material.BONE) {
TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();
if (tamingManager.canUseBeastLore()) {
tamingManager.beastLore(target);
event.setCancelled(true);
return;
}
}
if (isFriendlyPet(player, (Tameable) target)) {
return;
}
}
if (ItemUtils.isSword(heldItem)) {
if (!shouldProcessSkill(target, SkillType.SWORDS)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
processSwordCombat(target, player, event.getDamage());
}
}
else if (ItemUtils.isAxe(heldItem)) {
if (!shouldProcessSkill(target, SkillType.AXES)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.AXES)) {
processAxeCombat(target, player, event);
}
}
else if (heldItem.getType() == Material.AIR) {
if (!shouldProcessSkill(target, SkillType.UNARMED)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
processUnarmedCombat(target, player, event);
}
}
}
switch (damager.getType()) {
case WOLF:
Wolf wolf = (Wolf) damager;
AnimalTamer tamer = wolf.getOwner();
if (tamer == null || !(tamer instanceof Player) || !shouldProcessSkill(target, SkillType.TAMING)) {
break;
}
Player master = (Player) tamer;
if (Misc.isNPCEntity(master)) {
break;
}
if (Permissions.skillEnabled(master, SkillType.TAMING)) {
processTamingCombat(target, master, wolf, event);
}
break;
case ARROW:
LivingEntity shooter = ((Arrow) damager).getShooter();
if (shooter == null || !(shooter instanceof Player) || !shouldProcessSkill(target, SkillType.ARCHERY)) {
break;
}
Player player = (Player) shooter;
if (Misc.isNPCEntity(player)) {
break;
}
if (Permissions.skillEnabled(player, SkillType.ARCHERY)) {
processArcheryCombat(target, player, event, damager);
}
break; break;
default: default:
@ -261,12 +276,11 @@ public final class CombatUtils {
} }
if (target instanceof Player) { if (target instanceof Player) {
Player player = (Player) target; if (Misc.isNPCEntity(target)) {
if (Misc.isNPCEntity(player)) {
return; return;
} }
Player player = (Player) target;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager(); AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
@ -285,24 +299,6 @@ public final class CombatUtils {
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage()); swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
} }
} }
if (damager.getType() == EntityType.ARROW) {
LivingEntity shooter = ((Arrow) damager).getShooter();
if (shooter instanceof Player || !SkillType.UNARMED.getPVEEnabled()) {
return;
}
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
if (unarmedManager.canDeflect()) {
event.setCancelled(unarmedManager.deflectCheck());
if (event.isCancelled()) {
return;
}
}
}
} }
else if (attacker instanceof Player) { else if (attacker instanceof Player) {
Player player = (Player) attacker; Player player = (Player) attacker;

View File

@ -462,7 +462,7 @@ public class SkillUtils {
* @param shouldArmSwing true if an armswing event should be fired, false otherwise * @param shouldArmSwing true if an armswing event should be fired, false otherwise
* @return true if the event wasn't cancelled, false otherwise * @return true if the event wasn't cancelled, false otherwise
*/ */
public static boolean blockBreakSimulate(Block block, Player player, Boolean shouldArmSwing) { public static boolean blockBreakSimulate(Block block, Player player, boolean shouldArmSwing) {
PluginManager pluginManger = mcMMO.p.getServer().getPluginManager(); PluginManager pluginManger = mcMMO.p.getServer().getPluginManager();
// Support for NoCheat // Support for NoCheat