mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
More work on McMMOPlayer
This commit is contained in:
parent
c460eec0ab
commit
5b8811bd09
@ -35,7 +35,7 @@ public final class ExperienceAPI {
|
||||
* @param XP The amount of XP to add
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ public final class ExperienceAPI {
|
||||
* @param XP The amount of XP to add
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public final class ExperienceAPI {
|
||||
* @param XP The amount of XP to add
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ public final class ExperienceAPI {
|
||||
* @return the power level of the player
|
||||
*/
|
||||
public static int getPowerLevel(Player player) {
|
||||
return Users.getProfile(player).getPowerLevel();
|
||||
return Users.getPlayer(player).getPowerLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -49,7 +50,8 @@ public class AddxpCommand implements CommandExecutor {
|
||||
skill = Skills.getSkillType(args[0]);
|
||||
|
||||
PlayerProfile profile = Users.getProfile(modifiedPlayer);
|
||||
profile.addXPOverride(skill, xp);
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
|
||||
mcMMOPlayer.addXPOverride(skill, xp);
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
skillName = "all skills";
|
||||
@ -80,6 +82,7 @@ public class AddxpCommand implements CommandExecutor {
|
||||
case 3:
|
||||
modifiedPlayer = plugin.getServer().getPlayer(args[0]);
|
||||
String playerName = modifiedPlayer.getName();
|
||||
McMMOPlayer mcMMOPlayer = Users.getPlayer(modifiedPlayer);
|
||||
PlayerProfile profile = Users.getProfile(modifiedPlayer);
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
@ -97,7 +100,7 @@ public class AddxpCommand implements CommandExecutor {
|
||||
skill = Skills.getSkillType(args[1]);
|
||||
String message;
|
||||
|
||||
profile.addXPOverride(skill, xp);
|
||||
mcMMOPlayer.addXPOverride(skill, xp);
|
||||
|
||||
if (skill.equals(SkillType.ALL)) {
|
||||
skillName = "all skills";
|
||||
|
@ -50,7 +50,7 @@ public class InspectCommand implements CommandExecutor {
|
||||
CommandHelper.printGatheringSkills(player, sender);
|
||||
CommandHelper.printCombatSkills(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;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.commands.CommandHelper;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
@ -19,7 +18,6 @@ public class McstatsCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
PlayerProfile profile = Users.getProfile(player);
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Stats.Own.Stats"));
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
|
||||
@ -28,7 +26,7 @@ public class McstatsCommand implements CommandExecutor {
|
||||
CommandHelper.printCombatSkills(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;
|
||||
}
|
||||
|
224
src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java
Normal file
224
src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java
Normal 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;
|
||||
}
|
||||
}
|
@ -7,29 +7,20 @@ import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
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.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.PartyManager;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModChecks;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class PlayerProfile {
|
||||
|
||||
/* HUD */
|
||||
private SpoutHud spoutHud;
|
||||
private HudType hudType = SpoutConfig.getInstance().defaultHudType;
|
||||
private SkillType lastGained;
|
||||
private SkillType skillLock;
|
||||
|
||||
/* Party Stuff */
|
||||
private Party party;
|
||||
@ -37,7 +28,7 @@ public class PlayerProfile {
|
||||
|
||||
/* Toggles */
|
||||
private boolean loaded;
|
||||
private boolean xpBarLocked;
|
||||
|
||||
private boolean placedAnvil;
|
||||
private boolean partyChatMode, adminChatMode;
|
||||
private boolean godMode;
|
||||
@ -55,17 +46,17 @@ public class PlayerProfile {
|
||||
/* mySQL STUFF */
|
||||
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<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>();
|
||||
HashMap<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
|
||||
|
||||
private Player player;
|
||||
private OfflinePlayer player;
|
||||
private String playerName;
|
||||
private final static String location = mcMMO.usersFile;
|
||||
|
||||
public PlayerProfile(OfflinePlayer offlinePlayer, boolean addNew) {
|
||||
this.player = player.getPlayer();
|
||||
public PlayerProfile(OfflinePlayer player, boolean addNew) {
|
||||
this.player = player;
|
||||
this.playerName = player.getName();
|
||||
|
||||
party = PartyManager.getInstance().getPlayerParty(playerName);
|
||||
@ -93,9 +84,9 @@ public class PlayerProfile {
|
||||
}
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
// public Player getPlayer() {
|
||||
// return player;
|
||||
// }
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
@ -119,9 +110,9 @@ public class PlayerProfile {
|
||||
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userId + ")");
|
||||
}
|
||||
else {
|
||||
for (HudType hudType : HudType.values()) {
|
||||
if (hudType.toString().equals(huds.get(1).get(0))) {
|
||||
this.hudType = hudType;
|
||||
for (HudType type : HudType.values()) {
|
||||
if (type.toString().equals(huds.get(1).get(0))) {
|
||||
spoutHud.setHudType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,9 +250,9 @@ public class PlayerProfile {
|
||||
if (character.length > 32)
|
||||
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
|
||||
if (character.length > 33) {
|
||||
for (HudType hudType : HudType.values()) {
|
||||
if (hudType.toString().equalsIgnoreCase(character[33])) {
|
||||
this.hudType = hudType;
|
||||
for (HudType type : HudType.values()) {
|
||||
if (type.toString().equalsIgnoreCase(character[33])) {
|
||||
spoutHud.setHudType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -290,7 +281,7 @@ public class PlayerProfile {
|
||||
|
||||
// if we are using mysql save to database
|
||||
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() + "cooldowns SET "
|
||||
+ " 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.SKULL_SPLIITER)) + ":");
|
||||
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(skillsXp.get(SkillType.FISHING) + ":");
|
||||
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
|
||||
@ -498,14 +489,6 @@ public class PlayerProfile {
|
||||
* HUD Stuff
|
||||
*/
|
||||
|
||||
public HudType getHudType() {
|
||||
return hudType;
|
||||
}
|
||||
|
||||
public void setHudType(HudType hudType) {
|
||||
this.hudType = hudType;
|
||||
}
|
||||
|
||||
public SpoutHud getSpoutHud() {
|
||||
return spoutHud;
|
||||
}
|
||||
@ -515,31 +498,39 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
public void setXpBarLocked(boolean locked) {
|
||||
xpBarLocked = locked;
|
||||
spoutHud.setXpBarLocked(locked);
|
||||
}
|
||||
|
||||
public boolean getXpBarLocked() {
|
||||
return xpBarLocked;
|
||||
return spoutHud.getXpBarLocked();
|
||||
}
|
||||
|
||||
public void toggleXpBarLocked() {
|
||||
xpBarLocked = !xpBarLocked;
|
||||
spoutHud.toggleXpBarLocked();
|
||||
}
|
||||
|
||||
public void setSkillLock(SkillType newvalue) {
|
||||
skillLock = newvalue;
|
||||
public void setSkillLock(SkillType type) {
|
||||
spoutHud.setSkillLock(type);
|
||||
}
|
||||
|
||||
public SkillType getSkillLock() {
|
||||
return skillLock;
|
||||
return spoutHud.getSkillLock();
|
||||
}
|
||||
|
||||
public void setLastGained(SkillType newvalue) {
|
||||
lastGained = newvalue;
|
||||
public HudType getHudType() {
|
||||
return spoutHud.getHudType();
|
||||
}
|
||||
|
||||
public void setHudType(HudType type) {
|
||||
spoutHud.setHudType(type);
|
||||
}
|
||||
|
||||
public void setLastGained(SkillType type) {
|
||||
spoutHud.setLastGained(type);
|
||||
}
|
||||
|
||||
public SkillType getLastGained() {
|
||||
return lastGained;
|
||||
return spoutHud.getLastGained();
|
||||
}
|
||||
|
||||
public void updateXpBar() {
|
||||
@ -928,99 +919,99 @@ public class PlayerProfile {
|
||||
skills.put(skillType, skills.get(skillType) + newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 newValue) {
|
||||
if (skillType.equals(SkillType.ALL)) {
|
||||
for (SkillType x : SkillType.values()) {
|
||||
if (x.equals(SkillType.ALL)) {
|
||||
continue;
|
||||
}
|
||||
// /**
|
||||
// * 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 newValue) {
|
||||
// if (skillType.equals(SkillType.ALL)) {
|
||||
// for (SkillType x : SkillType.values()) {
|
||||
// if (x.equals(SkillType.ALL)) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerXpGainEvent(player, skillType, newValue));
|
||||
skillsXp.put(skillType, skillsXp.get(skillType) + newValue);
|
||||
lastGained = 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 newValue) {
|
||||
// int xp = newValue * Config.getInstance().xpGainMultiplier;
|
||||
// addXPOverride(skillType, xp);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 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 newValue) {
|
||||
int xp = newValue * Config.getInstance().xpGainMultiplier;
|
||||
addXPOverride(skillType, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = partyModifier(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());
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Can we make this so we do perks by doing "mcmmo.perks.xp.[multiplier]" ?
|
||||
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));
|
||||
skillsXp.put(skillType, skillsXp.get(skillType) + xp);
|
||||
lastGained = skillType;
|
||||
}
|
||||
// /**
|
||||
// * 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 = partyModifier(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());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //TODO: Can we make this so we do perks by doing "mcmmo.perks.xp.[multiplier]" ?
|
||||
// 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));
|
||||
// skillsXp.put(skillType, skillsXp.get(skillType) + xp);
|
||||
// spoutHud.setLastGained(skillType);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Remove XP from a skill.
|
||||
@ -1096,52 +1087,52 @@ public class PlayerProfile {
|
||||
* @return the XP remaining until next level
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return the power level of the player
|
||||
*/
|
||||
public int getPowerLevel() {
|
||||
int powerLevel = 0;
|
||||
// /**
|
||||
// * Gets the power level of a player.
|
||||
// *
|
||||
// * @return the power level of the player
|
||||
// */
|
||||
// public int getPowerLevel() {
|
||||
// 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)) {
|
||||
powerLevel += getSkillLevel(type);
|
||||
}
|
||||
}
|
||||
|
||||
return powerLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the party XP modifier.
|
||||
*
|
||||
* @param skillType Type of skill to check
|
||||
* @return the party bonus multiplier
|
||||
*/
|
||||
private double partyModifier(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 = getSkillLevel(skillType);
|
||||
|
||||
if (leaderSkill >= playerSkill) {
|
||||
int difference = leaderSkill - playerSkill;
|
||||
bonusModifier = (difference * 0.75) / 100.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bonusModifier;
|
||||
}
|
||||
// /**
|
||||
// * Calculate the party XP modifier.
|
||||
// *
|
||||
// * @param skillType Type of skill to check
|
||||
// * @return the party bonus multiplier
|
||||
// */
|
||||
// private double partyModifier(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 = getSkillLevel(skillType);
|
||||
//
|
||||
// if (leaderSkill >= playerSkill) {
|
||||
// int difference = leaderSkill - playerSkill;
|
||||
// bonusModifier = (difference * 0.75) / 100.0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return bonusModifier;
|
||||
// }
|
||||
|
||||
/*
|
||||
* Party Stuff
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.datatypes;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
@ -8,13 +9,20 @@ import com.gmail.nossr50.datatypes.popups.Menu;
|
||||
import com.gmail.nossr50.datatypes.popups.XpBar;
|
||||
|
||||
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 XpBar xpBar;
|
||||
|
||||
public SpoutHud(PlayerProfile playerProfile) {
|
||||
this.playerProfile = playerProfile;
|
||||
public SpoutHud(McMMOPlayer mcMMOPlayer) {
|
||||
this.player = mcMMOPlayer.getPlayer();
|
||||
this.profile = mcMMOPlayer.getProfile();
|
||||
|
||||
initializeXpBar();
|
||||
}
|
||||
@ -28,7 +36,7 @@ public class SpoutHud {
|
||||
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.
|
||||
*/
|
||||
public void updateXpBar() {
|
||||
SkillType skillType = playerProfile.getXpBarLocked() ? playerProfile.getSkillLock() : playerProfile.getLastGained();
|
||||
SkillType skillType = xpBarLocked ? skillLock : lastGained;
|
||||
|
||||
if (skillType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
xpBar.update(skillType, playerProfile);
|
||||
xpBar.update(skillType, profile);
|
||||
}
|
||||
|
||||
public boolean isMenuOpened() {
|
||||
@ -50,7 +58,7 @@ public class SpoutHud {
|
||||
}
|
||||
|
||||
public void openMenu() {
|
||||
menu = new Menu(SpoutManager.getPlayer(playerProfile.getPlayer()), playerProfile);
|
||||
menu = new Menu(SpoutManager.getPlayer(player), profile);
|
||||
}
|
||||
|
||||
public void onMenuClose() {
|
||||
@ -62,6 +70,42 @@ public class SpoutHud {
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.datatypes.popups;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.getspout.spoutapi.SpoutManager;
|
||||
import org.getspout.spoutapi.gui.GenericLabel;
|
||||
import org.getspout.spoutapi.gui.GenericPopup;
|
||||
import org.getspout.spoutapi.gui.InGameHUD;
|
||||
@ -22,7 +21,7 @@ public class Menu extends GenericPopup {
|
||||
private static int centerX = 427 / 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
|
||||
titleLabel.setText(ChatColor.GOLD + "~mcMMO Menu~"); //TODO: Needs more locale
|
||||
titleLabel.setWidth(100);
|
||||
@ -63,7 +62,7 @@ public class Menu extends GenericPopup {
|
||||
escapeButton.connect(new Slot() {
|
||||
@Override
|
||||
public void activate() {
|
||||
SpoutManager.getPlayer(playerProfile.getPlayer()).getMainScreen().closePopup();
|
||||
spoutPlayer.getMainScreen().closePopup();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class PlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
Users.addUser(event.getPlayer()).actualizeRespawnATS();
|
||||
Users.addUser(event.getPlayer()).getProfile().actualizeRespawnATS();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ import org.getspout.spoutapi.gui.ScreenType;
|
||||
import org.getspout.spoutapi.player.SpoutPlayer;
|
||||
|
||||
import com.gmail.nossr50.config.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.SpoutHud;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.buttons.McmmoButton;
|
||||
@ -28,14 +29,15 @@ public class SpoutListener implements Listener {
|
||||
@EventHandler
|
||||
public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,20 +1,23 @@
|
||||
package com.gmail.nossr50.runnables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class ProfileSaveTask implements Runnable {
|
||||
private McMMOPlayer mcMMOPlayer;
|
||||
private PlayerProfile playerProfile;
|
||||
|
||||
public ProfileSaveTask(PlayerProfile playerProfile) {
|
||||
this.playerProfile = playerProfile;
|
||||
public ProfileSaveTask(McMMOPlayer mcMMOPlayer) {
|
||||
this.mcMMOPlayer = mcMMOPlayer;
|
||||
this.playerProfile = mcMMOPlayer.getProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
playerProfile.save();
|
||||
|
||||
if (!playerProfile.getPlayer().isOnline()) {
|
||||
if (!mcMMOPlayer.getPlayer().isOnline()) {
|
||||
Users.remove(playerProfile.getPlayerName());
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package com.gmail.nossr50.runnables;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
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.util.Users;
|
||||
|
||||
@ -20,8 +20,8 @@ public class SaveTimer implements Runnable {
|
||||
int count = 1;
|
||||
BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler();
|
||||
|
||||
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
|
||||
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(playerProfile), count);
|
||||
for (McMMOPlayer mcMMOPlayer : Users.getPlayers().values()) {
|
||||
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(mcMMOPlayer), count);
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class Fishing {
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.SpoutConfig;
|
||||
import com.gmail.nossr50.datatypes.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.PlayerStat;
|
||||
import com.gmail.nossr50.datatypes.SkillType;
|
||||
@ -180,14 +181,15 @@ public class Skills {
|
||||
* @param player The player whose skill to update
|
||||
*/
|
||||
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();
|
||||
|
||||
if (skillType != SkillType.ALL) {
|
||||
ps.statVal = profile.getSkillLevel(skillType);
|
||||
}
|
||||
else {
|
||||
ps.statVal = profile.getPowerLevel();
|
||||
ps.statVal = mcMMOPlayer.getPowerLevel();
|
||||
}
|
||||
|
||||
ps.name = player.getName();
|
||||
@ -207,7 +209,7 @@ public class Skills {
|
||||
if (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));
|
||||
skillups++;
|
||||
profile.skillUp(skillType, 1);
|
||||
@ -240,7 +242,7 @@ public class Skills {
|
||||
|
||||
/* Update custom titles */
|
||||
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 {
|
||||
@ -499,7 +501,7 @@ public class Skills {
|
||||
*/
|
||||
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
|
||||
if (type.getPermissions(player)) {
|
||||
profile.addXP(type, xp);
|
||||
Users.getPlayer(player).addXP(type, xp);
|
||||
xpCheckSkill(type, player, profile);
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,11 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
|
||||
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.
|
||||
@ -33,57 +34,50 @@ public class Users {
|
||||
* Add a new user.
|
||||
*
|
||||
* @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();
|
||||
PlayerProfile playerProfile = profiles.get(playerName);
|
||||
McMMOPlayer mcMMOPlayer = players.get(playerName);
|
||||
|
||||
if (playerProfile != null) {
|
||||
//The player object is different on each reconnection and must be updated
|
||||
playerProfile.setPlayer(player);
|
||||
if (mcMMOPlayer != null) {
|
||||
mcMMOPlayer.setPlayer(player); //The player object is different on each reconnection and must be updated
|
||||
}
|
||||
else {
|
||||
playerProfile = new PlayerProfile(player, true);
|
||||
|
||||
profiles.put(playerName, playerProfile);
|
||||
mcMMOPlayer = new McMMOPlayer(player);
|
||||
players.put(playerName, mcMMOPlayer);
|
||||
}
|
||||
|
||||
return playerProfile;
|
||||
return mcMMOPlayer;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Remove a user.
|
||||
*
|
||||
* @param playerName The name of the player to remove
|
||||
*/
|
||||
public static void remove(String playerName) {
|
||||
profiles.remove(playerName);
|
||||
players.remove(playerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all users.
|
||||
*/
|
||||
public static void clearAll() {
|
||||
profiles.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* Save all users.
|
||||
*/
|
||||
public static void saveAll() {
|
||||
for (PlayerProfile playerProfile : profiles.values()) {
|
||||
playerProfile.save();
|
||||
}
|
||||
players.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all PlayerProfiles.
|
||||
*
|
||||
* @return a HashMap containing the PlayerProfile of everyone in the database
|
||||
* Save all users.
|
||||
*/
|
||||
public static Map<String, PlayerProfile> getProfiles() {
|
||||
return profiles;
|
||||
public static void saveAll() {
|
||||
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
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user