Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.skyline.core.bans.commands;
- import net.skyline.core.Core;
- import net.skyline.core.bans.Ban;
- import net.skyline.core.bans.enums.PunishmentLength;
- import net.skyline.core.utils.ProfileUtils;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import java.util.UUID;
- public class BanCommand extends Command {
- private Core plugin;
- public BanCommand(Core plugin, String name) {
- super(name);
- this.plugin = plugin;
- this.setUsage(ChatColor.RED + "/ban <player> <length> <reason> [-s]");
- }
- private final String DEFAULT_REASON = "Unfair Advantage";
- @Override
- public boolean execute(CommandSender sender, String s, String[] args) {
- if (!(sender.hasPermission("hexade.ban"))) {
- sender.sendMessage(ChatColor.RED + "No Permission.");
- return true;
- }
- if (args.length < 2) {
- sender.sendMessage(this.usageMessage);
- return true;
- }
- if (ProfileUtils.lookup(args[0]) != null) {
- ProfileUtils.PlayerProfile victim = ProfileUtils.lookup(args[0]);
- String reason = "";
- Ban ban = new Ban(sender, victim, plugin);
- Long current = System.currentTimeMillis() / 1000;
- if (endsWith(args[1],"m", "h", "d", "w") && (isNumber(args[1].substring(0, args[1].length() - 1)))) {
- Long length = Long.parseLong(args[1].substring(0, args[1].length() - 1));
- switch (args[1].substring(args[1].length() - 1)) {
- case "m":
- ban.setLength((PunishmentLength.MINUTE.getLength() * length) + current);
- ban.setType(PunishmentLength.MINUTE);
- break;
- case "h":
- ban.setLength((PunishmentLength.HOUR.getLength() * length) + current);
- ban.setType(PunishmentLength.HOUR);
- break;
- case "d":
- ban.setLength((PunishmentLength.DAY.getLength() * length) + current);
- ban.setType(PunishmentLength.DAY);
- break;
- case "w":
- ban.setLength((PunishmentLength.WEEK.getLength() * length) + current);
- ban.setType(PunishmentLength.WEEK);
- break;
- }
- for (int i = 2; i < args.length; i++) {
- reason = "";
- if (args[i].equalsIgnoreCase("-s")) continue;
- reason += args[i] + " ";
- }
- } else {
- ban.setLength(PunishmentLength.PERM.getLength() + current);
- ban.setType(PunishmentLength.PERM);
- for (int i = 1; i < args.length; i++) {
- if (args[i].equalsIgnoreCase("-s")) continue;
- reason += args[i] + " ";
- }
- }
- ban.setSilent(isSilent(args));
- if (reason == "") reason = DEFAULT_REASON;
- ban.setReason(reason);
- ban.executePunishment();
- Player player = Bukkit.getPlayer(victim.getId());
- if (player != null) player.kickPlayer(plugin.getUtilites().getBanMsg(ban.getType(), ban.getLength(), reason));
- } else {
- sender.sendMessage(ChatColor.RED + "Couldn't find player.");
- }
- return true;
- }
- private boolean endsWith(String string, String... ends){
- for (String valid : ends){
- if (string.endsWith(valid)) return true;
- }
- return false;
- }
- private boolean isSilent(String[] args) {
- return args[args.length - 1].equalsIgnoreCase("-s");
- }
- private boolean isNumber(String num) {
- if (num == null) throw new IllegalArgumentException("The potential number can't be null");
- return num.matches("\\d+");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement