Advertisement
phanatic

Untitled

Nov 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. package net.skyline.core.bans.commands;
  2.  
  3. import net.skyline.core.Core;
  4. import net.skyline.core.bans.Ban;
  5. import net.skyline.core.bans.enums.PunishmentLength;
  6. import net.skyline.core.utils.ProfileUtils;
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandSender;
  11. import org.bukkit.entity.Player;
  12.  
  13. import java.util.UUID;
  14.  
  15. public class BanCommand extends Command {
  16.  
  17. private Core plugin;
  18.  
  19. public BanCommand(Core plugin, String name) {
  20. super(name);
  21. this.plugin = plugin;
  22. this.setUsage(ChatColor.RED + "/ban <player> <length> <reason> [-s]");
  23. }
  24.  
  25. private final String DEFAULT_REASON = "Unfair Advantage";
  26. @Override
  27. public boolean execute(CommandSender sender, String s, String[] args) {
  28.  
  29. if (!(sender.hasPermission("hexade.ban"))) {
  30. sender.sendMessage(ChatColor.RED + "No Permission.");
  31. return true;
  32. }
  33. if (args.length < 2) {
  34. sender.sendMessage(this.usageMessage);
  35. return true;
  36. }
  37. if (ProfileUtils.lookup(args[0]) != null) {
  38. ProfileUtils.PlayerProfile victim = ProfileUtils.lookup(args[0]);
  39. String reason = "";
  40. Ban ban = new Ban(sender, victim, plugin);
  41.  
  42. Long current = System.currentTimeMillis() / 1000;
  43. if (endsWith(args[1],"m", "h", "d", "w") && (isNumber(args[1].substring(0, args[1].length() - 1)))) {
  44. Long length = Long.parseLong(args[1].substring(0, args[1].length() - 1));
  45. switch (args[1].substring(args[1].length() - 1)) {
  46. case "m":
  47. ban.setLength((PunishmentLength.MINUTE.getLength() * length) + current);
  48. ban.setType(PunishmentLength.MINUTE);
  49. break;
  50. case "h":
  51. ban.setLength((PunishmentLength.HOUR.getLength() * length) + current);
  52. ban.setType(PunishmentLength.HOUR);
  53. break;
  54. case "d":
  55. ban.setLength((PunishmentLength.DAY.getLength() * length) + current);
  56. ban.setType(PunishmentLength.DAY);
  57. break;
  58. case "w":
  59. ban.setLength((PunishmentLength.WEEK.getLength() * length) + current);
  60. ban.setType(PunishmentLength.WEEK);
  61. break;
  62. }
  63.  
  64. for (int i = 2; i < args.length; i++) {
  65. reason = "";
  66. if (args[i].equalsIgnoreCase("-s")) continue;
  67. reason += args[i] + " ";
  68. }
  69. } else {
  70. ban.setLength(PunishmentLength.PERM.getLength() + current);
  71. ban.setType(PunishmentLength.PERM);
  72. for (int i = 1; i < args.length; i++) {
  73. if (args[i].equalsIgnoreCase("-s")) continue;
  74. reason += args[i] + " ";
  75. }
  76. }
  77. ban.setSilent(isSilent(args));
  78. if (reason == "") reason = DEFAULT_REASON;
  79. ban.setReason(reason);
  80. ban.executePunishment();
  81. Player player = Bukkit.getPlayer(victim.getId());
  82. if (player != null) player.kickPlayer(plugin.getUtilites().getBanMsg(ban.getType(), ban.getLength(), reason));
  83. } else {
  84. sender.sendMessage(ChatColor.RED + "Couldn't find player.");
  85. }
  86. return true;
  87. }
  88.  
  89. private boolean endsWith(String string, String... ends){
  90. for (String valid : ends){
  91. if (string.endsWith(valid)) return true;
  92. }
  93. return false;
  94.  
  95. }
  96. private boolean isSilent(String[] args) {
  97. return args[args.length - 1].equalsIgnoreCase("-s");
  98. }
  99. private boolean isNumber(String num) {
  100. if (num == null) throw new IllegalArgumentException("The potential number can't be null");
  101. return num.matches("\\d+");
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement