mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-29 12:07:54 +01:00
We were calling deflect twice. Also made individual functions for each
type of combat.
This commit is contained in:
parent
3f7b17961f
commit
a1792fe125
@ -170,7 +170,7 @@ public class EntityListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
CombatUtils.combatChecks(event, attacker, target);
|
||||
CombatUtils.processCombatAttack(event, attacker, target);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -261,7 +261,10 @@ public class mcMMO extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void checkForUpdates() {
|
||||
if (Config.getInstance().getUpdateCheckEnabled()) {
|
||||
if (!Config.getInstance().getUpdateCheckEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
updateAvailable = UpdateChecker.updateAvailable();
|
||||
}
|
||||
@ -274,11 +277,9 @@ public class mcMMO extends JavaPlugin {
|
||||
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadConfigFiles() {
|
||||
// Force the loading of config files
|
||||
Config configInstance = Config.getInstance();
|
||||
TreasureConfig.getInstance();
|
||||
HiddenConfig.getInstance();
|
||||
AdvancedConfig.getInstance();
|
||||
@ -286,19 +287,19 @@ public class mcMMO extends JavaPlugin {
|
||||
|
||||
List<Repairable> repairables = new ArrayList<Repairable>();
|
||||
|
||||
if (configInstance.getToolModsEnabled()) {
|
||||
if (Config.getInstance().getToolModsEnabled()) {
|
||||
repairables.addAll(CustomToolConfig.getInstance().getLoadedRepairables());
|
||||
}
|
||||
|
||||
if (configInstance.getArmorModsEnabled()) {
|
||||
if (Config.getInstance().getArmorModsEnabled()) {
|
||||
repairables.addAll(CustomArmorConfig.getInstance().getLoadedRepairables());
|
||||
}
|
||||
|
||||
if (configInstance.getBlockModsEnabled()) {
|
||||
if (Config.getInstance().getBlockModsEnabled()) {
|
||||
CustomBlockConfig.getInstance();
|
||||
}
|
||||
|
||||
if (configInstance.getEntityModsEnabled()) {
|
||||
if (Config.getInstance().getEntityModsEnabled()) {
|
||||
CustomEntityConfig.getInstance();
|
||||
}
|
||||
|
||||
@ -309,14 +310,16 @@ public class mcMMO extends JavaPlugin {
|
||||
repairableManager.registerRepairables(repairables);
|
||||
|
||||
// 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!");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupSpout() {
|
||||
// Check for Spout
|
||||
if (getServer().getPluginManager().isPluginEnabled("Spout")) {
|
||||
if (!getServer().getPluginManager().isPluginEnabled("Spout")) {
|
||||
return;
|
||||
}
|
||||
|
||||
spoutEnabled = true;
|
||||
|
||||
SpoutConfig.getInstance();
|
||||
@ -324,7 +327,6 @@ public class mcMMO extends JavaPlugin {
|
||||
SpoutUtils.preCacheFiles();
|
||||
SpoutUtils.reloadSpoutPlayers(); // Handle spout players after a /reload
|
||||
}
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
|
@ -46,46 +46,8 @@ import com.gmail.nossr50.util.player.UserManager;
|
||||
public final class CombatUtils {
|
||||
private CombatUtils() {}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
private static void processSwordCombat(LivingEntity target, Player player, int damage) {
|
||||
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();
|
||||
|
||||
if (swordsManager.canActivateAbility()) {
|
||||
@ -97,18 +59,14 @@ public final class CombatUtils {
|
||||
}
|
||||
|
||||
if (swordsManager.canUseSerratedStrike()) {
|
||||
swordsManager.serratedStrikes(target, event.getDamage());
|
||||
swordsManager.serratedStrikes(target, damage);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if (axesManager.canActivateAbility()) {
|
||||
@ -136,13 +94,9 @@ public final class CombatUtils {
|
||||
|
||||
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();
|
||||
|
||||
if (unarmedManager.canActivateAbility()) {
|
||||
@ -163,25 +117,8 @@ public final class CombatUtils {
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (damager.getType()) {
|
||||
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)) {
|
||||
private static void processTamingCombat(LivingEntity target, Player master, Wolf wolf, EntityDamageByEntityEvent event) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(master);
|
||||
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
|
||||
|
||||
@ -199,29 +136,8 @@ public final class CombatUtils {
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.TAMING);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
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)) {
|
||||
private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager();
|
||||
|
||||
@ -245,15 +161,114 @@ public final class CombatUtils {
|
||||
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.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;
|
||||
|
||||
default:
|
||||
@ -261,12 +276,11 @@ public final class CombatUtils {
|
||||
}
|
||||
|
||||
if (target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
|
||||
if (Misc.isNPCEntity(player)) {
|
||||
if (Misc.isNPCEntity(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) target;
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||
AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();
|
||||
|
||||
@ -285,24 +299,6 @@ public final class CombatUtils {
|
||||
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) {
|
||||
Player player = (Player) attacker;
|
||||
|
@ -462,7 +462,7 @@ public class SkillUtils {
|
||||
* @param shouldArmSwing true if an armswing event should be fired, 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();
|
||||
|
||||
// Support for NoCheat
|
||||
|
Loading…
Reference in New Issue
Block a user