More work on McMMOPlayer

This commit is contained in:
GJ 2012-07-06 11:57:17 -04:00
parent c460eec0ab
commit 5b8811bd09
15 changed files with 523 additions and 243 deletions

View File

@ -35,7 +35,7 @@ public final class ExperienceAPI {
* @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 static void addRawXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverride(skillType, XP); Users.getPlayer(player).addXPOverride(skillType, XP);
checkXP(player, skillType); checkXP(player, skillType);
} }
@ -49,7 +49,7 @@ public final class ExperienceAPI {
* @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 static void addMultipliedXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXPOverrideBonus(skillType, XP); Users.getPlayer(player).addXPOverrideBonus(skillType, XP);
checkXP(player, skillType); checkXP(player, skillType);
} }
@ -63,7 +63,7 @@ public final class ExperienceAPI {
* @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 static void addXP(Player player, SkillType skillType, int XP) {
Users.getProfile(player).addXP(skillType, XP); Users.getPlayer(player).addXP(skillType, XP);
checkXP(player, skillType); checkXP(player, skillType);
} }
@ -133,7 +133,7 @@ public final class ExperienceAPI {
* @return the power level of the player * @return the power level of the player
*/ */
public static int getPowerLevel(Player player) { public static int getPowerLevel(Player player) {
return Users.getProfile(player).getPowerLevel(); return Users.getPlayer(player).getPowerLevel();
} }
/** /**

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.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; 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;
@ -49,7 +50,8 @@ public class AddxpCommand implements CommandExecutor {
skill = Skills.getSkillType(args[0]); skill = Skills.getSkillType(args[0]);
PlayerProfile profile = Users.getProfile(modifiedPlayer); PlayerProfile profile = Users.getProfile(modifiedPlayer);
profile.addXPOverride(skill, xp); McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
mcMMOPlayer.addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) { if (skill.equals(SkillType.ALL)) {
skillName = "all skills"; skillName = "all skills";
@ -80,6 +82,7 @@ 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();
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
PlayerProfile profile = Users.getProfile(modifiedPlayer); PlayerProfile profile = Users.getProfile(modifiedPlayer);
if (!profile.isLoaded()) { if (!profile.isLoaded()) {
@ -97,7 +100,7 @@ public class AddxpCommand implements CommandExecutor {
skill = Skills.getSkillType(args[1]); skill = Skills.getSkillType(args[1]);
String message; String message;
profile.addXPOverride(skill, xp); mcMMOPlayer.addXPOverride(skill, xp);
if (skill.equals(SkillType.ALL)) { if (skill.equals(SkillType.ALL)) {
skillName = "all skills"; skillName = "all skills";

View File

@ -50,7 +50,7 @@ public class InspectCommand implements CommandExecutor {
CommandHelper.printGatheringSkills(player, sender); CommandHelper.printGatheringSkills(player, sender);
CommandHelper.printCombatSkills(player, sender); CommandHelper.printCombatSkills(player, sender);
CommandHelper.printMiscSkills(player, sender); CommandHelper.printMiscSkills(player, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { profile.getPowerLevel() })); sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { Users.getPlayer(player).getPowerLevel() }));
return true; return true;
} }

View File

@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.commands.CommandHelper; import com.gmail.nossr50.commands.CommandHelper;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -19,7 +18,6 @@ public class McstatsCommand implements CommandExecutor {
} }
Player player = (Player) sender; Player player = (Player) sender;
PlayerProfile profile = Users.getProfile(player);
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats")); player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote")); player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
@ -28,7 +26,7 @@ public class McstatsCommand implements CommandExecutor {
CommandHelper.printCombatSkills(player); CommandHelper.printCombatSkills(player);
CommandHelper.printMiscSkills(player); CommandHelper.printMiscSkills(player);
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { String.valueOf(profile.getPowerLevel()) })); player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", new Object[] { String.valueOf(Users.getPlayer(player).getPowerLevel()) }));
return true; return true;
} }

View File

@ -0,0 +1,224 @@
package com.gmail.nossr50.datatypes;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users;
public class McMMOPlayer {
private Player player;
private PlayerProfile profile;
private Party party;
private Party invite;
public McMMOPlayer (Player player) {
this.player = player;
this.profile = new PlayerProfile(player, true);
this.party = PartyManager.getInstance().getPlayerParty(player.getName());
}
/**
* Gets the power level of this player.
*
* @return the power level of the player
*/
public int getPowerLevel() {
int powerLevel = 0;
for (SkillType type : SkillType.values()) {
if (type.getPermissions(player)) {
powerLevel += profile.getSkillLevel(type);
}
}
return powerLevel;
}
/**
* Calculate the party XP modifier.
*
* @param skillType Type of skill to check
* @return the party bonus multiplier
*/
private double calculatePartyXPModifier(SkillType skillType) {
double bonusModifier = 0.0;
for (Player member : party.getOnlineMembers()) {
if (party.getLeader().equals(member.getName())) {
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
PlayerProfile partyLeader = Users.getProfile(member);
int leaderSkill = partyLeader.getSkillLevel(skillType);
int playerSkill = profile.getSkillLevel(skillType);
if (leaderSkill >= playerSkill) {
int difference = leaderSkill - playerSkill;
bonusModifier = (difference * 0.75) / 100.0;
}
}
}
}
return bonusModifier;
}
/**
* Adds XP to the player, doesn't calculate for XP Rate
*
* @param skillType The skill to add XP to
* @param newValue The amount of XP to add
*/
public void addXPOverride(SkillType skillType, int xp) {
if (skillType.equals(SkillType.ALL)) {
for (SkillType type : SkillType.values()) {
if (type.equals(SkillType.ALL)) {
continue;
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, type, xp));
profile.setSkillXPLevel(type, profile.getSkillXpLevel(type) + xp);
}
}
else {
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
profile.setLastGained(skillType);
}
}
/**
* Adds XP to the player, this ignores skill modifiers.
*
* @param skillType The skill to add XP to
* @param newValue The amount of XP to add
*/
public void addXPOverrideBonus(SkillType skillType, int xp) {
int modifiedXp = xp * Config.getInstance().xpGainMultiplier;
addXPOverride(skillType, modifiedXp);
}
/**
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
*
* @param skillType The skill to add XP to
* @param newvalue The amount of XP to add
*/
public void addXP(SkillType skillType, int newValue) {
if (player.getGameMode().equals(GameMode.CREATIVE)) {
return;
}
double bonusModifier = 0;
if (inParty()) {
bonusModifier = calculatePartyXPModifier(skillType);
}
int xp = (int) (newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier;
if (bonusModifier > 0) {
if (bonusModifier >= 2) {
bonusModifier = 2;
}
double trueBonus = bonusModifier * xp;
xp += trueBonus;
}
if (Config.getInstance().getToolModsEnabled()) {
ItemStack item = player.getItemInHand();
CustomTool tool = ModChecks.getToolFromItemStack(item);
if (tool != null) {
xp = (int) (xp * tool.getXpMultiplier());
}
}
if (player.hasPermission("mcmmo.perks.xp.quadruple")) {
xp = xp * 4;
}
else if (player.hasPermission("mcmmo.perks.xp.triple")) {
xp = xp * 3;
}
else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) {
xp = (int) (xp * 2.5);
}
else if (player.hasPermission("mcmmo.perks.xp.double")) {
xp = xp * 2;
}
else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) {
xp = (int) (xp * 1.5);
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
profile.setSkillXPLevel(skillType, profile.getSkillXpLevel(skillType) + xp);
profile.setLastGained(skillType);
}
// Players & Profiles
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
public PlayerProfile getProfile() {
return profile;
}
// Party Stuff
public void setInvite(Party invite) {
this.invite = invite;
}
public Party getInvite() {
return invite;
}
public boolean hasPartyInvite() {
if (invite != null) {
return true;
}
else {
return false;
}
}
public void setParty(Party party) {
this.party = party;
}
public Party getParty() {
return party;
}
public boolean inParty() {
if (party != null) {
return true;
}
else {
return false;
}
}
public void removeParty() {
party = null;
}
public void removeInvite() {
invite = null;
}
}

View File

@ -7,29 +7,20 @@ import java.io.FileWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.SpoutConfig; import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.mods.CustomTool;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.ModChecks;
import com.gmail.nossr50.util.Users;
public class PlayerProfile { public class PlayerProfile {
/* HUD */ /* HUD */
private SpoutHud spoutHud; private SpoutHud spoutHud;
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
private SkillType lastGained;
private SkillType skillLock;
/* Party Stuff */ /* Party Stuff */
private Party party; private Party party;
@ -37,7 +28,7 @@ public class PlayerProfile {
/* Toggles */ /* Toggles */
private boolean loaded; private boolean loaded;
private boolean xpBarLocked;
private boolean placedAnvil; private boolean placedAnvil;
private boolean partyChatMode, adminChatMode; private boolean partyChatMode, adminChatMode;
private boolean godMode; private boolean godMode;
@ -55,17 +46,17 @@ public class PlayerProfile {
/* mySQL STUFF */ /* mySQL STUFF */
private int userId; private int userId;
HashMap<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); //Skills and Levels private HashMap<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); //Skills and Levels
HashMap<SkillType, Integer> skillsXp = new HashMap<SkillType, Integer>(); //Skills and XP HashMap<SkillType, Integer> skillsXp = new HashMap<SkillType, Integer>(); //Skills and XP
HashMap<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); HashMap<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>();
HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>(); HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private Player player; private OfflinePlayer player;
private String playerName; private String playerName;
private final static String location = mcMMO.usersFile; private final static String location = mcMMO.usersFile;
public PlayerProfile(OfflinePlayer offlinePlayer, boolean addNew) { public PlayerProfile(OfflinePlayer player, boolean addNew) {
this.player = player.getPlayer(); this.player = player;
this.playerName = player.getName(); this.playerName = player.getName();
party = PartyManager.getInstance().getPlayerParty(playerName); party = PartyManager.getInstance().getPlayerParty(playerName);
@ -93,9 +84,9 @@ public class PlayerProfile {
} }
} }
public Player getPlayer() { // public Player getPlayer() {
return player; // return player;
} // }
public String getPlayerName() { public String getPlayerName() {
return playerName; return playerName;
@ -119,9 +110,9 @@ public class PlayerProfile {
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userId + ")"); mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userId + ")");
} }
else { else {
for (HudType hudType : HudType.values()) { for (HudType type : HudType.values()) {
if (hudType.toString().equals(huds.get(1).get(0))) { if (type.toString().equals(huds.get(1).get(0))) {
this.hudType = hudType; spoutHud.setHudType(type);
} }
} }
} }
@ -259,9 +250,9 @@ public class PlayerProfile {
if (character.length > 32) if (character.length > 32)
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32])); skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
if (character.length > 33) { if (character.length > 33) {
for (HudType hudType : HudType.values()) { for (HudType type : HudType.values()) {
if (hudType.toString().equalsIgnoreCase(character[33])) { if (type.toString().equalsIgnoreCase(character[33])) {
this.hudType = hudType; spoutHud.setHudType(type);
} }
} }
} }
@ -290,7 +281,7 @@ public class PlayerProfile {
// if we are using mysql save to database // if we are using mysql save to database
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + spoutHud.getHudType().toString() + "' WHERE user_id = " + userId);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userId); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userId);
mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET " mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET "
+ " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER) + " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
@ -384,7 +375,7 @@ public class PlayerProfile {
writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":");
writer.append(hudType.toString() + ":"); writer.append(spoutHud.getHudType().toString() + ":");
writer.append(skills.get(SkillType.FISHING) + ":"); writer.append(skills.get(SkillType.FISHING) + ":");
writer.append(skillsXp.get(SkillType.FISHING) + ":"); writer.append(skillsXp.get(SkillType.FISHING) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
@ -498,14 +489,6 @@ public class PlayerProfile {
* HUD Stuff * HUD Stuff
*/ */
public HudType getHudType() {
return hudType;
}
public void setHudType(HudType hudType) {
this.hudType = hudType;
}
public SpoutHud getSpoutHud() { public SpoutHud getSpoutHud() {
return spoutHud; return spoutHud;
} }
@ -515,31 +498,39 @@ public class PlayerProfile {
} }
public void setXpBarLocked(boolean locked) { public void setXpBarLocked(boolean locked) {
xpBarLocked = locked; spoutHud.setXpBarLocked(locked);
} }
public boolean getXpBarLocked() { public boolean getXpBarLocked() {
return xpBarLocked; return spoutHud.getXpBarLocked();
} }
public void toggleXpBarLocked() { public void toggleXpBarLocked() {
xpBarLocked = !xpBarLocked; spoutHud.toggleXpBarLocked();
} }
public void setSkillLock(SkillType newvalue) { public void setSkillLock(SkillType type) {
skillLock = newvalue; spoutHud.setSkillLock(type);
} }
public SkillType getSkillLock() { public SkillType getSkillLock() {
return skillLock; return spoutHud.getSkillLock();
} }
public void setLastGained(SkillType newvalue) { public HudType getHudType() {
lastGained = newvalue; return spoutHud.getHudType();
}
public void setHudType(HudType type) {
spoutHud.setHudType(type);
}
public void setLastGained(SkillType type) {
spoutHud.setLastGained(type);
} }
public SkillType getLastGained() { public SkillType getLastGained() {
return lastGained; return spoutHud.getLastGained();
} }
public void updateXpBar() { public void updateXpBar() {
@ -928,99 +919,99 @@ public class PlayerProfile {
skills.put(skillType, skills.get(skillType) + newValue); skills.put(skillType, skills.get(skillType) + newValue);
} }
/** // /**
* Adds XP to the player, doesn't calculate for XP Rate // * Adds XP to the player, doesn't calculate for XP Rate
* // *
* @param skillType The skill to add XP to // * @param skillType The skill to add XP to
* @param newValue The amount of XP to add // * @param newValue The amount of XP to add
*/ // */
public void addXPOverride(SkillType skillType, int newValue) { // public void addXPOverride(SkillType skillType, int newValue) {
if (skillType.equals(SkillType.ALL)) { // if (skillType.equals(SkillType.ALL)) {
for (SkillType x : SkillType.values()) { // for (SkillType x : SkillType.values()) {
if (x.equals(SkillType.ALL)) { // if (x.equals(SkillType.ALL)) {
continue; // continue;
} // }
//
// mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, x, newValue));
// skillsXp.put(x, skillsXp.get(x) + newValue);
// }
// }
// else {
// mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, newValue));
// skillsXp.put(skillType, skillsXp.get(skillType) + newValue);
// spoutHud.setLastGained(skillType);
// }
// }
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, x, newValue)); // /**
skillsXp.put(x, skillsXp.get(x) + newValue); // * Adds XP to the player, this ignores skill modifiers.
} // *
} // * @param skillType The skill to add XP to
else { // * @param newValue The amount of XP to add
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, newValue)); // */
skillsXp.put(skillType, skillsXp.get(skillType) + newValue); // public void addXPOverrideBonus(SkillType skillType, int newValue) {
lastGained = skillType; // int xp = newValue * Config.getInstance().xpGainMultiplier;
} // addXPOverride(skillType, xp);
} // }
/** // /**
* Adds XP to the player, this ignores skill modifiers. // * Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
* // *
* @param skillType The skill to add XP to // * @param skillType The skill to add XP to
* @param newValue The amount of XP to add // * @param newvalue The amount of XP to add
*/ // */
public void addXPOverrideBonus(SkillType skillType, int newValue) { // public void addXP(SkillType skillType, int newValue) {
int xp = newValue * Config.getInstance().xpGainMultiplier; // if (player.getGameMode().equals(GameMode.CREATIVE)) {
addXPOverride(skillType, xp); // return;
} // }
//
/** // double bonusModifier = 0;
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions //
* // if (inParty()) {
* @param skillType The skill to add XP to // bonusModifier = partyModifier(skillType);
* @param newvalue The amount of XP to add // }
*/ //
public void addXP(SkillType skillType, int newValue) { // int xp = (int) (newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier;
if (player.getGameMode().equals(GameMode.CREATIVE)) { //
return; // if (bonusModifier > 0) {
} // if (bonusModifier >= 2) {
// bonusModifier = 2;
double bonusModifier = 0; // }
//
if (inParty()) { // double trueBonus = bonusModifier * xp;
bonusModifier = partyModifier(skillType); // xp += trueBonus;
} // }
//
int xp = (int) (newValue / skillType.getXpModifier()) * Config.getInstance().xpGainMultiplier; // if (Config.getInstance().getToolModsEnabled()) {
// ItemStack item = player.getItemInHand();
if (bonusModifier > 0) { // CustomTool tool = ModChecks.getToolFromItemStack(item);
if (bonusModifier >= 2) { //
bonusModifier = 2; // if (tool != null) {
} // xp = (int) (xp * tool.getXpMultiplier());
// }
double trueBonus = bonusModifier * xp; // }
xp += trueBonus; //
} // //TODO: Can we make this so we do perks by doing "mcmmo.perks.xp.[multiplier]" ?
// if (player.hasPermission("mcmmo.perks.xp.quadruple")) {
if (Config.getInstance().getToolModsEnabled()) { // xp = xp * 4;
ItemStack item = player.getItemInHand(); // }
CustomTool tool = ModChecks.getToolFromItemStack(item); // else if (player.hasPermission("mcmmo.perks.xp.triple")) {
// xp = xp * 3;
if (tool != null) { // }
xp = (int) (xp * tool.getXpMultiplier()); // else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) {
} // xp = (int) (xp * 2.5);
} // }
// else if (player.hasPermission("mcmmo.perks.xp.double")) {
//TODO: Can we make this so we do perks by doing "mcmmo.perks.xp.[multiplier]" ? // xp = xp * 2;
if (player.hasPermission("mcmmo.perks.xp.quadruple")) { // }
xp = xp * 4; // else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) {
} // xp = (int) (xp * 1.5);
else if (player.hasPermission("mcmmo.perks.xp.triple")) { // }
xp = xp * 3; //
} // mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
else if (player.hasPermission("mcmmo.perks.xp.150percentboost")) { // skillsXp.put(skillType, skillsXp.get(skillType) + xp);
xp = (int) (xp * 2.5); // spoutHud.setLastGained(skillType);
} // }
else if (player.hasPermission("mcmmo.perks.xp.double")) {
xp = xp * 2;
}
else if (player.hasPermission("mcmmo.perks.xp.50percentboost")) {
xp = (int) (xp * 1.5);
}
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, xp));
skillsXp.put(skillType, skillsXp.get(skillType) + xp);
lastGained = skillType;
}
/** /**
* Remove XP from a skill. * Remove XP from a skill.
@ -1096,52 +1087,52 @@ public class PlayerProfile {
* @return the XP remaining until next level * @return the XP remaining until next level
*/ */
public int getXpToLevel(SkillType skillType) { public int getXpToLevel(SkillType skillType) {
return 1020 + (skills.get(skillType) * Config.getInstance().getFormulaMultiplierCurve()); //Do we REALLY need to cast to int here? return 1020 + (skills.get(skillType) * Config.getInstance().getFormulaMultiplierCurve());
} }
/** // /**
* Gets the power level of a player. // * Gets the power level of a player.
* // *
* @return the power level of the player // * @return the power level of the player
*/ // */
public int getPowerLevel() { // public int getPowerLevel() {
int powerLevel = 0; // int powerLevel = 0;
//
// for (SkillType type : SkillType.values()) {
// if (type.getPermissions(player)) {
// powerLevel += getSkillLevel(type);
// }
// }
//
// return powerLevel;
// }
for (SkillType type : SkillType.values()) { // /**
if (type.getPermissions(player)) { // * Calculate the party XP modifier.
powerLevel += getSkillLevel(type); // *
} // * @param skillType Type of skill to check
} // * @return the party bonus multiplier
// */
return powerLevel; // private double partyModifier(SkillType skillType) {
} // double bonusModifier = 0.0;
//
/** // for (Player member : party.getOnlineMembers()) {
* Calculate the party XP modifier. // if (party.getLeader().equals(member.getName())) {
* // if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
* @param skillType Type of skill to check // PlayerProfile PartyLeader = Users.getProfile(member);
* @return the party bonus multiplier // int leaderSkill = PartyLeader.getSkillLevel(skillType);
*/ // int playerSkill = getSkillLevel(skillType);
private double partyModifier(SkillType skillType) { //
double bonusModifier = 0.0; // if (leaderSkill >= playerSkill) {
// int difference = leaderSkill - playerSkill;
for (Player member : party.getOnlineMembers()) { // bonusModifier = (difference * 0.75) / 100.0;
if (party.getLeader().equals(member.getName())) { // }
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) { // }
PlayerProfile PartyLeader = Users.getProfile(member); // }
int leaderSkill = PartyLeader.getSkillLevel(skillType); // }
int playerSkill = getSkillLevel(skillType); //
// return bonusModifier;
if (leaderSkill >= playerSkill) { // }
int difference = leaderSkill - playerSkill;
bonusModifier = (difference * 0.75) / 100.0;
}
}
}
}
return bonusModifier;
}
/* /*
* Party Stuff * Party Stuff

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.datatypes; package com.gmail.nossr50.datatypes;
import org.bukkit.entity.Player;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
@ -8,13 +9,20 @@ import com.gmail.nossr50.datatypes.popups.Menu;
import com.gmail.nossr50.datatypes.popups.XpBar; import com.gmail.nossr50.datatypes.popups.XpBar;
public class SpoutHud { public class SpoutHud {
private PlayerProfile playerProfile; private Player player;
private PlayerProfile profile;
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
private SkillType lastGained;
private SkillType skillLock;
private boolean xpBarLocked;
private Menu menu; private Menu menu;
private XpBar xpBar; private XpBar xpBar;
public SpoutHud(PlayerProfile playerProfile) { public SpoutHud(McMMOPlayer mcMMOPlayer) {
this.playerProfile = playerProfile; this.player = mcMMOPlayer.getPlayer();
this.profile = mcMMOPlayer.getProfile();
initializeXpBar(); initializeXpBar();
} }
@ -28,7 +36,7 @@ public class SpoutHud {
xpBar.removeWidgets(); xpBar.removeWidgets();
} }
xpBar = new XpBar(SpoutManager.getPlayer(playerProfile.getPlayer()), playerProfile.getHudType()); xpBar = new XpBar(SpoutManager.getPlayer(player), hudType);
} }
} }
@ -36,13 +44,13 @@ public class SpoutHud {
* Update the XP bar. * Update the XP bar.
*/ */
public void updateXpBar() { public void updateXpBar() {
SkillType skillType = playerProfile.getXpBarLocked() ? playerProfile.getSkillLock() : playerProfile.getLastGained(); SkillType skillType = xpBarLocked ? skillLock : lastGained;
if (skillType == null) { if (skillType == null) {
return; return;
} }
xpBar.update(skillType, playerProfile); xpBar.update(skillType, profile);
} }
public boolean isMenuOpened() { public boolean isMenuOpened() {
@ -50,7 +58,7 @@ public class SpoutHud {
} }
public void openMenu() { public void openMenu() {
menu = new Menu(SpoutManager.getPlayer(playerProfile.getPlayer()), playerProfile); menu = new Menu(SpoutManager.getPlayer(player), profile);
} }
public void onMenuClose() { public void onMenuClose() {
@ -62,6 +70,42 @@ public class SpoutHud {
menu.close(); menu.close();
} }
SpoutManager.getPlayer(playerProfile.getPlayer()).getMainScreen().removeWidgets(mcMMO.p); SpoutManager.getPlayer(player).getMainScreen().removeWidgets(mcMMO.p);
}
public HudType getHudType() {
return hudType;
}
public void setHudType(HudType type) {
this.hudType = type;
}
public SkillType getLastGained() {
return lastGained;
}
public void setLastGained(SkillType type) {
this.lastGained = type;
}
public boolean getXpBarLocked() {
return xpBarLocked;
}
public void setXpBarLocked(boolean locked) {
this.xpBarLocked = locked;
}
public void toggleXpBarLocked() {
xpBarLocked = !xpBarLocked;
}
public SkillType getSkillLock() {
return skillLock;
}
public void setSkillLock(SkillType type) {
this.skillLock = type;
} }
} }

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.datatypes.popups; package com.gmail.nossr50.datatypes.popups;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.gui.GenericLabel; import org.getspout.spoutapi.gui.GenericLabel;
import org.getspout.spoutapi.gui.GenericPopup; import org.getspout.spoutapi.gui.GenericPopup;
import org.getspout.spoutapi.gui.InGameHUD; import org.getspout.spoutapi.gui.InGameHUD;
@ -22,7 +21,7 @@ public class Menu extends GenericPopup {
private static int centerX = 427 / 2; private static int centerX = 427 / 2;
private static int centerY = 240 / 2; private static int centerY = 240 / 2;
public Menu(SpoutPlayer spoutPlayer, final PlayerProfile playerProfile) { public Menu(final SpoutPlayer spoutPlayer, final PlayerProfile playerProfile) {
//240, 427 are the bottom right //240, 427 are the bottom right
titleLabel.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale titleLabel.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale
titleLabel.setWidth(100); titleLabel.setWidth(100);
@ -63,7 +62,7 @@ public class Menu extends GenericPopup {
escapeButton.connect(new Slot() { escapeButton.connect(new Slot() {
@Override @Override
public void activate() { public void activate() {
SpoutManager.getPlayer(playerProfile.getPlayer()).getMainScreen().closePopup(); spoutPlayer.getMainScreen().closePopup();
} }
}); });

View File

@ -122,7 +122,7 @@ public class PlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) { public void onPlayerLogin(PlayerLoginEvent event) {
Users.addUser(event.getPlayer()).actualizeRespawnATS(); Users.addUser(event.getPlayer()).getProfile().actualizeRespawnATS();
} }
/** /**

View File

@ -12,6 +12,7 @@ import org.getspout.spoutapi.gui.ScreenType;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.config.SpoutConfig; import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.SpoutHud; import com.gmail.nossr50.datatypes.SpoutHud;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.buttons.McmmoButton; import com.gmail.nossr50.datatypes.buttons.McmmoButton;
@ -28,14 +29,15 @@ public class SpoutListener implements Listener {
@EventHandler @EventHandler
public void onSpoutCraftEnable(SpoutCraftEnableEvent event) { public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
SpoutPlayer spoutPlayer = event.getPlayer(); SpoutPlayer spoutPlayer = event.getPlayer();
PlayerProfile playerProfile = Users.getProfile(spoutPlayer); McMMOPlayer mcMMOPlayer = Users.getPlayer(spoutPlayer);
PlayerProfile profile = mcMMOPlayer.getProfile();
//TODO: Add custom titles based on skills //TODO: Add custom titles based on skills
if (SpoutConfig.getInstance().getShowPowerLevel()) { if (SpoutConfig.getInstance().getShowPowerLevel()) {
spoutPlayer.setTitle(spoutPlayer.getName() + "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(playerProfile.getPowerLevel())); spoutPlayer.setTitle(spoutPlayer.getName() + "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(mcMMOPlayer.getPowerLevel()));
} }
playerProfile.setSpoutHud(new SpoutHud(playerProfile)); //Setup Party HUD stuff profile.setSpoutHud(new SpoutHud(mcMMOPlayer)); //Setup Party HUD stuff
} }
/** /**

View File

@ -1,20 +1,23 @@
package com.gmail.nossr50.runnables; package com.gmail.nossr50.runnables;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class ProfileSaveTask implements Runnable { public class ProfileSaveTask implements Runnable {
private McMMOPlayer mcMMOPlayer;
private PlayerProfile playerProfile; private PlayerProfile playerProfile;
public ProfileSaveTask(PlayerProfile playerProfile) { public ProfileSaveTask(McMMOPlayer mcMMOPlayer) {
this.playerProfile = playerProfile; this.mcMMOPlayer = mcMMOPlayer;
this.playerProfile = mcMMOPlayer.getProfile();
} }
@Override @Override
public void run() { public void run() {
playerProfile.save(); playerProfile.save();
if (!playerProfile.getPlayer().isOnline()) { if (!mcMMOPlayer.getPlayer().isOnline()) {
Users.remove(playerProfile.getPlayerName()); Users.remove(playerProfile.getPlayerName());
} }
} }

View File

@ -3,7 +3,7 @@ package com.gmail.nossr50.runnables;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
@ -20,8 +20,8 @@ public class SaveTimer implements Runnable {
int count = 1; int count = 1;
BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler(); BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler();
for (PlayerProfile playerProfile : Users.getProfiles().values()) { for (McMMOPlayer mcMMOPlayer : Users.getPlayers().values()) {
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(playerProfile), count); bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(mcMMOPlayer), count);
count++; count++;
} }

View File

@ -109,7 +109,7 @@ public class Fishing {
} }
if (random.nextDouble() * randomChance <= treasure.getDropChance()) { if (random.nextDouble() * randomChance <= treasure.getDropChance()) {
Users.getProfile(player).addXP(SkillType.FISHING, treasure.getXp()); Users.getPlayer(player).addXP(SkillType.FISHING, treasure.getXp());
theCatch.setItemStack(treasure.getDrop()); theCatch.setItemStack(treasure.getDrop());
} }
} }

View File

@ -14,6 +14,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.SpoutConfig; import com.gmail.nossr50.config.SpoutConfig;
import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.datatypes.PlayerStat;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
@ -180,14 +181,15 @@ public class Skills {
* @param player The player whose skill to update * @param player The player whose skill to update
*/ */
public static void processLeaderboardUpdate(SkillType skillType, Player player) { public static void processLeaderboardUpdate(SkillType skillType, Player player) {
PlayerProfile profile = Users.getProfile(player); McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
PlayerProfile profile = mcMMOPlayer.getProfile();
PlayerStat ps = new PlayerStat(); PlayerStat ps = new PlayerStat();
if (skillType != SkillType.ALL) { if (skillType != SkillType.ALL) {
ps.statVal = profile.getSkillLevel(skillType); ps.statVal = profile.getSkillLevel(skillType);
} }
else { else {
ps.statVal = profile.getPowerLevel(); ps.statVal = mcMMOPlayer.getPowerLevel();
} }
ps.name = player.getName(); ps.name = player.getName();
@ -207,7 +209,7 @@ public class Skills {
if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) { if (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) { while (profile.getSkillXpLevel(skillType) >= profile.getXpToLevel(skillType)) {
if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= profile.getPowerLevel() + 1)) { if ((skillType.getMaxLevel() >= profile.getSkillLevel(skillType) + 1) && (Misc.getPowerLevelCap() >= Users.getPlayer(player).getPowerLevel() + 1)) {
profile.removeXP(skillType, profile.getXpToLevel(skillType)); profile.removeXP(skillType, profile.getXpToLevel(skillType));
skillups++; skillups++;
profile.skillUp(skillType, 1); profile.skillUp(skillType, 1);
@ -240,7 +242,7 @@ public class Skills {
/* Update custom titles */ /* Update custom titles */
if (SpoutConfig.getInstance().getShowPowerLevel()) { if (SpoutConfig.getInstance().getShowPowerLevel()) {
spoutPlayer.setTitle(spoutPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE + "." + ChatColor.GREEN + String.valueOf(profile.getPowerLevel())); spoutPlayer.setTitle(spoutPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" + ChatColor.WHITE + "." + ChatColor.GREEN + String.valueOf(Users.getPlayer(player).getPowerLevel()));
} }
} }
else { else {
@ -499,7 +501,7 @@ public class Skills {
*/ */
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) { public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
if (type.getPermissions(player)) { if (type.getPermissions(player)) {
profile.addXP(type, xp); Users.getPlayer(player).addXP(type, xp);
xpCheckSkill(type, player, profile); xpCheckSkill(type, player, profile);
} }
} }

View File

@ -9,10 +9,11 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
public class Users { public class Users {
private static Map<String, PlayerProfile> profiles = new HashMap<String, PlayerProfile>(); private static Map<String, McMMOPlayer> players = new HashMap<String, McMMOPlayer>();
/** /**
* Load users. * Load users.
@ -33,57 +34,50 @@ public class Users {
* Add a new user. * Add a new user.
* *
* @param player The player to create a user record for * @param player The player to create a user record for
* @return the player's profile * @return the player's {@link McMMOPlayer} object
*/ */
public static PlayerProfile addUser(Player player) { public static McMMOPlayer addUser(Player player) {
String playerName = player.getName(); String playerName = player.getName();
PlayerProfile playerProfile = profiles.get(playerName); McMMOPlayer mcMMOPlayer = players.get(playerName);
if (playerProfile != null) { if (mcMMOPlayer != null) {
//The player object is different on each reconnection and must be updated mcMMOPlayer.setPlayer(player); //The player object is different on each reconnection and must be updated
playerProfile.setPlayer(player);
} }
else { else {
playerProfile = new PlayerProfile(player, true); mcMMOPlayer = new McMMOPlayer(player);
players.put(playerName, mcMMOPlayer);
profiles.put(playerName, playerProfile);
} }
return playerProfile; return mcMMOPlayer;
} }
/* /**
* Remove a user. * Remove a user.
* *
* @param playerName The name of the player to remove * @param playerName The name of the player to remove
*/ */
public static void remove(String playerName) { public static void remove(String playerName) {
profiles.remove(playerName); players.remove(playerName);
} }
/** /**
* Clear all users. * Clear all users.
*/ */
public static void clearAll() { public static void clearAll() {
profiles.clear(); players.clear();
}
/*
* Save all users.
*/
public static void saveAll() {
for (PlayerProfile playerProfile : profiles.values()) {
playerProfile.save();
}
} }
/** /**
* Get all PlayerProfiles. * Save all users.
*
* @return a HashMap containing the PlayerProfile of everyone in the database
*/ */
public static Map<String, PlayerProfile> getProfiles() { public static void saveAll() {
return profiles; for (McMMOPlayer mcMMOPlayer : players.values()) {
mcMMOPlayer.getProfile().save();
}
}
public static Map<String, McMMOPlayer> getPlayers() {
return players;
} }
/** /**
@ -103,6 +97,26 @@ public class Users {
* @return the player's profile * @return the player's profile
*/ */
public static PlayerProfile getProfile(String playerName) { public static PlayerProfile getProfile(String playerName) {
return profiles.get(playerName); return players.get(playerName).getProfile();
}
/**
* Get the McMMOPlayer of a player by name.
*
* @param player The name of the player whose McMMOPlayer to retrieve
* @return the player's McMMOPlayer object
*/
public static McMMOPlayer getPlayer(String playerName) {
return players.get(playerName);
}
/**
* Get the McMMOPlayer of a player.
*
* @param player The player whose McMMOPlayer to retrieve
* @return the player's McMMOPlayer object
*/
public static McMMOPlayer getPlayer(Player player) {
return getPlayer(player.getName());
} }
} }