Skip to content

Commit

Permalink
Moved ability and tool stuff from McMMOPlayer to SkillManager classes
Browse files Browse the repository at this point in the history
Warning: Because Woodcutting and Repair don't have a "proper" manager
class, this doesn't work yet.
  • Loading branch information
bm01 committed Mar 3, 2013
1 parent 1b461ac commit 12b548b
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 198 deletions.
21 changes: 11 additions & 10 deletions src/main/java/com/gmail/nossr50/api/AbilityAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,46 @@
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.skills.SkillManager;
import com.gmail.nossr50.util.player.UserManager;

public final class AbilityAPI {
private AbilityAPI() {}

public static boolean berserkEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.BERSERK);
return UserManager.getPlayer(player).getSkillManager(SkillType.UNARMED).getAbilityMode();
}

public static boolean gigaDrillBreakerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.GIGA_DRILL_BREAKER);
return UserManager.getPlayer(player).getSkillManager(SkillType.EXCAVATION).getAbilityMode();
}

public static boolean greenTerraEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.GREEN_TERRA);
return UserManager.getPlayer(player).getSkillManager(SkillType.HERBALISM).getAbilityMode();
}

public static boolean serratedStrikesEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.SERRATED_STRIKES);
return UserManager.getPlayer(player).getSkillManager(SkillType.SWORDS).getAbilityMode();
}

public static boolean skullSplitterEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.SKULL_SPLITTER);
return UserManager.getPlayer(player).getSkillManager(SkillType.AXES).getAbilityMode();
}

public static boolean superBreakerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.SUPER_BREAKER);
return UserManager.getPlayer(player).getSkillManager(SkillType.MINING).getAbilityMode();
}

public static boolean treeFellerEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(AbilityType.TREE_FELLER);
return UserManager.getPlayer(player).getSkillManager(SkillType.WOODCUTTING).getAbilityMode();
}

public static boolean isAnyAbilityEnabled(Player player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);

for (AbilityType ability : AbilityType.values()) {
if (mcMMOPlayer.getAbilityMode(ability)) {
for (SkillManager skillManager : mcMMOPlayer.getSkillManagers().values()) {
if (skillManager.getAbilityMode()) {
return true;
}
}
Expand Down
115 changes: 12 additions & 103 deletions src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.datatypes.party.Party;
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.datatypes.spout.huds.McMMOHud;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.PartyManager;
Expand Down Expand Up @@ -69,11 +67,6 @@ public class McMMOPlayer {
private boolean placedSalvageAnvil;
private boolean godMode;

private Map<AbilityType, Boolean> abilityMode = new HashMap<AbilityType, Boolean>();
private Map<AbilityType, Boolean> abilityInformed = new HashMap<AbilityType, Boolean>();
private Map<ToolType, Boolean> toolPreparationMode = new HashMap<ToolType, Boolean>();
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();

private int recentlyHurt;
private int respawnATS;

Expand Down Expand Up @@ -103,16 +96,6 @@ public McMMOPlayer(Player player) {
e.printStackTrace();
mcMMO.p.getPluginLoader().disablePlugin(mcMMO.p);
}

for (AbilityType abilityType : AbilityType.values()) {
abilityMode.put(abilityType, false);
abilityInformed.put(abilityType, true); // This is intended
}

for (ToolType toolType : ToolType.values()) {
toolPreparationMode.put(toolType, false);
toolATS.put(toolType, 0);
}
}

public AcrobaticsManager getAcrobaticsManager() {
Expand Down Expand Up @@ -159,6 +142,14 @@ public UnarmedManager getUnarmedManager() {
return (UnarmedManager) skillManagers.get(SkillType.UNARMED);
}

public SkillManager getSkillManager(SkillType skillType) {
return skillManagers.get(skillType);
}

public Map<SkillType, SkillManager> getSkillManagers() {
return skillManagers;
}

/*
* Abilities
*/
Expand All @@ -167,61 +158,11 @@ public UnarmedManager getUnarmedManager() {
* Reset the mode of all abilities.
*/
public void resetAbilityMode() {
for (AbilityType ability : AbilityType.values()) {
setAbilityMode(ability, false);
for (SkillManager skillManager : skillManagers.values()) {
skillManager.setAbilityMode(false);
}
}

/**
* Get the mode of an ability.
*
* @param ability The ability to check
* @return true if the ability is enabled, false otherwise
*/
public boolean getAbilityMode(AbilityType ability) {
return abilityMode.get(ability);
}

/**
* Set the mode of an ability.
*
* @param ability The ability to check
* @param bool True if the ability is active, false otherwise
*/
public void setAbilityMode(AbilityType ability, boolean bool) {
abilityMode.put(ability, bool);
}

/**
* Get the informed state of an ability
*
* @param ability The ability to check
* @return true if the ability is informed, false otherwise
*/
public boolean getAbilityInformed(AbilityType ability) {
return abilityInformed.get(ability);
}

/**
* Set the informed state of an ability.
*
* @param ability The ability to check
* @param bool True if the ability is informed, false otherwise
*/
public void setAbilityInformed(AbilityType ability, boolean bool) {
abilityInformed.put(ability, bool);
}

/**
* Get the current prep mode of a tool.
*
* @param tool Tool to get the mode for
* @return true if the tool is prepped, false otherwise
*/
public boolean getToolPreparationMode(ToolType tool) {
return toolPreparationMode.get(tool);
}

public boolean getAbilityUse() {
return abilityUse;
}
Expand All @@ -238,43 +179,11 @@ public void toggleAbilityUse() {
* Reset the prep modes of all tools.
*/
public void resetToolPrepMode() {
for (ToolType tool : ToolType.values()) {
setToolPreparationMode(tool, false);
for (SkillManager skillManager : skillManagers.values()) {
skillManager.getTool().setPreparationMode(false);
}
}

/**
* Set the current prep mode of a tool.
*
* @param tool Tool to set the mode for
* @param bool true if the tool should be prepped, false otherwise
*/
public void setToolPreparationMode(ToolType tool, boolean bool) {
toolPreparationMode.put(tool, bool);
}

/**
* Get the current prep ATS of a tool.
*
* @param tool Tool to get the ATS for
* @return the ATS for the tool
*/
public long getToolPreparationATS(ToolType tool) {
return toolATS.get(tool);
}

/**
* Set the current prep ATS of a tool.
*
* @param tool Tool to set the ATS for
* @param ATS the ATS of the tool
*/
public void setToolPreparationATS(ToolType tool, long ATS) {
int startTime = (int) (ATS / Misc.TIME_CONVERSION_FACTOR);

toolATS.put(tool, startTime);
}

/*
* Recently Hurt
*/
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/gmail/nossr50/datatypes/skills/SkillType.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ public enum SkillType {

private Class<? extends SkillManager> managerClass;
private AbilityType ability;
private ToolType tool;
private ToolType toolType;

private SkillType(Class<? extends SkillManager> managerClass) {
this.managerClass = managerClass;
ability = null;
tool = null;
toolType = null;
}

private SkillType(Class<? extends SkillManager> managerClass, AbilityType ability, ToolType tool) {
this.managerClass = managerClass;
this.ability = ability;
this.tool = tool;
this.toolType = tool;
}

public Class<? extends SkillManager> getManagerClass() {
Expand Down Expand Up @@ -77,8 +77,8 @@ public boolean getDoubleDropsDisabled() {
return Config.getInstance().getDoubleDropsDisabled(this);
}

public ToolType getTool() {
return tool;
public ToolType getToolType() {
return toolType;
}

public double getXpModifier() {
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/gmail/nossr50/datatypes/skills/Tool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.gmail.nossr50.datatypes.skills;

import java.util.HashMap;
import java.util.Map;

import com.gmail.nossr50.util.Misc;

public class Tool {
private static Map<ToolType, Tool> tools = new HashMap<ToolType, Tool>();
private boolean preparationMode = true;
private long preparationATS;

private Tool(ToolType toolType) {
tools.put(toolType, this);
}

public boolean getPreparationMode() {
return preparationMode;
}

public void setPreparationMode(boolean preparationMode) {
this.preparationMode = preparationMode;
}

public long getPreparationATS() {
return preparationATS;
}

public void setPreparationATS(long toolPreparationATS) {
int startTime = (int) (toolPreparationATS / Misc.TIME_CONVERSION_FACTOR);

preparationATS = startTime;
}

public static Tool getTool(ToolType toolType) {
Tool tool = tools.get(toolType);

if (tool == null) {
tool = new Tool(toolType);
}

return tool;
}
}
27 changes: 14 additions & 13 deletions src/main/java/com/gmail/nossr50/listeners/BlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
Expand Down Expand Up @@ -176,16 +175,17 @@ public void onBlockBreak(BlockBreakEvent event) {
/* MINING */
else if (BlockUtils.affectedBySuperBreaker(blockState) && ItemUtils.isPickaxe(heldItem) && Permissions.skillEnabled(player, SkillType.MINING) && !mcMMO.placeStore.isTrue(blockState)) {
MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();

miningManager.miningBlockCheck(blockState);

if (mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) {
if (miningManager.getAbilityMode()) {
miningManager.miningBlockCheck(blockState);
}
}

/* WOOD CUTTING */
else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillType.WOODCUTTING) && !mcMMO.placeStore.isTrue(blockState)) {
if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) {
if (mcMMOPlayer.getSkillManager(SkillType.WOODCUTTING).getAbilityMode() && Permissions.treeFeller(player) && ItemUtils.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(blockState, player);
}
else {
Expand All @@ -203,9 +203,10 @@ else if (BlockUtils.isLog(blockState) && Permissions.skillEnabled(player, SkillT
/* EXCAVATION */
else if (BlockUtils.affectedByGigaDrillBreaker(blockState) && ItemUtils.isShovel(heldItem) && Permissions.skillEnabled(player, SkillType.EXCAVATION) && !mcMMO.placeStore.isTrue(blockState)) {
ExcavationManager excavationManager = UserManager.getPlayer(player).getExcavationManager();

excavationManager.excavationBlockCheck(blockState);

if (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
if (excavationManager.getAbilityMode()) {
excavationManager.gigaDrillBreaker(blockState);
}
}
Expand Down Expand Up @@ -281,29 +282,29 @@ public void onBlockDamage(BlockDamageEvent event) {
ItemStack heldItem = player.getItemInHand();

if (HiddenConfig.getInstance().useEnchantmentBuffs()) {
if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER))) {
if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getSkillManager(SkillType.MINING).getAbilityMode()) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getAbilityMode())) {
SkillUtils.removeAbilityBuff(heldItem);
}
}
else {
if ((mcMMOPlayer.getAbilityMode(AbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) {
if ((mcMMOPlayer.getSkillManager(SkillType.MINING).getAbilityMode() && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getAbilityMode() && !BlockUtils.affectedByGigaDrillBreaker(blockState))) {
SkillUtils.handleAbilitySpeedDecrease(player);
}
}

if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
if (mcMMOPlayer.getSkillManager(SkillType.HERBALISM).getTool().getPreparationMode() && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.HERBALISM);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) {
else if (mcMMOPlayer.getSkillManager(SkillType.WOODCUTTING).getTool().getPreparationMode() && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.WOODCUTTING);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
else if (mcMMOPlayer.getSkillManager(SkillType.MINING).getTool().getPreparationMode() && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.MINING);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
else if (mcMMOPlayer.getSkillManager(SkillType.EXCAVATION).getTool().getPreparationMode() && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.EXCAVATION);
}
else if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
else if (mcMMOPlayer.getSkillManager(SkillType.UNARMED).getTool().getPreparationMode() && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
SkillUtils.abilityCheck(mcMMOPlayer, SkillType.UNARMED);
}
}
Expand All @@ -313,7 +314,7 @@ else if (mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && heldItem.getType(
*
* We don't need to check permissions here because they've already been checked for the ability to even activate.
*/
if (mcMMOPlayer.getAbilityMode(AbilityType.TREE_FELLER) && BlockUtils.isLog(blockState)) {
if (mcMMOPlayer.getSkillManager(SkillType.WOODCUTTING).getTool().getPreparationMode() && BlockUtils.isLog(blockState)) {
player.playSound(blockState.getLocation(), Sound.FIZZ, Misc.FIZZ_VOLUME, Misc.FIZZ_PITCH);
}
}
Expand Down Expand Up @@ -351,7 +352,7 @@ public void onBlockDamageHigher(BlockDamageEvent event) {
blockState.update(true);
}
}
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) {
else if (mcMMOPlayer.getSkillManager(SkillType.UNARMED).getTool().getPreparationMode()) {
if (SkillUtils.triggerCheck(player, block, AbilityType.BERSERK)) {
if (heldItem.getType() == Material.AIR) {
plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
Expand Down
Loading

0 comments on commit 12b548b

Please sign in to comment.