Heh, API functions shouldn't be static...

This commit is contained in:
GJ 2012-03-29 23:08:51 -04:00
parent 7de19f8087
commit f547523c3e
4 changed files with 123 additions and 105 deletions

View File

@ -14,7 +14,7 @@ public class ExperienceAPI {
* @param player The player to check * @param player The player to check
* @param skillType The skill to check * @param skillType The skill to check
*/ */
private static void checkXP(Player player, SkillType skillType) { private void checkXP(Player player, SkillType skillType) {
if (skillType.equals(SkillType.ALL)) { if (skillType.equals(SkillType.ALL)) {
Skills.XpCheckAll(player); Skills.XpCheckAll(player);
} }
@ -32,7 +32,7 @@ public class ExperienceAPI {
* @param skillType The skill to add XP to * @param skillType The skill to add XP to
* @param XP The amount of XP to add * @param XP The amount of XP to add
*/ */
public static void addRawXP(Player player, SkillType skillType, int XP) { public void addRawXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverride(skillType, XP); Users.getProfile(player).addXPOverride(skillType, XP);
checkXP(player, skillType); checkXP(player, skillType);
} }
@ -46,7 +46,7 @@ public class ExperienceAPI {
* @param skillType The skill to add XP to * @param skillType The skill to add XP to
* @param XP The amount of XP to add * @param XP The amount of XP to add
*/ */
public static void addMultipliedXP(Player player, SkillType skillType, int XP) { public void addMultipliedXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverrideBonus(skillType, XP); Users.getProfile(player).addXPOverrideBonus(skillType, XP);
checkXP(player, skillType); checkXP(player, skillType);
} }
@ -60,7 +60,7 @@ public class ExperienceAPI {
* @param skillType The skill to add XP to * @param skillType The skill to add XP to
* @param XP The amount of XP to add * @param XP The amount of XP to add
*/ */
public static void addXP(Player player, SkillType skillType, int XP) { public void addXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXP(skillType, XP); Users.getProfile(player).addXP(skillType, XP);
checkXP(player, skillType); checkXP(player, skillType);
} }
@ -74,7 +74,7 @@ public class ExperienceAPI {
* @param skillType The skill to get XP for * @param skillType The skill to get XP for
* @return the amount of XP in a given skill * @return the amount of XP in a given skill
*/ */
public static int getXP(Player player, SkillType skillType) { public int getXP(Player player, SkillType skillType) {
return Users.getProfile(player).getSkillXpLevel(skillType); return Users.getProfile(player).getSkillXpLevel(skillType);
} }
@ -87,7 +87,7 @@ public class ExperienceAPI {
* @param skillType The skill to get the XP amount for * @param skillType The skill to get the XP amount for
* @return the amount of XP left before leveling up a specifc skill * @return the amount of XP left before leveling up a specifc skill
*/ */
public static int getXPToNextLevel(Player player, SkillType skillType) { public int getXPToNextLevel(Player player, SkillType skillType) {
return Users.getProfile(player).getXpToLevel(skillType); return Users.getProfile(player).getXpToLevel(skillType);
} }
@ -100,7 +100,7 @@ public class ExperienceAPI {
* @param skillType Type of skill to add levels to * @param skillType Type of skill to add levels to
* @param levels Number of levels to add * @param levels Number of levels to add
*/ */
public static void addLevel(Player player, SkillType skillType, int levels) { public void addLevel(Player player, SkillType skillType, int levels) {
Users.getProfile(player).addLevels(skillType, levels); Users.getProfile(player).addLevels(skillType, levels);
} }
@ -113,7 +113,7 @@ public class ExperienceAPI {
* @param skillType The skill to get the level for * @param skillType The skill to get the level for
* @return the level of a given skill * @return the level of a given skill
*/ */
public static int getLevel(Player player, SkillType skillType) { public int getLevel(Player player, SkillType skillType) {
return Users.getProfile(player).getSkillLevel(skillType); return Users.getProfile(player).getSkillLevel(skillType);
} }
@ -125,7 +125,7 @@ public class ExperienceAPI {
* @param player The player to get the power level for * @param player The player to get the power level for
* @return the power level of the player * @return the power level of the player
*/ */
public static int getPowerLevel(Player player) { public int getPowerLevel(Player player) {
return Users.getProfile(player).getPowerLevel(); return Users.getProfile(player).getPowerLevel();
} }
} }

View File

@ -20,7 +20,7 @@ public class PartyAPI {
* @param player The player to check the party name of * @param player The player to check the party name of
* @return the name of the player's party * @return the name of the player's party
*/ */
public static String getPartyName(Player player) { public String getPartyName(Player player) {
return Users.getProfile(player).getParty(); return Users.getProfile(player).getParty();
} }
@ -32,7 +32,7 @@ public class PartyAPI {
* @param player The player to check * @param player The player to check
* @return true if the player is in a party, false otherwise * @return true if the player is in a party, false otherwise
*/ */
public static boolean inParty(Player player) { public boolean inParty(Player player) {
return Users.getProfile(player).inParty(); return Users.getProfile(player).inParty();
} }
@ -45,7 +45,7 @@ public class PartyAPI {
* @param playerb The second player to check * @param playerb The second player to check
* @return true if the two players are in the same party, false otherwise * @return true if the two players are in the same party, false otherwise
*/ */
public static boolean inSameParty(Player playera, Player playerb) { public boolean inSameParty(Player playera, Player playerb) {
return Party.getInstance().inSameParty(playera, playerb); return Party.getInstance().inSameParty(playera, playerb);
} }
@ -56,7 +56,7 @@ public class PartyAPI {
* *
* @return the list of parties. * @return the list of parties.
*/ */
public static ArrayList<String> getParties() { public ArrayList<String> getParties() {
String location = "plugins/mcMMO/mcmmo.users"; String location = "plugins/mcMMO/mcmmo.users";
ArrayList<String> parties = new ArrayList<String>(); ArrayList<String> parties = new ArrayList<String>();
@ -96,7 +96,7 @@ public class PartyAPI {
* @param player The player to check * @param player The player to check
* @return all the players in the player's party * @return all the players in the player's party
*/ */
public static ArrayList<Player> getPartyMembers(Player player) { public ArrayList<Player> getPartyMembers(Player player) {
return Party.getInstance().getPartyMembers(player); return Party.getInstance().getPartyMembers(player);
} }

View File

@ -6,96 +6,114 @@ import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
public enum SkillType public enum SkillType {
{ ACROBATICS(LoadProperties.levelCapAcrobatics, LoadProperties.acrobaticsxpmodifier),
ACROBATICS(LoadProperties.levelCapAcrobatics, LoadProperties.acrobaticsxpmodifier), ALL, //This one is just for convenience
ALL, //This one is just for convenience ARCHERY(LoadProperties.levelCapArchery, LoadProperties.archeryxpmodifier),
ARCHERY(LoadProperties.levelCapArchery, LoadProperties.archeryxpmodifier), AXES(AbilityType.SKULL_SPLIITER, LoadProperties.levelCapAxes, ToolType.AXE, LoadProperties.axesxpmodifier),
AXES(AbilityType.SKULL_SPLIITER, LoadProperties.levelCapAxes, ToolType.AXE, LoadProperties.axesxpmodifier), EXCAVATION(AbilityType.GIGA_DRILL_BREAKER, LoadProperties.levelCapExcavation, ToolType.SHOVEL, LoadProperties.excavationxpmodifier),
EXCAVATION(AbilityType.GIGA_DRILL_BREAKER, LoadProperties.levelCapExcavation, ToolType.SHOVEL, LoadProperties.excavationxpmodifier), FISHING(LoadProperties.levelCapFishing, LoadProperties.fishingxpmodifier),
FISHING(LoadProperties.levelCapFishing, LoadProperties.fishingxpmodifier), HERBALISM(AbilityType.GREEN_TERRA, LoadProperties.levelCapHerbalism, ToolType.HOE, LoadProperties.herbalismxpmodifier),
HERBALISM(AbilityType.GREEN_TERRA, LoadProperties.levelCapHerbalism, ToolType.HOE, LoadProperties.herbalismxpmodifier), MINING(AbilityType.SUPER_BREAKER, LoadProperties.levelCapMining, ToolType.PICKAXE, LoadProperties.miningxpmodifier),
MINING(AbilityType.SUPER_BREAKER, LoadProperties.levelCapMining, ToolType.PICKAXE, LoadProperties.miningxpmodifier), REPAIR(LoadProperties.levelCapRepair, LoadProperties.repairxpmodifier),
REPAIR(LoadProperties.levelCapRepair, LoadProperties.repairxpmodifier), SWORDS(AbilityType.SERRATED_STRIKES, LoadProperties.levelCapSwords, ToolType.SWORD, LoadProperties.swordsxpmodifier),
SWORDS(AbilityType.SERRATED_STRIKES, LoadProperties.levelCapSwords, ToolType.SWORD, LoadProperties.swordsxpmodifier), TAMING(LoadProperties.levelCapTaming, LoadProperties.tamingxpmodifier),
TAMING(LoadProperties.levelCapTaming, LoadProperties.tamingxpmodifier), UNARMED(AbilityType.BERSERK, LoadProperties.levelCapUnarmed, ToolType.FISTS, LoadProperties.unarmedxpmodifier),
UNARMED(AbilityType.BERSERK, LoadProperties.levelCapUnarmed, ToolType.FISTS, LoadProperties.unarmedxpmodifier), WOODCUTTING(AbilityType.TREE_FELLER, LoadProperties.levelCapWoodcutting, ToolType.AXE, LoadProperties.woodcuttingxpmodifier);
WOODCUTTING(AbilityType.TREE_FELLER, LoadProperties.levelCapWoodcutting, ToolType.AXE, LoadProperties.woodcuttingxpmodifier);
private AbilityType ability; private AbilityType ability;
private int maxLevel; private int maxLevel;
private ToolType tool; private ToolType tool;
private double xpModifier; private double xpModifier;
private SkillType() private SkillType() {
{ this.ability = null;
this.ability = null; this.maxLevel = 0;
this.maxLevel = 0; this.tool = null;
this.tool = null; this.xpModifier = 0;
this.xpModifier = 0; }
}
private SkillType(AbilityType ability, int maxLevel, ToolType tool, double xpModifier) private SkillType(AbilityType ability, int maxLevel, ToolType tool, double xpModifier) {
{ this.ability = ability;
this.ability = ability; this.maxLevel = maxLevel;
this.maxLevel = maxLevel; this.tool = tool;
this.tool = tool; this.xpModifier = xpModifier;
this.xpModifier = xpModifier; }
}
private SkillType(int maxLevel, double xpModifier) private SkillType(int maxLevel, double xpModifier) {
{ this(null, maxLevel, null, xpModifier);
this(null, maxLevel, null, xpModifier); }
}
public AbilityType getAbility() public AbilityType getAbility() {
{ return ability;
return this.ability; }
}
public int getMaxLevel() /**
{ * Get the max level of this skill.
if(maxLevel > 0) *
return maxLevel; * @return the max level of this skill
else */
return Integer.MAX_VALUE; public int getMaxLevel() {
} if (maxLevel > 0) {
return maxLevel;
}
else {
return Integer.MAX_VALUE;
}
}
public ToolType getTool() { public ToolType getTool() {
return tool; return tool;
} }
public boolean getPermissions(Player player) /**
{ * Get the base permissions associated with this skill.
switch(this) *
{ * @param player The player to check the permissions for
case ACROBATICS: * @return true if the player has permissions, false otherwise
return mcPermissions.getInstance().acrobatics(player); */
case ARCHERY: public boolean getPermissions(Player player) {
return mcPermissions.getInstance().archery(player); switch (this) {
case AXES: case ACROBATICS:
return mcPermissions.getInstance().axes(player); return mcPermissions.getInstance().acrobatics(player);
case EXCAVATION:
return mcPermissions.getInstance().excavation(player); case ARCHERY:
case FISHING: return mcPermissions.getInstance().archery(player);
return mcPermissions.getInstance().fishing(player);
case HERBALISM: case AXES:
return mcPermissions.getInstance().herbalism(player); return mcPermissions.getInstance().axes(player);
case MINING:
return mcPermissions.getInstance().mining(player); case EXCAVATION:
case REPAIR: return mcPermissions.getInstance().excavation(player);
return mcPermissions.getInstance().repair(player);
case SWORDS: case FISHING:
return mcPermissions.getInstance().swords(player); return mcPermissions.getInstance().fishing(player);
case TAMING:
return mcPermissions.getInstance().taming(player); case HERBALISM:
case UNARMED: return mcPermissions.getInstance().herbalism(player);
return mcPermissions.getInstance().unarmed(player);
case WOODCUTTING: case MINING:
return mcPermissions.getInstance().woodcutting(player); return mcPermissions.getInstance().mining(player);
}
return false; case REPAIR:
} return mcPermissions.getInstance().repair(player);
case SWORDS:
return mcPermissions.getInstance().swords(player);
case TAMING:
return mcPermissions.getInstance().taming(player);
case UNARMED:
return mcPermissions.getInstance().unarmed(player);
case WOODCUTTING:
return mcPermissions.getInstance().woodcutting(player);
default:
return false;
}
}
public double getXpModifier() { public double getXpModifier() {
return xpModifier; return xpModifier;

View File

@ -163,7 +163,7 @@ public class mcMMO extends JavaPlugin {
* @param player Player whose profile to get * @param player Player whose profile to get
* @return the PlayerProfile object * @return the PlayerProfile object
*/ */
public static PlayerProfile getPlayerProfile(Player player) { public PlayerProfile getPlayerProfile(Player player) {
return Users.getProfile(player); return Users.getProfile(player);
} }