mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 11:14:44 +02:00
Add UUID support! - zreed, slipcor, t00thpick1
This commit updates our database managers to use UUIDs instead of usernames for persistent storage. Fixes #1979
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.api;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -86,6 +87,14 @@ public final class ExperienceAPI {
|
||||
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds raw XP to an offline player.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @deprecated We're using float for our XP values now
|
||||
* replaced by {@link #addRawXPOffline(String playerName, String skillType, float XP)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addRawXPOffline(String playerName, String skillType, int XP) {
|
||||
addRawXPOffline(playerName, skillType, (float) XP);
|
||||
@ -96,6 +105,9 @@ public final class ExperienceAPI {
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @deprecated We're using uuids to get an offline player
|
||||
* replaced by {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
|
||||
*
|
||||
* @param playerName The player to add XP to
|
||||
* @param skillType The skill to add XP to
|
||||
* @param XP The amount of XP to add
|
||||
@ -103,10 +115,27 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addRawXPOffline(String playerName, String skillType, float XP) {
|
||||
addOfflineXP(playerName, getSkillType(skillType), (int) Math.floor(XP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds raw XP to an offline player.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The UUID of player to add XP to
|
||||
* @param skillType The skill to add XP to
|
||||
* @param XP The amount of XP to add
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void addRawXPOffline(UUID uuid, String skillType, float XP) {
|
||||
addOfflineXP(uuid, getSkillType(skillType), (int) Math.floor(XP));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds XP to the player, calculates for XP Rate only.
|
||||
* </br>
|
||||
@ -152,6 +181,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
|
||||
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
|
||||
}
|
||||
@ -203,6 +233,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
|
||||
SkillType skill = getSkillType(skillType);
|
||||
|
||||
@ -273,10 +304,28 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getOfflineXP(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getSkillXpLevel(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of XP an offline player has in a specific skill.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to get XP for
|
||||
* @param skillType The skill to get XP for
|
||||
* @return the amount of XP in a given skill
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getOfflineXP(UUID uuid, String skillType) {
|
||||
return getOfflineProfile(uuid).getSkillXpLevel(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw amount of XP a player has in a specific skill.
|
||||
* </br>
|
||||
@ -306,10 +355,28 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
@Deprecated
|
||||
public static float getOfflineXPRaw(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw amount of XP an offline player has in a specific skill.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to get XP for
|
||||
* @param skillType The skill to get XP for
|
||||
* @return the amount of XP in a given skill
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static float getOfflineXPRaw(UUID uuid, String skillType) {
|
||||
return getOfflineProfile(uuid).getSkillXpLevelRaw(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total amount of XP needed to reach the next level.
|
||||
* </br>
|
||||
@ -339,10 +406,28 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getOfflineXPToNextLevel(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getXpToLevel(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total amount of XP an offline player needs to reach the next level.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to get XP for
|
||||
* @param skillType The skill to get XP for
|
||||
* @return the total amount of XP needed to reach the next level
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static int getOfflineXPToNextLevel(UUID uuid, String skillType) {
|
||||
return getOfflineProfile(uuid).getXpToLevel(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of XP remaining until the next level.
|
||||
* </br>
|
||||
@ -376,14 +461,34 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getOfflineXPRemaining(String playerName, String skillType) {
|
||||
SkillType skill = getNonChildSkillType(skillType);
|
||||
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
|
||||
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of XP an offline player has left before leveling up.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to get XP for
|
||||
* @param skillType The skill to get XP for
|
||||
* @return the amount of XP needed to reach the next level
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static float getOfflineXPRemaining(UUID uuid, String skillType) {
|
||||
SkillType skill = getNonChildSkillType(skillType);
|
||||
PlayerProfile profile = getOfflineProfile(uuid);
|
||||
|
||||
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add levels to a skill.
|
||||
* </br>
|
||||
@ -411,6 +516,7 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static void addLevelOffline(String playerName, String skillType, int levels) {
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
SkillType skill = getSkillType(skillType);
|
||||
@ -430,6 +536,37 @@ public final class ExperienceAPI {
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add levels to a skill for an offline player.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to add levels to
|
||||
* @param skillType Type of skill to add levels to
|
||||
* @param levels Number of levels to add
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void addLevelOffline(UUID uuid, String skillType, int levels) {
|
||||
PlayerProfile profile = getOfflineProfile(uuid);
|
||||
SkillType skill = getSkillType(skillType);
|
||||
|
||||
if (skill.isChildSkill()) {
|
||||
Set<SkillType> parentSkills = FamilyTree.getParents(skill);
|
||||
|
||||
for (SkillType parentSkill : parentSkills) {
|
||||
profile.addLevels(parentSkill, (levels / parentSkills.size()));
|
||||
}
|
||||
|
||||
profile.scheduleAsyncSave();
|
||||
return;
|
||||
}
|
||||
|
||||
profile.addLevels(skill, levels);
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level a player has in a specific skill.
|
||||
* </br>
|
||||
@ -457,10 +594,27 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getLevelOffline(String playerName, String skillType) {
|
||||
return getOfflineProfile(playerName).getSkillLevel(getSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level an offline player has in a specific skill.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to get the level for
|
||||
* @param skillType The skill to get the level for
|
||||
* @return the level of a given skill
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static int getLevelOffline(UUID uuid, String skillType) {
|
||||
return getOfflineProfile(uuid).getSkillLevel(getSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the power level of a player.
|
||||
* </br>
|
||||
@ -483,6 +637,7 @@ public final class ExperienceAPI {
|
||||
*
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getPowerLevelOffline(String playerName) {
|
||||
int powerLevel = 0;
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
@ -494,6 +649,27 @@ public final class ExperienceAPI {
|
||||
return powerLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the power level of an offline player.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to get the power level for
|
||||
* @return the power level of the player
|
||||
*
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static int getPowerLevelOffline(UUID uuid) {
|
||||
int powerLevel = 0;
|
||||
PlayerProfile profile = getOfflineProfile(uuid);
|
||||
|
||||
for (SkillType type : SkillType.NON_CHILD_SKILLS) {
|
||||
powerLevel += profile.getSkillLevel(type);
|
||||
}
|
||||
|
||||
return powerLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level cap of a specific skill.
|
||||
* </br>
|
||||
@ -533,10 +709,28 @@ public final class ExperienceAPI {
|
||||
*
|
||||
* @return the position on the leaderboard
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getPlayerRankSkill(String playerName, String skillType) {
|
||||
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position on the leaderboard of a player.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The name of the player to check
|
||||
* @param skillType The skill to check
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*
|
||||
* @return the position on the leaderboard
|
||||
*/
|
||||
public static int getPlayerRankSkill(UUID uuid, String skillType) {
|
||||
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(uuid).getPlayerName()).get(getNonChildSkillType(skillType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position on the power level leaderboard of a player.
|
||||
@ -549,10 +743,26 @@ public final class ExperienceAPI {
|
||||
*
|
||||
* @return the position on the power level leaderboard
|
||||
*/
|
||||
@Deprecated
|
||||
public static int getPlayerRankOverall(String playerName) {
|
||||
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(playerName).getPlayerName()).get(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position on the power level leaderboard of a player.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The name of the player to check
|
||||
*
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*
|
||||
* @return the position on the power level leaderboard
|
||||
*/
|
||||
public static int getPlayerRankOverall(UUID uuid) {
|
||||
return mcMMO.getDatabaseManager().readRank(getOfflineProfile(uuid).getPlayerName()).get(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the level of a player in a specific skill type.
|
||||
* </br>
|
||||
@ -580,10 +790,27 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
@Deprecated
|
||||
public static void setLevelOffline(String playerName, String skillType, int skillLevel) {
|
||||
getOfflineProfile(playerName).modifySkill(getSkillType(skillType), skillLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the level of an offline player in a specific skill type.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to set the level of
|
||||
* @param skillType The skill to set the level for
|
||||
* @param skillLevel The value to set the level to
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
*/
|
||||
public static void setLevelOffline(UUID uuid, String skillType, int skillLevel) {
|
||||
getOfflineProfile(uuid).modifySkill(getSkillType(skillType), skillLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the XP of a player in a specific skill type.
|
||||
* </br>
|
||||
@ -613,10 +840,28 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
@Deprecated
|
||||
public static void setXPOffline(String playerName, String skillType, int newValue) {
|
||||
getOfflineProfile(playerName).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the XP of an offline player in a specific skill type.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to set the XP of
|
||||
* @param skillType The skill to set the XP for
|
||||
* @param newValue The value to set the XP to
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static void setXPOffline(UUID uuid, String skillType, int newValue) {
|
||||
getOfflineProfile(uuid).setSkillXpLevel(getNonChildSkillType(skillType), newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes XP from a player in a specific skill type.
|
||||
* </br>
|
||||
@ -646,12 +891,37 @@ public final class ExperienceAPI {
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
@Deprecated
|
||||
public static void removeXPOffline(String playerName, String skillType, int xp) {
|
||||
getOfflineProfile(playerName).removeXp(getNonChildSkillType(skillType), xp);
|
||||
}
|
||||
|
||||
// Utility methods follow.
|
||||
/**
|
||||
* Removes XP from an offline player in a specific skill type.
|
||||
* </br>
|
||||
* This function is designed for API usage.
|
||||
*
|
||||
* @param uuid The player to change the XP of
|
||||
* @param skillType The skill to change the XP for
|
||||
* @param xp The amount of XP to remove
|
||||
*
|
||||
* @throws InvalidSkillException if the given skill is not valid
|
||||
* @throws InvalidPlayerException if the given player does not exist in the database
|
||||
* @throws UnsupportedOperationException if the given skill is a child skill
|
||||
*/
|
||||
public static void removeXPOffline(UUID uuid, String skillType, int xp) {
|
||||
getOfflineProfile(uuid).removeXp(getNonChildSkillType(skillType), xp);
|
||||
}
|
||||
|
||||
// Utility methods follow.
|
||||
private static void addOfflineXP(UUID playerUniqueId, SkillType skill, int XP) {
|
||||
PlayerProfile profile = getOfflineProfile(playerUniqueId);
|
||||
|
||||
profile.addXp(skill, XP);
|
||||
profile.save();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static void addOfflineXP(String playerName, SkillType skill, int XP) {
|
||||
PlayerProfile profile = getOfflineProfile(playerName);
|
||||
|
||||
@ -659,8 +929,20 @@ public final class ExperienceAPI {
|
||||
profile.scheduleAsyncSave();
|
||||
}
|
||||
|
||||
private static PlayerProfile getOfflineProfile(UUID uuid) {
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, false);
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
throw new InvalidPlayerException();
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static PlayerProfile getOfflineProfile(String playerName) {
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false);
|
||||
UUID uuid = mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId();
|
||||
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, false);
|
||||
|
||||
if (!profile.isLoaded()) {
|
||||
throw new InvalidPlayerException();
|
||||
|
Reference in New Issue
Block a user