mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Major refactoring. This WILL break any mcMMO-related plugin that
does not properly hook into the API classes. This consolidates the skill-related classes into their own individual packages, and moves several misc skill classes into the main Skill package as well. This also moves all Party & Spout related files into their own respective packages as well.
This commit is contained in:
@ -1,542 +0,0 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
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.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
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.runnables.BleedTimer;
|
||||
import com.gmail.nossr50.runnables.GainXp;
|
||||
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
|
||||
import com.gmail.nossr50.skills.archery.ArcheryManager;
|
||||
import com.gmail.nossr50.skills.axes.AxeManager;
|
||||
import com.gmail.nossr50.skills.swords.Swords;
|
||||
import com.gmail.nossr50.skills.swords.SwordsManager;
|
||||
import com.gmail.nossr50.skills.taming.TamingManager;
|
||||
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
|
||||
public class Combat {
|
||||
private static Config configInstance = Config.getInstance();
|
||||
|
||||
/**
|
||||
* Apply combat modifiers and process and XP gain.
|
||||
*
|
||||
* @param event The event to run the combat checks on.
|
||||
*/
|
||||
public static void combatChecks(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamage() == 0 || event.getEntity().isDead()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity damager = event.getDamager();
|
||||
LivingEntity target = (LivingEntity) event.getEntity();
|
||||
|
||||
boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
|
||||
boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
|
||||
|
||||
switch (damager.getType()) {
|
||||
case PLAYER:
|
||||
Player attacker = (Player) event.getDamager();
|
||||
ItemStack itemInHand = attacker.getItemInHand();
|
||||
|
||||
if (ItemChecks.isSword(itemInHand)) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!configInstance.getSwordsPVP()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!configInstance.getSwordsPVE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Skills.abilityCheck(attacker, SkillType.SWORDS);
|
||||
|
||||
SwordsManager swordsManager = new SwordsManager(attacker);
|
||||
swordsManager.bleedCheck(target);
|
||||
swordsManager.serratedStrikes(target, event.getDamage());
|
||||
|
||||
startGainXp(attacker, swordsManager.getProfile(), target, SkillType.SWORDS);
|
||||
}
|
||||
else if (ItemChecks.isAxe(itemInHand) && Permissions.axes(attacker)) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!configInstance.getAxesPVP()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!configInstance.getAxesPVE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Skills.abilityCheck(attacker, SkillType.AXES);
|
||||
|
||||
AxeManager axeManager = new AxeManager(attacker);
|
||||
axeManager.bonusDamage(event);
|
||||
axeManager.criticalHitCheck(event);
|
||||
axeManager.impact(event);
|
||||
axeManager.skullSplitter(event);
|
||||
|
||||
startGainXp(attacker, axeManager.getProfile(), target, SkillType.AXES);
|
||||
}
|
||||
else if (itemInHand.getType() == Material.AIR && Permissions.unarmed(attacker)) {
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!configInstance.getUnarmedPVP()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!configInstance.getUnarmedPVE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Skills.abilityCheck(attacker, SkillType.UNARMED);
|
||||
|
||||
UnarmedManager unarmedManager = new UnarmedManager(attacker);
|
||||
|
||||
unarmedManager.bonusDamage(event);
|
||||
|
||||
if (unarmedManager.getProfile().getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(attacker)) {
|
||||
event.setDamage((int) (event.getDamage() * 1.5));
|
||||
}
|
||||
|
||||
if (targetIsPlayer) {
|
||||
unarmedManager.disarmCheck((Player) target);
|
||||
}
|
||||
|
||||
startGainXp(attacker, unarmedManager.getProfile(), target, SkillType.UNARMED);
|
||||
}
|
||||
else if (itemInHand.getType() == Material.BONE && target instanceof Tameable) {
|
||||
TamingManager tamingManager = new TamingManager(attacker);
|
||||
tamingManager.beastLore(target);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WOLF:
|
||||
Wolf wolf = (Wolf) damager;
|
||||
|
||||
if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
|
||||
Player master = (Player) wolf.getOwner();
|
||||
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!configInstance.getTamingPVP()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!configInstance.getTamingPVE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TamingManager tamingManager = new TamingManager(master);
|
||||
|
||||
tamingManager.fastFoodService(wolf, event.getDamage());
|
||||
tamingManager.sharpenedClaws(event);
|
||||
tamingManager.gore(event);
|
||||
|
||||
startGainXp(master, Users.getProfile(master), target, SkillType.TAMING);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ARROW:
|
||||
LivingEntity shooter = ((Arrow) damager).getShooter();
|
||||
|
||||
if (shooter == null || shooter.getType() != EntityType.PLAYER) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (targetIsPlayer || targetIsTamedPet) {
|
||||
if (!configInstance.getArcheryPVP()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (!configInstance.getArcheryPVE()) {
|
||||
return;
|
||||
}
|
||||
|
||||
archeryCheck((Player) shooter, target, event);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (targetIsPlayer) {
|
||||
Player player = (Player) target;
|
||||
|
||||
AcrobaticsManager acroManager = new AcrobaticsManager(player);
|
||||
SwordsManager swordsManager = new SwordsManager(player);
|
||||
|
||||
if (damager.getType() == EntityType.PLAYER) {
|
||||
if (configInstance.getSwordsPVP()) {
|
||||
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||
}
|
||||
|
||||
if (configInstance.getAcrobaticsPVP()) {
|
||||
acroManager.dodgeCheck(event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (configInstance.getSwordsPVE() && damager instanceof LivingEntity) {
|
||||
swordsManager.counterAttackChecks((LivingEntity) damager, event.getDamage());
|
||||
}
|
||||
|
||||
if (configInstance.getAcrobaticsPVE()) {
|
||||
if (damager instanceof LightningStrike && configInstance.getDodgeLightningDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
acroManager.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.
|
||||
*/
|
||||
public static void archeryCheck(Player shooter, LivingEntity target, EntityDamageByEntityEvent event) {
|
||||
if (target instanceof Player) {
|
||||
Player defender = (Player) target;
|
||||
|
||||
if (defender.getItemInHand().getType().equals(Material.AIR)) {
|
||||
if (configInstance.getUnarmedPVP()) {
|
||||
UnarmedManager unarmedManager = new UnarmedManager(defender);
|
||||
unarmedManager.deflectCheck(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArcheryManager archeryManager = new ArcheryManager(shooter);
|
||||
|
||||
archeryManager.skillShot(event);
|
||||
|
||||
if (target instanceof Player) {
|
||||
archeryManager.dazeCheck((Player) target, event);
|
||||
}
|
||||
|
||||
if (!(shooter.getItemInHand().containsEnchantment(Enchantment.ARROW_INFINITE))) {
|
||||
archeryManager.trackArrows(target);
|
||||
}
|
||||
|
||||
if (target != shooter) {
|
||||
PlayerProfile profile = Users.getProfile(shooter);
|
||||
startGainXp(shooter, profile, 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) {
|
||||
if (Misc.isNPC((Player) entity)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(entity instanceof LivingEntity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (numberOfTargets <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!shouldBeAffected(attacker, entity)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
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()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (defender == player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PartyManager.getInstance().inSameParty(player, defender)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (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) {
|
||||
Tameable pet = (Tameable) entity;
|
||||
|
||||
if (Misc.isFriendlyPet(player, pet)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -17,10 +17,10 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.DatabaseUpdate;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.datatypes.SpoutHud;
|
||||
import com.gmail.nossr50.runnables.SQLReconnect;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
import com.gmail.nossr50.spout.SpoutStuff;
|
||||
import com.gmail.nossr50.spout.huds.SpoutHud;
|
||||
|
||||
public class Database {
|
||||
|
||||
|
@ -4,8 +4,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
|
||||
public abstract class Hardcore {
|
||||
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.Skills;
|
||||
|
||||
public class Item {
|
||||
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
|
||||
public class Leaderboard {
|
||||
private static mcMMO plugin = mcMMO.p;
|
||||
|
@ -4,8 +4,9 @@ import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
import com.gmail.nossr50.skills.Skills;
|
||||
|
||||
public class Page {
|
||||
|
||||
|
@ -3,7 +3,7 @@ package com.gmail.nossr50.util;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.skills.SkillType;
|
||||
|
||||
public class Permissions {
|
||||
public static boolean hasPermission(CommandSender sender, String perm)
|
||||
|
@ -1,517 +0,0 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
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.config.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.datatypes.ToolType;
|
||||
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.spout.SpoutStuff;
|
||||
|
||||
public class Skills {
|
||||
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
||||
public static int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength();
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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()) {
|
||||
SpoutStuff.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) {
|
||||
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);
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
ToolType tool = type.getTool();
|
||||
|
||||
if (!profile.getToolPreparationMode(tool)) {
|
||||
return;
|
||||
}
|
||||
|
||||
profile.setToolPreparationMode(tool, false);
|
||||
|
||||
AbilityType ability = type.getAbility();
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
if (!ability.getPermissions(player)) {
|
||||
activate = false;
|
||||
return activate;
|
||||
}
|
||||
|
||||
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 (player == null)
|
||||
return;
|
||||
|
||||
if (type.getPermissions(player)) {
|
||||
if (Users.getPlayer(player) == null)
|
||||
return;
|
||||
|
||||
if ((type.getMaxLevel() < profile.getSkillLevel(type) + 1) || (Misc.getPowerLevelCap() < Users.getPlayer(player).getPowerLevel() + 1))
|
||||
return;
|
||||
|
||||
Users.getPlayer(player).addXP(type, xp);
|
||||
xpCheckSkill(type, player, profile);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user