Turned ToolType to public static final over enum

This commit is contained in:
ile123ile 2014-08-31 17:42:23 -07:00
parent 628f59ba54
commit b18d81836d
8 changed files with 99 additions and 52 deletions

View File

@ -105,11 +105,6 @@ public class McMMOPlayer {
profile.setUniqueId(uuid); profile.setUniqueId(uuid);
} }
/*
* I'm using this method because it makes code shorter and safer (we don't have to add all SkillTypes manually),
* but I actually have no idea about the performance impact, if there is any.
* If in the future someone wants to remove this, don't forget to also remove what is in the SkillType enum. - bm01
*/
try { try {
for (SkillType skillType : SkillType.getSkillList()) { for (SkillType skillType : SkillType.getSkillList()) {
skillManagers.put(skillType, skillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this)); skillManagers.put(skillType, skillType.getManagerClass().getConstructor(McMMOPlayer.class).newInstance(this));
@ -125,7 +120,7 @@ public class McMMOPlayer {
abilityInformed.put(abilityType, true); // This is intended abilityInformed.put(abilityType, true); // This is intended
} }
for (ToolType toolType : ToolType.values()) { for (ToolType toolType : ToolType.getToolList()) {
toolMode.put(toolType, false); toolMode.put(toolType, false);
} }
} }
@ -274,7 +269,7 @@ public class McMMOPlayer {
* Reset the prep modes of all tools. * Reset the prep modes of all tools.
*/ */
public void resetToolPrepMode() { public void resetToolPrepMode() {
for (ToolType tool : ToolType.values()) { for (ToolType tool : ToolType.getToolList()) {
setToolPreparationMode(tool, false); setToolPreparationMode(tool, false);
} }
} }

View File

@ -72,18 +72,18 @@ public class SkillType {
public static final SkillType acrobatics = createSkill("ACROBATICS" , AcrobaticsManager.class , AcrobaticsCommand.class , false, Color.WHITE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.dodge, SecondaryAbility.gracefullRoll, SecondaryAbility.roll)); public static final SkillType acrobatics = createSkill("ACROBATICS" , AcrobaticsManager.class , AcrobaticsCommand.class , false, Color.WHITE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.dodge, SecondaryAbility.gracefullRoll, SecondaryAbility.roll));
public static final SkillType alchemy = createSkill("ALCHEMY" , AlchemyManager.class , AlchemyCommand.class , false, Color.FUCHSIA, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.catalysis, SecondaryAbility.concoctions)); public static final SkillType alchemy = createSkill("ALCHEMY" , AlchemyManager.class , AlchemyCommand.class , false, Color.FUCHSIA, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.catalysis, SecondaryAbility.concoctions));
public static final SkillType archery = createSkill("ARCHERY" , ArcheryManager.class , ArcheryCommand.class , false, Color.MAROON, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.daze, SecondaryAbility.retrieve, SecondaryAbility.skillShot)); public static final SkillType archery = createSkill("ARCHERY" , ArcheryManager.class , ArcheryCommand.class , false, Color.MAROON, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.daze, SecondaryAbility.retrieve, SecondaryAbility.skillShot));
public static final SkillType axes = createSkill("AXES" , AxesManager.class , AxesCommand.class , false, Color.AQUA, SkillUseType.COMBAT, AbilityType.skullSplitter, ToolType.AXE, ImmutableList.of(SecondaryAbility.armorImpact, SecondaryAbility.axeMastery, SecondaryAbility.criticalHit, SecondaryAbility.greaterImpact)); public static final SkillType axes = createSkill("AXES" , AxesManager.class , AxesCommand.class , false, Color.AQUA, SkillUseType.COMBAT, AbilityType.skullSplitter, ToolType.axe, ImmutableList.of(SecondaryAbility.armorImpact, SecondaryAbility.axeMastery, SecondaryAbility.criticalHit, SecondaryAbility.greaterImpact));
public static final SkillType excavation = createSkill("EXCAVATION" , ExcavationManager.class , ExcavationCommand.class , false, Color.fromRGB(139, 69, 19), SkillUseType.GATHERING, AbilityType.gigaDrillBreaker, ToolType.SHOVEL, ImmutableList.of(SecondaryAbility.excavationTreasureHunter)); public static final SkillType excavation = createSkill("EXCAVATION" , ExcavationManager.class , ExcavationCommand.class , false, Color.fromRGB(139, 69, 19), SkillUseType.GATHERING, AbilityType.gigaDrillBreaker, ToolType.shovel, ImmutableList.of(SecondaryAbility.excavationTreasureHunter));
public static final SkillType fishing = createSkill("FISHING" , FishingManager.class , FishingCommand.class , false, Color.NAVY, SkillUseType.GATHERING, ImmutableList.of(SecondaryAbility.fishermansDiet, SecondaryAbility.fishingTreasureHunter, SecondaryAbility.iceFishing, SecondaryAbility.magicHunter, SecondaryAbility.masterAngler, SecondaryAbility.shake)); public static final SkillType fishing = createSkill("FISHING" , FishingManager.class , FishingCommand.class , false, Color.NAVY, SkillUseType.GATHERING, ImmutableList.of(SecondaryAbility.fishermansDiet, SecondaryAbility.fishingTreasureHunter, SecondaryAbility.iceFishing, SecondaryAbility.magicHunter, SecondaryAbility.masterAngler, SecondaryAbility.shake));
public static final SkillType herbalism = createSkill("HERBALISM" , HerbalismManager.class , HerbalismCommand.class , false, Color.GREEN, SkillUseType.GATHERING, AbilityType.greenTerra, ToolType.HOE, ImmutableList.of(SecondaryAbility.farmersDiet, SecondaryAbility.greenThumbPlant, SecondaryAbility.greenThumbBlock, SecondaryAbility.herbalismDoubleDrops, SecondaryAbility.hylianLuck, SecondaryAbility.shroomThumb)); public static final SkillType herbalism = createSkill("HERBALISM" , HerbalismManager.class , HerbalismCommand.class , false, Color.GREEN, SkillUseType.GATHERING, AbilityType.greenTerra, ToolType.hoe, ImmutableList.of(SecondaryAbility.farmersDiet, SecondaryAbility.greenThumbPlant, SecondaryAbility.greenThumbBlock, SecondaryAbility.herbalismDoubleDrops, SecondaryAbility.hylianLuck, SecondaryAbility.shroomThumb));
public static final SkillType mining = createSkill("MINING" , MiningManager.class , MiningCommand.class , false, Color.GRAY, SkillUseType.GATHERING, AbilityType.superBreaker, ToolType.PICKAXE, ImmutableList.of(SecondaryAbility.miningDoubleDrops)); public static final SkillType mining = createSkill("MINING" , MiningManager.class , MiningCommand.class , false, Color.GRAY, SkillUseType.GATHERING, AbilityType.superBreaker, ToolType.pickaxe, ImmutableList.of(SecondaryAbility.miningDoubleDrops));
public static final SkillType repair = createSkill("REPAIR" , RepairManager.class , RepairCommand.class , false, Color.SILVER, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.arcaneForging, SecondaryAbility.repairMastery, SecondaryAbility.superRepair)); public static final SkillType repair = createSkill("REPAIR" , RepairManager.class , RepairCommand.class , false, Color.SILVER, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.arcaneForging, SecondaryAbility.repairMastery, SecondaryAbility.superRepair));
public static final SkillType salvage = createSkill("SALVAGE" , SalvageManager.class , SalvageCommand.class , true, Color.ORANGE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.advancedSalvage, SecondaryAbility.arcaneSalvage)); public static final SkillType salvage = createSkill("SALVAGE" , SalvageManager.class , SalvageCommand.class , true, Color.ORANGE, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.advancedSalvage, SecondaryAbility.arcaneSalvage));
public static final SkillType smelting = createSkill("SMELTING" , SmeltingManager.class , SmeltingCommand.class , true, Color.YELLOW, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.fluxMining, SecondaryAbility.fuelEfficiency, SecondaryAbility.secondSmelt)); public static final SkillType smelting = createSkill("SMELTING" , SmeltingManager.class , SmeltingCommand.class , true, Color.YELLOW, SkillUseType.MISC, ImmutableList.of(SecondaryAbility.fluxMining, SecondaryAbility.fuelEfficiency, SecondaryAbility.secondSmelt));
public static final SkillType swords = createSkill("SWORDS" , SwordsManager.class , SwordsCommand.class , false, Color.fromRGB(178, 34, 34), SkillUseType.COMBAT, AbilityType.serratedStrikes, ToolType.SWORD, ImmutableList.of(SecondaryAbility.bleed, SecondaryAbility.counter)); public static final SkillType swords = createSkill("SWORDS" , SwordsManager.class , SwordsCommand.class , false, Color.fromRGB(178, 34, 34), SkillUseType.COMBAT, AbilityType.serratedStrikes, ToolType.sword, ImmutableList.of(SecondaryAbility.bleed, SecondaryAbility.counter));
public static final SkillType taming = createSkill("TAMING" , TamingManager.class , TamingCommand.class , false, Color.PURPLE, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.beastLore, SecondaryAbility.callOfTheWild, SecondaryAbility.enviromentallyAware, SecondaryAbility.fastFood, SecondaryAbility.gore, SecondaryAbility.holyHound, SecondaryAbility.sharpenedClaws, SecondaryAbility.shockProof, SecondaryAbility.thickFur)); public static final SkillType taming = createSkill("TAMING" , TamingManager.class , TamingCommand.class , false, Color.PURPLE, SkillUseType.COMBAT, ImmutableList.of(SecondaryAbility.beastLore, SecondaryAbility.callOfTheWild, SecondaryAbility.enviromentallyAware, SecondaryAbility.fastFood, SecondaryAbility.gore, SecondaryAbility.holyHound, SecondaryAbility.sharpenedClaws, SecondaryAbility.shockProof, SecondaryAbility.thickFur));
public static final SkillType unarmed = createSkill("UNARMED" , UnarmedManager.class , UnarmedCommand.class , false, Color.BLACK, SkillUseType.COMBAT, AbilityType.berserk, ToolType.FISTS, ImmutableList.of(SecondaryAbility.blockCracker, SecondaryAbility.deflect, SecondaryAbility.disarm, SecondaryAbility.ironArm, SecondaryAbility.ironGrip)); public static final SkillType unarmed = createSkill("UNARMED" , UnarmedManager.class , UnarmedCommand.class , false, Color.BLACK, SkillUseType.COMBAT, AbilityType.berserk, ToolType.fists, ImmutableList.of(SecondaryAbility.blockCracker, SecondaryAbility.deflect, SecondaryAbility.disarm, SecondaryAbility.ironArm, SecondaryAbility.ironGrip));
public static final SkillType woodcutting = createSkill("WOODCUTTING", WoodcuttingManager.class , WoodcuttingCommand.class , false, Color.OLIVE, SkillUseType.GATHERING, AbilityType.treeFeller, ToolType.AXE, ImmutableList.of(SecondaryAbility.leafBlower, SecondaryAbility.woodcuttingDoubleDrops)); public static final SkillType woodcutting = createSkill("WOODCUTTING", WoodcuttingManager.class , WoodcuttingCommand.class , false, Color.OLIVE, SkillUseType.GATHERING, AbilityType.treeFeller, ToolType.axe, ImmutableList.of(SecondaryAbility.leafBlower, SecondaryAbility.woodcuttingDoubleDrops));
private String name; private String name;

View File

@ -1,18 +1,56 @@
package com.gmail.nossr50.datatypes.skills; package com.gmail.nossr50.datatypes.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.ItemUtils; import com.gmail.nossr50.util.ItemUtils;
public enum ToolType { public class ToolType {
AXE(LocaleLoader.getString("Axes.Ability.Lower"), LocaleLoader.getString("Axes.Ability.Ready")), private static List<ToolType> tools = new ArrayList<ToolType>();
FISTS(LocaleLoader.getString("Unarmed.Ability.Lower"), LocaleLoader.getString("Unarmed.Ability.Ready")),
HOE(LocaleLoader.getString("Herbalism.Ability.Lower"), LocaleLoader.getString("Herbalism.Ability.Ready")), public static final ToolType axe = new ToolType("Axes") {
PICKAXE(LocaleLoader.getString("Mining.Ability.Lower"), LocaleLoader.getString("Mining.Ability.Ready")), @Override
SHOVEL(LocaleLoader.getString("Excavation.Ability.Lower"), LocaleLoader.getString("Excavation.Ability.Ready")), public boolean inHand(ItemStack itemStack) {
SWORD(LocaleLoader.getString("Swords.Ability.Lower"), LocaleLoader.getString("Swords.Ability.Ready")); return ItemUtils.isAxe(itemStack);
}
};
public static final ToolType fists = createToolType("Unarmed", Material.AIR);
public static final ToolType hoe = new ToolType("Herbalism") {
@Override
public boolean inHand(ItemStack itemStack) {
return ItemUtils.isHoe(itemStack);
}
};
public static final ToolType pickaxe = new ToolType("Mining") {
@Override
public boolean inHand(ItemStack itemStack) {
return ItemUtils.isPickaxe(itemStack);
}
};
public static final ToolType shovel = new ToolType("Excavation") {
@Override
public boolean inHand(ItemStack itemStack) {
return ItemUtils.isShovel(itemStack);
}
};
public static final ToolType sword = new ToolType("Swords") {
@Override
public boolean inHand(ItemStack itemStack) {
return ItemUtils.isSword(itemStack);
}
};
static {
tools.add(axe);
tools.add(hoe);
tools.add(pickaxe);
tools.add(shovel);
tools.add(sword);
}
private String lowerTool; private String lowerTool;
private String raiseTool; private String raiseTool;
@ -22,6 +60,10 @@ public enum ToolType {
this.raiseTool = raiseTool; this.raiseTool = raiseTool;
} }
private ToolType(String toolName) {
this(LocaleLoader.getString(toolName + ".Ability.Lower"), LocaleLoader.getString(toolName + ".Ability.Ready"));
}
public String getLowerTool() { public String getLowerTool() {
return lowerTool; return lowerTool;
} }
@ -30,6 +72,33 @@ public enum ToolType {
return raiseTool; return raiseTool;
} }
public static ToolType createToolType(String toolName, final Material material) {
ToolType tool = new ToolType(toolName) {
@Override
public boolean inHand(ItemStack itemStack) {
return itemStack.getType() == material;
}
};
tools.add(tool);
return tool;
}
public static ToolType createToolType(String toolName, final Material... materials) {
ToolType tool = new ToolType(toolName) {
@Override
public boolean inHand(ItemStack itemStack) {
for(Material material : materials) {
if(itemStack.getType() == material) {
return true;
}
}
return false;
}
};
tools.add(tool);
return tool;
}
/** /**
* Check to see if the item is of the appropriate type. * Check to see if the item is of the appropriate type.
* *
@ -37,27 +106,10 @@ public enum ToolType {
* @return true if the item is the right type, false otherwise * @return true if the item is the right type, false otherwise
*/ */
public boolean inHand(ItemStack itemStack) { public boolean inHand(ItemStack itemStack) {
switch (this) { return false;
case AXE:
return ItemUtils.isAxe(itemStack);
case FISTS:
return itemStack.getType() == Material.AIR;
case HOE:
return ItemUtils.isHoe(itemStack);
case PICKAXE:
return ItemUtils.isPickaxe(itemStack);
case SHOVEL:
return ItemUtils.isShovel(itemStack);
case SWORD:
return ItemUtils.isSword(itemStack);
default:
return false;
}
} }
public static List<ToolType> getToolList() {
return tools;
}
} }

View File

@ -311,19 +311,19 @@ public class BlockListener implements Listener {
} }
} }
if (mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) { if (mcMMOPlayer.getToolPreparationMode(ToolType.hoe) && ItemUtils.isHoe(heldItem) && (BlockUtils.affectedByGreenTerra(blockState) || BlockUtils.canMakeMossy(blockState)) && Permissions.greenTerra(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.herbalism); mcMMOPlayer.checkAbilityActivation(SkillType.herbalism);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.axe) && ItemUtils.isAxe(heldItem) && BlockUtils.isLog(blockState) && Permissions.treeFeller(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.woodcutting); mcMMOPlayer.checkAbilityActivation(SkillType.woodcutting);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.PICKAXE) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.pickaxe) && ItemUtils.isPickaxe(heldItem) && BlockUtils.affectedBySuperBreaker(blockState) && Permissions.superBreaker(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.mining); mcMMOPlayer.checkAbilityActivation(SkillType.mining);
} }
else if (mcMMOPlayer.getToolPreparationMode(ToolType.SHOVEL) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) { else if (mcMMOPlayer.getToolPreparationMode(ToolType.shovel) && ItemUtils.isShovel(heldItem) && BlockUtils.affectedByGigaDrillBreaker(blockState) && Permissions.gigaDrillBreaker(player)) {
mcMMOPlayer.checkAbilityActivation(SkillType.excavation); mcMMOPlayer.checkAbilityActivation(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.getToolPreparationMode(ToolType.fists) && heldItem.getType() == Material.AIR && (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW || BlockUtils.affectedByBlockCracker(blockState) && Permissions.berserk(player))) {
mcMMOPlayer.checkAbilityActivation(SkillType.unarmed); mcMMOPlayer.checkAbilityActivation(SkillType.unarmed);
} }
} }

View File

@ -47,7 +47,7 @@ public class AxesManager extends SkillManager {
} }
public boolean canActivateAbility() { public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer()); return mcMMOPlayer.getToolPreparationMode(ToolType.axe) && Permissions.skullSplitter(getPlayer());
} }
/** /**

View File

@ -69,7 +69,7 @@ public class HerbalismManager extends SkillManager {
} }
public boolean canActivateAbility() { public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer()); return mcMMOPlayer.getToolPreparationMode(ToolType.hoe) && Permissions.greenTerra(getPlayer());
} }
public boolean canGreenTerraPlant() { public boolean canGreenTerraPlant() {

View File

@ -27,7 +27,7 @@ public class SwordsManager extends SkillManager {
} }
public boolean canActivateAbility() { public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.SWORD) && Permissions.serratedStrikes(getPlayer()); return mcMMOPlayer.getToolPreparationMode(ToolType.sword) && Permissions.serratedStrikes(getPlayer());
} }
public boolean canUseBleed() { public boolean canUseBleed() {

View File

@ -30,7 +30,7 @@ public class UnarmedManager extends SkillManager {
} }
public boolean canActivateAbility() { public boolean canActivateAbility() {
return mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && Permissions.berserk(getPlayer()); return mcMMOPlayer.getToolPreparationMode(ToolType.fists) && Permissions.berserk(getPlayer());
} }
public boolean canUseIronArm() { public boolean canUseIronArm() {