mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-31 22:59:35 +01:00
Replaced playerName fields in PlayerProfile and Users by the Player object
This commit is contained in:
parent
b8be1d1866
commit
56aff1d191
@ -16,7 +16,7 @@ public class ExperienceAPI {
|
|||||||
*/
|
*/
|
||||||
private void checkXP(Player player, SkillType skillType) {
|
private void checkXP(Player player, SkillType skillType) {
|
||||||
if (skillType.equals(SkillType.ALL)) {
|
if (skillType.equals(SkillType.ALL)) {
|
||||||
Skills.xpCheckAll(player);
|
Skills.xpCheckAll(player, Users.getProfile(player));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Skills.xpCheckSkill(skillType, player, Users.getProfile(player));
|
Skills.xpCheckSkill(skillType, player, Users.getProfile(player));
|
||||||
@ -61,7 +61,7 @@ public class ExperienceAPI {
|
|||||||
* @param XP The amount of XP to add
|
* @param XP The amount of XP to add
|
||||||
*/
|
*/
|
||||||
public void addXP(Player player, SkillType skillType, int XP) {
|
public void addXP(Player player, SkillType skillType, int XP) {
|
||||||
Users.getProfile(player).addXP(player, skillType, XP);
|
Users.getProfile(player).addXP(skillType, XP);
|
||||||
checkXP(player, skillType);
|
checkXP(player, skillType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class AddxpCommand implements CommandExecutor {
|
|||||||
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + xp + " experience in " + skillName + "!"); //TODO: Needs more locale.
|
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + xp + " experience in " + skillName + "!"); //TODO: Needs more locale.
|
||||||
|
|
||||||
if (skill.equals(SkillType.ALL)) {
|
if (skill.equals(SkillType.ALL)) {
|
||||||
Skills.xpCheckAll(modifiedPlayer);
|
Skills.xpCheckAll(modifiedPlayer, profile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Skills.xpCheckSkill(skill, modifiedPlayer, profile);
|
Skills.xpCheckSkill(skill, modifiedPlayer, profile);
|
||||||
@ -112,7 +112,7 @@ public class AddxpCommand implements CommandExecutor {
|
|||||||
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + xp + " experience in " + skillName + "!"); //TODO: Needs more locale.
|
modifiedPlayer.sendMessage(ChatColor.GREEN + "You were awarded " + xp + " experience in " + skillName + "!"); //TODO: Needs more locale.
|
||||||
|
|
||||||
if (skill.equals(SkillType.ALL)) {
|
if (skill.equals(SkillType.ALL)) {
|
||||||
Skills.xpCheckAll(modifiedPlayer);
|
Skills.xpCheckAll(modifiedPlayer, profile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Skills.xpCheckSkill(skill, modifiedPlayer, profile);
|
Skills.xpCheckSkill(skill, modifiedPlayer, profile);
|
||||||
|
@ -98,7 +98,7 @@ public class McremoveCommand implements CommandExecutor {
|
|||||||
//Force PlayerProfile stuff to update
|
//Force PlayerProfile stuff to update
|
||||||
Player player = plugin.getServer().getPlayer(playerName);
|
Player player = plugin.getServer().getPlayer(playerName);
|
||||||
|
|
||||||
if (player != null && Users.players.containsKey(playerName.toLowerCase())) {
|
if (player != null && Users.getProfiles().containsKey(player)) {
|
||||||
Users.removeUser(player);
|
Users.removeUser(player);
|
||||||
Users.addUser(player);
|
Users.addUser(player);
|
||||||
}
|
}
|
||||||
|
@ -60,12 +60,12 @@ public class PlayerProfile {
|
|||||||
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 String playerName;
|
private Player player;
|
||||||
private final static String location = mcMMO.usersFile;
|
private final static String location = mcMMO.usersFile;
|
||||||
|
|
||||||
public PlayerProfile(String name, boolean addNew) {
|
public PlayerProfile(Player player, boolean addNew) {
|
||||||
hud = SpoutConfig.getInstance().defaulthud;
|
hud = SpoutConfig.getInstance().defaulthud;
|
||||||
playerName = name;
|
this.player = player;
|
||||||
|
|
||||||
for (AbilityType abilityType : AbilityType.values()) {
|
for (AbilityType abilityType : AbilityType.values()) {
|
||||||
skillsDATS.put(abilityType, 0);
|
skillsDATS.put(abilityType, 0);
|
||||||
@ -91,17 +91,14 @@ public class PlayerProfile {
|
|||||||
lastlogin = ((Long) (System.currentTimeMillis() / 1000)).intValue();
|
lastlogin = ((Long) (System.currentTimeMillis() / 1000)).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlayerName() {
|
//This method is actually never used
|
||||||
return this.playerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return mcMMO.p.getServer().getPlayer(playerName);
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadMySQL() {
|
public boolean loadMySQL() {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'");
|
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + player.getName() + "'");
|
||||||
|
|
||||||
this.userid = id;
|
this.userid = id;
|
||||||
|
|
||||||
@ -183,8 +180,8 @@ public class PlayerProfile {
|
|||||||
|
|
||||||
public void addMySQLPlayer() {
|
public void addMySQLPlayer() {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 +")");
|
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"users (user, lastlogin) VALUES ('" + player.getName() + "'," + System.currentTimeMillis() / 1000 +")");
|
||||||
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'");
|
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + player.getName() + "'");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"cooldowns (user_id) VALUES ("+id+")");
|
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"cooldowns (user_id) VALUES ("+id+")");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"skills (user_id) VALUES ("+id+")");
|
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"skills (user_id) VALUES ("+id+")");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"experience (user_id) VALUES ("+id+")");
|
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"experience (user_id) VALUES ("+id+")");
|
||||||
@ -203,7 +200,7 @@ public class PlayerProfile {
|
|||||||
//Find if the line contains the player we want.
|
//Find if the line contains the player we want.
|
||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
|
|
||||||
if(!character[0].equals(playerName)){continue;}
|
if(!character[0].equals(player.getName())){continue;}
|
||||||
|
|
||||||
//Get Mining
|
//Get Mining
|
||||||
if(character.length > 1 && Misc.isInt(character[1]))
|
if(character.length > 1 && Misc.isInt(character[1]))
|
||||||
@ -355,12 +352,12 @@ public class PlayerProfile {
|
|||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
//Read the line in and copy it to the output it's not the player
|
//Read the line in and copy it to the output it's not the player
|
||||||
//we want to edit
|
//we want to edit
|
||||||
if (!line.split(":")[0].equalsIgnoreCase(playerName)) {
|
if (!line.split(":")[0].equalsIgnoreCase(player.getName())) {
|
||||||
writer.append(line).append("\r\n");
|
writer.append(line).append("\r\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//Otherwise write the new player information
|
//Otherwise write the new player information
|
||||||
writer.append(playerName + ":");
|
writer.append(player.getName() + ":");
|
||||||
writer.append(skills.get(SkillType.MINING) + ":");
|
writer.append(skills.get(SkillType.MINING) + ":");
|
||||||
writer.append("" + ":");
|
writer.append("" + ":");
|
||||||
writer.append(party+":");
|
writer.append(party+":");
|
||||||
@ -442,7 +439,7 @@ public class PlayerProfile {
|
|||||||
BufferedWriter out = new BufferedWriter(file);
|
BufferedWriter out = new BufferedWriter(file);
|
||||||
|
|
||||||
//Add the player to the end
|
//Add the player to the end
|
||||||
out.append(playerName + ":");
|
out.append(player.getName() + ":");
|
||||||
out.append(0 + ":"); //mining
|
out.append(0 + ":"); //mining
|
||||||
out.append(""+":");
|
out.append(""+":");
|
||||||
out.append(party+":");
|
out.append(party+":");
|
||||||
@ -971,8 +968,6 @@ public class PlayerProfile {
|
|||||||
* @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) {
|
||||||
Player player = mcMMO.p.getServer().getPlayer(playerName);
|
|
||||||
|
|
||||||
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)) {
|
||||||
@ -1004,11 +999,10 @@ public class PlayerProfile {
|
|||||||
/**
|
/**
|
||||||
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
|
* Adds XP to the player, this is affected by skill modifiers and XP Rate and Permissions
|
||||||
*
|
*
|
||||||
* @param player The player to add XP to
|
|
||||||
* @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 addXP(Player player, SkillType skillType, int newValue) {
|
public void addXP(SkillType skillType, int newValue) {
|
||||||
if (System.currentTimeMillis() < ((xpGainATS * 1000) + 250) || player.getGameMode().equals(GameMode.CREATIVE)) {
|
if (System.currentTimeMillis() < ((xpGainATS * 1000) + 250) || player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1142,7 +1136,6 @@ public class PlayerProfile {
|
|||||||
* @return the power level of the player
|
* @return the power level of the player
|
||||||
*/
|
*/
|
||||||
public int getPowerLevel() {
|
public int getPowerLevel() {
|
||||||
Player player = mcMMO.p.getServer().getPlayer(playerName);
|
|
||||||
int powerLevel = 0;
|
int powerLevel = 0;
|
||||||
|
|
||||||
for (SkillType type : SkillType.values()) {
|
for (SkillType type : SkillType.values()) {
|
||||||
@ -1161,15 +1154,12 @@ public class PlayerProfile {
|
|||||||
* @return the party bonus multiplier
|
* @return the party bonus multiplier
|
||||||
*/
|
*/
|
||||||
private double partyModifier(SkillType skillType) {
|
private double partyModifier(SkillType skillType) {
|
||||||
Player player = getPlayer();
|
|
||||||
double bonusModifier = 0.0;
|
double bonusModifier = 0.0;
|
||||||
|
|
||||||
for (Player x : Party.getInstance().getOnlineMembers(player)) {
|
for (Player member : Party.getInstance().getOnlineMembers(player)) {
|
||||||
String memberName = x.getName();
|
if (!member.equals(player) && Party.getInstance().isPartyLeader(member.getName(), getParty())) {
|
||||||
|
if (Misc.isNear(player.getLocation(), member.getLocation(), 25.0)) {
|
||||||
if (!memberName.equals(playerName) && Party.getInstance().isPartyLeader(memberName, getParty())) {
|
PlayerProfile PartyLeader = Users.getProfile(member);
|
||||||
if (Misc.isNear(player.getLocation(), x.getLocation(), 25.0)) {
|
|
||||||
PlayerProfile PartyLeader = Users.getProfile(x);
|
|
||||||
int leaderSkill = PartyLeader.getSkillLevel(skillType);
|
int leaderSkill = PartyLeader.getSkillLevel(skillType);
|
||||||
int playerSkill = getSkillLevel(skillType);
|
int playerSkill = getSkillLevel(skillType);
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ public class PlayerListener implements Listener {
|
|||||||
BleedTimer.bleedOut(player);
|
BleedTimer.bleedOut(player);
|
||||||
|
|
||||||
//Schedule PlayerProfile removal 2 minutes after quitting
|
//Schedule PlayerProfile removal 2 minutes after quitting
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveProfileFromMemoryTask(player.getName()), 2400);
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveProfileFromMemoryTask(player), 2400);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,12 +148,10 @@ public class Party {
|
|||||||
*/
|
*/
|
||||||
public ArrayList<Player> getAllMembers(Player player) {
|
public ArrayList<Player> getAllMembers(Player player) {
|
||||||
ArrayList<Player> players = new ArrayList<Player>();
|
ArrayList<Player> players = new ArrayList<Player>();
|
||||||
HashMap<String, PlayerProfile> profiles = Users.getProfiles();
|
HashMap<Player, PlayerProfile> profiles = Users.getProfiles();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
for (String name : profiles.keySet()) {
|
for (Player otherPlayer : profiles.keySet()) {
|
||||||
Player otherPlayer = profiles.get(name).getPlayer();
|
|
||||||
|
|
||||||
if (otherPlayer != null && inSameParty(otherPlayer, player)) {
|
if (otherPlayer != null && inSameParty(otherPlayer, player)) {
|
||||||
players.add(otherPlayer);
|
players.add(otherPlayer);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class GainXp implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int health = target.getHealth();
|
int health = target.getHealth();
|
||||||
int damage = baseHealth - health;
|
int damage = baseHealth - health;
|
||||||
|
|
||||||
//May avoid negative xp, we don't know what other plugins do with the entity health
|
//May avoid negative xp, we don't know what other plugins do with the entity health
|
||||||
if (damage <= 0) {
|
if (damage <= 0) {
|
||||||
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
|
|||||||
import com.gmail.nossr50.util.Users;
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
public class ProfileSaveTask implements Runnable {
|
public class ProfileSaveTask implements Runnable {
|
||||||
Player player = null;
|
private Player player;
|
||||||
|
|
||||||
public ProfileSaveTask(Player player) {
|
public ProfileSaveTask(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -14,7 +14,7 @@ public class ProfileSaveTask implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Users.getProfileByName(player.getName()).save();
|
Users.getProfile(player).save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package com.gmail.nossr50.runnables;
|
package com.gmail.nossr50.runnables;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.gmail.nossr50.util.Users;
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
public class RemoveProfileFromMemoryTask implements Runnable {
|
public class RemoveProfileFromMemoryTask implements Runnable {
|
||||||
private String playerName = null;
|
private Player player;
|
||||||
|
|
||||||
public RemoveProfileFromMemoryTask(String playerName) {
|
public RemoveProfileFromMemoryTask(Player player) {
|
||||||
this.playerName = playerName;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//Check if the profile still exists (stuff like MySQL reconnection removes profiles)
|
//Check if the profile still exists (stuff like MySQL reconnection removes profiles)
|
||||||
if (Users.players.containsKey(playerName.toLowerCase())) {
|
if (Users.getProfiles().containsKey(player)) {
|
||||||
Users.getProfileByName(playerName.toLowerCase()).save(); //We save here so players don't quit/reconnect to cause lag
|
Users.getProfile(player).save(); //We save here so players don't quit/reconnect to cause lag
|
||||||
Users.removeUserByName(playerName.toLowerCase());
|
Users.removeUser(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ public class SQLReconnect implements Runnable {
|
|||||||
if (!Database.isConnected()) {
|
if (!Database.isConnected()) {
|
||||||
Database.connect();
|
Database.connect();
|
||||||
if (Database.isConnected()) {
|
if (Database.isConnected()) {
|
||||||
for (PlayerProfile x : Users.players.values()) {
|
for (PlayerProfile x : Users.getProfiles().values()) {
|
||||||
x.save(); //Save all profiles
|
x.save(); //Save all profiles
|
||||||
}
|
}
|
||||||
|
|
||||||
Users.players.clear(); //Clear the profiles
|
Users.getProfiles().clear(); //Clear the profiles
|
||||||
for (Player x : plugin.getServer().getOnlinePlayers()) {
|
for (Player x : plugin.getServer().getOnlinePlayers()) {
|
||||||
Users.addUser(x); //Add in new profiles, forcing them to 'load' again from MySQL
|
Users.addUser(x); //Add in new profiles, forcing them to 'load' again from MySQL
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class Fishing {
|
|||||||
FishingTreasure treasure = rewards.get(random.nextInt(rewards.size()));
|
FishingTreasure treasure = rewards.get(random.nextInt(rewards.size()));
|
||||||
|
|
||||||
if (random.nextDouble() * 100 <= treasure.getDropChance()) {
|
if (random.nextDouble() * 100 <= treasure.getDropChance()) {
|
||||||
Users.getProfile(player).addXP(player, SkillType.FISHING, treasure.getXp());
|
Users.getProfile(player).addXP(SkillType.FISHING, treasure.getXp());
|
||||||
theCatch.setItemStack(treasure.getDrop());
|
theCatch.setItemStack(treasure.getDrop());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,15 +248,16 @@ public class Skills {
|
|||||||
* Check XP of all skills.
|
* Check XP of all skills.
|
||||||
*
|
*
|
||||||
* @param player The player to check XP for.
|
* @param player The player to check XP for.
|
||||||
|
* @param profile The profile of the player whose skill to check
|
||||||
*/
|
*/
|
||||||
public static void xpCheckAll(Player player) {
|
public static void xpCheckAll(Player player, PlayerProfile profile) {
|
||||||
for (SkillType x : SkillType.values()) {
|
for (SkillType skillType : SkillType.values()) {
|
||||||
//Don't want to do anything with this one
|
//Don't want to do anything with this one
|
||||||
if (x == SkillType.ALL) {
|
if (skillType == SkillType.ALL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
xpCheckSkill(x, player, Users.getProfile(player));
|
xpCheckSkill(skillType, player, profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +460,7 @@ public class Skills {
|
|||||||
* @param xp the amount of XP to gain
|
* @param xp the amount of XP to gain
|
||||||
*/
|
*/
|
||||||
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
|
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
|
||||||
profile.addXP(player, type, xp);
|
profile.addXP(type, xp);
|
||||||
xpCheckSkill(type, player, profile);
|
xpCheckSkill(type, player, profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,18 +12,15 @@ import com.gmail.nossr50.mcMMO;
|
|||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
|
|
||||||
public class Users {
|
public class Users {
|
||||||
private final static mcMMO plugin = mcMMO.p;
|
private static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>();
|
||||||
public static HashMap<String, PlayerProfile> players = new HashMap<String, PlayerProfile>();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load users.
|
* Load users.
|
||||||
*/
|
*/
|
||||||
public static void loadUsers() {
|
public static void loadUsers() {
|
||||||
|
|
||||||
|
|
||||||
new File(mcMMO.flatFileDirectory).mkdir();
|
new File(mcMMO.flatFileDirectory).mkdir();
|
||||||
new File(mcMMO.leaderboardDirectory).mkdir();
|
new File(mcMMO.leaderboardDirectory).mkdir();
|
||||||
|
|
||||||
File theDir = new File(mcMMO.usersFile);
|
File theDir = new File(mcMMO.usersFile);
|
||||||
|
|
||||||
if (!theDir.exists()) {
|
if (!theDir.exists()) {
|
||||||
@ -43,8 +40,8 @@ public class Users {
|
|||||||
* @param player The player to create a user record for
|
* @param player The player to create a user record for
|
||||||
*/
|
*/
|
||||||
public static void addUser(Player player) {
|
public static void addUser(Player player) {
|
||||||
if (!players.containsKey(player.getName().toLowerCase())) {
|
if (!players.containsKey(player)) {
|
||||||
players.put(player.getName().toLowerCase(), new PlayerProfile(player.getName(), true));
|
players.put(player, new PlayerProfile(player, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +57,7 @@ public class Users {
|
|||||||
*
|
*
|
||||||
* @return a HashMap containing the PlayerProfile of everyone in the database
|
* @return a HashMap containing the PlayerProfile of everyone in the database
|
||||||
*/
|
*/
|
||||||
public static HashMap<String, PlayerProfile> getProfiles() {
|
public static HashMap<Player, PlayerProfile> getProfiles() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,11 +67,10 @@ public class Users {
|
|||||||
* @param player The player to remove
|
* @param player The player to remove
|
||||||
*/
|
*/
|
||||||
public static void removeUser(Player player) {
|
public static void removeUser(Player player) {
|
||||||
|
|
||||||
//Only remove PlayerProfile if user is offline and we have it in memory
|
//Only remove PlayerProfile if user is offline and we have it in memory
|
||||||
if (!player.isOnline() && players.containsKey(player.getName().toLowerCase())) {
|
if (!player.isOnline() && players.containsKey(player)) {
|
||||||
players.get(player.getName().toLowerCase()).save();
|
players.get(player).save();
|
||||||
players.remove(player.getName().toLowerCase());
|
players.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +80,7 @@ public class Users {
|
|||||||
* @param playerName The name of the player to remove
|
* @param playerName The name of the player to remove
|
||||||
*/
|
*/
|
||||||
public static void removeUserByName(String playerName) {
|
public static void removeUserByName(String playerName) {
|
||||||
players.remove(playerName.toLowerCase());
|
players.remove(mcMMO.p.getServer().getOfflinePlayer(playerName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +90,7 @@ public class Users {
|
|||||||
* @return the player's profile
|
* @return the player's profile
|
||||||
*/
|
*/
|
||||||
public static PlayerProfile getProfile(OfflinePlayer player) {
|
public static PlayerProfile getProfile(OfflinePlayer player) {
|
||||||
return getProfileByName(player.getName());
|
return players.get(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,17 +100,28 @@ public class Users {
|
|||||||
* @return the player's profile
|
* @return the player's profile
|
||||||
*/
|
*/
|
||||||
public static PlayerProfile getProfileByName(String playerName) {
|
public static PlayerProfile getProfileByName(String playerName) {
|
||||||
if (plugin.getServer().getOfflinePlayer(playerName).isOnline() || players.containsKey(playerName.toLowerCase())) {
|
Player player = mcMMO.p.getServer().getPlayer(playerName);
|
||||||
if (players.containsKey(playerName.toLowerCase())) {
|
PlayerProfile profile = players.get(player);
|
||||||
return players.get(playerName.toLowerCase());
|
|
||||||
|
if (profile == null) {
|
||||||
|
if (player != null) {
|
||||||
|
PlayerProfile newProfile = new PlayerProfile(player, true);
|
||||||
|
|
||||||
|
players.put(player, newProfile);
|
||||||
|
return newProfile;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
players.put(playerName.toLowerCase(), new PlayerProfile(playerName, true));
|
mcMMO.p.getLogger().severe("getProfileByName(" + playerName + ") just returned null :(");
|
||||||
return players.get(playerName.toLowerCase());
|
|
||||||
|
for (StackTraceElement ste : new Throwable().getStackTrace()) {
|
||||||
|
System.out.println(ste);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new PlayerProfile(playerName, false);
|
return profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user