mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 15:16:45 +01:00
Fixed the bug with mmoedit and mcstats, reworked PlayerProfile hashmaps to
be stored by String instead of Player
This commit is contained in:
parent
5ae15bfb71
commit
4377716474
@ -15,7 +15,7 @@ public class Users {
|
|||||||
String directory = "plugins/mcMMO/FlatFileStuff/";
|
String directory = "plugins/mcMMO/FlatFileStuff/";
|
||||||
String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/";
|
String directoryb = "plugins/mcMMO/FlatFileStuff/Leaderboards/";
|
||||||
|
|
||||||
public static HashMap<Player, PlayerProfile> players = new HashMap<Player, PlayerProfile>();
|
public static HashMap<String, PlayerProfile> players = new HashMap<String, PlayerProfile>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load users.
|
* Load users.
|
||||||
@ -42,8 +42,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)) {
|
if (!players.containsKey(player.getName().toLowerCase())) {
|
||||||
players.put(player, new PlayerProfile(player.getName()));
|
players.put(player.getName().toLowerCase(), new PlayerProfile(player.getName().toLowerCase()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,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<Player, PlayerProfile> getProfiles() {
|
public static HashMap<String, PlayerProfile> getProfiles() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,9 +71,9 @@ public class Users {
|
|||||||
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)) {
|
if (!player.isOnline() && players.containsKey(player.getName().toLowerCase())) {
|
||||||
players.get(player).save();
|
players.get(player.getName().toLowerCase()).save();
|
||||||
players.remove(player);
|
players.remove(player.getName().toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,17 +83,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) {
|
||||||
Player target = null;
|
players.remove(playerName.toLowerCase());
|
||||||
|
|
||||||
for (Player player : players.keySet()) {
|
|
||||||
PlayerProfile PP = players.get(player);
|
|
||||||
|
|
||||||
if (PP.getPlayerName().equals(playerName)) {
|
|
||||||
target = player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
players.remove(target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,12 +93,28 @@ public class Users {
|
|||||||
* @return the player's profile
|
* @return the player's profile
|
||||||
*/
|
*/
|
||||||
public static PlayerProfile getProfile(Player player) {
|
public static PlayerProfile getProfile(Player player) {
|
||||||
if(players.get(player) != null) {
|
if(players.get(player.getName().toLowerCase()) != null) {
|
||||||
return players.get(player);
|
return players.get(player.getName().toLowerCase());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
players.put(player, new PlayerProfile(player.getName()));
|
players.put(player.getName().toLowerCase(), new PlayerProfile(player.getName().toLowerCase()));
|
||||||
return players.get(player);
|
return players.get(player.getName().toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the profile of an online player.
|
||||||
|
*
|
||||||
|
* @param player The player whose profile to retrieve
|
||||||
|
* @return the player's profile
|
||||||
|
*/
|
||||||
|
public static PlayerProfile getProfile(String playerName) {
|
||||||
|
if(players.get(playerName.toLowerCase()) != null) {
|
||||||
|
return players.get(playerName.toLowerCase());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
players.put(playerName.toLowerCase(), new PlayerProfile(playerName.toLowerCase()));
|
||||||
|
return players.get(playerName.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +125,7 @@ public class Users {
|
|||||||
* @return the player's profile
|
* @return the player's profile
|
||||||
*/
|
*/
|
||||||
public static PlayerProfile getOfflineProfile(String playerName) {
|
public static PlayerProfile getOfflineProfile(String playerName) {
|
||||||
return new PlayerProfile(playerName, false);
|
return new PlayerProfile(playerName.toLowerCase(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.commands.general;
|
package com.gmail.nossr50.commands.general;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -42,7 +43,15 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
} else if (args.length == 3)
|
} else if (args.length == 3)
|
||||||
{
|
{
|
||||||
PlayerProfile PPt = Users.getOfflineProfile(args[0]);
|
PlayerProfile PPt = null;
|
||||||
|
|
||||||
|
if(Users.players.containsKey(args[0].toLowerCase())) {
|
||||||
|
PPt = Users.players.get(args[0].toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PPt == null)
|
||||||
|
Users.getOfflineProfile(args[0]); //Only grab offline profile if the above failed
|
||||||
|
|
||||||
if(!PPt.isLoaded())
|
if(!PPt.isLoaded())
|
||||||
{
|
{
|
||||||
sender.sendMessage("Player does not exist in the database!");
|
sender.sendMessage("Player does not exist in the database!");
|
||||||
@ -76,7 +85,15 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
if (args.length == 3)
|
if (args.length == 3)
|
||||||
{
|
{
|
||||||
PlayerProfile PPt = Users.getOfflineProfile(args[0]);
|
PlayerProfile PPt = null;
|
||||||
|
|
||||||
|
if(Users.players.containsKey(args[0].toLowerCase())) {
|
||||||
|
PPt = Users.players.get(args[0].toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PPt == null)
|
||||||
|
Users.getOfflineProfile(args[0]); //Only grab offline profile if the above failed
|
||||||
|
|
||||||
if(!PPt.isLoaded())
|
if(!PPt.isLoaded())
|
||||||
{
|
{
|
||||||
sender.sendMessage("Player does not exist in the database!");
|
sender.sendMessage("Player does not exist in the database!");
|
||||||
@ -86,7 +103,7 @@ public class MmoeditCommand implements CommandExecutor {
|
|||||||
if (m.isInt(args[2]) && Skills.isSkill(args[1]))
|
if (m.isInt(args[2]) && Skills.isSkill(args[1]))
|
||||||
{
|
{
|
||||||
int newvalue = Integer.valueOf(args[2]);
|
int newvalue = Integer.valueOf(args[2]);
|
||||||
Users.getOfflineProfile(args[0]).modifyskill(Skills.getSkillType(args[1]), newvalue);
|
PPt.modifyskill(Skills.getSkillType(args[1]), newvalue);
|
||||||
player.sendMessage(ChatColor.RED + args[1] + " has been modified for "+args[0]);
|
player.sendMessage(ChatColor.RED + args[1] + " has been modified for "+args[0]);
|
||||||
}
|
}
|
||||||
} else if (args.length == 2)
|
} else if (args.length == 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user