McremoveCommand.java 1.9 KB

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