Straightening up our InventoryListener, SwordsManager, TamingManager,

and UnarmedManager.
This commit is contained in:
GJ 2013-03-03 01:31:14 -05:00
parent cbe9cae4ea
commit 7c28be5e62
5 changed files with 68 additions and 40 deletions

View File

@ -18,8 +18,8 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.skills.smelting.SmeltingManager;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
@ -93,13 +93,11 @@ public class InventoryListener implements Listener {
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemUtils.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (Misc.isNPCEntity(player)) {
if (Misc.isNPCEntity(player) || !Permissions.fuelEfficiency(player)) {
return;
}
if (Permissions.fuelEfficiency(player)) {
event.setBurnTime(UserManager.getPlayer(player).getSmeltingManager().fuelEfficiency(event.getBurnTime()));
}
event.setBurnTime(UserManager.getPlayer(player).getSmeltingManager().fuelEfficiency(event.getBurnTime()));
}
}
}
@ -114,13 +112,11 @@ public class InventoryListener implements Listener {
if (plugin.furnaceIsTracked(furnaceBlock) && smelting != null && ItemUtils.isSmeltable(smelting)) {
Player player = plugin.getFurnacePlayer(furnaceBlock);
if (Misc.isNPCEntity(player)) {
if (Misc.isNPCEntity(player) || !Permissions.skillEnabled(player, SkillType.SMELTING)) {
return;
}
if (Permissions.skillEnabled(player, SkillType.SMELTING)) {
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(event.getSource().getType(), event.getResult()));
}
event.setResult(UserManager.getPlayer(player).getSmeltingManager().smeltProcessing(event.getSource().getType(), event.getResult()));
}
}
}
@ -133,10 +129,12 @@ public class InventoryListener implements Listener {
ItemStack result = ((Furnace) furnaceBlock).getInventory().getResult();
if (plugin.furnaceIsTracked(furnaceBlock) && result != null && ItemUtils.isSmelted(result)) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(event.getPlayer());
Player player = event.getPlayer();
if (mcMMOPlayer.getPlayer().equals(plugin.getFurnacePlayer(furnaceBlock))) {
event.setExpToDrop(mcMMOPlayer.getSmeltingManager().vanillaXPBoost(event.getExpToDrop()));
SmeltingManager smeltingManager = UserManager.getPlayer(player).getSmeltingManager();
if (smeltingManager.canUseVanillaXpBoost()) {
event.setExpToDrop(smeltingManager.vanillaXPBoost(event.getExpToDrop()));
}
}
}

View File

@ -4,10 +4,13 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
@ -17,6 +20,18 @@ public class SwordsManager extends SkillManager {
super(mcMMOPlayer, SkillType.SWORDS);
}
public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.SWORD) && Permissions.serratedStrikes(getPlayer());
}
public boolean canUseBleed() {
return Permissions.bleed(getPlayer());
}
public boolean canUseSerratedStrike() {
return mcMMOPlayer.getAbilityMode(AbilityType.SERRATED_STRIKES) && Permissions.serratedStrikes(getPlayer());
}
/**
* Check for Bleed effect.
*

View File

@ -42,6 +42,10 @@ public class TamingManager extends SkillManager {
return getSkillLevel() > Taming.holyHoundUnlockLevel && Permissions.holyHound(getPlayer());
}
public boolean canUseBeastLore(LivingEntity target) {
return target instanceof Tameable && Permissions.beastLore(getPlayer());
}
/**
* Award XP for taming.
*

View File

@ -1,12 +1,15 @@
package com.gmail.nossr50.skills.unarmed;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
@ -19,6 +22,22 @@ public class UnarmedManager extends SkillManager {
super(mcMMOPlayer, SkillType.UNARMED);
}
public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && Permissions.berserk(getPlayer());
}
public boolean canUseIronArm() {
return Permissions.bonusDamage(getPlayer(), skill);
}
public boolean canUseBerserk() {
return mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(getPlayer());
}
public boolean canDisarm(LivingEntity target) {
return target instanceof Player && ((Player) target).getItemInHand().getType() != Material.AIR && Permissions.disarm(getPlayer());
}
/**
* Check for disarm.
*

View File

@ -21,9 +21,7 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
@ -84,23 +82,21 @@ public final class CombatUtils {
}
if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
boolean canSerratedStrike = Permissions.serratedStrikes(player); // So we don't have to check the same permission twice
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
if (mcMMOPlayer.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
if (swordsManager.canActivateAbility()) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.SWORDS);
}
SwordsManager swordsManager = mcMMOPlayer.getSwordsManager();
if (Permissions.bleed(player)) {
if (swordsManager.canUseBleed()) {
swordsManager.bleedCheck(target);
}
if (mcMMOPlayer.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
if (swordsManager.canUseSerratedStrike()) {
swordsManager.serratedStrikes(target, event.getDamage());
}
startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
startGainXp(swordsManager.getMcMMOPlayer(), target, SkillType.SWORDS);
}
}
else if (ItemUtils.isAxe(heldItem)) {
@ -138,41 +134,37 @@ public final class CombatUtils {
}
}
else if (heldItem.getType() == Material.AIR) {
if (targetIsPlayer || targetIsTamedPet) {
if (!SkillType.UNARMED.getPVPEnabled()) {
return;
}
}
else if (!SkillType.UNARMED.getPVEEnabled()) {
if (((targetIsPlayer || targetIsTamedPet) && !SkillType.UNARMED.getPVPEnabled()) || (!targetIsPlayer && !targetIsTamedPet && !SkillType.UNARMED.getPVEEnabled())) {
return;
}
if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
boolean canBerserk = Permissions.berserk(player); // So we don't have to check the same permission twice
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
if (unarmedManager.canActivateAbility()) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED);
}
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
if (Permissions.bonusDamage(player, SkillType.UNARMED)) {
if (unarmedManager.canUseIronArm()) {
event.setDamage(unarmedManager.ironArmCheck(event.getDamage()));
}
if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
if (unarmedManager.canUseBerserk()) {
event.setDamage(unarmedManager.berserkDamage(event.getDamage()));
}
if (target instanceof Player && Permissions.disarm(player)) {
Player defender = (Player) target;
if (defender.getItemInHand().getType() != Material.AIR) {
unarmedManager.disarmCheck((Player) target);
}
if (unarmedManager.canDisarm(target)) {
unarmedManager.disarmCheck((Player) target);
}
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
startGainXp(unarmedManager.getMcMMOPlayer(), target, SkillType.UNARMED);
}
}
else if (heldItem.getType() == Material.BONE) {
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
if (tamingManager.canUseBeastLore(target)) {
tamingManager.beastLore(target);
}
}
}