Tweaked some stuff with adding XP, added an ExperienceAPI class.

This commit is contained in:
GJ
2012-03-29 14:24:41 -04:00
parent 26ed6aa840
commit 6c1ee24101
18 changed files with 184 additions and 98 deletions

View File

@ -0,0 +1,118 @@
package com.gmail.nossr50.api;
import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.skills.Skills;
public class ExperienceAPI {
/**
* Check the XP of a player. This should be called after giving XP to process level-ups.
*
* @param player The player to check
* @param skillType The skill to check
*/
private static void checkXP(Player player, SkillType skillType) {
if (skillType.equals(SkillType.ALL)) {
Skills.XpCheckAll(player);
}
else {
Skills.XpCheckSkill(skillType, player);
}
}
/**
* Adds XP to the player, doesn't calculate for XP Rate or other modifiers.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*/
public static void addRawXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverride(skillType, XP);
checkXP(player, skillType);
}
/**
* Adds XP to the player, calculates for XP Rate but not skill modifiers.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*/
public static void addMultipliedXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverrideBonus(skillType, XP);
checkXP(player, skillType);
}
/**
* Adds XP to the player, calculates for XP Rate and skill modifiers.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*/
public static void addXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXP(skillType, XP);
checkXP(player, skillType);
}
/**
* Get the amount of XP a player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param player The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*/
public static int getXP(Player player, SkillType skillType) {
return Users.getProfile(player).getSkillXpLevel(skillType);
}
/**
* Get the amount of XP left before leveling up.
* </br>
* This function is designed for API usage.
*
* @param player The player 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
*/
public static int getXPToNextLevel(Player player, SkillType skillType) {
return Users.getProfile(player).getXpToLevel(skillType);
}
/**
* Add levels to a skill.
* </br>
* This function is designed for API usage.
*
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add
*/
public static void addLevel(Player player, SkillType skillType, int levels) {
Users.getProfile(player).addLevels(skillType, levels);
}
/**
* Get the level a player has in a specific skill.
* </br>
* This function is designed for API usage.
*
* @param player The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
*/
public static int getLevel(Player player, SkillType skillType) {
return Users.getProfile(player).getSkillLevel(skillType);
}
}

View File

@ -8,7 +8,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.datatypes.PlayerProfile;
public class PartyAPI {
@ -21,8 +20,7 @@ public class PartyAPI {
* @return the name of the player's party
*/
public static String getPartyName(Player player) {
PlayerProfile PP = Users.getProfile(player);
return PP.getParty();
return Users.getProfile(player).getParty();
}
/**
@ -34,8 +32,7 @@ public class PartyAPI {
* @return true if the player is in a party, false otherwise
*/
public static boolean inParty(Player player) {
PlayerProfile PP = Users.getProfile(player);
return PP.inParty();
return Users.getProfile(player).inParty();
}
/**
@ -48,13 +45,8 @@ public class PartyAPI {
* @return true if the two players are in the same party, false otherwise
*/
public static boolean inSameParty(Player playera, Player playerb) {
if (Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()) {
if (Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())) {
return true;
}
else {
return false;
}
if (inParty(playera) && inParty(playerb) && getPartyName(playera).equals(getPartyName(playerb))) {
return true;
}
else {
return false;