From 30d5a1d8881ff7708ee84efa50eff53d82f80705 Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Fri, 7 Aug 2020 20:51:47 -0400 Subject: [PATCH] -q arg for more commands - add `-q` arg for tban, warn, and tempban - add reasons to tban (#259) --- .idea/misc.xml | 2 +- .../totalfreedommod/command/Command_tban.java | 89 ++++++++++++++----- .../command/Command_tempban.java | 41 ++++++--- .../totalfreedommod/command/Command_warn.java | 56 +++++++----- 4 files changed, 132 insertions(+), 56 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 982bac40..602a0ddb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,5 +7,5 @@ - + \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java index a768890b..e7ce0b6a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tban.java @@ -8,6 +8,7 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; +import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; @@ -15,7 +16,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) -@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/ [reason]", aliases = "noob") +@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/ [-q] [reason]", aliases = "noob") public class Command_tban extends FreedomCommand { @@ -27,6 +28,17 @@ public class Command_tban extends FreedomCommand return false; } + boolean quiet = args[0].equalsIgnoreCase("-q"); + if (quiet) + { + args = org.apache.commons.lang3.ArrayUtils.subarray(args, 1, args.length); + + if (args.length < 1) + { + return false; + } + } + final String username; final List ips = new ArrayList<>(); @@ -49,27 +61,65 @@ public class Command_tban extends FreedomCommand final PlayerData entry = plugin.pl.getData(player); username = player.getName(); ips.addAll(entry.getIps()); - - // Strike with lightning - final Location targetPos = player.getLocation(); - for (int x = -1; x <= 1; x++) - { - for (int z = -1; z <= 1; z++) - { - final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z); - targetPos.getWorld().strikeLightning(strike_pos); - } - } - - // Kill player - player.setHealth(0.0); } String reason = null; - - if (player != null) + if (args.length > 1) { - FUtil.bcastMsg(sender.getName() + " - Tempbanning: " + player.getName() + " for 5 minutes", ChatColor.RED); + reason = StringUtils.join(args, " ", 1, args.length); + } + + StringBuilder kick = new StringBuilder() + .append(ChatColor.RED) + .append("You have been temporarily banned for five minutes. Please read totalfreedom.me for more info."); + + if (!quiet) + { + // Strike with lightning + if (player != null) + { + final Location targetPos = player.getLocation(); + for (int x = -1; x <= 1; x++) + { + for (int z = -1; z <= 1; z++) + { + final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z); + targetPos.getWorld().strikeLightning(strike_pos); + } + } + + // Kill player + player.setHealth(0.0); + + if (reason != null) + { + FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes - Reason: " + reason, true); + kick.append("\n") + .append(ChatColor.RED) + .append("Reason: ") + .append(ChatColor.GOLD) + .append(reason); + } + else + { + FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes", true); + } + } + } + else + { + if (player != null) + { + if (reason != null) + { + msg("Quietly temporarily banned " + player.getName() + " for 5 minutes."); + kick.append("\n") + .append(ChatColor.RED) + .append("Reason: ") + .append(ChatColor.GOLD) + .append(reason); + } + } } // Ban player @@ -83,12 +133,11 @@ public class Command_tban extends FreedomCommand // Kick player if (player != null) { - player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info."); + player.kickPlayer(kick.toString()); } // Log ban plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason)); - return true; } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java index 4310387a..c1d85427 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_tempban.java @@ -18,7 +18,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Temporarily ban someone.", usage = "/ [playername] [duration] [reason]") +@CommandParameters(description = "Temporarily ban someone.", usage = "/ [-q] [duration] [reason]") public class Command_tempban extends FreedomCommand { @@ -32,6 +32,17 @@ public class Command_tempban extends FreedomCommand return false; } + boolean quiet = args[0].equalsIgnoreCase("-q"); + if (quiet) + { + args = org.apache.commons.lang3.ArrayUtils.subarray(args, 1, args.length); + + if (args.length < 1) + { + return false; + } + } + final String username; final List ips = new ArrayList<>(); @@ -55,6 +66,7 @@ public class Command_tempban extends FreedomCommand username = player.getName(); ips.addAll(entry.getIps()); } + final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName()); Date expires = FUtil.parseDateOffset("30m"); @@ -72,18 +84,25 @@ public class Command_tempban extends FreedomCommand message.append(", Reason: \"").append(reason).append("\""); } - // strike with lightning effect: - final Location targetPos = player.getLocation(); - for (int x = -1; x <= 1; x++) + if (!quiet) { - for (int z = -1; z <= 1; z++) + // Strike with lightning + final Location targetPos = player.getLocation(); + for (int x = -1; x <= 1; x++) { - final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z); - targetPos.getWorld().strikeLightningEffect(strike_pos); + for (int z = -1; z <= 1; z++) + { + final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z); + targetPos.getWorld().strikeLightningEffect(strike_pos); + } } - } - FUtil.adminAction(sender.getName(), message.toString(), true); + FUtil.adminAction(sender.getName(), message.toString(), true); + } + else + { + msg("Quietly temporarily banned " + player.getName() + "."); + } Ban ban = Ban.forPlayerName(username, sender, expires, reason); for (String ip : ips) @@ -92,9 +111,7 @@ public class Command_tempban extends FreedomCommand } plugin.bm.addBan(ban); player.kickPlayer(ban.bakeKickMessage()); - plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason)); - return true; } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java index ad7f46aa..e3c86f5f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_warn.java @@ -9,33 +9,40 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Warns the specified player.", usage = "/ ") +@CommandParameters(description = "Warns the specified player.", usage = "/ [-q] ") public class Command_warn extends FreedomCommand { @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if (args.length < 2) + if (args.length == 0) { return false; } - Player player = getPlayer(args[0]); + boolean quiet = args[0].equalsIgnoreCase("-q"); + if (quiet) + { + args = org.apache.commons.lang3.ArrayUtils.subarray(args, 1, args.length); + if (args.length < 1) + { + return false; + } + } + + Player player = getPlayer(args[0]); if (player == null) { msg(PLAYER_NOT_FOUND); return true; } - if (sender instanceof Player) + if (playerSender == player) { - if (player.equals(playerSender)) - { - msg(ChatColor.RED + "Please, don't try to warn yourself."); - return true; - } + msg(ChatColor.RED + "Please, don't try to warn yourself."); + return true; } if (plugin.al.isAdmin(player)) @@ -45,23 +52,26 @@ public class Command_warn extends FreedomCommand } String warnReason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " "); - - msg(player, ChatColor.RED + "[WARNING] You received a warning from " + sender.getName() + ": " + warnReason); player.sendTitle(ChatColor.RED + "You've been warned.", ChatColor.YELLOW + "Reason: " + warnReason, 20, 100, 60); msg(ChatColor.GREEN + "You have successfully warned " + player.getName()); - final StringBuilder adminNotice = new StringBuilder() - .append(ChatColor.RED) - .append(sender.getName()) - .append(" - ") - .append("Warning: ") - .append(player.getName()) - .append(" - Reason: ") - .append(ChatColor.YELLOW) - .append(warnReason); - plugin.al.messageAllAdmins(adminNotice.toString()); + if (quiet) + { + msg("Warned " + player.getName() + " quietly"); + return true; + } + + msg(player, ChatColor.RED + "[WARNING] You received a warning from " + sender.getName() + ": " + warnReason); + String adminNotice = ChatColor.RED + + sender.getName() + + " - " + + "Warning: " + + player.getName() + + " - Reason: " + + ChatColor.YELLOW + + warnReason; + plugin.al.messageAllAdmins(adminNotice); plugin.pl.getPlayer(player).incrementWarnings(); - return true; } -} +} \ No newline at end of file