McremoveCommand.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.gmail.nossr50.commands.database;
  2. import com.gmail.nossr50.locale.LocaleLoader;
  3. import com.gmail.nossr50.mcMMO;
  4. import com.gmail.nossr50.util.commands.CommandUtils;
  5. import com.google.common.collect.ImmutableList;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.command.TabExecutor;
  10. import org.bukkit.util.StringUtil;
  11. import org.jetbrains.annotations.NotNull;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import java.util.UUID;
  15. public class McremoveCommand implements TabExecutor {
  16. @Override
  17. public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
  18. if (args.length == 1) {
  19. String playerName = CommandUtils.getMatchedPlayerName(args[0]);
  20. if (mcMMO.getUserManager().getOfflinePlayer(playerName) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName, false))) {
  21. return true;
  22. }
  23. UUID uuid = null;
  24. if (Bukkit.getPlayer(playerName) != null) {
  25. uuid = Bukkit.getPlayer(playerName).getUniqueId();
  26. }
  27. if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) {
  28. sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
  29. } else {
  30. sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen.
  31. }
  32. return true;
  33. }
  34. return false;
  35. }
  36. @Override
  37. public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
  38. if (args.length == 1) {
  39. List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
  40. return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
  41. }
  42. return ImmutableList.of();
  43. }
  44. }