more refactoring/rewrites for player data loading stuff

This commit is contained in:
nossr50 2020-12-10 17:15:14 -08:00
parent 0e22583df4
commit 64e1d1a9d7
19 changed files with 126 additions and 80 deletions

View File

@ -200,6 +200,11 @@
<artifactId>mcMMO-API</artifactId> <artifactId>mcMMO-API</artifactId>
<version>0.01.00-SNAPSHOT</version> <version>0.01.00-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>com.neetgames</groupId>
<artifactId>jmal-core</artifactId>
<version>0.01.00-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>com.neetgames</groupId> <groupId>com.neetgames</groupId>
<artifactId>jmal</artifactId> <artifactId>jmal</artifactId>

View File

@ -25,7 +25,7 @@ public class SamePartyPredicate<T extends CommandSender> implements Predicate<T>
} else { } else {
if(t instanceof Player) { if(t instanceof Player) {
Player player = (Player) t; Player player = (Player) t;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); McMMOPlayer mcMMOPlayer = mcMMO.getUserManager().queryPlayer(player);
if(mcMMOPlayer != null) { if(mcMMOPlayer != null) {
return mcMMOPlayer.getParty() == party; return mcMMOPlayer.getParty() == party;
} }

View File

@ -4,26 +4,27 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class AbilityToggleCommand extends ToggleCommand { public class AbilityToggleCommand extends ToggleCommand {
@Override @Override
protected boolean hasOtherPermission(CommandSender sender) { protected boolean hasOtherPermission(@NotNull CommandSender sender) {
return Permissions.mcabilityOthers(sender); return Permissions.mcabilityOthers(sender);
} }
@Override @Override
protected boolean hasSelfPermission(CommandSender sender) { protected boolean hasSelfPermission(@NotNull CommandSender sender) {
return Permissions.mcability(sender); return Permissions.mcability(sender);
} }
@Override @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.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mmoPlayer.getSuperAbilityManager().getAbilityActivationPermission() ? "Off" : "On")));
mmoPlayer.getSuperAbilityManager().toggleAbilityActivationPermission(); mmoPlayer.getSuperAbilityManager().toggleAbilityActivationPermission();
} }
@Override @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)); sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle", playerName));
} }
} }

View File

@ -97,13 +97,13 @@ public class CommandManager {
} }
public void validateLoadedData(@NotNull Player player) { 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!"); throw new ConditionFailedException("Your mcMMO player data has not yet loaded!");
} }
} }
public void validatePlayerParty(@NotNull Player player) { public void validatePlayerParty(@NotNull Player player) {
McMMOPlayer mmoPlayer = UserManager.getPlayer(player); McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(player);
if(mmoPlayer.getParty() == null) { if(mmoPlayer.getParty() == null) {
throw new ConditionFailedException(LocaleLoader.getString("Commands.Party.None")); throw new ConditionFailedException(LocaleLoader.getString("Commands.Party.None"));

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.commands;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.database.FlatFileDatabaseManager; import com.gmail.nossr50.database.FlatFileDatabaseManager;
import com.gmail.nossr50.database.SQLDatabaseManager; import com.gmail.nossr50.database.SQLDatabaseManager;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -19,8 +20,8 @@ public class MHDCommand implements TabExecutor {
if (mcMMO.getDatabaseManager() instanceof SQLDatabaseManager) { if (mcMMO.getDatabaseManager() instanceof SQLDatabaseManager) {
SQLDatabaseManager m = (SQLDatabaseManager) mcMMO.getDatabaseManager(); SQLDatabaseManager m = (SQLDatabaseManager) mcMMO.getDatabaseManager();
m.resetMobHealthSettings(); m.resetMobHealthSettings();
for (mmoPlayer player : mcMMO.getUserManager().getPlayers()) { for (McMMOPlayer mmoPlayer : mcMMO.getUserManager().getPlayers()) {
player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault()); mmoPlayer.setMobHealthBarType(Config.getInstance().getMobHealthbarDefault());
} }
sender.sendMessage("Mob health reset"); sender.sendMessage("Mob health reset");
return true; return true;
@ -28,8 +29,8 @@ public class MHDCommand implements TabExecutor {
if (mcMMO.getDatabaseManager() instanceof FlatFileDatabaseManager) { if (mcMMO.getDatabaseManager() instanceof FlatFileDatabaseManager) {
FlatFileDatabaseManager m = (FlatFileDatabaseManager) mcMMO.getDatabaseManager(); FlatFileDatabaseManager m = (FlatFileDatabaseManager) mcMMO.getDatabaseManager();
m.resetMobHealthSettings(); m.resetMobHealthSettings();
for (mmoPlayer player : mcMMO.getUserManager().getPlayers()) { for (McMMOPlayer mmoPlayer : mcMMO.getUserManager().getPlayers()) {
player.getProfile().setMobHealthbarType(Config.getInstance().getMobHealthbarDefault()); mmoPlayer.setMobHealthBarType(Config.getInstance().getMobHealthbarDefault());
} }
sender.sendMessage("Mob health reset"); sender.sendMessage("Mob health reset");
return true; return true;

View File

@ -4,26 +4,27 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class McgodCommand extends ToggleCommand { public class McgodCommand extends ToggleCommand {
@Override @Override
protected boolean hasOtherPermission(CommandSender sender) { protected boolean hasOtherPermission(@NotNull CommandSender sender) {
return Permissions.mcgodOthers(sender); return Permissions.mcgodOthers(sender);
} }
@Override @Override
protected boolean hasSelfPermission(CommandSender sender) { protected boolean hasSelfPermission(@NotNull CommandSender sender) {
return Permissions.mcgod(sender); return Permissions.mcgod(sender);
} }
@Override @Override
protected void applyCommandAction(McMMOPlayer mmoPlayer) { protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) {
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.GodMode." + (mmoPlayer.getGodMode() ? "Disabled" : "Enabled"))); mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.GodMode." + (mmoPlayer.getGodMode() ? "Disabled" : "Enabled")));
mmoPlayer.toggleGodMode(); mmoPlayer.toggleGodMode();
} }
@Override @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)); sender.sendMessage(LocaleLoader.getString("Commands.GodMode.Toggle", playerName));
} }
} }

View File

@ -4,30 +4,31 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class McrefreshCommand extends ToggleCommand { public class McrefreshCommand extends ToggleCommand {
@Override @Override
protected boolean hasOtherPermission(CommandSender sender) { protected boolean hasOtherPermission(@NotNull CommandSender sender) {
return Permissions.mcrefreshOthers(sender); return Permissions.mcrefreshOthers(sender);
} }
@Override @Override
protected boolean hasSelfPermission(CommandSender sender) { protected boolean hasSelfPermission(@NotNull CommandSender sender) {
return Permissions.mcrefresh(sender); return Permissions.mcrefresh(sender);
} }
@Override @Override
protected void applyCommandAction(McMMOPlayer mmoPlayer) { protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) {
mmoPlayer.setRecentlyHurtTimestamp(0); mmoPlayer.setRecentlyHurtTimestamp(0);
mmoPlayer.resetCooldowns(); mmoPlayer.getSuperAbilityManager().resetCooldowns();
mmoPlayer.getSuperAbilityManager().unprimeAllAbilityTools(); mmoPlayer.getSuperAbilityManager().unprimeAllAbilityTools();
mmoPlayer.getSuperAbilityManager().resetSuperAbilities(); mmoPlayer.getSuperAbilityManager().disableSuperAbilities();
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh")); mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
} }
@Override @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)); sender.sendMessage(LocaleLoader.getString("Commands.mcrefresh.Success", playerName));
} }
} }

View File

@ -1,11 +1,16 @@
package com.gmail.nossr50.commands; package com.gmail.nossr50.commands;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; 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.gmail.nossr50.util.commands.CommandUtils;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -30,7 +35,14 @@ public abstract class ToggleCommand implements TabExecutor {
return true; 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; return true;
case 1: case 1:
@ -40,17 +52,18 @@ public abstract class ToggleCommand implements TabExecutor {
} }
String playerName = CommandUtils.getMatchedPlayerName(args[0]); 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; return true;
} }
if (CommandUtils.isOffline(sender, mmoPlayer.getPlayer())) { if(mmoOther.getPlayer().isOnline()) {
return true; return false;
} }
applyCommandAction(mmoPlayer); applyCommandAction(mmoOther);
sendSuccessMessage(sender, playerName); sendSuccessMessage(sender, playerName);
return true; return true;
@ -68,8 +81,8 @@ public abstract class ToggleCommand implements TabExecutor {
return ImmutableList.of(); return ImmutableList.of();
} }
protected abstract boolean hasOtherPermission(CommandSender sender); protected abstract boolean hasOtherPermission(@NotNull CommandSender sender);
protected abstract boolean hasSelfPermission(CommandSender sender); protected abstract boolean hasSelfPermission(@NotNull CommandSender sender);
protected abstract void applyCommandAction(McMMOPlayer mmoPlayer); protected abstract void applyCommandAction(@NotNull McMMOPlayer mmoPlayer);
protected abstract void sendSuccessMessage(CommandSender sender, String playerName); protected abstract void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String playerName);
} }

View File

@ -1,6 +1,8 @@
package com.gmail.nossr50.commands.admin; package com.gmail.nossr50.commands.admin;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; 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 com.gmail.nossr50.util.player.NotificationManager;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -13,7 +15,13 @@ public class PlayerDebugCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if(sender instanceof Player) { 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 mmoPlayer.toggleDebugMode(); //Toggle debug mode
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mmoPlayer.isDebugMode())); NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mmoPlayer.isDebugMode()));
return true; return true;

View File

@ -5,26 +5,27 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class McChatSpy extends ToggleCommand { public class McChatSpy extends ToggleCommand {
@Override @Override
protected boolean hasOtherPermission(CommandSender sender) { protected boolean hasOtherPermission(@NotNull CommandSender sender) {
return Permissions.adminChatSpyOthers(sender); return Permissions.adminChatSpyOthers(sender);
} }
@Override @Override
protected boolean hasSelfPermission(CommandSender sender) { protected boolean hasSelfPermission(@NotNull CommandSender sender) {
return Permissions.adminChatSpy(sender); return Permissions.adminChatSpy(sender);
} }
@Override @Override
protected void applyCommandAction(McMMOPlayer mmoPlayer) { protected void applyCommandAction(@NotNull McMMOPlayer mmoPlayer) {
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.AdminChatSpy." + (mmoPlayer.isPartyChatSpying() ? "Disabled" : "Enabled"))); mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.AdminChatSpy." + (mmoPlayer.isPartyChatSpying() ? "Disabled" : "Enabled")));
mmoPlayer.togglePartyChatSpying(); mmoPlayer.togglePartyChatSpying();
} }
@Override @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)); sender.sendMessage(LocaleLoader.getString("Commands.AdminChatSpy.Toggle", playerName));
} }
} }

View File

@ -10,6 +10,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils; import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager; import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; 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) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) { if (args.length == 1) {
String playerName = CommandUtils.getMatchedPlayerName(args[0]); 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. PlayerProfile playerProfile = mcMMO.getUserManager().queryPlayer(playerName);
if (mmoPlayer == null) { Player targetPlayer = Bukkit.getPlayer(playerName);
PlayerProfile profile = mcMMO.getDatabaseManager().queryPlayerDataByUUID(playerName, false); // Temporary Profile
if (!CommandUtils.isLoaded(sender, profile)) { if(playerProfile == null) {
//TODO: Localize
sender.sendMessage("Data was not found in the database for the given player name!");
return true; 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); ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, profile);
if (!Config.getInstance().getInspectUseChat()) { if (!Config.getInstance().getInspectUseChat()) {
@ -59,30 +66,29 @@ public class InspectCommand implements TabExecutor {
for (PrimarySkillType skill : PrimarySkillType.MISC_SKILLS) { for (PrimarySkillType skill : PrimarySkillType.MISC_SKILLS) {
sender.sendMessage(CommandUtils.displaySkill(profile, skill)); sender.sendMessage(CommandUtils.displaySkill(profile, skill));
} }
} else { } 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")); sender.sendMessage(LocaleLoader.getString("Inspect.Offline"));
return true; return true;
} else if (CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) { } else if (CommandUtils.tooFar(sender, targetPlayer, Permissions.inspectFar(sender))) {
return true; return true;
} }
if (Config.getInstance().getScoreboardsEnabled() && sender instanceof Player && Config.getInstance().getInspectUseBoard()) { if (Config.getInstance().getScoreboardsEnabled()
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, mmoPlayer); && sender instanceof Player && Config.getInstance().getInspectUseBoard()) {
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, playerProfile);
if (!Config.getInstance().getInspectUseChat()) { if (!Config.getInstance().getInspectUseChat()) {
return true; return true;
} }
} }
sender.sendMessage(LocaleLoader.getString("Inspect.Stats", target.getName())); sender.sendMessage(LocaleLoader.getString("Inspect.Stats", targetPlayer.getName()));
CommandUtils.printGatheringSkills(target, sender); CommandUtils.printGatheringSkills(targetPlayer, sender);
CommandUtils.printCombatSkills(target, sender); CommandUtils.printCombatSkills(targetPlayer, sender);
CommandUtils.printMiscSkills(target, sender); CommandUtils.printMiscSkills(targetPlayer, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mmoPlayer.getPowerLevel())); sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", playerProfile.getExperienceManager().getPowerLevel()));
} }
return true; return true;

View File

@ -1,9 +1,9 @@
package com.gmail.nossr50.database; 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.PersistentPlayerDataBuilder;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.neetgames.mcmmo.exceptions.ProfileRetrievalException;
import org.apache.commons.lang.NullArgumentException; import org.apache.commons.lang.NullArgumentException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,13 +1,13 @@
package com.gmail.nossr50.database; 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.config.Config;
import com.gmail.nossr50.datatypes.database.DatabaseType; import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.database.PlayerStat; import com.gmail.nossr50.datatypes.database.PlayerStat;
import com.gmail.nossr50.datatypes.player.MMODataSnapshot; import com.gmail.nossr50.datatypes.player.MMODataSnapshot;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; 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.apache.commons.lang.NullArgumentException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -97,6 +97,15 @@ public interface DatabaseManager {
*/ */
@Nullable PlayerProfile queryPlayerDataByUUID(@NotNull UUID uuid, @NotNull String playerName) throws ProfileRetrievalException, NullArgumentException; @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 * 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, * If it fails to find data for this player, or if it does find data but the data is corrupted,

View File

@ -38,17 +38,12 @@ import net.kyori.adventure.identity.Identity;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue; 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.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class McMMOPlayer extends PlayerProfile implements Identified { public class McMMOPlayer extends PlayerProfile implements Identified {
@ -549,7 +544,7 @@ public class McMMOPlayer extends PlayerProfile implements Identified {
* Etc... * Etc...
*/ */
public void cleanup() { public void cleanup() {
superAbilityManager.resetSuperAbilities(); superAbilityManager.disableSuperAbilities();
getTamingManager().cleanupAllSummons(); getTamingManager().cleanupAllSummons();
} }

View File

@ -26,7 +26,7 @@
// //
// SkillUtils.removeAbilityBoostsFromInventory(player); // SkillUtils.removeAbilityBoostsFromInventory(player);
// //
// McMMOPlayer mmoPlayer = UserManager.getPlayer(player); // McMMOPlayer mmoPlayer = mcMMO.getUserManager().queryPlayer(player);
// //
// if(mmoPlayer == null) // if(mmoPlayer == null)
// return; // return;

View File

@ -57,6 +57,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -428,7 +429,7 @@ public class mcMMO extends JavaPlugin {
return salvageableManager; return salvageableManager;
} }
public static DatabaseManager getDatabaseManager() { public static @NotNull DatabaseManager getDatabaseManager() {
return databaseManager; return databaseManager;
} }
@ -666,7 +667,7 @@ public class mcMMO extends JavaPlugin {
return spawnedProjectileTracker; return spawnedProjectileTracker;
} }
public static UserManager getUserManager() { public static @NotNull UserManager getUserManager() {
return userManager; return userManager;
} }

View File

@ -13,6 +13,7 @@ import com.google.common.collect.ImmutableList;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -118,15 +119,6 @@ public final class CommandUtils {
return hasPlayerDataKey; 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) { public static boolean isInvalidInteger(CommandSender sender, String value) {
if (StringUtils.isInt(value)) { if (StringUtils.isInt(value)) {
return false; return false;
@ -204,11 +196,11 @@ public final class CommandUtils {
printMiscSkills(player, player); printMiscSkills(player, player);
} }
public static String displaySkill(PlayerProfile profile, PrimarySkillType skill) { public static String displaySkill(@NotNull PlayerProfile profile, @NotNull PrimarySkillType skill) {
if (skill.isChildSkill()) { if (skill.isChildSkill()) {
return LocaleLoader.getString("Skills.ChildStats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill)); 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), 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)); return LocaleLoader.getString("Skills.Stats", LocaleLoader.getString(StringUtils.getCapitalized(skill.toString()) + ".Listener") + " ", profile.getSkillLevel(skill), profile.getSkillXpLevel(skill), profile.getXpToLevel(skill));

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.interactions.NotificationType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; 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.AbilityToolType;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; 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 com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -35,9 +37,11 @@ public class SuperAbilityManager {
private boolean abilityActivationPermission = true; private boolean abilityActivationPermission = true;
private final Map<AbilityToolType, Boolean> toolMode = new HashMap<>(); private final Map<AbilityToolType, Boolean> toolMode = new HashMap<>();
private final PersistentPlayerData persistentPlayerData;
public SuperAbilityManager(McMMOPlayer mmoPlayer) { public SuperAbilityManager(@NotNull McMMOPlayer mmoPlayer, @NotNull PersistentPlayerData persistentPlayerData) {
this.mmoPlayer = mmoPlayer; this.mmoPlayer = mmoPlayer;
this.persistentPlayerData = persistentPlayerData;
this.player = mmoPlayer.getPlayer(); this.player = mmoPlayer.getPlayer();
for (SuperAbilityType superAbilityType : SuperAbilityType.values()) { for (SuperAbilityType superAbilityType : SuperAbilityType.values()) {
@ -231,13 +235,17 @@ public class SuperAbilityManager {
/** /**
* Reset the mode of all abilities. * Reset the mode of all abilities.
*/ */
public void resetSuperAbilities() { public void disableSuperAbilities() {
for (SuperAbilityType ability : SuperAbilityType.values()) { for (SuperAbilityType ability : SuperAbilityType.values()) {
// Correctly disable and handle any special deactivate code // Correctly disable and handle any special deactivate code
new AbilityDisableTask(mmoPlayer, ability).run(); new AbilityDisableTask(mmoPlayer, ability).run();
} }
} }
public void resetCooldowns() {
this.persistentPlayerData.resetCooldowns();
}
/** /**
* Get the mode of an ability. * Get the mode of an ability.
* *

View File

@ -67,6 +67,10 @@ public final class UserManager {
return null; return null;
} }
public @Nullable PlayerProfile queryPlayer(@NotNull String playerName) {
return mcMMO.getDatabaseManager().queryPlayerByName(playerName);
}
/** /**
* Remove a user. * Remove a user.
* *