diff --git a/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java b/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java new file mode 100644 index 000000000..c4e556737 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/commands/AbilityToggleCommand.java @@ -0,0 +1,29 @@ +package com.gmail.nossr50.commands; + +import com.gmail.nossr50.datatypes.player.McMMOPlayer; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.util.Permissions; +import org.bukkit.command.CommandSender; + +public class AbilityToggleCommand extends ToggleCommand { + @Override + protected boolean hasOtherPermission(CommandSender sender) { + return Permissions.mcabilityOthers(sender); + } + + @Override + protected boolean hasSelfPermission(CommandSender sender) { + return Permissions.mcability(sender); + } + + @Override + protected void applyCommandAction(McMMOPlayer mcMMOPlayer) { + mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On"))); + mcMMOPlayer.toggleAbilityUse(); + } + + @Override + protected void sendSuccessMessage(CommandSender sender, String playerName) { + sender.sendMessage(LocaleLoader.getString("Commands.Ability.Toggle", playerName)); + } +} diff --git a/src/main/java/com/gmail/nossr50/commands/database/RemoveCommand.java b/src/main/java/com/gmail/nossr50/commands/database/RemoveCommand.java new file mode 100644 index 000000000..e3bb66c34 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/commands/database/RemoveCommand.java @@ -0,0 +1,54 @@ +package com.gmail.nossr50.commands.database; + +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.util.commands.CommandUtils; +import com.gmail.nossr50.util.player.UserManager; +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; +import org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class RemoveCommand implements TabExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + if (args.length == 1) { + String playerName = CommandUtils.getMatchedPlayerName(args[0]); + + if (UserManager.getOfflinePlayer(playerName) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName))) { + return true; + } + + UUID uuid = null; + + if (Bukkit.getPlayer(playerName) != null) { + uuid = Bukkit.getPlayer(playerName).getUniqueId(); + } + + if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) { + sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName)); + } else { + sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen. + } + + return true; + } + return false; + } + + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { + if (args.length == 1) { + List playerNames = CommandUtils.getOnlinePlayerNames(sender); + return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size())); + } + return ImmutableList.of(); + } +} diff --git a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java index b0410a3dd..7b1c34e80 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java @@ -7,6 +7,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; +import com.neetgames.mcmmo.experience.XPGainReason; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java index 801bc3b03..f65baac39 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java @@ -8,6 +8,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; +import com.neetgames.mcmmo.experience.XPGainReason; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/SkillResetCommand.java similarity index 98% rename from src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java rename to src/main/java/com/gmail/nossr50/commands/experience/SkillResetCommand.java index e73d96183..890982735 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/SkillResetCommand.java @@ -1,6 +1,5 @@ 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; @@ -27,7 +26,7 @@ import java.util.UUID; * This class mirrors the structure of ExperienceCommand, except the * value/quantity argument is removed. */ -public class SkillresetCommand implements TabExecutor { +public class SkillResetCommand implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { PrimarySkillType skill; diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 206ae2cc1..aba711ca0 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -708,10 +708,6 @@ public class mcMMO extends JavaPlugin { return spawnedProjectileTracker; } - public static @NotNull UserManager getUserManager() { - return userManager; - } - public static @NotNull PartyManager getPartyManager() { return partyManager; } diff --git a/src/main/java/com/gmail/nossr50/util/EventUtils.java b/src/main/java/com/gmail/nossr50/util/EventUtils.java index ecc77c753..e80cec0b8 100644 --- a/src/main/java/com/gmail/nossr50/util/EventUtils.java +++ b/src/main/java/com/gmail/nossr50/util/EventUtils.java @@ -1,6 +1,7 @@ package com.gmail.nossr50.util; 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.datatypes.skills.SubSkillType; @@ -31,6 +32,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.player.NotificationManager; import com.gmail.nossr50.util.skills.CombatUtils; +import com.neetgames.mcmmo.experience.XPGainReason; import com.neetgames.mcmmo.party.Party; import com.neetgames.mcmmo.player.OnlineMMOPlayer; import org.bukkit.block.Block; diff --git a/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java b/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java index 9274989f9..4e1810d0a 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandRegistrationManager.java @@ -6,11 +6,12 @@ import com.gmail.nossr50.commands.admin.McmmoReloadLocaleCommand; import com.gmail.nossr50.commands.admin.PlayerDebugCommand; import com.gmail.nossr50.commands.chat.McChatSpy; import com.gmail.nossr50.commands.database.McpurgeCommand; +import com.gmail.nossr50.commands.database.RemoveCommand; import com.gmail.nossr50.commands.database.MmoshowdbCommand; import com.gmail.nossr50.commands.experience.AddlevelsCommand; import com.gmail.nossr50.commands.experience.AddxpCommand; import com.gmail.nossr50.commands.experience.MmoeditCommand; -import com.gmail.nossr50.commands.experience.SkillresetCommand; +import com.gmail.nossr50.commands.experience.SkillResetCommand; import com.gmail.nossr50.commands.party.PartyCommand; import com.gmail.nossr50.commands.party.teleport.PtpCommand; import com.gmail.nossr50.commands.player.*; @@ -206,7 +207,7 @@ public final class CommandRegistrationManager { command.setPermission("mcmmo.commands.skillreset;mcmmo.commands.skillreset.others"); // Only need the main ones, not the individual skill ones command.setPermissionMessage(permissionsMessage); command.setUsage(LocaleLoader.getString("Commands.Usage.2", "skillreset", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]", "<" + LocaleLoader.getString("Commands.Usage.Skill") + ">")); - command.setExecutor(new SkillresetCommand()); + command.setExecutor(new SkillResetCommand()); } private static void registerXprateCommand() { @@ -302,7 +303,7 @@ public final class CommandRegistrationManager { command.setPermission("mcmmo.commands.mcremove"); command.setPermissionMessage(permissionsMessage); command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcremove", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">")); - command.setExecutor(new DatabaseRemovePlayerCommand()); + command.setExecutor(new RemoveCommand()); } private static void registerMmoshowdbCommand() { 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 8571246f5..e525c0ca4 100644 --- a/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java +++ b/src/main/java/com/gmail/nossr50/util/commands/CommandUtils.java @@ -1,11 +1,13 @@ package com.gmail.nossr50.util.commands; 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.Misc; +import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.text.StringUtils; import com.google.common.collect.ImmutableList; @@ -77,9 +79,9 @@ public final class CommandUtils { * * @return true if the player is online and a valid mmoPlayer object was found */ - public static boolean checkPlayerExistence(CommandSender sender, String playerName, OnlineMMOPlayer mmoPlayer) { - if (mmoPlayer != null) { - if (CommandUtils.hidden(sender, Misc.adaptPlayer(mmoPlayer), false)) { + public static boolean checkPlayerExistence(CommandSender sender, String playerName, McMMOPlayer mcMMOPlayer) { + if (mcMMOPlayer != null) { + if (CommandUtils.hidden(sender, mcMMOPlayer.getPlayer(), false)) { sender.sendMessage(LocaleLoader.getString("Commands.Offline")); return false; } @@ -88,7 +90,7 @@ public final class CommandUtils { PlayerProfile profile = new PlayerProfile(playerName, false); - if (hasNoProfile(sender, profile)) { + if (unloadedProfile(sender, profile)) { return false; } @@ -96,12 +98,12 @@ public final class CommandUtils { return false; } - public static boolean hasNoProfile(CommandSender sender, PlayerProfile profile) { + public static boolean unloadedProfile(CommandSender sender, PlayerProfile profile) { if (profile.isLoaded()) { return false; } - + sender.sendMessage(LocaleLoader.getString("Commands.Offline")); return true; } @@ -119,6 +121,15 @@ 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; @@ -207,10 +218,10 @@ public final class CommandUtils { } private static void printGroupedSkillData(Player inspect, CommandSender display, String header, List skillGroup) { - if(UserManager.queryPlayer(inspect) == null) + if(UserManager.getPlayer(inspect) == null) return; - PlayerProfile profile = UserManager.queryPlayer(inspect); + PlayerProfile profile = UserManager.getPlayer(inspect).getProfile(); List displayData = new ArrayList<>(); displayData.add(header);