From 64e1d1a9d7fd8caf9c7f3e10e21a8548b562a647 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 10 Dec 2020 17:15:14 -0800 Subject: [PATCH] more refactoring/rewrites for player data loading stuff --- pom.xml | 5 +++ .../nossr50/chat/SamePartyPredicate.java | 2 +- .../commands/AbilityToggleCommand.java | 9 ++-- .../nossr50/commands/CommandManager.java | 4 +- .../gmail/nossr50/commands/MHDCommand.java | 9 ++-- .../gmail/nossr50/commands/McgodCommand.java | 9 ++-- .../nossr50/commands/McrefreshCommand.java | 13 +++--- .../gmail/nossr50/commands/ToggleCommand.java | 33 +++++++++----- .../commands/admin/PlayerDebugCommand.java | 10 ++++- .../nossr50/commands/chat/McChatSpy.java | 9 ++-- .../commands/player/InspectCommand.java | 44 +++++++++++-------- .../database/AbstractDatabaseManager.java | 2 +- .../nossr50/database/DatabaseManager.java | 13 +++++- .../nossr50/datatypes/player/McMMOPlayer.java | 7 +-- .../nossr50/listeners/CommandListener.java | 2 +- src/main/java/com/gmail/nossr50/mcMMO.java | 5 ++- .../nossr50/util/commands/CommandUtils.java | 14 ++---- .../util/input/SuperAbilityManager.java | 12 ++++- .../nossr50/util/player/UserManager.java | 4 ++ 19 files changed, 126 insertions(+), 80 deletions(-) diff --git a/pom.xml b/pom.xml index 2f833b073..2485b458b 100755 --- a/pom.xml +++ b/pom.xml @@ -200,6 +200,11 @@ mcMMO-API 0.01.00-SNAPSHOT + + com.neetgames + jmal-core + 0.01.00-SNAPSHOT + com.neetgames jmal diff --git a/src/main/java/com/gmail/nossr50/chat/SamePartyPredicate.java b/src/main/java/com/gmail/nossr50/chat/SamePartyPredicate.java index 6d4636d6c..ce319c908 100644 --- a/src/main/java/com/gmail/nossr50/chat/SamePartyPredicate.java +++ b/src/main/java/com/gmail/nossr50/chat/SamePartyPredicate.java @@ -25,7 +25,7 @@ public class SamePartyPredicate implements Predicate } else { if(t instanceof Player) { Player player = (Player) t; - McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + McMMOPlayer mcMMOPlayer = mcMMO.getUserManager().queryPlayer(player); if(mcMMOPlayer != null) { return mcMMOPlayer.getParty() == party; } diff --git a/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java b/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java index 4e7bf99fc..0388a1852 100644 --- a/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java @@ -4,26 +4,27 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class AbilityToggleCommand extends ToggleCommand { @Override - protected boolean hasOtherPermission(CommandSender sender) { + protected boolean hasOtherPermission(@NotNull CommandSender sender) { return Permissions.mcabilityOthers(sender); } @Override - protected boolean hasSelfPermission(CommandSender sender) { + protected boolean hasSelfPermission(@NotNull CommandSender sender) { return Permissions.mcability(sender); } @Override - protected void applyCommandAction(McMMOPlayer mmoPlayer) { + protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) { mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mmoPlayer.getSuperAbilityManager().getAbilityActivationPermission() ? "Off" : "On"))); mmoPlayer.getSuperAbilityManager().toggleAbilityActivationPermission(); } @Override - protected void sendSuccessMessage(CommandSender sender, String playerName) { + protected void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String playerName) { sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle", playerName)); } } diff --git a/src/main/java/com/gmail/nossr50/commands/CommandManager.java b/src/main/java/com/gmail/nossr50/commands/CommandManager.java index de5d4a7fd..8732924c1 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandManager.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandManager.java @@ -97,13 +97,13 @@ public class CommandManager { } public void validateLoadedData(@NotNull Player player) { - if(UserManager.getPlayer(player) == null) { + if(mcMMO.getUserManager().queryPlayer(player) == null) { throw new ConditionFailedException("Your mcMMO player data has not yet loaded!"); } } public void validatePlayerParty(@NotNull Player player) { - McMMOPlayer mmoPlayer = UserManager.getPlayer(player); + McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(player); if(mmoPlayer.getParty() == null) { throw new ConditionFailedException(LocaleLoader.getString("Commands.Party.None")); diff --git a/src/main/java/com/gmail/nossr50/commands/MHDCommand.java b/src/main/java/com/gmail/nossr50/commands/MHDCommand.java index f69f4014a..7340b277e 100644 --- a/src/main/java/com/gmail/nossr50/commands/MHDCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/MHDCommand.java @@ -3,6 +3,7 @@ package com.gmail.nossr50.commands; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.database.FlatFileDatabaseManager; import com.gmail.nossr50.database.SQLDatabaseManager; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.mcMMO; import com.google.common.collect.ImmutableList; import org.bukkit.command.Command; @@ -19,8 +20,8 @@ public class MHDCommand implements TabExecutor { if (mcMMO.getDatabaseManager() instanceof SQLDatabaseManager) { SQLDatabaseManager m = (SQLDatabaseManager) mcMMO.getDatabaseManager(); m.resetMobHealthSettings(); - for (mmoPlayer player : mcMMO.getUserManager().getPlayers()) { - player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault()); + for (McMMOPlayer mmoPlayer : mcMMO.getUserManager().getPlayers()) { + mmoPlayer.setMobHealthBarType(Config.getInstance().getMobHealthbarDefault()); } sender.sendMessage("Mob health reset"); return true; @@ -28,8 +29,8 @@ public class MHDCommand implements TabExecutor { if (mcMMO.getDatabaseManager() instanceof FlatFileDatabaseManager) { FlatFileDatabaseManager m = (FlatFileDatabaseManager) mcMMO.getDatabaseManager(); m.resetMobHealthSettings(); - for (mmoPlayer player : mcMMO.getUserManager().getPlayers()) { - player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault()); + for (McMMOPlayer mmoPlayer : mcMMO.getUserManager().getPlayers()) { + mmoPlayer.setMobHealthBarType(Config.getInstance().getMobHealthbarDefault()); } sender.sendMessage("Mob health reset"); return true; diff --git a/src/main/java/com/gmail/nossr50/commands/McgodCommand.java b/src/main/java/com/gmail/nossr50/commands/McgodCommand.java index a7736acdf..fc36a34f8 100644 --- a/src/main/java/com/gmail/nossr50/commands/McgodCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McgodCommand.java @@ -4,26 +4,27 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class McgodCommand extends ToggleCommand { @Override - protected boolean hasOtherPermission(CommandSender sender) { + protected boolean hasOtherPermission(@NotNull CommandSender sender) { return Permissions.mcgodOthers(sender); } @Override - protected boolean hasSelfPermission(CommandSender sender) { + protected boolean hasSelfPermission(@NotNull CommandSender sender) { return Permissions.mcgod(sender); } @Override - protected void applyCommandAction(McMMOPlayer mmoPlayer) { + protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) { mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.GodMode." + (mmoPlayer.getGodMode() ? "Disabled" : "Enabled"))); mmoPlayer.toggleGodMode(); } @Override - protected void sendSuccessMessage(CommandSender sender, String playerName) { + protected void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String playerName) { sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Toggle", playerName)); } } diff --git a/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java b/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java index 35a3fe1ca..7618a2a92 100644 --- a/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/McrefreshCommand.java @@ -4,30 +4,31 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class McrefreshCommand extends ToggleCommand { @Override - protected boolean hasOtherPermission(CommandSender sender) { + protected boolean hasOtherPermission(@NotNull CommandSender sender) { return Permissions.mcrefreshOthers(sender); } @Override - protected boolean hasSelfPermission(CommandSender sender) { + protected boolean hasSelfPermission(@NotNull CommandSender sender) { return Permissions.mcrefresh(sender); } @Override - protected void applyCommandAction(McMMOPlayer mmoPlayer) { + protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) { mmoPlayer.setRecentlyHurtTimestamp(0); - mmoPlayer.resetCooldowns(); + mmoPlayer.getSuperAbilityManager().resetCooldowns(); mmoPlayer.getSuperAbilityManager().unprimeAllAbilityTools(); - mmoPlayer.getSuperAbilityManager().resetSuperAbilities(); + mmoPlayer.getSuperAbilityManager().disableSuperAbilities(); mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); } @Override - protected void sendSuccessMessage(CommandSender sender, String playerName) { + protected void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String playerName) { sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", playerName)); } } diff --git a/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java index 7b49565b9..61a9f9fab 100644 --- a/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/ToggleCommand.java @@ -1,11 +1,16 @@ package com.gmail.nossr50.commands; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.commands.CommandUtils; import com.google.common.collect.ImmutableList; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; import org.bukkit.util.StringUtil; import org.jetbrains.annotations.NotNull; @@ -30,7 +35,14 @@ public abstract class ToggleCommand implements TabExecutor { return true; } - applyCommandAction(mcMMO.getUserManager().getPlayer(sender.getName())); + McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer((Player) sender); + + if(mmoPlayer != null) { + applyCommandAction(mmoPlayer); + } else { + mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.NotLoaded")); + } + return true; case 1: @@ -40,17 +52,18 @@ public abstract class ToggleCommand implements TabExecutor { } String playerName = CommandUtils.getMatchedPlayerName(args[0]); - McMMOPlayer mmoPlayer = mcMMO.getUserManager().getPlayer(playerName); + Player otherPlayer = Bukkit.getPlayer(playerName); + McMMOPlayer mmoOther = mcMMO.getUserManager().queryPlayer(otherPlayer); - if (!CommandUtils.checkPlayerExistence(sender, playerName, mmoPlayer)) { + if (!CommandUtils.checkPlayerExistence(sender, playerName, mmoOther)) { return true; } - if (CommandUtils.isOffline(sender, mmoPlayer.getPlayer())) { - return true; + if(mmoOther.getPlayer().isOnline()) { + return false; } - applyCommandAction(mmoPlayer); + applyCommandAction(mmoOther); sendSuccessMessage(sender, playerName); return true; @@ -68,8 +81,8 @@ public abstract class ToggleCommand implements TabExecutor { return ImmutableList.of(); } - protected abstract boolean hasOtherPermission(CommandSender sender); - protected abstract boolean hasSelfPermission(CommandSender sender); - protected abstract void applyCommandAction(McMMOPlayer mmoPlayer); - protected abstract void sendSuccessMessage(CommandSender sender, String playerName); + protected abstract boolean hasOtherPermission(@NotNull CommandSender sender); + protected abstract boolean hasSelfPermission(@NotNull CommandSender sender); + protected abstract void applyCommandAction(@NotNull McMMOPlayer mmoPlayer); + protected abstract void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String playerName); } diff --git a/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java b/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java index 4b1fbaaf9..6e93b2ea5 100644 --- a/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/admin/PlayerDebugCommand.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.commands.admin; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.player.NotificationManager; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -13,7 +15,13 @@ public class PlayerDebugCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if(sender instanceof Player) { - McMMOPlayer mmoPlayer = mcMMO.getUserManager().getPlayer((Player) sender); + McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer((Player) sender); + + if(mmoPlayer == null) { + sender.sendMessage(LocaleLoader.getString("Commands.NotLoaded")); + return true; + } + mmoPlayer.toggleDebugMode(); //Toggle debug mode NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mmoPlayer.isDebugMode())); return true; diff --git a/src/main/java/com/gmail/nossr50/commands/chat/McChatSpy.java b/src/main/java/com/gmail/nossr50/commands/chat/McChatSpy.java index 4d8026dc9..101231f20 100644 --- a/src/main/java/com/gmail/nossr50/commands/chat/McChatSpy.java +++ b/src/main/java/com/gmail/nossr50/commands/chat/McChatSpy.java @@ -5,26 +5,27 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; public class McChatSpy extends ToggleCommand { @Override - protected boolean hasOtherPermission(CommandSender sender) { + protected boolean hasOtherPermission(@NotNull CommandSender sender) { return Permissions.adminChatSpyOthers(sender); } @Override - protected boolean hasSelfPermission(CommandSender sender) { + protected boolean hasSelfPermission(@NotNull CommandSender sender) { return Permissions.adminChatSpy(sender); } @Override - protected void applyCommandAction(McMMOPlayer mmoPlayer) { + protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) { mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.AdminChatSpy." + (mmoPlayer.isPartyChatSpying() ? "Disabled" : "Enabled"))); mmoPlayer.togglePartyChatSpying(); } @Override - protected void sendSuccessMessage(CommandSender sender, String playerName) { + protected void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String playerName) { sender.sendMessage(LocaleLoader.getString("Commands.AdminChatSpy.Toggle", playerName)); } } diff --git a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java index 8c76f5943..9ba96359e 100644 --- a/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/player/InspectCommand.java @@ -10,6 +10,7 @@ import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.google.common.collect.ImmutableList; +import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -25,17 +26,23 @@ 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 mmoPlayer = mcMMO.getUserManager().queryPlayerName(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) { - PlayerProfile profile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName, false); // Temporary Profile + PlayerProfile playerProfile = mcMMO.getUserManager().queryPlayer(playerName); + Player targetPlayer = Bukkit.getPlayer(playerName); - if (!CommandUtils.isLoaded(sender, profile)) { - return true; - } + if(playerProfile == null) { + //TODO: Localize + sender.sendMessage("Data was not found in the database for the given player name!"); + return true; + } - if (Config.getInstance().getScoreboardsEnabled() && sender instanceof Player && Config.getInstance().getInspectUseBoard()) { + + if(targetPlayer == null) { + //Target is offline + + if (Config.getInstance().getScoreboardsEnabled() + && sender instanceof Player + && Config.getInstance().getInspectUseBoard()) { ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, profile); if (!Config.getInstance().getInspectUseChat()) { @@ -59,30 +66,29 @@ public class InspectCommand implements TabExecutor { for (PrimarySkillType skill : PrimarySkillType.MISC_SKILLS) { sender.sendMessage(CommandUtils.displaySkill(profile, skill)); } - } else { - Player target = mmoPlayer.getPlayer(); - if (CommandUtils.hidden(sender, target, Permissions.inspectHidden(sender))) { + if (CommandUtils.hidden(sender, targetPlayer, Permissions.inspectHidden(sender))) { sender.sendMessage(LocaleLoader.getString("Inspect.Offline")); return true; - } else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) { + } else if (CommandUtils.tooFar(sender, targetPlayer, Permissions.inspectFar(sender))) { return true; } - if (Config.getInstance().getScoreboardsEnabled() && sender instanceof Player && Config.getInstance().getInspectUseBoard()) { - ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, mmoPlayer); + if (Config.getInstance().getScoreboardsEnabled() + && sender instanceof Player && Config.getInstance().getInspectUseBoard()) { + ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, playerProfile); if (!Config.getInstance().getInspectUseChat()) { return true; } } - 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", mmoPlayer.getPowerLevel())); + 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.getExperienceManager().getPowerLevel())); } return true; diff --git a/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java b/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java index 8376de8a9..3f1bf1ca8 100644 --- a/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/AbstractDatabaseManager.java @@ -1,9 +1,9 @@ package com.gmail.nossr50.database; -import com.gmail.nossr50.api.exceptions.ProfileRetrievalException; import com.gmail.nossr50.datatypes.player.PersistentPlayerDataBuilder; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.mcMMO; +import com.neetgames.mcmmo.exceptions.ProfileRetrievalException; import org.apache.commons.lang.NullArgumentException; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java index 2c5e6235a..12586f3d2 100644 --- a/src/main/java/com/gmail/nossr50/database/DatabaseManager.java +++ b/src/main/java/com/gmail/nossr50/database/DatabaseManager.java @@ -1,13 +1,13 @@ package com.gmail.nossr50.database; -import com.gmail.nossr50.api.exceptions.InvalidSkillException; -import com.gmail.nossr50.api.exceptions.ProfileRetrievalException; 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 org.apache.commons.lang.NullArgumentException; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -97,6 +97,15 @@ public interface DatabaseManager { */ @Nullable PlayerProfile 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 PlayerProfile 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, diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 1fe65046e..fd25a49d0 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -38,17 +38,12 @@ import net.kyori.adventure.identity.Identity; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.permissions.Permissible; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.UUID; public class McMMOPlayer extends PlayerProfile implements Identified { @@ -549,7 +544,7 @@ public class McMMOPlayer extends PlayerProfile implements Identified { * Etc... */ public void cleanup() { - superAbilityManager.resetSuperAbilities(); + superAbilityManager.disableSuperAbilities(); getTamingManager().cleanupAllSummons(); } diff --git a/src/main/java/com/gmail/nossr50/listeners/CommandListener.java b/src/main/java/com/gmail/nossr50/listeners/CommandListener.java index 484faa5bb..da0a43e4d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/CommandListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/CommandListener.java @@ -26,7 +26,7 @@ // // SkillUtils.removeAbilityBoostsFromInventory(player); // -// McMMOPlayer mmoPlayer = UserManager.getPlayer(player); +// McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(player); // // if(mmoPlayer == null) // return; diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index d43b8150c..72a9686da 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -57,6 +57,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -428,7 +429,7 @@ public class mcMMO extends JavaPlugin { return salvageableManager; } - public static DatabaseManager getDatabaseManager() { + public static @NotNull DatabaseManager getDatabaseManager() { return databaseManager; } @@ -666,7 +667,7 @@ public class mcMMO extends JavaPlugin { return spawnedProjectileTracker; } - public static UserManager getUserManager() { + public static @NotNull UserManager getUserManager() { return userManager; } diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java index 8d40480d5..f6b2a554c 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java @@ -13,6 +13,7 @@ import com.google.common.collect.ImmutableList; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -118,15 +119,6 @@ public final class CommandUtils { return hasPlayerDataKey; } - public static boolean isLoaded(CommandSender sender, PlayerProfile profile) { - if (profile.isLoaded()) { - return true; - } - - sender.sendMessage(LocaleLoader.getString("Commands.NotLoaded")); - return false; - } - public static boolean isInvalidInteger(CommandSender sender, String value) { if (StringUtils.isInt(value)) { return false; @@ -204,11 +196,11 @@ public final class CommandUtils { printMiscSkills(player, player); } - public static String displaySkill(PlayerProfile profile, PrimarySkillType skill) { + public static String displaySkill(@NotNull PlayerProfile profile, @NotNull PrimarySkillType skill) { if (skill.isChildSkill()) { return LocaleLoader.getString("Skills.ChildStats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill)); } - if (profile.getSkillLevel(skill) == Config.getInstance().getLevelCap(skill)){ + if (profile.getExperienceManager().getSkillLevel(skill) == Config.getInstance().getLevelCap(skill)){ return LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), LocaleLoader.getString("Skills.MaxXP")); } return LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill)); diff --git a/src/main/java/com/gmail/nossr50/util/input/SuperAbilityManager.java b/src/main/java/com/gmail/nossr50/util/input/SuperAbilityManager.java index 5e0a088ba..fd24a44fe 100644 --- a/src/main/java/com/gmail/nossr50/util/input/SuperAbilityManager.java +++ b/src/main/java/com/gmail/nossr50/util/input/SuperAbilityManager.java @@ -4,6 +4,7 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.datatypes.player.PersistentPlayerData; import com.gmail.nossr50.datatypes.skills.AbilityToolType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; @@ -20,6 +21,7 @@ import com.gmail.nossr50.util.sounds.SoundManager; import com.gmail.nossr50.util.sounds.SoundType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -35,9 +37,11 @@ public class SuperAbilityManager { private boolean abilityActivationPermission = true; private final Map toolMode = new HashMap<>(); + private final PersistentPlayerData persistentPlayerData; - public SuperAbilityManager(McMMOPlayer mmoPlayer) { + public SuperAbilityManager(@NotNull McMMOPlayer mmoPlayer, @NotNull PersistentPlayerData persistentPlayerData) { this.mmoPlayer = mmoPlayer; + this.persistentPlayerData = persistentPlayerData; this.player = mmoPlayer.getPlayer(); for (SuperAbilityType superAbilityType : SuperAbilityType.values()) { @@ -231,13 +235,17 @@ public class SuperAbilityManager { /** * Reset the mode of all abilities. */ - public void resetSuperAbilities() { + public void disableSuperAbilities() { for (SuperAbilityType ability : SuperAbilityType.values()) { // Correctly disable and handle any special deactivate code new AbilityDisableTask(mmoPlayer, ability).run(); } } + public void resetCooldowns() { + this.persistentPlayerData.resetCooldowns(); + } + /** * Get the mode of an ability. * diff --git a/src/main/java/com/gmail/nossr50/util/player/UserManager.java b/src/main/java/com/gmail/nossr50/util/player/UserManager.java index c0867fbaa..c43c15a35 100644 --- a/src/main/java/com/gmail/nossr50/util/player/UserManager.java +++ b/src/main/java/com/gmail/nossr50/util/player/UserManager.java @@ -67,6 +67,10 @@ public final class UserManager { return null; } + public @Nullable PlayerProfile queryPlayer(@NotNull String playerName) { + return mcMMO.getDatabaseManager().queryPlayerByName(playerName); + } + /** * Remove a user. *