mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-14 10:09:23 +02:00
More work on McMMOPlayer
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user