mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 19:54:44 +02:00
More major refactoring. My OCD is better now.
This commit is contained in:
@ -0,0 +1,211 @@
|
||||
package com.gmail.nossr50.skills.utilities;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public enum AbilityType {
|
||||
BERSERK(
|
||||
Config.getInstance().getAbilityCooldownBerserk(),
|
||||
Config.getInstance().getAbilityMaxTicksBerserk(),
|
||||
"Unarmed.Skills.Berserk.On",
|
||||
"Unarmed.Skills.Berserk.Off",
|
||||
"Unarmed.Skills.Berserk.Other.On",
|
||||
"Unarmed.Skills.Berserk.Refresh",
|
||||
"Unarmed.Skills.Berserk.Other.Off"),
|
||||
|
||||
SUPER_BREAKER(
|
||||
Config.getInstance().getAbilityCooldownSuperBreaker(),
|
||||
Config.getInstance().getAbilityMaxTicksSuperBreaker(),
|
||||
"Mining.Skills.SuperBreaker.On",
|
||||
"Mining.Skills.SuperBreaker.Off",
|
||||
"Mining.Skills.SuperBreaker.Other.On",
|
||||
"Mining.Skills.SuperBreaker.Refresh",
|
||||
"Mining.Skills.SuperBreaker.Other.Off"),
|
||||
|
||||
GIGA_DRILL_BREAKER(
|
||||
Config.getInstance().getAbilityCooldownGigaDrillBreaker(),
|
||||
Config.getInstance().getAbilityMaxTicksGigaDrillBreaker(),
|
||||
"Excavation.Skills.GigaDrillBreaker.On",
|
||||
"Excavation.Skills.GigaDrillBreaker.Off",
|
||||
"Excavation.Skills.GigaDrillBreaker.Other.On",
|
||||
"Excavation.Skills.GigaDrillBreaker.Refresh",
|
||||
"Excavation.Skills.GigaDrillBreaker.Other.Off"),
|
||||
|
||||
GREEN_TERRA(
|
||||
Config.getInstance().getAbilityCooldownGreenTerra(),
|
||||
Config.getInstance().getAbilityMaxTicksGreenTerra(),
|
||||
"Herbalism.Skills.GTe.On",
|
||||
"Herbalism.Skills.GTe.Off",
|
||||
"Herbalism.Skills.GTe.Other.On",
|
||||
"Herbalism.Skills.GTe.Refresh",
|
||||
"Herbalism.Skills.GTe.Other.Off"),
|
||||
|
||||
SKULL_SPLIITER(
|
||||
Config.getInstance().getAbilityCooldownSkullSplitter(),
|
||||
Config.getInstance().getAbilityMaxTicksSkullSplitter(),
|
||||
"Axes.Skills.SS.On",
|
||||
"Axes.Skills.SS.Off",
|
||||
"Axes.Skills.SS.Other.On",
|
||||
"Axes.Skills.SS.Refresh",
|
||||
"Axes.Skills.SS.Other.Off"),
|
||||
|
||||
TREE_FELLER(
|
||||
Config.getInstance().getAbilityCooldownTreeFeller(),
|
||||
Config.getInstance().getAbilityMaxTicksTreeFeller(),
|
||||
"Woodcutting.Skills.TreeFeller.On",
|
||||
"Woodcutting.Skills.TreeFeller.Off",
|
||||
"Woodcutting.Skills.TreeFeller.Other.On",
|
||||
"Woodcutting.Skills.TreeFeller.Refresh",
|
||||
"Woodcutting.Skills.TreeFeller.Other.Off"),
|
||||
|
||||
SERRATED_STRIKES(
|
||||
Config.getInstance().getAbilityCooldownSerratedStrikes(),
|
||||
Config.getInstance().getAbilityMaxTicksSerratedStrikes(),
|
||||
"Swords.Skills.SS.On",
|
||||
"Swords.Skills.SS.Off",
|
||||
"Swords.Skills.SS.Other.On",
|
||||
"Swords.Skills.SS.Refresh",
|
||||
"Swords.Skills.SS.Other.Off"),
|
||||
|
||||
BLAST_MINING(
|
||||
Config.getInstance().getAbilityCooldownBlastMining(),
|
||||
Config.getInstance().getAbilityMaxTicksBlastMining(),
|
||||
null,
|
||||
null,
|
||||
"Mining.Blast.Other.On",
|
||||
"Mining.Blast.Refresh",
|
||||
null),
|
||||
|
||||
LEAF_BLOWER(
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
|
||||
private int cooldown;
|
||||
private int maxTicks;
|
||||
private String abilityOn;
|
||||
private String abilityOff;
|
||||
private String abilityPlayer;
|
||||
private String abilityRefresh;
|
||||
private String abilityPlayerOff;
|
||||
|
||||
private AbilityType(int cooldown, int maxTicks, String abilityOn, String abilityOff, String abilityPlayer, String abilityRefresh, String abilityPlayerOff) {
|
||||
this.cooldown = cooldown;
|
||||
this.maxTicks = maxTicks;
|
||||
this.abilityOn = abilityOn;
|
||||
this.abilityOff = abilityOff;
|
||||
this.abilityPlayer = abilityPlayer;
|
||||
this.abilityRefresh = abilityRefresh;
|
||||
this.abilityPlayerOff = abilityPlayerOff;
|
||||
}
|
||||
|
||||
public int getCooldown() {
|
||||
return this.cooldown;
|
||||
}
|
||||
|
||||
public String getAbilityOn() {
|
||||
return LocaleLoader.getString(this.abilityOn);
|
||||
}
|
||||
|
||||
public String getAbilityOff() {
|
||||
return LocaleLoader.getString(this.abilityOff);
|
||||
}
|
||||
|
||||
public String getAbilityPlayer(Player player) {
|
||||
return LocaleLoader.getString(this.abilityPlayer, new Object[] {player.getName()});
|
||||
}
|
||||
|
||||
public String getAbilityPlayerOff(Player player) {
|
||||
return LocaleLoader.getString(this.abilityPlayerOff, new Object[] {player.getName()});
|
||||
}
|
||||
|
||||
public String getAbilityRefresh() {
|
||||
return LocaleLoader.getString(this.abilityRefresh);
|
||||
}
|
||||
|
||||
public int getMaxTicks() {
|
||||
return this.maxTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the permissions for this ability.
|
||||
*
|
||||
* @param player Player to check permissions for
|
||||
* @return true if the player has permissions, false otherwise
|
||||
*/
|
||||
public boolean getPermissions(Player player) {
|
||||
|
||||
switch (this) {
|
||||
case BERSERK:
|
||||
return Permissions.berserk(player);
|
||||
|
||||
case BLAST_MINING:
|
||||
return Permissions.blastMining(player);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return Permissions.gigaDrillBreaker(player);
|
||||
|
||||
case GREEN_TERRA:
|
||||
return Permissions.greenTerra(player);
|
||||
|
||||
case LEAF_BLOWER:
|
||||
return Permissions.leafBlower(player);
|
||||
|
||||
case SERRATED_STRIKES:
|
||||
return Permissions.serratedStrikes(player);
|
||||
|
||||
case SKULL_SPLIITER:
|
||||
return Permissions.skullSplitter(player);
|
||||
|
||||
case SUPER_BREAKER:
|
||||
return Permissions.superBreaker(player);
|
||||
|
||||
case TREE_FELLER:
|
||||
return Permissions.treeFeller(player);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block is affected by this ability.
|
||||
*
|
||||
* @param Block the block to check
|
||||
* @return true if the block is affected by this ability, false otherwise
|
||||
*/
|
||||
public boolean blockCheck(Block block) {
|
||||
switch (this) {
|
||||
case BERSERK:
|
||||
return (BlockChecks.canBeGigaDrillBroken(block) || block.getType() == Material.SNOW);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return BlockChecks.canBeGigaDrillBroken(block);
|
||||
|
||||
case GREEN_TERRA:
|
||||
return BlockChecks.canMakeMossy(block);
|
||||
|
||||
case LEAF_BLOWER:
|
||||
return block.getType() == Material.LEAVES;
|
||||
|
||||
case SUPER_BREAKER:
|
||||
return BlockChecks.canBeSuperBroken(block);
|
||||
|
||||
case TREE_FELLER:
|
||||
return block.getType() == Material.LOG;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,584 @@
|
||||
package com.gmail.nossr50.skills.utilities;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.entity.LightningStrike;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.party.PartyManager;
|
||||
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
|
||||
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.axes.AxeManager;
|
||||
import com.gmail.nossr50.skills.axes.Axes;
|
||||
import com.gmail.nossr50.skills.runnables.BleedTimer;
|
||||
import com.gmail.nossr50.skills.runnables.GainXp;
|
||||
import com.gmail.nossr50.skills.swords.Swords;
|
||||
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.unarmed.Unarmed;
|
||||
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public final class CombatTools {
|
||||
private static Config configInstance = Config.getInstance();
|
||||
|
||||
private CombatTools() {}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
|
||||
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
|
||||
|
||||
if (attacker instanceof Player) {
|
||||
Player player = (Player) attacker;
|
||||
|
||||
if (Misc.isNPCPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
Material heldItemType = heldItem.getType();
|
||||
|
||||
if (ItemChecks.isSword(heldItem)) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!Swords.pvpEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!Swords.pveEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.swords(player)) {
|
||||
SwordsManager swordsManager = new SwordsManager(player);
|
||||
PlayerProfile profile = swordsManager.getProfile();
|
||||
boolean canSerratedStrike = Permissions.serratedStrikes(player); //So we don't have to check the same permission twice
|
||||
|
||||
if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
|
||||
SkillTools.abilityCheck(player, SkillType.SWORDS);
|
||||
}
|
||||
|
||||
if (Permissions.swordsBleed(player) && shouldBeAffected(player, target)) {
|
||||
swordsManager.bleedCheck(target);
|
||||
}
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
|
||||
swordsManager.serratedStrikes(target, event.getDamage());
|
||||
}
|
||||
|
||||
startGainXp(player, profile, target, SkillType.SWORDS);
|
||||
}
|
||||
}
|
||||
else if (ItemChecks.isAxe(heldItem)) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!Axes.pvpEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!Axes.pveEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.axes(player)) {
|
||||
AxeManager axeManager = new AxeManager(player);
|
||||
PlayerProfile profile = axeManager.getProfile();
|
||||
boolean canSkullSplit = Permissions.skullSplitter(player); //So we don't have to check the same permission twice
|
||||
if (profile.getToolPreparationMode(ToolType.AXE) && canSkullSplit) {
|
||||
SkillTools.abilityCheck(player, SkillType.AXES);
|
||||
}
|
||||
|
||||
if (Permissions.axeBonus(player)) {
|
||||
axeManager.bonusDamage(event);
|
||||
}
|
||||
|
||||
if (!target.isDead() && Permissions.criticalHit(player) && shouldBeAffected(player, target)) {
|
||||
axeManager.criticalHitCheck(event, target);
|
||||
}
|
||||
|
||||
if (!target.isDead() && Permissions.impact(player)) {
|
||||
axeManager.impact(event, target);
|
||||
}
|
||||
|
||||
if (!target.isDead() && profile.getAbilityMode(AbilityType.SKULL_SPLIITER) && canSkullSplit) {
|
||||
axeManager.skullSplitter(target, event.getDamage());
|
||||
}
|
||||
|
||||
startGainXp(player, profile, target, SkillType.AXES);
|
||||
}
|
||||
}
|
||||
else if (heldItemType == Material.AIR) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!configInstance.getUnarmedPVP()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!configInstance.getUnarmedPVE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.unarmed(player)) {
|
||||
UnarmedManager unarmedManager = new UnarmedManager(player);
|
||||
PlayerProfile profile = unarmedManager.getProfile();
|
||||
boolean canBerserk = Permissions.berserk(player); //So we don't have to check the same permission twice
|
||||
|
||||
if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
|
||||
SkillTools.abilityCheck(player, SkillType.UNARMED);
|
||||
}
|
||||
|
||||
if (Permissions.unarmedBonus(player)) {
|
||||
unarmedManager.bonusDamage(event);
|
||||
}
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
|
||||
unarmedManager.berserkDamage(event);
|
||||
}
|
||||
|
||||
if (target instanceof Player && Permissions.disarm(player)) {
|
||||
unarmedManager.disarmCheck(target);
|
||||
}
|
||||
|
||||
startGainXp(player, unarmedManager.getProfile(), target, SkillType.UNARMED);
|
||||
}
|
||||
}
|
||||
else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player)) {
|
||||
TamingManager tamingManager = new TamingManager(player);
|
||||
tamingManager.beastLore(target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
Entity damager = event.getDamager();
|
||||
|
||||
switch (damager.getType()) {
|
||||
case WOLF:
|
||||
Wolf wolf = (Wolf) damager;
|
||||
|
||||
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
||||
Player master = (Player) wolf.getOwner();
|
||||
|
||||
if (Misc.isNPCPlayer(master)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!Taming.pvpEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!Taming.pveEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.taming(master)) {
|
||||
TamingManager tamingManager = new TamingManager(master);
|
||||
int skillLevel = tamingManager.getSkillLevel();
|
||||
|
||||
if (skillLevel >= Taming.fastFoodServiceUnlockLevel && Permissions.fastFoodService(master)) {
|
||||
tamingManager.fastFoodService(wolf, event.getDamage());
|
||||
}
|
||||
|
||||
if (skillLevel >= Taming.sharpenedClawsUnlockLevel && Permissions.sharpenedClaws(master)) {
|
||||
tamingManager.sharpenedClaws(event);
|
||||
}
|
||||
|
||||
if (Permissions.gore(master)) {
|
||||
tamingManager.gore(event);
|
||||
}
|
||||
|
||||
if (target != master) {
|
||||
startGainXp(master, tamingManager.getProfile(), 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 (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!Archery.pvpEnabled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!Archery.pveEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
archeryCheck((Player) shooter, target, event);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (targetIsPlayer) {
|
||||
Player player = (Player) target;
|
||||
|
||||
if (Misc.isNPCPlayer(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
|
||||
if (damager instanceof Player) {
|
||||
if (Swords.pvpEnabled && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
|
||||
SwordsManager swordsManager = new SwordsManager(player);
|
||||
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||
}
|
||||
|
||||
if (Acrobatics.pvpEnabled && Permissions.dodge(player)) {
|
||||
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
|
||||
acrobaticsManager.dodgeCheck(event);
|
||||
}
|
||||
|
||||
if (Unarmed.pvpEnabled && heldItem.getType() == Material.AIR && Permissions.deflect(player)) {
|
||||
UnarmedManager unarmedManager = new UnarmedManager(player);
|
||||
unarmedManager.deflectCheck(event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Swords.pveEnabled && damager instanceof LivingEntity && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) {
|
||||
SwordsManager swordsManager = new SwordsManager(player);
|
||||
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||
}
|
||||
|
||||
if (Acrobatics.pveEnabled && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) && Permissions.dodge(player)) {
|
||||
AcrobaticsManager acrobaticsManager = new AcrobaticsManager(player);
|
||||
acrobaticsManager.dodgeCheck(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process archery abilities.
|
||||
*
|
||||
* @param shooter The player shooting
|
||||
* @param target The defending entity
|
||||
* @param event The event to run the archery checks on.
|
||||
*/
|
||||
private static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) {
|
||||
if (Misc.isNPCPlayer(shooter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Permissions.archery(shooter)) {
|
||||
ArcheryManager archeryManager = new ArcheryManager(shooter);
|
||||
archeryManager.skillShot(event);
|
||||
|
||||
if (target instanceof Player && Permissions.daze(shooter)) {
|
||||
archeryManager.dazeCheck((Player) target, event);
|
||||
}
|
||||
|
||||
if (!(shooter.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE)) && Permissions.trackArrows(shooter)) {
|
||||
archeryManager.trackArrows(target);
|
||||
}
|
||||
|
||||
if (target != shooter) {
|
||||
archeryManager.distanceXpBonus(target);
|
||||
startGainXp(shooter, archeryManager.getProfile(), target, SkillType.ARCHERY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to damage target for value dmg with reason CUSTOM
|
||||
*
|
||||
* @param target LivingEntity which to attempt to damage
|
||||
* @param dmg Amount of damage to attempt to do
|
||||
*/
|
||||
public static void dealDamage(LivingEntity target, int dmg) {
|
||||
dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to damage target for value dmg with reason cause
|
||||
*
|
||||
* @param target LivingEntity which to attempt to damage
|
||||
* @param dmg Amount of damage to attempt to do
|
||||
* @param cause DamageCause to pass to damage event
|
||||
*/
|
||||
private static void dealDamage(LivingEntity target, int dmg, DamageCause cause) {
|
||||
if (configInstance.getEventCallbackEnabled()) {
|
||||
EntityDamageEvent ede = new FakeEntityDamageEvent(target, cause, dmg);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
if (ede.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.damage(ede.getDamage());
|
||||
}
|
||||
else {
|
||||
target.damage(dmg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
|
||||
*
|
||||
* @param target LivingEntity which to attempt to damage
|
||||
* @param dmg Amount of damage to attempt to do
|
||||
* @param attacker Player to pass to event as damager
|
||||
*/
|
||||
private static void dealDamage(LivingEntity target, int dmg, Player attacker) {
|
||||
if (configInstance.getEventCallbackEnabled()) {
|
||||
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
if (ede.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.damage(ede.getDamage());
|
||||
}
|
||||
else {
|
||||
target.damage(dmg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply Area-of-Effect ability actions.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param target The defending entity
|
||||
* @param damage The initial damage amount
|
||||
* @param type The type of skill being used
|
||||
*/
|
||||
public static void applyAbilityAoE(Player attacker, LivingEntity target, int damage, SkillType type) {
|
||||
int numberOfTargets = Misc.getTier(attacker.getItemInHand()); //The higher the weapon tier, the more targets you hit
|
||||
int damageAmount = damage;
|
||||
|
||||
if (damageAmount < 1) {
|
||||
damageAmount = 1;
|
||||
}
|
||||
|
||||
for (Entity entity : target.getNearbyEntities(2.5, 2.5, 2.5)) {
|
||||
if ((entity instanceof Player && Misc.isNPCPlayer((Player) entity)) || !(entity instanceof LivingEntity) || !shouldBeAffected(attacker, entity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (numberOfTargets <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
PlayerAnimationEvent armswing = new PlayerAnimationEvent(attacker);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(armswing);
|
||||
|
||||
switch (type) {
|
||||
case SWORDS:
|
||||
if (entity instanceof Player) {
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Swords.Combat.SS.Struck"));
|
||||
}
|
||||
|
||||
BleedTimer.add((LivingEntity) entity, Swords.serratedStrikesBleedTicks);
|
||||
|
||||
break;
|
||||
|
||||
case AXES:
|
||||
if (entity instanceof Player) {
|
||||
((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.Cleave.Struck"));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dealDamage((LivingEntity) entity, damageAmount, attacker);
|
||||
numberOfTargets--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the task that gives combat XP.
|
||||
*
|
||||
* @param attacker The attacking player
|
||||
* @param profile The player's PlayerProfile
|
||||
* @param target The defending entity
|
||||
* @param skillType The skill being used
|
||||
*/
|
||||
public static void startGainXp(Player attacker, PlayerProfile profile, LivingEntity target, SkillType skillType) {
|
||||
double baseXP = 0;
|
||||
|
||||
if (target instanceof Player) {
|
||||
if (!configInstance.getExperienceGainsPlayerVersusPlayerEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player defender = (Player) target;
|
||||
|
||||
if (System.currentTimeMillis() >= Users.getProfile(defender).getRespawnATS() + 5) {
|
||||
baseXP = 20 * configInstance.getPlayerVersusPlayerXP();
|
||||
}
|
||||
}
|
||||
else if (!mcMMO.placeStore.isSpawnedMob(target)) {
|
||||
if (target instanceof Animals && !mcMMO.placeStore.isSpawnedPet(target)) {
|
||||
baseXP = configInstance.getAnimalsXP();
|
||||
}
|
||||
else {
|
||||
EntityType type = target.getType();
|
||||
|
||||
switch (type) {
|
||||
case BAT:
|
||||
baseXP = configInstance.getAnimalsXP();
|
||||
break;
|
||||
|
||||
case BLAZE:
|
||||
baseXP = configInstance.getBlazeXP();
|
||||
break;
|
||||
|
||||
case CAVE_SPIDER:
|
||||
baseXP = configInstance.getCaveSpiderXP();
|
||||
break;
|
||||
|
||||
case CREEPER:
|
||||
baseXP = configInstance.getCreeperXP();
|
||||
break;
|
||||
|
||||
case ENDER_DRAGON:
|
||||
baseXP = configInstance.getEnderDragonXP();
|
||||
break;
|
||||
|
||||
case ENDERMAN:
|
||||
baseXP = configInstance.getEndermanXP();
|
||||
break;
|
||||
|
||||
case GHAST:
|
||||
baseXP = configInstance.getGhastXP();
|
||||
break;
|
||||
|
||||
case GIANT:
|
||||
baseXP = configInstance.getGiantXP();
|
||||
break;
|
||||
|
||||
case MAGMA_CUBE:
|
||||
baseXP = configInstance.getMagmaCubeXP();
|
||||
break;
|
||||
|
||||
case IRON_GOLEM:
|
||||
if (!((IronGolem) target).isPlayerCreated()) {
|
||||
baseXP = configInstance.getIronGolemXP();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PIG_ZOMBIE:
|
||||
baseXP = configInstance.getPigZombieXP();
|
||||
break;
|
||||
|
||||
case SILVERFISH:
|
||||
baseXP = configInstance.getSilverfishXP();
|
||||
break;
|
||||
|
||||
case SKELETON:
|
||||
switch(((Skeleton) target).getSkeletonType()) {
|
||||
case WITHER:
|
||||
baseXP = configInstance.getWitherSkeletonXP();
|
||||
break;
|
||||
default:
|
||||
baseXP = configInstance.getSkeletonXP();
|
||||
break;
|
||||
}
|
||||
case SLIME:
|
||||
baseXP = configInstance.getSlimeXP();
|
||||
break;
|
||||
|
||||
case SPIDER:
|
||||
baseXP = configInstance.getSpiderXP();
|
||||
break;
|
||||
|
||||
case WITCH:
|
||||
baseXP = configInstance.getWitchXP();
|
||||
break;
|
||||
|
||||
case WITHER:
|
||||
baseXP = configInstance.getWitherXP();
|
||||
break;
|
||||
|
||||
case ZOMBIE:
|
||||
baseXP = configInstance.getZombieXP();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
baseXP *= 10;
|
||||
}
|
||||
|
||||
if (baseXP != 0) {
|
||||
mcMMO.p.getServer().getScheduler().scheduleSyncDelayedTask(mcMMO.p, new GainXp(attacker, profile, skillType, baseXP, target), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the given LivingEntity should be affected by a combat ability.
|
||||
*
|
||||
* @param player The attacking Player
|
||||
* @param livingEntity The defending LivingEntity
|
||||
* @return true if the Entity should be damaged, false otherwise.
|
||||
*/
|
||||
public static boolean shouldBeAffected(Player player, Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
Player defender = (Player) entity;
|
||||
|
||||
if (!defender.getWorld().getPVP() || defender == player || PartyManager.inSameParty(player, defender) || Users.getProfile(defender).getGodMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//It may seem a bit redundant but we need a check here to prevent bleed from being applied in applyAbilityAoE()
|
||||
EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(player, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(ede);
|
||||
|
||||
if (ede.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Tameable) {
|
||||
if (Misc.isFriendlyPet(player, (Tameable) entity)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
535
src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java
Normal file
535
src/main/java/com/gmail/nossr50/skills/utilities/SkillTools.java
Normal file
@ -0,0 +1,535 @@
|
||||
package com.gmail.nossr50.skills.utilities;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
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.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.party.ShareHandler;
|
||||
import com.gmail.nossr50.spout.SpoutConfig;
|
||||
import com.gmail.nossr50.spout.SpoutTools;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class SkillTools {
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
|
||||
public static boolean abilitiesEnabled = Config.getInstance().getAbilitiesEnabled();
|
||||
|
||||
public static void handleFoodSkills(Player player, SkillType skill, FoodLevelChangeEvent event, int baseLevel, int maxLevel, int rankChange) {
|
||||
int skillLevel = Users.getProfile(player).getSkillLevel(skill);
|
||||
int currentFoodLevel = player.getFoodLevel();
|
||||
int newFoodLevel = event.getFoodLevel();
|
||||
int foodChange = newFoodLevel - currentFoodLevel;
|
||||
|
||||
for (int i = baseLevel; i <= maxLevel; i+= rankChange) {
|
||||
if (skillLevel >= 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the cooldown for an item or ability is expired.
|
||||
*
|
||||
* @param oldTime The time the ability or item was last used
|
||||
* @param cooldown The amount of time that must pass between uses
|
||||
* @param player The player whose cooldown is being checked
|
||||
* @return true if the cooldown is over, false otherwise
|
||||
*/
|
||||
public static boolean cooldownOver(long oldTime, int cooldown, Player player) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
int adjustedCooldown = cooldown;
|
||||
|
||||
//Reduced Cooldown Donor Perks
|
||||
if (Permissions.cooldownsHalved(player)) {
|
||||
adjustedCooldown = (int) (adjustedCooldown * 0.5);
|
||||
}
|
||||
else if (Permissions.cooldownsThirded(player)) {
|
||||
adjustedCooldown = (int) (adjustedCooldown * 0.66);
|
||||
}
|
||||
else if (Permissions.cooldownsQuartered(player)) {
|
||||
adjustedCooldown = (int) (adjustedCooldown * 0.75);
|
||||
}
|
||||
|
||||
if (currentTime - oldTime >= (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time remaining until the cooldown expires.
|
||||
*
|
||||
* @param deactivatedTimeStamp Time of deactivation
|
||||
* @param cooldown The length of the cooldown
|
||||
* @return the number of seconds remaining before the cooldown expires
|
||||
*/
|
||||
public static int calculateTimeLeft(long deactivatedTimeStamp, int cooldown, Player player) {
|
||||
int adjustedCooldown = cooldown;
|
||||
|
||||
//Reduced Cooldown Donor Perks
|
||||
if (Permissions.cooldownsHalved(player)) {
|
||||
adjustedCooldown = (int) (adjustedCooldown * 0.5);
|
||||
}
|
||||
else if (Permissions.cooldownsThirded(player)) {
|
||||
adjustedCooldown = (int) (adjustedCooldown * 0.66);
|
||||
}
|
||||
else if (Permissions.cooldownsQuartered(player)) {
|
||||
adjustedCooldown = (int) (adjustedCooldown * 0.75);
|
||||
}
|
||||
|
||||
return (int) (((deactivatedTimeStamp + (adjustedCooldown * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the player when the cooldown expires.
|
||||
*
|
||||
* @param player The player to send a message to
|
||||
* @param profile The profile of the player
|
||||
* @param ability The ability to watch cooldowns for
|
||||
*/
|
||||
public static void watchCooldown(Player player, PlayerProfile profile, AbilityType ability) {
|
||||
if (player == null || profile == null || ability == null)
|
||||
return;
|
||||
|
||||
if (!profile.getAbilityInformed(ability) && cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
profile.setAbilityInformed(ability, true);
|
||||
player.sendMessage(ability.getAbilityRefresh());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process activating abilities & readying the tool.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param skill The skill the ability is tied to
|
||||
*/
|
||||
public static void activationCheck(Player player, SkillType skill) {
|
||||
if (Config.getInstance().getAbilitiesOnlyActivateWhenSneaking() && !player.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerProfile profile = Users.getProfile(player);
|
||||
AbilityType ability = skill.getAbility();
|
||||
ToolType tool = skill.getTool();
|
||||
ItemStack inHand = player.getItemInHand();
|
||||
|
||||
if (ModChecks.isCustomTool(inHand) && !ModChecks.getToolFromItemStack(inHand).isAbilityEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if any abilities are active */
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!profile.getAbilityUse()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (AbilityType x : AbilityType.values()) {
|
||||
if (profile.getAbilityMode(x)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Woodcutting & Axes need to be treated differently.
|
||||
* Basically the tool always needs to ready and we check to see if the cooldown is over when the user takes action
|
||||
*/
|
||||
if (ability.getPermissions(player) && tool.inHand(inHand) && !profile.getToolPreparationMode(tool)) {
|
||||
if (skill != SkillType.WOODCUTTING && skill != SkillType.AXES) {
|
||||
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player) }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
||||
player.sendMessage(tool.getRaiseTool());
|
||||
}
|
||||
|
||||
profile.setToolPreparationATS(tool, System.currentTimeMillis());
|
||||
profile.setToolPreparationMode(tool, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors various things relating to skill abilities.
|
||||
*
|
||||
* @param player The player using the skill
|
||||
* @param profile The profile of the player
|
||||
* @param curTime The current system time
|
||||
* @param skill The skill being monitored
|
||||
*/
|
||||
public static void monitorSkill(Player player, PlayerProfile profile, long curTime, SkillType skill) {
|
||||
final int FOUR_SECONDS = 4000;
|
||||
|
||||
ToolType tool = skill.getTool();
|
||||
AbilityType ability = skill.getAbility();
|
||||
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.getToolPreparationMode(tool) && curTime - (profile.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
|
||||
profile.setToolPreparationMode(tool, false);
|
||||
|
||||
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
||||
player.sendMessage(tool.getLowerTool());
|
||||
}
|
||||
}
|
||||
|
||||
if (ability.getPermissions(player)) {
|
||||
if (profile.getAbilityMode(ability) && (profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
|
||||
if (ability == AbilityType.BERSERK) {
|
||||
player.setCanPickupItems(true);
|
||||
}
|
||||
|
||||
profile.setAbilityMode(ability, false);
|
||||
profile.setAbilityInformed(ability, false);
|
||||
player.sendMessage(ability.getAbilityOff());
|
||||
|
||||
Misc.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the XP of a skill.
|
||||
*
|
||||
* @param skillType The skill to check
|
||||
* @param player The player whose skill to check
|
||||
* @param profile The profile of the player whose skill to check
|
||||
*/
|
||||
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
|
||||
int skillups = 0;
|
||||
|
||||
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
||||
|
||||
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
|
||||
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
|
||||
profile.removeXP(skillType, profile.getXpToLevel(skillType));
|
||||
skillups++;
|
||||
profile.skillUp(skillType, 1);
|
||||
|
||||
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
|
||||
}
|
||||
else {
|
||||
profile.addLevels(skillType, 0);
|
||||
}
|
||||
}
|
||||
|
||||
String capitalized = Misc.getCapitalized(skillType.toString());
|
||||
|
||||
/* Spout Stuff */
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutPlayer spoutPlayer = SpoutManager.getPlayer(player);
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
SpoutTools.levelUpNotification(skillType, spoutPlayer);
|
||||
|
||||
/* Update custom titles */
|
||||
if (SpoutConfig.getInstance().getShowPowerLevel()) {
|
||||
spoutPlayer.setTitle(LocaleLoader.getString("Spout.Title", new Object[] {spoutPlayer.getName(), Users.getPlayer(player).getPowerLevel()} ));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), profile.getSkillLevel(skillType)}));
|
||||
}
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), profile.getSkillLevel(skillType)}));
|
||||
}
|
||||
}
|
||||
|
||||
if (mcMMO.spoutEnabled) {
|
||||
SpoutPlayer spoutPlayer = (SpoutPlayer) player;
|
||||
|
||||
if (spoutPlayer != null && spoutPlayer.isSpoutCraftEnabled()) {
|
||||
if (SpoutConfig.getInstance().getXPBarEnabled()) {
|
||||
profile.getSpoutHud().updateXpBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check XP of all skills.
|
||||
*
|
||||
* @param player The player to check XP for.
|
||||
* @param profile The profile of the player whose skill to check
|
||||
*/
|
||||
public static void xpCheckAll(Player player, PlayerProfile profile) {
|
||||
for (SkillType skillType : SkillType.values()) {
|
||||
//Don't want to do anything with this one
|
||||
if (skillType == SkillType.ALL || skillType.isChildSkill()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xpCheckSkill(skillType, player, profile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the skill represented by the given string
|
||||
*
|
||||
* @param skillName The name of the skill
|
||||
* @return the SkillType if it exists, null otherwise
|
||||
*/
|
||||
public static SkillType getSkillType(String skillName) {
|
||||
for (SkillType x : SkillType.values()) {
|
||||
if (x.toString().equals(skillName.toUpperCase())) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given string represents a valid skill
|
||||
*
|
||||
* @param skillname The name of the skill to check
|
||||
* @return true if this is a valid skill, false otherwise
|
||||
*/
|
||||
public static boolean isSkill(String skillName) {
|
||||
if (getSkillType(skillName) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isLocalizedSkill(String skillName) {
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skillName.equalsIgnoreCase(LocaleLoader.getString(Misc.getCapitalized(skill.toString() + ".SkillName")))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String translateLocalizedSkill(String skillName) {
|
||||
for (SkillType skill : SkillType.values()) {
|
||||
if (skillName.equalsIgnoreCase(LocaleLoader.getString(Misc.getCapitalized(skill.toString() + ".SkillName")))) {
|
||||
return skill.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String localizeSkillName(SkillType skill) {
|
||||
return Misc.getCapitalized(LocaleLoader.getString(Misc.getCapitalized(skill.toString()) + ".SkillName"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has any combat skill permissions.
|
||||
*
|
||||
* @param player The player to check permissions for
|
||||
* @return true if the player has combat skills, false otherwise
|
||||
*/
|
||||
public static boolean hasCombatSkills(Player player) {
|
||||
if (Permissions.axes(player)
|
||||
|| Permissions.archery(player)
|
||||
|| Permissions.swords(player)
|
||||
|| Permissions.taming(player)
|
||||
|| Permissions.unarmed(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has any gathering skill permissions.
|
||||
*
|
||||
* @param player The player to check permissions for
|
||||
* @return true if the player has gathering skills, false otherwise
|
||||
*/
|
||||
public static boolean hasGatheringSkills(Player player) {
|
||||
if (Permissions.excavation(player)
|
||||
|| Permissions.fishing(player)
|
||||
|| Permissions.herbalism(player)
|
||||
|| Permissions.mining(player)
|
||||
|| Permissions.woodcutting(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has any misc skill permissions.
|
||||
*
|
||||
* @param player The player to check permissions for
|
||||
* @return true if the player has misc skills, false otherwise
|
||||
*/
|
||||
public static boolean hasMiscSkills(Player player) {
|
||||
if (Permissions.acrobatics(player) || Permissions.repair(player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle tool durability loss from abilities.
|
||||
*
|
||||
* @param inHand The item to damage
|
||||
* @param durabilityLoss The durability to remove from the item
|
||||
*/
|
||||
public static void abilityDurabilityLoss(ItemStack inHand, int durabilityLoss) {
|
||||
if (Config.getInstance().getAbilitiesDamageTools()) {
|
||||
if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
|
||||
int level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
if (Misc.getRandom().nextInt(level + 1) > 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if an ability can be activated.
|
||||
*
|
||||
* @param player The player activating the ability
|
||||
* @param type The skill the ability is based on
|
||||
*/
|
||||
public static void abilityCheck(Player player, SkillType type) {
|
||||
PlayerProfile profile = Users.getProfile(player);
|
||||
ToolType tool = type.getTool();
|
||||
AbilityType ability = type.getAbility();
|
||||
|
||||
profile.setToolPreparationMode(tool, false);
|
||||
|
||||
/* Axes and Woodcutting are odd because they share the same tool.
|
||||
* We show them the too tired message when they take action.
|
||||
*/
|
||||
if (type == SkillType.WOODCUTTING || type == SkillType.AXES) {
|
||||
if (!profile.getAbilityMode(ability) && !cooldownOver(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { calculateTimeLeft(profile.getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player) }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int ticks = 2 + (profile.getSkillLevel(type) / abilityLengthIncreaseLevel);
|
||||
|
||||
if (Permissions.activationTwelve(player)) {
|
||||
ticks = ticks + 12;
|
||||
}
|
||||
else if (Permissions.activationEight(player)) {
|
||||
ticks = ticks + 8;
|
||||
}
|
||||
else if (Permissions.activationFour(player)) {
|
||||
ticks = ticks + 4;
|
||||
}
|
||||
|
||||
int maxTicks = ability.getMaxTicks();
|
||||
|
||||
if (maxTicks != 0 && ticks > maxTicks) {
|
||||
ticks = maxTicks;
|
||||
}
|
||||
|
||||
if (!profile.getAbilityMode(ability) && cooldownOver(profile.getSkillDATS(ability), ability.getCooldown(), player)) {
|
||||
player.sendMessage(ability.getAbilityOn());
|
||||
|
||||
Misc.sendSkillMessage(player, ability.getAbilityPlayer(player));
|
||||
|
||||
profile.setSkillDATS(ability, System.currentTimeMillis() + (ticks * Misc.TIME_CONVERSION_FACTOR));
|
||||
profile.setAbilityMode(ability, true);
|
||||
if (ability == AbilityType.BERSERK) {
|
||||
player.setCanPickupItems(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if ability should be triggered.
|
||||
*
|
||||
* @param player The player using the ability
|
||||
* @param block The block modified by the ability
|
||||
* @param ability The ability to check
|
||||
* @return true if the ability should activate, false otherwise
|
||||
*/
|
||||
public static boolean triggerCheck(Player player, Block block, AbilityType ability) {
|
||||
boolean activate = true;
|
||||
|
||||
switch (ability) {
|
||||
case BERSERK:
|
||||
case GIGA_DRILL_BREAKER:
|
||||
case SUPER_BREAKER:
|
||||
case LEAF_BLOWER:
|
||||
if (!ability.blockCheck(block)) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!Misc.blockBreakSimulate(block, player, true)) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case GREEN_TERRA:
|
||||
if (!ability.blockCheck(block)) {
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
activate = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return activate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the processing of XP gain from individual skills.
|
||||
*
|
||||
* @param player The player that gained XP
|
||||
* @param profile The profile of the player gaining XP
|
||||
* @param type The type of skill to gain XP from
|
||||
* @param xp the amount of XP to gain
|
||||
*/
|
||||
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
|
||||
if ((type.getMaxLevel() < profile.getSkillLevel(type) + 1) || (Misc.getPowerLevelCap() < Users.getPlayer(player).getPowerLevel() + 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (profile.inParty()) {
|
||||
xp = (int) ShareHandler.checkXpSharing(xp, player, profile.getParty());
|
||||
ShareHandler.handleEqualExpShare(xp, player, profile.getParty(), type);
|
||||
}
|
||||
|
||||
Users.getPlayer(player).addXP(type, xp);
|
||||
xpCheckSkill(type, player, profile);
|
||||
}
|
||||
}
|
156
src/main/java/com/gmail/nossr50/skills/utilities/SkillType.java
Normal file
156
src/main/java/com/gmail/nossr50/skills/utilities/SkillType.java
Normal file
@ -0,0 +1,156 @@
|
||||
package com.gmail.nossr50.skills.utilities;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public enum SkillType {
|
||||
ACROBATICS(Config.getInstance().getLevelCapAcrobatics(), Config.getInstance().getFormulaMultiplierAcrobatics()),
|
||||
ALL, //This one is just for convenience
|
||||
ARCHERY(Config.getInstance().getLevelCapArchery(), Config.getInstance().getFormulaMultiplierArchery()),
|
||||
AXES(AbilityType.SKULL_SPLIITER, Config.getInstance().getLevelCapAxes(), ToolType.AXE, Config.getInstance().getFormulaMultiplierAxes()),
|
||||
EXCAVATION(AbilityType.GIGA_DRILL_BREAKER, Config.getInstance().getLevelCapExcavation(), ToolType.SHOVEL, Config.getInstance().getFormulaMultiplierExcavation()),
|
||||
FISHING(Config.getInstance().getLevelCapFishing(), Config.getInstance().getFormulaMultiplierFishing()),
|
||||
HERBALISM(AbilityType.GREEN_TERRA, Config.getInstance().getLevelCapHerbalism(), ToolType.HOE, Config.getInstance().getFormulaMultiplierHerbalism()),
|
||||
MINING(AbilityType.SUPER_BREAKER, Config.getInstance().getLevelCapMining(), ToolType.PICKAXE, Config.getInstance().getFormulaMultiplierMining()),
|
||||
REPAIR(Config.getInstance().getLevelCapRepair(), Config.getInstance().getFormulaMultiplierRepair()),
|
||||
SMELTING(Config.getInstance().getLevelCapSmelting(), 0),
|
||||
SWORDS(AbilityType.SERRATED_STRIKES, Config.getInstance().getLevelCapSwords(), ToolType.SWORD, Config.getInstance().getFormulaMultiplierSwords()),
|
||||
TAMING(Config.getInstance().getLevelCapTaming(), Config.getInstance().getFormulaMultiplierTaming()),
|
||||
UNARMED(AbilityType.BERSERK, Config.getInstance().getLevelCapUnarmed(), ToolType.FISTS, Config.getInstance().getFormulaMultiplierUnarmed()),
|
||||
WOODCUTTING(AbilityType.TREE_FELLER, Config.getInstance().getLevelCapWoodcutting(), ToolType.AXE, Config.getInstance().getFormulaMultiplierWoodcutting());
|
||||
|
||||
private AbilityType ability;
|
||||
private int maxLevel;
|
||||
private ToolType tool;
|
||||
private double xpModifier;
|
||||
|
||||
private SkillType() {
|
||||
this.ability = null;
|
||||
this.maxLevel = 0;
|
||||
this.tool = null;
|
||||
this.xpModifier = 0;
|
||||
}
|
||||
|
||||
private SkillType(AbilityType ability, int maxLevel, ToolType tool, double xpModifier) {
|
||||
this.ability = ability;
|
||||
this.maxLevel = maxLevel;
|
||||
this.tool = tool;
|
||||
this.xpModifier = xpModifier;
|
||||
}
|
||||
|
||||
private SkillType(int maxLevel, double xpModifier) {
|
||||
this(null, maxLevel, null, xpModifier);
|
||||
}
|
||||
|
||||
public AbilityType getAbility() {
|
||||
return ability;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max level of this skill.
|
||||
*
|
||||
* @return the max level of this skill
|
||||
*/
|
||||
public int getMaxLevel() {
|
||||
if (maxLevel > 0) {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public ToolType getTool() {
|
||||
return tool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base permissions associated with this skill.
|
||||
*
|
||||
* @param player The player to check the permissions for
|
||||
* @return true if the player has permissions, false otherwise
|
||||
*/
|
||||
public boolean getPermissions(Player player) {
|
||||
switch (this) {
|
||||
case ACROBATICS:
|
||||
return Permissions.acrobatics(player);
|
||||
|
||||
case ARCHERY:
|
||||
return Permissions.archery(player);
|
||||
|
||||
case AXES:
|
||||
return Permissions.axes(player);
|
||||
|
||||
case EXCAVATION:
|
||||
return Permissions.excavation(player);
|
||||
|
||||
case FISHING:
|
||||
return Permissions.fishing(player);
|
||||
|
||||
case HERBALISM:
|
||||
return Permissions.herbalism(player);
|
||||
|
||||
case MINING:
|
||||
return Permissions.mining(player);
|
||||
|
||||
case REPAIR:
|
||||
return Permissions.repair(player);
|
||||
|
||||
case SWORDS:
|
||||
return Permissions.swords(player);
|
||||
|
||||
case TAMING:
|
||||
return Permissions.taming(player);
|
||||
|
||||
case UNARMED:
|
||||
return Permissions.unarmed(player);
|
||||
|
||||
case WOODCUTTING:
|
||||
return Permissions.woodcutting(player);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public double getXpModifier() {
|
||||
return xpModifier;
|
||||
}
|
||||
|
||||
public static SkillType getSkill(String skillName) {
|
||||
if (skillName.equalsIgnoreCase("powerlevel") || skillName.equalsIgnoreCase("all")) {
|
||||
return SkillType.ALL;
|
||||
}
|
||||
|
||||
for (SkillType type : SkillType.values()) {
|
||||
if (type.name().equalsIgnoreCase(skillName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("[DEBUG] Invalid mcMMO skill (" + skillName + ")");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the skill level for this skill.
|
||||
*
|
||||
* @param player The player to check
|
||||
* @return
|
||||
*/
|
||||
public int getSkillLevel(Player player) {
|
||||
return Users.getProfile(player).getSkillLevel(this);
|
||||
}
|
||||
|
||||
public boolean isChildSkill() {
|
||||
switch (this) {
|
||||
case SMELTING:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.gmail.nossr50.skills.utilities;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.ItemChecks;
|
||||
|
||||
public enum ToolType {
|
||||
AXE(LocaleLoader.getString("Axes.Ability.Lower"), LocaleLoader.getString("Axes.Ability.Ready")),
|
||||
FISTS(LocaleLoader.getString("Unarmed.Ability.Lower"), LocaleLoader.getString("Unarmed.Ability.Ready")),
|
||||
HOE(LocaleLoader.getString("Herbalism.Ability.Lower"), LocaleLoader.getString("Herbalism.Ability.Ready")),
|
||||
PICKAXE(LocaleLoader.getString("Mining.Ability.Lower"), LocaleLoader.getString("Mining.Ability.Ready")),
|
||||
SHOVEL(LocaleLoader.getString("Excavation.Ability.Lower"), LocaleLoader.getString("Excavation.Ability.Ready")),
|
||||
SWORD(LocaleLoader.getString("Swords.Ability.Lower"), LocaleLoader.getString("Swords.Ability.Ready"));
|
||||
|
||||
private String lowerTool;
|
||||
private String raiseTool;
|
||||
|
||||
private ToolType(String lowerTool, String raiseTool) {
|
||||
this.lowerTool = lowerTool;
|
||||
this.raiseTool = raiseTool;
|
||||
}
|
||||
|
||||
public String getLowerTool() {
|
||||
return lowerTool;
|
||||
}
|
||||
|
||||
public String getRaiseTool() {
|
||||
return raiseTool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the item is of the appropriate type.
|
||||
*
|
||||
* @param is The item to check
|
||||
* @return true if the item is the right type, false otherwise
|
||||
*/
|
||||
public boolean inHand(ItemStack is) {
|
||||
switch (this) {
|
||||
case AXE:
|
||||
return ItemChecks.isAxe(is);
|
||||
|
||||
case FISTS:
|
||||
return is.getType().equals(Material.AIR);
|
||||
|
||||
case HOE:
|
||||
return ItemChecks.isHoe(is);
|
||||
|
||||
case PICKAXE:
|
||||
return ItemChecks.isPickaxe(is);
|
||||
|
||||
case SHOVEL:
|
||||
return ItemChecks.isShovel(is);
|
||||
|
||||
case SWORD:
|
||||
return ItemChecks.isSword(is);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user