Merge branch 'master' of github.com:mcMMO-Dev/mcMMO into tridentsxbows

This commit is contained in:
nossr50
2021-03-16 14:18:09 -07:00
28 changed files with 1779 additions and 2993 deletions

View File

@@ -22,7 +22,7 @@ public class DatabaseAPI {
* @return true if the player exists in the DB, false if they do not
*/
public boolean doesPlayerExistInDB(UUID uuid) {
PlayerProfile playerProfile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(uuid);
PlayerProfile playerProfile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(uuid, null);
return playerProfile.isLoaded();
}

File diff suppressed because it is too large Load Diff

View File

@@ -58,7 +58,7 @@ public class ConvertDatabaseCommand implements CommandExecutor {
}
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
PlayerProfile profile = oldDatabase.queryPlayerDataByUUID(player.getUniqueId());
PlayerProfile profile = oldDatabase.queryPlayerDataByUUID(player.getUniqueId(), null);
if(profile == null)
continue;

View File

@@ -23,7 +23,7 @@ public class DatabaseRemovePlayerCommand implements TabExecutor {
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
if (mcMMO.getUserManager().queryPlayer(playerName) == null
&& CommandUtils.hasNoProfile(sender, mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName, false))) {
&& CommandUtils.hasNoProfile(sender, mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName))) {
sender.sendMessage(LocaleLoader.getString("Commands.Offline"));
return true;
}

View File

@@ -1,14 +1,13 @@
package com.gmail.nossr50.commands.experience;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import com.neetgames.mcmmo.player.MMOPlayer;
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import com.neetgames.mcmmo.skill.RootSkill;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -16,7 +15,6 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -25,7 +23,7 @@ import java.util.UUID;
public abstract class ExperienceCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
RootSkill rootSkill;
PrimarySkillType skill;
if(args.length < 2) {
return false;
@@ -46,27 +44,27 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
rootSkill = mcMMO.p.getSkillRegister().getSkill(args[0]);
skill = PrimarySkillType.getSkill(args[0]);
if (args[1].equalsIgnoreCase("all")) {
rootSkill = null;
skill = null;
}
if (rootSkill != null && rootSkill.isChildSkill()) {
if (skill != null && skill.isChildSkill())
{
sender.sendMessage(LocaleLoader.getString("Commands.Skill.ChildSkill"));
return true;
}
//Profile not loaded
Player player = (Player) sender;
OnlineMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(player);
if(mmoPlayer == null) {
if(UserManager.getPlayer(sender.getName()) == null)
{
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
editValues(mmoPlayer, rootSkill, Integer.parseInt(args[1]), isSilent(args));
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill, Integer.parseInt(args[1]), isSilent(args));
return true;
} else if((args.length == 3 && !isSilent(args))
|| (args.length == 4 && isSilent(args))) {
@@ -79,13 +77,13 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
rootSkill = mcMMO.p.getSkillRegister().getSkill(args[1]);
skill = PrimarySkillType.getSkill(args[1]);
if (args[1].equalsIgnoreCase("all")) {
rootSkill = null;
skill = null;
}
if (rootSkill != null && rootSkill.isChildSkill())
if (skill != null && skill.isChildSkill())
{
sender.sendMessage(LocaleLoader.getString("Commands.Skill.ChildSkill"));
return true;
@@ -94,25 +92,31 @@ public abstract class ExperienceCommand implements TabExecutor {
int value = Integer.parseInt(args[2]);
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
OnlineMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(playerName);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
// If the mmoPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mmoPlayer == null) {
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
UUID uuid = null;
OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(playerName);
if (player != null) {
uuid = player.getUniqueId();
}
PlayerProfile profile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName, uuid, false);
OfflinePlayer offlinePlayer = mcMMO.p.getServer().getOfflinePlayer(playerName);
PlayerProfile profile;
if (CommandUtils.hasNoProfile(sender, profile)) {
return true;
uuid = offlinePlayer.getUniqueId();
profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, null);
//Check loading by UUID
if (CommandUtils.unloadedProfile(sender, profile)) {
//Check loading by name
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
if(CommandUtils.unloadedProfile(sender, profile)) {
return true;
}
}
editValues(null, profile, rootSkill, value, isSilent(args));
editValues(null, profile, skill, value, isSilent(args));
}
else {
editValues(Misc.adaptPlayer(mmoPlayer), mcMMOPlayer.getProfile(), rootSkill, value, isSilent(args));
editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill, value, isSilent(args));
}
handleSenderMessage(sender, playerName, skill);
@@ -148,27 +152,27 @@ public abstract class ExperienceCommand implements TabExecutor {
protected abstract boolean permissionsCheckSelf(CommandSender sender);
protected abstract boolean permissionsCheckOthers(CommandSender sender);
protected abstract void handleCommand(Player player, PlayerProfile profile, RootSkill rootSkill, int value);
protected abstract void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill, int value);
protected abstract void handlePlayerMessageAll(Player player, int value, boolean isSilent);
protected abstract void handlePlayerMessageSkill(Player player, int value, RootSkill rootSkill, boolean isSilent);
protected abstract void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent);
private boolean validateArguments(CommandSender sender, String skillName, String value) {
return !(CommandUtils.isInvalidInteger(sender, value) || (!skillName.equalsIgnoreCase("all") && CommandUtils.isInvalidSkill(sender, skillName)));
}
protected static void handleSenderMessage(CommandSender sender, String playerName, RootSkill rootSkill) {
if (rootSkill == null) {
protected static void handleSenderMessage(CommandSender sender, String playerName, PrimarySkillType skill) {
if (skill == null) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", rootSkill.getName(), playerName));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", skill.getName(), playerName));
}
}
protected void editValues(@NotNull MMOPlayer mmoPlayer, @Nullable RootSkill rootSkill, int value, boolean isSilent) {
if (primarySkillType == null) {
for (PrimarySkillType type : PrimarySkillType.NON_CHILD_SKILLS) {
handleCommand(player, profile, type, value);
protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill, int value, boolean isSilent) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
handleCommand(player, profile, primarySkillType, value);
}
if (player != null) {
@@ -176,10 +180,10 @@ public abstract class ExperienceCommand implements TabExecutor {
}
}
else {
handleCommand(player, profile, primarySkillType, value);
handleCommand(player, profile, skill, value);
if (player != null) {
handlePlayerMessageSkill(player, value, primarySkillType, isSilent);
handlePlayerMessageSkill(player, value, skill, isSilent);
}
}
}

View File

@@ -1,14 +1,16 @@
package com.gmail.nossr50.commands.experience;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import com.neetgames.mcmmo.skill.RootSkill;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -28,7 +30,7 @@ import java.util.UUID;
public class SkillresetCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
RootSkill rootSkill;
PrimarySkillType skill;
switch (args.length) {
case 1:
if (CommandUtils.noConsoleUsage(sender)) {
@@ -45,14 +47,13 @@ public class SkillresetCommand implements TabExecutor {
}
if (args[0].equalsIgnoreCase("all")) {
rootSkill = null;
skill = null;
}
else {
rootSkill = mcMMO.p.getSkillRegister().getSkill(args[0]);
skill = PrimarySkillType.getSkill(args[0]);
}
editValues((Player) sender, mcMMO.getUserManager().queryPlayer(player)
, skill);
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill);
return true;
case 2:
@@ -66,32 +67,38 @@ public class SkillresetCommand implements TabExecutor {
}
if (args[1].equalsIgnoreCase("all")) {
rootSkill = null;
skill = null;
}
else {
rootSkill = mcMMO.p.getSkillRegister().getSkill(args[1]);
skill = PrimarySkillType.getSkill(args[1]);
}
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
OnlineMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(playerName);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
// If the mmoPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mmoPlayer == null) {
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
UUID uuid = null;
OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(playerName);
if (player != null) {
uuid = player.getUniqueId();
}
PlayerProfile profile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName, uuid, false);
uuid = player.getUniqueId();
if (CommandUtils.hasNoProfile(sender, profile)) {
return true;
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid, playerName);
//Check loading by UUID
if (CommandUtils.unloadedProfile(sender, profile)) {
//Didn't find it by UUID so try to find it by name
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
//Check if it was present in DB
if(CommandUtils.unloadedProfile(sender, profile)) {
return true;
}
}
editValues(null, profile, skill);
}
else {
editValues(Misc.adaptPlayer(mmoPlayer), mmoPlayer, skill);
editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill);
}
handleSenderMessage(sender, playerName, skill);
@@ -115,18 +122,18 @@ public class SkillresetCommand implements TabExecutor {
}
}
protected void handleCommand(Player player, PlayerProfile profile, RootSkill rootSkill) {
int levelsRemoved = profile.getSkillLevel(rootSkill);
float xpRemoved = profile.getSkillXpLevelRaw(rootSkill);
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill) {
int levelsRemoved = profile.getSkillLevel(skill);
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.modifySkill(rootSkill, 0);
profile.modifySkill(skill, 0);
if (player == null) {
profile.scheduleAsyncSave();
return;
}
EventUtils.tryLevelChangeEvent(player, rootSkill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
EventUtils.tryLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
}
protected boolean permissionsCheckSelf(CommandSender sender) {
@@ -141,26 +148,26 @@ public class SkillresetCommand implements TabExecutor {
player.sendMessage(LocaleLoader.getString("Commands.Reset.All"));
}
protected void handlePlayerMessageSkill(Player player, RootSkill rootSkill) {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", rootSkill.getName()));
protected void handlePlayerMessageSkill(Player player, PrimarySkillType skill) {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", skill.getName()));
}
private boolean validateArguments(CommandSender sender, String skillName) {
return skillName.equalsIgnoreCase("all") || !CommandUtils.isInvalidSkill(sender, skillName);
}
protected static void handleSenderMessage(CommandSender sender, String playerName, RootSkill rootSkill) {
if (rootSkill == null) {
protected static void handleSenderMessage(CommandSender sender, String playerName, PrimarySkillType skill) {
if (skill == null) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
}
else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", rootSkill.getName(), playerName));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", skill.getName(), playerName));
}
}
protected void editValues(Player player, PlayerProfile profile, RootSkill rootSkill) {
if (rootSkill == null) {
for (RootSkill rootSkill : PrimarySkillType.NON_CHILD_SKILLS) {
protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill) {
if (skill == null) {
for (PrimarySkillType primarySkillType : PrimarySkillType.NON_CHILD_SKILLS) {
handleCommand(player, profile, primarySkillType);
}

View File

@@ -1,15 +1,16 @@
package com.gmail.nossr50.commands.player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList;
import com.neetgames.mcmmo.skill.RootSkill;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -25,19 +26,15 @@ public class InspectCommand implements TabExecutor {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
PlayerProfile playerProfile = mcMMO.getUserManager().queryPlayer(playerName);
Player targetPlayer = Bukkit.getPlayer(playerName);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName); // Temporary Profile
if(playerProfile == null) {
//TODO: Localize
sender.sendMessage("Data was not found in the database for the given player name!");
return true;
}
if(targetPlayer == null) {
//Target is offline
if (!CommandUtils.isLoaded(sender, profile)) {
return true;
}
if (Config.getInstance().getScoreboardsEnabled()
&& sender instanceof Player
@@ -52,42 +49,48 @@ public class InspectCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Inspect.OfflineStats", playerName));
sender.sendMessage(LocaleLoader.getString("Stats.Header.Gathering"));
for (RootSkill rootSkill : PrimarySkillType.GATHERING_SKILLS) {
for (PrimarySkillType skill : PrimarySkillType.GATHERING_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill));
}
sender.sendMessage(LocaleLoader.getString("Stats.Header.Combat"));
for (RootSkill rootSkill : PrimarySkillType.COMBAT_SKILLS) {
for (PrimarySkillType skill : PrimarySkillType.COMBAT_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill));
}
sender.sendMessage(LocaleLoader.getString("Stats.Header.Misc"));
for (RootSkill rootSkill : PrimarySkillType.MISC_SKILLS) {
for (PrimarySkillType skill : PrimarySkillType.MISC_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill));
}
} else {
if (CommandUtils.hidden(sender, targetPlayer, Permissions.inspectHidden(sender))) {
sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true;
} else if (CommandUtils.tooFar(sender, targetPlayer, Permissions.inspectFar(sender))) {
} else {
Player target = mcMMOPlayer.getPlayer();
boolean isVanished = false;
if (CommandUtils.hidden(sender, target, Permissions.inspectHidden(sender))) {
isVanished = true;
}
//Only distance check players who are online and not vanished
if (!isVanished && CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
return true;
}
if (Config.getInstance().getScoreboardsEnabled()
&& sender instanceof Player && Config.getInstance().getInspectUseBoard()) {
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, playerProfile);
&& sender instanceof Player
&& Config.getInstance().getInspectUseBoard()) {
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, mcMMOPlayer);
if (!Config.getInstance().getInspectUseChat()) {
return true;
}
}
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", targetPlayer.getName()));
CommandUtils.printGatheringSkills(targetPlayer, sender);
CommandUtils.printCombatSkills(targetPlayer, sender);
CommandUtils.printMiscSkills(targetPlayer, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", playerProfile.getExperienceHandler().getPowerLevel()));
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName()));
CommandUtils.printGatheringSkills(target, sender);
CommandUtils.printCombatSkills(target, sender);
CommandUtils.printMiscSkills(target, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
}
return true;

View File

@@ -1,16 +1,11 @@
package com.gmail.nossr50.database;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.MMODataSnapshot;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.neetgames.mcmmo.exceptions.InvalidSkillException;
import com.neetgames.mcmmo.exceptions.ProfileRetrievalException;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.neetgames.mcmmo.skill.RootSkill;
import org.apache.commons.lang.NullArgumentException;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,35 +34,36 @@ public interface DatabaseManager {
* Remove a user from the database.
*
* @param playerName The name of the user to remove
* @param uuid uuid of player to remove, can be null
* @param uuid player UUID, can be null
* @return true if the user was successfully removed, false otherwise
*/
boolean removeUser(@NotNull String playerName, @Nullable UUID uuid);
boolean removeUser(String playerName, UUID uuid);
/**
* Removes any cache used for faster lookups
* Currently only used for SQL
* @param uuid target UUID to cleanup
*/
void removeCache(@NotNull UUID uuid);
void cleanupUser(UUID uuid);
/**
* Save a user to the database.
*
* @param mmoDataSnapshot Snapshot of player data to save
* @param profile The profile of the player to save
* @return true if successful, false on failure
*/
boolean saveUser(@NotNull MMODataSnapshot mmoDataSnapshot);
boolean saveUser(PlayerProfile profile);
/**
* Retrieve leaderboard info.
* Will never be null but it may be empty
*
* @param rootSkill The skill to retrieve info on
* @param skill The skill to retrieve info on
* @param pageNumber Which page in the leaderboards to retrieve
* @param statsPerPage The number of stats per page
* @return the requested leaderboard information
*/
@NotNull List<PlayerStat> readLeaderboard(@NotNull RootSkill rootSkill, int pageNumber, int statsPerPage) throws InvalidSkillException;
@NotNull List<PlayerStat> readLeaderboard(@Nullable PrimarySkillType skill, int pageNumber, int statsPerPage) throws InvalidSkillException;
/**
* Retrieve rank info into a HashMap from PrimarySkillType to the rank.
@@ -78,74 +74,60 @@ public interface DatabaseManager {
* @param playerName The name of the user to retrieve the rankings for
* @return the requested rank information
*/
@NotNull Map<RootSkill, Integer> readRank(@NotNull String playerName);
Map<PrimarySkillType, Integer> readRank(String playerName);
/**
* Add a new user to the database.
* @param playerName The name of the player to be added to the database
*
* @param playerName The name of the player to be added to the database
* @param uuid The uuid of the player to be added to the database
*/
void insertNewUser(@NotNull String playerName, @NotNull UUID uuid) throws Exception;
void newUser(String playerName, UUID uuid);
@Nullable MMOPlayerData queryPlayerDataByPlayer(@NotNull Player player) throws ProfileRetrievalException, NullArgumentException;
@NotNull PlayerProfile newUser(@NotNull Player player);
/**
* Load player data (in the form of {@link PlayerProfile}) if player data exists
* Returns null if it doesn't
* Load a player from the database.
*
* @param playerName The name of the player to load from the database
* @return The player's data, or an unloaded PlayerProfile if not found
* and createNew is false
*/
@NotNull PlayerProfile loadPlayerProfile(@NotNull String playerName);
/**
* Load a player from the database.
*
* @param uuid The uuid of the player to load from the database
* @param playerName the current player name for this player
* @return The player's data, or null if not found
* @return The player's data, or an unloaded PlayerProfile if not found
*/
@Nullable MMOPlayerData queryPlayerDataByUUID(@NotNull UUID uuid, @NotNull String playerName) throws ProfileRetrievalException, NullArgumentException;
/**
* Load player data (in the form of {@link PlayerProfile}) if player data exists
* Returns null if it doesn't
*
* @param playerName the current player name for this player
* @return The player's data, or null if not found
*/
@Nullable MMOPlayerData queryPlayerByName(@NotNull String playerName) throws ProfileRetrievalException;
/**
* This method queries the DB for player data for target player
* If it fails to find data for this player, or if it does find data but the data is corrupted,
* it will then proceed to make brand new data for the target player, which will be saved to the DB during the next save
*
* This method will return null for all other errors, which indicates a problem with the DB, in which case mcMMO
* will try to load the player data periodically, but that isn't handled in this method
*
* @param player target player
* @return {@link PlayerProfile} for the target player
*/
@Nullable MMOPlayerData initPlayerProfile(@NotNull Player player) throws Exception;
@NotNull PlayerProfile loadPlayerProfile(@NotNull UUID uuid, @Nullable String playerName);
/**
* Get all users currently stored in the database.
*
* @return list of playernames
*/
@NotNull List<String> getStoredUsers();
List<String> getStoredUsers();
/**
* Convert all users from this database to the provided database using
* {@link #saveUser(MMODataSnapshot)}.
* {@link #saveUser(PlayerProfile)}.
*
* @param destination The DatabaseManager to save to
*/
void convertUsers(@NotNull DatabaseManager destination);
void convertUsers(DatabaseManager destination);
// boolean saveUserUUID(String userName, UUID uuid);
boolean saveUserUUID(String userName, UUID uuid);
// boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
/**
* Retrieve the type of database in use. Custom databases should return CUSTOM.
*
* @return The type of database
*/
@NotNull DatabaseType getDatabaseType();
DatabaseType getDatabaseType();
/**
* Called when the plugin disables

View File

@@ -33,6 +33,9 @@ import java.util.concurrent.locks.ReentrantLock;
public final class SQLDatabaseManager extends AbstractDatabaseManager {
private static final String ALL_QUERY_VERSION = "total";
public static final String MOBHEALTHBAR_VARCHAR = "VARCHAR(50)";
public static final String UUID_VARCHAR = "VARCHAR(36)";
public static final String USER_VARCHAR = "VARCHAR(40)";
private final String tablePrefix = Config.getInstance().getMySQLTablePrefix();
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
@@ -45,6 +48,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private final ReentrantLock massUpdateLock = new ReentrantLock();
private final String CHARSET_SQL = "utf8mb4"; //This is compliant with UTF-8 while "utf8" is not, confusing but this is how it is.
protected SQLDatabaseManager() {
String connectionString = "jdbc:mysql://" + Config.getInstance().getMySQLServerName()
+ ":" + Config.getInstance().getMySQLServerPort() + "/" + Config.getInstance().getMySQLDatabaseName();
@@ -565,6 +570,24 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
}
}
@Override
public @NotNull PlayerProfile newUser(@NotNull Player player) {
try {
Connection connection = getConnection(PoolIdentifier.SAVE);
int id = newUser(connection, player.getName(), player.getUniqueId());
if (id == -1) {
return new PlayerProfile(player.getName(), player.getUniqueId(), false);
} else {
return loadPlayerProfile(player.getUniqueId(), player.getName());
}
} catch (SQLException e) {
e.printStackTrace();
}
return new PlayerProfile(player.getName(), player.getUniqueId(), false);
}
private int newUser(Connection connection, String playerName, UUID uuid) {
ResultSet resultSet = null;
PreparedStatement statement = null;
@@ -603,11 +626,26 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
return -1;
}
public @NotNull PlayerProfile loadPlayerProfile(@NotNull String playerName) {
try {
return loadPlayerFromDB(null, playerName);
} catch (RuntimeException e) {
e.printStackTrace();
return new PlayerProfile(playerName, false);
}
}
public @NotNull PlayerProfile loadPlayerProfile(@NotNull UUID uuid, @Nullable String playerName) {
return loadPlayerFromDB(uuid, playerName);
@Override
public @Nullable MMOPlayerData queryPlayerDataByPlayer(@NotNull Player player) throws ProfileRetrievalException, NullArgumentException {
return loadPlayerProfile(player, player.getName(), player.getUniqueId());
}
private PlayerProfile loadPlayerFromDB(@Nullable UUID uuid, @Nullable String playerName) throws RuntimeException {
if(uuid == null && playerName == null) {
throw new RuntimeException("Error looking up player, both UUID and playerName are null and one must not be.");
}
@Override
public @Nullable MMOPlayerData queryPlayerDataByUUID(@NotNull UUID uuid, @NotNull String playerName) throws ProfileRetrievalException, NullArgumentException {
return loadPlayerProfile(null, playerName, uuid);
@@ -623,15 +661,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
int id = getUserID(connection, playerName, playerUUID);
if (id == -1) {
// There is no such user
if (player != null) {
id = newUser(connection, playerName, playerUUID);
if (id == -1) {
return null;
}
} else {
return null;
}
// There is no such user
return new PlayerProfile(playerName, false);
}
// There is such a user
writeMissingRows(connection, id);
@@ -648,7 +679,10 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
resultSet.close();
statement.close();
if (!playerName.isEmpty() && !playerName.equalsIgnoreCase(name) && playerUUID != null) {
if (playerName != null
&& !playerName.isEmpty()
&& !playerName.equalsIgnoreCase(name)
&& playerUUID != null) {
statement = connection.prepareStatement(
"UPDATE `" + tablePrefix + "users` "
+ "SET user = ? "
@@ -685,10 +719,11 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
tryClose(connection);
}
return null;
//Return empty profile
return new PlayerProfile(playerName, false);
}
public void convertUsers(@NotNull DatabaseManager destination) {
public void convertUsers(DatabaseManager destination) {
PreparedStatement statement = null;
Connection connection = null;
ResultSet resultSet = null;
@@ -867,7 +902,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ "`lastlogin` int(32) unsigned NOT NULL,"
+ "PRIMARY KEY (`id`),"
+ "INDEX(`user`(20) ASC),"
+ "UNIQUE KEY `uuid` (`uuid`)) DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;");
+ "UNIQUE KEY `uuid` (`uuid`)) DEFAULT CHARSET=" + CHARSET_SQL + " AUTO_INCREMENT=1;");
tryClose(createStatement);
}
tryClose(resultSet);
@@ -881,7 +916,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ "`mobhealthbar` varchar(50) NOT NULL DEFAULT '" + Config.getInstance().getMobHealthbarDefault() + "',"
+ "`scoreboardtips` int(10) NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) "
+ "DEFAULT CHARSET=latin1;");
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
tryClose(createStatement);
}
tryClose(resultSet);
@@ -908,7 +943,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ "`tridents` int(32) unsigned NOT NULL DEFAULT '0',"
+ "`crossbows` int(32) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) "
+ "DEFAULT CHARSET=latin1;");
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
tryClose(createStatement);
}
tryClose(resultSet);
@@ -936,7 +971,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ "`crossbows` int(10) unsigned NOT NULL DEFAULT '0',"
+ "`total` int(10) unsigned NOT NULL DEFAULT '0',"
+ "PRIMARY KEY (`user_id`)) "
+ "DEFAULT CHARSET=latin1;");
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
tryClose(createStatement);
}
tryClose(resultSet);
@@ -1010,7 +1045,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
+ "`view_tridents` varchar(40) NOT NULL DEFAULT 'NORMAL',"
+ "`view_crossbows` varchar(40) NOT NULL DEFAULT 'NORMAL',"
+ "PRIMARY KEY (`user_id`)) "
+ "DEFAULT CHARSET=latin1;");
+ "DEFAULT CHARSET=" + CHARSET_SQL + ";");
tryClose(createStatement);
}
tryClose(resultSet);
@@ -1135,6 +1170,11 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
case ADD_UNIQUE_PLAYER_DATA:
checkUpgradeAddUniqueChimaeraWing(statement);
break;
case SQL_CHARSET_UTF8MB4:
updateCharacterSet(statement);
break;
case ADD_SQL_2_2:
checkUpgradeAddTridentsAndCrossbowsSQL(statement);
break;
@@ -1142,8 +1182,6 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
break;
}
mcMMO.getUpgradeManager().setUpgradeCompleted(upgrade);
}
catch (SQLException ex) {
printErrors(ex);
@@ -1358,6 +1396,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
statement.execute("ALTER TABLE `" + tablePrefix + "users` "
+ "DROP INDEX `user`,"
+ "ADD INDEX `user` (`user`(20) ASC)");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.DROP_NAME_UNIQUENESS);
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
@@ -1385,6 +1424,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private void checkUpgradeAddAlchemy(final Statement statement) throws SQLException {
try {
statement.executeQuery("SELECT `alchemy` FROM `" + tablePrefix + "skills` LIMIT 1");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_ALCHEMY);
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Alchemy...");
@@ -1396,6 +1436,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private void checkUpgradeAddBlastMiningCooldown(final Statement statement) throws SQLException {
try {
statement.executeQuery("SELECT `blast_mining` FROM `" + tablePrefix + "cooldowns` LIMIT 1");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_BLAST_MINING_COOLDOWN);
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Blast Mining...");
@@ -1406,6 +1447,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private void checkUpgradeAddUniqueChimaeraWing(final Statement statement) throws SQLException {
try {
statement.executeQuery("SELECT `chimaera_wing` FROM `" + tablePrefix + "cooldowns` LIMIT 1");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UNIQUE_PLAYER_DATA);
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Chimaera Wing...");
@@ -1416,6 +1458,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private void checkUpgradeAddFishing(final Statement statement) throws SQLException {
try {
statement.executeQuery("SELECT `fishing` FROM `" + tablePrefix + "skills` LIMIT 1");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_FISHING);
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for Fishing...");
@@ -1427,6 +1470,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private void checkUpgradeAddMobHealthbars(final Statement statement) throws SQLException {
try {
statement.executeQuery("SELECT `mobhealthbar` FROM `" + tablePrefix + "huds` LIMIT 1");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_MOB_HEALTHBARS);
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for mob healthbars...");
@@ -1437,6 +1481,7 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
private void checkUpgradeAddScoreboardTips(final Statement statement) throws SQLException {
try {
statement.executeQuery("SELECT `scoreboardtips` FROM `" + tablePrefix + "huds` LIMIT 1");
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_SCOREBOARD_TIPS);
}
catch (SQLException ex) {
mcMMO.p.getLogger().info("Updating mcMMO MySQL tables for scoreboard tips...");
@@ -1465,6 +1510,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
}
}
}
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_SQL_INDEXES);
}
catch (SQLException ex) {
printErrors(ex);
@@ -1494,7 +1541,11 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
mcMMO.p.getLogger().info("Adding UUIDs to mcMMO MySQL user table...");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD `uuid` varchar(36) NULL DEFAULT NULL");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` ADD UNIQUE INDEX `uuid` (`uuid`) USING BTREE");
new GetUUIDUpdatesRequired().runTaskLaterAsynchronously(mcMMO.p, 100); // wait until after first purge
}
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
}
catch (SQLException ex) {
printErrors(ex);
@@ -1502,8 +1553,6 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
finally {
tryClose(resultSet);
}
new GetUUIDUpdatesRequired().runTaskLaterAsynchronously(mcMMO.p, 100); // wait until after first purge
}
private class GetUUIDUpdatesRequired extends BukkitRunnable {
@@ -1561,6 +1610,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
mcMMO.p.getLogger().info("Removing party name from users table...");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "users` DROP COLUMN `party`");
}
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.DROP_SQL_PARTY_NAMES);
}
catch (SQLException ex) {
printErrors(ex);
@@ -1596,6 +1647,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_total` (`total`) USING BTREE");
connection.commit();
}
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_SKILL_TOTAL);
}
catch (SQLException ex) {
printErrors(ex);
@@ -1627,6 +1680,8 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
mcMMO.p.getLogger().info("Removing Spout HUD type from huds table...");
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "huds` DROP COLUMN `hudtype`");
}
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.DROP_SPOUT);
}
catch (SQLException ex) {
printErrors(ex);
@@ -1740,6 +1795,69 @@ public final class SQLDatabaseManager extends AbstractDatabaseManager {
}
}
private void updateCharacterSet(@NotNull Statement statement) {
//TODO: Could check the tables for being latin1 before executing queries but it seems moot because it is likely the same computational effort
/*
The following columns were set to use latin1 historically (now utf8mb4)
column user in <tablePrefix>users
column uuid in <tablePrefix>users
column mobhealthbar in <tablePrefix>huds
*/
//Alter users table
mcMMO.p.getLogger().info("SQL Converting tables from latin1 to utf8mb4");
//Update "user" column
try {
mcMMO.p.getLogger().info("Updating user column to new encoding");
statement.executeUpdate(getUpdateUserInUsersTableSQLQuery());
//Update "uuid" column
mcMMO.p.getLogger().info("Updating user column to new encoding");
statement.executeUpdate(getUpdateUUIDInUsersTableSQLQuery());
//Update "mobhealthbar" column
mcMMO.p.getLogger().info("Updating mobhealthbar column to new encoding");
statement.executeUpdate(getUpdateMobHealthBarInHudsTableSQLQuery());
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.SQL_CHARSET_UTF8MB4);
} catch (SQLException e) {
e.printStackTrace();
}
}
@NotNull
private String getUpdateUserInUsersTableSQLQuery() {
return "ALTER TABLE\n" +
" " + tablePrefix + "users\n" +
" CHANGE user user\n" +
" " + USER_VARCHAR + "\n" +
" CHARACTER SET utf8mb4\n" +
" COLLATE utf8mb4_unicode_ci;";
}
@NotNull
private String getUpdateUUIDInUsersTableSQLQuery() {
return "ALTER TABLE\n" +
" " + tablePrefix + "users\n" +
" CHANGE uuid uuid\n" +
" " + UUID_VARCHAR + "\n" +
" CHARACTER SET utf8mb4\n" +
" COLLATE utf8mb4_unicode_ci;";
}
@NotNull
private String getUpdateMobHealthBarInHudsTableSQLQuery() {
return "ALTER TABLE\n" +
" " + tablePrefix + "huds\n" +
" CHANGE mobhealthbar mobhealthbar\n" +
" " + MOBHEALTHBAR_VARCHAR + "\n" +
" CHARACTER SET utf8mb4\n" +
" COLLATE utf8mb4_unicode_ci;";
}
@Override
public void removeCache(@NotNull UUID uuid) {
cachedUserIDs.remove(uuid);

View File

@@ -17,5 +17,6 @@ public enum UpgradeType {
ADD_SQL_2_2,
FIX_SPELLING_NETHERITE_SALVAGE,
FIX_SPELLING_NETHERITE_REPAIR,
FIX_NETHERITE_SALVAGE_QUANTITIES
FIX_NETHERITE_SALVAGE_QUANTITIES,
SQL_CHARSET_UTF8MB4
}

View File

@@ -0,0 +1,41 @@
package com.gmail.nossr50.events;
import org.bukkit.entity.Item;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class McMMOReplaceVanillaTreasureEvent extends Event {
private @NotNull ItemStack replacementItemStack;
private final @NotNull Item originalItem;
public McMMOReplaceVanillaTreasureEvent(@NotNull Item originalItem, @NotNull ItemStack replacementItemStack) {
this.originalItem = originalItem;
this.replacementItemStack = replacementItemStack;
}
/** Rest of file is required boilerplate for custom events **/
private static final @NotNull HandlerList handlers = new HandlerList();
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}
public static @NotNull HandlerList getHandlerList() {
return handlers;
}
public @NotNull ItemStack getReplacementItemStack() {
return replacementItemStack;
}
public void setReplacementItemStack(@NotNull ItemStack replacementItemStack) {
this.replacementItemStack = replacementItemStack;
}
public @NotNull Item getOriginalItem() {
return originalItem;
}
}

View File

@@ -616,6 +616,7 @@ public class EntityListener implements Listener {
switch (cause) {
case CONTACT:
case FIRE:
case HOT_FLOOR:
case LAVA:
if (tamingManager.canUseEnvironmentallyAware()) {
tamingManager.processEnvironmentallyAware(wolf, event.getDamage());

View File

@@ -8,6 +8,9 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.neetgames.mcmmo.player.OnlineMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.events.McMMOReplaceVanillaTreasureEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
@@ -258,7 +261,7 @@ public class PlayerListener implements Listener {
*
* @param event The event to modify
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerFishHighest(PlayerFishEvent event) {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
@@ -292,12 +295,20 @@ public class PlayerListener implements Listener {
if(event.getCaught() != null) {
Item fishingCatch = (Item) event.getCaught();
if (Config.getInstance(). getFishingOverrideTreasures() &&
if (Config.getInstance().getFishingOverrideTreasures() &&
fishingCatch.getItemStack().getType() != Material.SALMON &&
fishingCatch.getItemStack().getType() != Material.COD &&
fishingCatch.getItemStack().getType() != Material.TROPICAL_FISH &&
fishingCatch.getItemStack().getType() != Material.PUFFERFISH) {
fishingCatch.setItemStack(new ItemStack(Material.SALMON, 1));
ItemStack replacementCatch = new ItemStack(Material.SALMON, 1);
McMMOReplaceVanillaTreasureEvent replaceVanillaTreasureEvent = new McMMOReplaceVanillaTreasureEvent(fishingCatch, replacementCatch);
Bukkit.getPluginManager().callEvent(replaceVanillaTreasureEvent);
//Replace
replacementCatch = replaceVanillaTreasureEvent.getReplacementItemStack();
fishingCatch.setItemStack(replacementCatch);
}
if (Permissions.vanillaXpBoost(player, PrimarySkillType.FISHING)) {

View File

@@ -615,7 +615,11 @@ public class mcMMO extends JavaPlugin {
private void scheduleTasks() {
// Periodic save timer (Saves every 10 minutes by default)
long saveIntervalTicks = Config.getInstance().getSaveInterval() * 1200;
long second = 20;
long minute = second * 60;
long saveIntervalTicks = Math.max(minute, Config.getInstance().getSaveInterval() * minute);
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
// Cleanup the backups folder

View File

@@ -31,7 +31,7 @@ public class FormulaConversionTask extends BukkitRunnable {
// If the mmoPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mmoPlayer == null) {
profile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName, false);
profile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName);
if (!profile.isLoaded()) {
mcMMO.p.debug("Profile not loaded.");

View File

@@ -99,7 +99,7 @@ public class UUIDUpdateAsyncTask implements Runnable {
position += batch.size();
plugin.getLogger().info(String.format("Conversion progress: %d/%d users", position, userNames.size()));
if (position == userNames.size()) {
if (position +1 >= userNames.size()) {
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
awaiter.countDown();
plugin.getLogger().info("UUID checks completed");

View File

@@ -2,12 +2,13 @@ package com.gmail.nossr50.runnables.player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.neetgames.mcmmo.player.MMOPlayerData;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.commands.McScoreboardKeepTask;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@@ -41,40 +42,46 @@ public class PlayerProfileLoadingTask extends BukkitRunnable {
return;
}
try {
MMOPlayerData mmoPlayerData = mcMMO.getDatabaseManager().queryPlayerDataByPlayer(player);
McMMOPlayer mmoPlayer = new McMMOPlayer(player, player.getUniqueId(), player.getName());
new ApplySuccessfulProfile(new McMMOPlayer(player, )).runTask(mcMMO.p);
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(player.getUniqueId(), player.getName());
if(!profile.isLoaded()) {
mcMMO.p.getLogger().info("Creating new data for player: "+player.getName());
//Profile isn't loaded so add as new user
profile = mcMMO.getDatabaseManager().newUser(player);
}
// If successful, schedule the apply
if (profile.isLoaded()) {
new ApplySuccessfulProfile(new McMMOPlayer(player, profile)).runTask(mcMMO.p);
EventUtils.callPlayerProfileLoadEvent(player, profile);
return;
} catch () {
// Print errors to console/logs if we're failing at least 2 times in a row to load the profile
if (attempt >= 3)
{
//Log the error
mcMMO.p.getLogger().severe(LocaleLoader.getString("Profile.Loading.FailureNotice",
player.getName(), String.valueOf(attempt)));
//Notify the admins
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Profile.Loading.FailureNotice", player.getName()), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
//Notify the player
player.sendMessage(LocaleLoader.getString("Profile.Loading.FailurePlayer", String.valueOf(attempt)).split("\n"));
}
// Increment attempt counter and try
attempt++;
new PlayerProfileLoadingTask(player, attempt).runTaskLaterAsynchronously(mcMMO.p, (100 + (attempt * 100)));
}
// Print errors to console/logs if we're failing at least 2 times in a row to load the profile
if (attempt >= 3)
{
//Log the error
mcMMO.p.getLogger().severe(LocaleLoader.getString("Profile.Loading.FailureNotice",
player.getName(), String.valueOf(attempt)));
//Notify the admins
mcMMO.p.getServer().broadcast(LocaleLoader.getString("Profile.Loading.FailureNotice", player.getName()), Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
//Notify the player
player.sendMessage(LocaleLoader.getString("Profile.Loading.FailurePlayer", String.valueOf(attempt)).split("\n"));
}
// Increment attempt counter and try
attempt++;
new PlayerProfileLoadingTask(player, attempt).runTaskLaterAsynchronously(mcMMO.p, (100 + (attempt * 100)));
}
private class ApplySuccessfulProfile extends BukkitRunnable {
private final McMMOPlayer mmoPlayer;
private final McMMOPlayer mcMMOPlayer;
private ApplySuccessfulProfile(McMMOPlayer mmoPlayer) {
this.mmoPlayer = mmoPlayer;
private ApplySuccessfulProfile(McMMOPlayer mcMMOPlayer) {
this.mcMMOPlayer = mcMMOPlayer;
}
// Synchronized task
@@ -86,8 +93,9 @@ public class PlayerProfileLoadingTask extends BukkitRunnable {
return;
}
mcMMO.getUserManager().track(mmoPlayer);
mmoPlayer.actualizeRespawnATS();
mcMMOPlayer.setupPartyData();
UserManager.track(mcMMOPlayer);
mcMMOPlayer.actualizeRespawnATS();
if (Config.getInstance().getScoreboardsEnabled()) {
ScoreboardManager.setupPlayer(player);

View File

@@ -138,7 +138,7 @@ public class SmeltingManager extends SkillManager {
ItemStack furnaceResult = furnaceInventory.getResult();
if(furnaceResult == null)
return false;
return true; //This actually means there is nothing yet in the resulting item slot, which means it should always be okay to double smelt
int resultAmount = furnaceResult.getAmount(); //Amount before double smelt
int itemLimit = furnaceResult.getMaxStackSize();

View File

@@ -344,6 +344,22 @@ public class ScoreboardManager {
}
}
public static void enablePlayerInspectScoreboard(@NotNull Player player, @NotNull McMMOPlayer targetMcMMOPlayer) {
ScoreboardWrapper wrapper = getWrapper(player);
if(wrapper == null) {
setupPlayer(player);
wrapper = getWrapper(player);
}
if(wrapper != null) {
wrapper.setOldScoreboard();
wrapper.setTypeInspectStats(targetMcMMOPlayer);
changeScoreboard(wrapper, Config.getInstance().getInspectScoreboardTime());
}
}
public static void enablePlayerCooldownScoreboard(Player player) {
ScoreboardWrapper wrapper = getWrapper(player);

View File

@@ -24,6 +24,7 @@ import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
@@ -321,6 +322,17 @@ public class ScoreboardWrapper {
loadObjective(LocaleLoader.getString("Scoreboard.Header.PlayerInspect", targetPlayer));
}
public void setTypeInspectStats(@NotNull McMMOPlayer mcMMOPlayer) {
this.sidebarType = SidebarType.STATS_BOARD;
targetPlayer = mcMMOPlayer.getPlayer().getName();
targetProfile = mcMMOPlayer.getProfile();
targetSkill = null;
leaderboardPage = -1;
loadObjective(LocaleLoader.getString("Scoreboard.Header.PlayerInspect", targetPlayer));
}
public void setTypeCooldowns() {
this.sidebarType = SidebarType.COOLDOWNS_BOARD;

View File

@@ -16,9 +16,12 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
public class TextUtils {
private static @Nullable LegacyComponentSerializer customLegacySerializer;
private TextUtils() {
// We don't want any instances of this class.
}
/**
* Makes a single component from an array of components, can optionally add prefixes and suffixes to come before and after each component
* @param componentsArray target array

View File

@@ -11,7 +11,7 @@ public class UpgradeManager extends ConfigLoader {
private final Set<UpgradeType> setNeededUpgrades;
public UpgradeManager() {
super("upgrades.yml");
super("upgrades_overhaul.yml"); //overhaul is added so we don't have any issues with classic
setNeededUpgrades = EnumSet.allOf(UpgradeType.class);