Change XP processing to use a single function.

This commit is contained in:
GJ 2012-06-04 09:30:51 -04:00
parent 2a27048174
commit 1e58c32a5f
12 changed files with 46 additions and 43 deletions

View File

@ -19,7 +19,7 @@ public class ExperienceAPI {
Skills.xpCheckAll(player); Skills.xpCheckAll(player);
} }
else { else {
Skills.xpCheckSkill(skillType, player); Skills.xpCheckSkill(skillType, player, Users.getProfile(player));
} }
} }

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -47,7 +48,8 @@ public class AddxpCommand implements CommandExecutor {
xp = Integer.valueOf(args[1]); xp = Integer.valueOf(args[1]);
skill = Skills.getSkillType(args[0]); skill = Skills.getSkillType(args[0]);
Users.getProfile(modifiedPlayer).addXPOverride(skill, xp); PlayerProfile profile = Users.getProfile(modifiedPlayer);
profile.addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) { if (skill.equals(SkillType.ALL)) {
skillName = "all skills"; skillName = "all skills";
@ -62,7 +64,7 @@ public class AddxpCommand implements CommandExecutor {
Skills.xpCheckAll(modifiedPlayer); Skills.xpCheckAll(modifiedPlayer);
} }
else { else {
Skills.xpCheckSkill(skill, modifiedPlayer); Skills.xpCheckSkill(skill, modifiedPlayer, profile);
} }
} }
else { else {
@ -78,8 +80,9 @@ public class AddxpCommand implements CommandExecutor {
case 3: case 3:
modifiedPlayer = plugin.getServer().getPlayer(args[0]); modifiedPlayer = plugin.getServer().getPlayer(args[0]);
String playerName = modifiedPlayer.getName(); String playerName = modifiedPlayer.getName();
PlayerProfile profile = Users.getProfile(modifiedPlayer);
if (!Users.getProfile(modifiedPlayer).isLoaded()) { if (!profile.isLoaded()) {
sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist")); sender.sendMessage(LocaleLoader.getString("Commands.DoesNotExist"));
return true; return true;
} }
@ -94,7 +97,7 @@ public class AddxpCommand implements CommandExecutor {
skill = Skills.getSkillType(args[1]); skill = Skills.getSkillType(args[1]);
String message; String message;
Users.getProfile(modifiedPlayer).addXPOverride(skill, xp); profile.addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) { if (skill.equals(SkillType.ALL)) {
skillName = "all skills"; skillName = "all skills";
@ -112,7 +115,7 @@ public class AddxpCommand implements CommandExecutor {
Skills.xpCheckAll(modifiedPlayer); Skills.xpCheckAll(modifiedPlayer);
} }
else { else {
Skills.xpCheckSkill(skill, modifiedPlayer); Skills.xpCheckSkill(skill, modifiedPlayer, profile);
} }
} }
else { else {

View File

@ -313,8 +313,7 @@ public class EntityListener implements Listener {
break; break;
} }
PP.addXP(player, SkillType.TAMING, xp); Skills.xpProcessing(player, PP, SkillType.TAMING, xp);
Skills.xpCheckSkill(SkillType.TAMING, player);
} }
} }
} }

View File

@ -39,7 +39,6 @@ public class GainXp implements Runnable {
damage += health; damage += health;
} }
PP.addXP(player, skillType, (int) (damage * baseXp)); Skills.xpProcessing(player, PP, skillType, (int) (damage * baseXp));
Skills.xpCheckSkill(skillType, player);
} }
} }

View File

@ -107,9 +107,7 @@ public class Excavation {
} }
} }
//Handle XP related tasks Skills.xpProcessing(player, PP, SkillType.EXCAVATION, xp);
PP.addXP(player, SkillType.EXCAVATION, xp);
Skills.xpCheckSkill(SkillType.EXCAVATION, player);
} }
/** /**

View File

@ -117,8 +117,7 @@ public class Fishing {
theCatch.getItemStack().setDurability((short) (random.nextInt(maxDurability))); //Change durability to random value theCatch.getItemStack().setDurability((short) (random.nextInt(maxDurability))); //Change durability to random value
} }
PP.addXP(player, SkillType.FISHING, Config.getInstance().getFishingBaseXP()); Skills.xpProcessing(player, PP, SkillType.FISHING, Config.getInstance().getFishingBaseXP());
Skills.xpCheckSkill(SkillType.FISHING, player);
} }
/** /**

View File

@ -288,8 +288,7 @@ public class Herbalism {
} }
} }
PP.addXP(player, SkillType.HERBALISM, xp); Skills.xpProcessing(player, PP, SkillType.HERBALISM, xp);
Skills.xpCheckSkill(SkillType.HERBALISM, player);
} }
/** /**

View File

@ -275,8 +275,7 @@ public class Mining {
break; break;
} }
PP.addXP(player, SkillType.MINING, xp); Skills.xpProcessing(player, PP, SkillType.MINING, xp);
Skills.xpCheckSkill(SkillType.MINING, player);
} }
/** /**

View File

@ -203,8 +203,7 @@ public class WoodCutting {
} }
if (Permissions.getInstance().woodcutting(player)) { if (Permissions.getInstance().woodcutting(player)) {
PP.addXP(player, SkillType.WOODCUTTING, xp); //Tree Feller gives nerf'd XP Skills.xpProcessing(player, PP, SkillType.WOODCUTTING, xp);
Skills.xpCheckSkill(SkillType.WOODCUTTING, player);
} }
} }
@ -384,8 +383,7 @@ public class WoodCutting {
} }
WoodCutting.woodCuttingProcCheck(player, block); WoodCutting.woodCuttingProcCheck(player, block);
PP.addXP(player, SkillType.WOODCUTTING, xp); Skills.xpProcessing(player, PP, SkillType.WOODCUTTING, xp);
Skills.xpCheckSkill(SkillType.WOODCUTTING, player);
} }
/** /**

View File

@ -58,8 +58,7 @@ public class Acrobatics {
/* Check for death */ /* Check for death */
if (health - damage >= 1) { if (health - damage >= 1) {
PP.addXP(player, SkillType.ACROBATICS, damage * ROLL_XP_MODIFIER); Skills.xpProcessing(player, PP, SkillType.ACROBATICS, damage * ROLL_XP_MODIFIER);
Skills.xpCheckSkill(SkillType.ACROBATICS, player);
event.setDamage(newDamage); event.setDamage(newDamage);
@ -76,8 +75,7 @@ public class Acrobatics {
} }
} }
else if (health - damage >= 1) { else if (health - damage >= 1) {
PP.addXP(player, SkillType.ACROBATICS, event.getDamage() * FALL_XP_MODIFIER); Skills.xpProcessing(player, PP, SkillType.ACROBATICS, event.getDamage() * FALL_XP_MODIFIER);
Skills.xpCheckSkill(SkillType.ACROBATICS, player);
} }
} }
@ -111,8 +109,7 @@ public class Acrobatics {
defender.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc")); defender.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc"));
if (System.currentTimeMillis() >= (5000 + PPd.getRespawnATS()) && defender.getHealth() >= 1) { if (System.currentTimeMillis() >= (5000 + PPd.getRespawnATS()) && defender.getHealth() >= 1) {
PPd.addXP(defender, SkillType.ACROBATICS, damage * DODGE_MODIFIER); Skills.xpProcessing(defender, PPd, SkillType.ACROBATICS, damage * DODGE_MODIFIER);
Skills.xpCheckSkill(SkillType.ACROBATICS, defender);
} }
int newDamage = damage / 2; int newDamage = damage / 2;

View File

@ -42,8 +42,7 @@ public class Repair {
dif = (short) (dif * modify); dif = (short) (dif * modify);
PP.addXP(player, SkillType.REPAIR, dif * 10); Skills.xpProcessing(player, PP, SkillType.REPAIR, dif * 10);
Skills.xpCheckSkill(SkillType.REPAIR, player);
//CLANG CLANG //CLANG CLANG
if (mcMMO.p.spoutEnabled) { if (mcMMO.p.spoutEnabled) {

View File

@ -181,24 +181,24 @@ public class Skills {
* *
* @param skillType The skill to check * @param skillType The skill to check
* @param player The player whose skill to check * @param player The player whose skill to check
* @param profile The profile of the player whose skill to check
*/ */
public static void xpCheckSkill(SkillType skillType, Player player) { public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
PlayerProfile PP = Users.getProfile(player);
int skillups = 0; int skillups = 0;
if (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) { if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
while (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) { while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= PP.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= PP.getPowerLevel() + 1)) { if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= profile.getPowerLevel() + 1)) {
PP.removeXP(skillType, PP.getXpToLevel(skillType)); profile.removeXP(skillType, profile.getXpToLevel(skillType));
skillups++; skillups++;
PP.skillUp(skillType, 1); profile.skillUp(skillType, 1);
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType); McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType);
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire); mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
} }
else { else {
PP.addLevels(skillType, 0); profile.addLevels(skillType, 0);
} }
} }
@ -222,15 +222,15 @@ public class Skills {
/* Update custom titles */ /* Update custom titles */
if (SpoutConfig.getInstance().getShowPowerLevel()) { if (SpoutConfig.getInstance().getShowPowerLevel()) {
sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE + "." + ChatColor.GREEN + String.valueOf(PP.getPowerLevel())); sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE + "." + ChatColor.GREEN + String.valueOf(profile.getPowerLevel()));
} }
} }
else { else {
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)})); player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), profile.getSkillLevel(skillType)}));
} }
} }
else { else {
player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), PP.getSkillLevel(skillType)})); player.sendMessage(LocaleLoader.getString(capitalized + ".Skillup", new Object[] {String.valueOf(skillups), profile.getSkillLevel(skillType)}));
} }
} }
@ -257,7 +257,7 @@ public class Skills {
continue; continue;
} }
xpCheckSkill(x, player); xpCheckSkill(x, player, Users.getProfile(player));
} }
} }
@ -450,4 +450,17 @@ public class Skills {
return activate; return activate;
} }
/**
* Handle the processing of XP gain from individual skills.
*
* @param player The player that gained XP
* @param profile The profile of the player gaining XP
* @param type The type of skill to gain XP from
* @param xp the amount of XP to gain
*/
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
profile.addXP(player, type, xp);
xpCheckSkill(type, player, profile);
}
} }