mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Cleaning up our UnarmedManager
This commit is contained in:
parent
10e7fe5560
commit
fbd016f86d
@ -1,31 +0,0 @@
|
|||||||
package com.gmail.nossr50.skills.unarmed;
|
|
||||||
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
|
||||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
||||||
|
|
||||||
public class DeflectEventHandler {
|
|
||||||
private UnarmedManager manager;
|
|
||||||
private EntityDamageEvent event;
|
|
||||||
protected int skillModifier;
|
|
||||||
|
|
||||||
protected DeflectEventHandler(UnarmedManager manager, EntityDamageEvent event) {
|
|
||||||
this.manager = manager;
|
|
||||||
this.event = event;
|
|
||||||
|
|
||||||
calculateSkillModifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void calculateSkillModifier() {
|
|
||||||
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.deflectMaxBonusLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sendAbilityMessage() {
|
|
||||||
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cancelEvent() {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
package com.gmail.nossr50.skills.unarmed;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
|
||||||
import com.gmail.nossr50.events.skills.McMMOPlayerDisarmEvent;
|
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
|
||||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
||||||
import com.gmail.nossr50.util.Misc;
|
|
||||||
|
|
||||||
public class DisarmEventHandler {
|
|
||||||
private UnarmedManager manager;
|
|
||||||
private Player defender;
|
|
||||||
private ItemStack inHand;
|
|
||||||
protected int skillModifier;
|
|
||||||
|
|
||||||
protected DisarmEventHandler(UnarmedManager manager, Player defender) {
|
|
||||||
this.manager = manager;
|
|
||||||
this.defender = defender;
|
|
||||||
this.inHand = defender.getItemInHand();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isHoldingItem() {
|
|
||||||
return (inHand.getType() != Material.AIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void calculateSkillModifier() {
|
|
||||||
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.disarmMaxBonusLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendAbilityMessage() {
|
|
||||||
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void handleDisarm() {
|
|
||||||
McMMOPlayerDisarmEvent event = new McMMOPlayerDisarmEvent(defender);
|
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if(!event.isCancelled()) {
|
|
||||||
Misc.dropItem(defender.getLocation(), inHand);
|
|
||||||
defender.setItemInHand(new ItemStack(Material.AIR));
|
|
||||||
|
|
||||||
sendAbilityMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.gmail.nossr50.skills.unarmed;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
|
||||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
||||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
|
||||||
import com.gmail.nossr50.util.Users;
|
|
||||||
|
|
||||||
public class IronGripEventHandler {
|
|
||||||
private UnarmedManager manager;
|
|
||||||
private Player defender;
|
|
||||||
protected int skillModifier;
|
|
||||||
|
|
||||||
protected IronGripEventHandler(UnarmedManager manager, Player defender) {
|
|
||||||
this.manager = manager;
|
|
||||||
this.defender = defender;
|
|
||||||
|
|
||||||
calculateSkillModifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void calculateSkillModifier() {
|
|
||||||
this.skillModifier = SkillTools.skillCheck(Users.getPlayer(defender).getProfile().getSkillLevel(SkillType.UNARMED), Unarmed.ironGripMaxBonusLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sendAbilityMessages() {
|
|
||||||
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
|
|
||||||
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.gmail.nossr50.skills.unarmed;
|
|
||||||
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
|
|
||||||
public class UnarmedBonusDamageEventHandler {
|
|
||||||
private UnarmedManager manager;
|
|
||||||
private EntityDamageEvent event;
|
|
||||||
|
|
||||||
protected int damageBonus;
|
|
||||||
|
|
||||||
protected UnarmedBonusDamageEventHandler(UnarmedManager manager, EntityDamageEvent event) {
|
|
||||||
this.manager = manager;
|
|
||||||
this.event = event;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void calculateDamageBonus() {
|
|
||||||
int damageBonus = 3 + (manager.getSkillLevel() / Unarmed.ironArmIncreaseLevel);
|
|
||||||
|
|
||||||
if (damageBonus > Unarmed.ironArmMaxBonusDamage) {
|
|
||||||
damageBonus = Unarmed.ironArmMaxBonusDamage;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.damageBonus = damageBonus;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void modifyEventDamage() {
|
|
||||||
int damage = event.getDamage();
|
|
||||||
int unarmedBonus = damage + damageBonus;
|
|
||||||
|
|
||||||
event.setDamage(damage + unarmedBonus);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,15 @@
|
|||||||
package com.gmail.nossr50.skills.unarmed;
|
package com.gmail.nossr50.skills.unarmed;
|
||||||
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||||
|
import com.gmail.nossr50.events.skills.McMMOPlayerDisarmEvent;
|
||||||
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.skills.SkillManager;
|
import com.gmail.nossr50.skills.SkillManager;
|
||||||
import com.gmail.nossr50.skills.utilities.PerksUtils;
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
@ -21,55 +24,48 @@ public class UnarmedManager extends SkillManager {
|
|||||||
*
|
*
|
||||||
* @param defender The defending player
|
* @param defender The defending player
|
||||||
*/
|
*/
|
||||||
public void disarmCheck(LivingEntity defender) {
|
public void disarmCheck(Player defender) {
|
||||||
Player defendingPlayer = (Player) defender;
|
if (SkillTools.activationSuccessful(getPlayer(), skill, Unarmed.disarmMaxChance, Unarmed.disarmMaxBonusLevel) && !hasIronGrip(defender)) {
|
||||||
DisarmEventHandler eventHandler = new DisarmEventHandler(this, defendingPlayer);
|
McMMOPlayerDisarmEvent disarmEvent = new McMMOPlayerDisarmEvent(defender);
|
||||||
|
mcMMO.p.getServer().getPluginManager().callEvent(disarmEvent);
|
||||||
|
|
||||||
if (eventHandler.isHoldingItem()) {
|
if (!disarmEvent.isCancelled()) {
|
||||||
eventHandler.calculateSkillModifier();
|
Misc.dropItem(defender.getLocation(), defender.getItemInHand());
|
||||||
|
|
||||||
float chance = (float) ((Unarmed.disarmMaxChance / Unarmed.disarmMaxBonusLevel) * getSkillLevel());
|
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||||
if (chance > Unarmed.disarmMaxChance) chance = (float) Unarmed.disarmMaxChance;
|
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||||
|
|
||||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
||||||
if (!hasIronGrip(defendingPlayer)) {
|
|
||||||
eventHandler.handleDisarm();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for arrow deflection.
|
* Check for arrow deflection.
|
||||||
*
|
|
||||||
* @param event The event to modify
|
|
||||||
*/
|
*/
|
||||||
public void deflectCheck(EntityDamageEvent event) {
|
public boolean deflectCheck() {
|
||||||
DeflectEventHandler eventHandler = new DeflectEventHandler(this, event);
|
Player player = getPlayer();
|
||||||
|
|
||||||
float chance = (float) ((Unarmed.deflectMaxChance / Unarmed.deflectMaxBonusLevel) * getSkillLevel());
|
if (SkillTools.activationSuccessful(player, skill, Unarmed.deflectMaxChance, Unarmed.deflectMaxBonusLevel)) {
|
||||||
if (chance > Unarmed.deflectMaxChance) chance = (float) Unarmed.deflectMaxChance;
|
player.sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||||
|
return true;
|
||||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
|
||||||
eventHandler.cancelEvent();
|
|
||||||
eventHandler.sendAbilityMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void berserkDamage(EntityDamageEvent event) {
|
public int berserkDamage(int damage) {
|
||||||
event.setDamage((int) (event.getDamage() * Unarmed.berserkDamageModifier));
|
return (int) (damage * Unarmed.berserkDamageModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle Unarmed bonus damage.
|
* Handle the effects of the Iron Arm ability
|
||||||
*
|
*
|
||||||
* @param event The event to modify.
|
* @param damage The amount of damage initially dealt by the event
|
||||||
|
* @return the modified event damage
|
||||||
*/
|
*/
|
||||||
public void bonusDamage(EntityDamageEvent event) {
|
public int ironArmCheck(int damage) {
|
||||||
UnarmedBonusDamageEventHandler eventHandler = new UnarmedBonusDamageEventHandler(this, event);
|
int unarmedBonus = Math.min(3 + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
|
||||||
|
|
||||||
eventHandler.calculateDamageBonus();
|
return damage + unarmedBonus;
|
||||||
eventHandler.modifyEventDamage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,16 +75,10 @@ public class UnarmedManager extends SkillManager {
|
|||||||
* @return true if the defender was not disarmed, false otherwise
|
* @return true if the defender was not disarmed, false otherwise
|
||||||
*/
|
*/
|
||||||
private boolean hasIronGrip(Player defender) {
|
private boolean hasIronGrip(Player defender) {
|
||||||
if (Misc.isNPCEntity(defender) || !Permissions.ironGrip(defender)) {
|
if (!Misc.isNPCEntity(defender) && Permissions.ironGrip(defender) && SkillTools.activationSuccessful(defender, skill, Unarmed.ironGripMaxChance, Unarmed.ironGripMaxBonusLevel)) {
|
||||||
return false;
|
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
|
||||||
}
|
getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
|
||||||
|
|
||||||
IronGripEventHandler eventHandler = new IronGripEventHandler(this, defender);
|
|
||||||
|
|
||||||
double chance = (Unarmed.ironGripMaxChance / Unarmed.ironGripMaxBonusLevel) * eventHandler.skillModifier;
|
|
||||||
|
|
||||||
if (chance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(defender, skill))) {
|
|
||||||
eventHandler.sendAbilityMessages();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,15 +152,19 @@ public final class CombatTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Permissions.bonusDamage(player, SkillType.UNARMED)) {
|
if (Permissions.bonusDamage(player, SkillType.UNARMED)) {
|
||||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).bonusDamage(event);
|
event.setDamage(SkillManagerStore.getInstance().getUnarmedManager(playerName).ironArmCheck(event.getDamage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
|
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
|
||||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).berserkDamage(event);
|
event.setDamage(SkillManagerStore.getInstance().getUnarmedManager(playerName).berserkDamage(event.getDamage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof Player && Permissions.disarm(player)) {
|
if (target instanceof Player && Permissions.disarm(player)) {
|
||||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).disarmCheck(target);
|
Player defender = (Player) target;
|
||||||
|
|
||||||
|
if (defender.getItemInHand().getType() != Material.AIR) {
|
||||||
|
SkillManagerStore.getInstance().getUnarmedManager(playerName).disarmCheck((Player) target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
||||||
@ -283,7 +287,11 @@ public final class CombatTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled() && ((Player) target).getItemInHand().getType() == Material.AIR && Permissions.arrowDeflect((Player) target)) {
|
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled() && ((Player) target).getItemInHand().getType() == Material.AIR && Permissions.arrowDeflect((Player) target)) {
|
||||||
SkillManagerStore.getInstance().getUnarmedManager(((Player) target).getName()).deflectCheck(event);
|
event.setCancelled(SkillManagerStore.getInstance().getUnarmedManager(((Player) target).getName()).deflectCheck());
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canDaze(target)) {
|
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canDaze(target)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user