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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -181,24 +181,24 @@ public class Skills {
*
* @param skillType The 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) {
PlayerProfile PP = Users.getProfile(player);
public static void xpCheckSkill(SkillType skillType, Player player, PlayerProfile profile) {
int skillups = 0;
if (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) {
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
while (PP.getSkillXpLevel(skillType) >= PP.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= PP.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= PP.getPowerLevel() + 1)) {
PP.removeXP(skillType, PP.getXpToLevel(skillType));
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= profile.getPowerLevel() + 1)) {
profile.removeXP(skillType, profile.getXpToLevel(skillType));
skillups++;
PP.skillUp(skillType, 1);
profile.skillUp(skillType, 1);
McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType);
mcMMO.p.getServer().getPluginManager().callEvent(eventToFire);
}
else {
PP.addLevels(skillType, 0);
profile.addLevels(skillType, 0);
}
}
@ -222,15 +222,15 @@ public class Skills {
/* Update custom titles */
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 {
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 {
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;
}
xpCheckSkill(x, player);
xpCheckSkill(x, player, Users.getProfile(player));
}
}
@ -450,4 +450,17 @@ public class Skills {
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);
}
}