-q arg for more commands

- add `-q` arg for tban, warn, and tempban
- add reasons to tban
(#259)
This commit is contained in:
speedxx 2020-08-07 20:51:47 -04:00
parent 86cf9dc344
commit 30d5a1d888
4 changed files with 132 additions and 56 deletions

2
.idea/misc.xml generated
View File

@ -7,5 +7,5 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="adopt-openj9-1.8" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project> </project>

View File

@ -8,6 +8,7 @@ import me.totalfreedom.totalfreedommod.punishments.Punishment;
import me.totalfreedom.totalfreedommod.punishments.PunishmentType; import me.totalfreedom.totalfreedommod.punishments.PunishmentType;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -15,7 +16,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true) @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> <username> [reason]", aliases = "noob") @CommandParameters(description = "Temporarily bans a player for five minutes.", usage = "/<command> [-q] <username> [reason]", aliases = "noob")
public class Command_tban extends FreedomCommand public class Command_tban extends FreedomCommand
{ {
@ -27,6 +28,17 @@ public class Command_tban extends FreedomCommand
return false; 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 String username;
final List<String> ips = new ArrayList<>(); final List<String> ips = new ArrayList<>();
@ -49,8 +61,23 @@ public class Command_tban extends FreedomCommand
final PlayerData entry = plugin.pl.getData(player); final PlayerData entry = plugin.pl.getData(player);
username = player.getName(); username = player.getName();
ips.addAll(entry.getIps()); ips.addAll(entry.getIps());
}
String reason = null;
if (args.length > 1)
{
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 // Strike with lightning
if (player != null)
{
final Location targetPos = player.getLocation(); final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
@ -63,13 +90,36 @@ public class Command_tban extends FreedomCommand
// Kill player // Kill player
player.setHealth(0.0); 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
String reason = null; {
FUtil.adminAction(sender.getName(), "Tempbanning " + player.getName() + " for 5 minutes", true);
}
}
}
else
{
if (player != null) if (player != null)
{ {
FUtil.bcastMsg(sender.getName() + " - Tempbanning: " + player.getName() + " for 5 minutes", ChatColor.RED); 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 // Ban player
@ -83,12 +133,11 @@ public class Command_tban extends FreedomCommand
// Kick player // Kick player
if (player != null) 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 // Log ban
plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason)); plugin.pul.logPunishment(new Punishment(username, ips.get(0), sender.getName(), PunishmentType.TEMPBAN, reason));
return true; return true;
} }
} }

View File

@ -18,7 +18,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [playername] [duration] [reason]") @CommandParameters(description = "Temporarily ban someone.", usage = "/<command> [-q] <username> [duration] [reason]")
public class Command_tempban extends FreedomCommand public class Command_tempban extends FreedomCommand
{ {
@ -32,6 +32,17 @@ public class Command_tempban extends FreedomCommand
return false; 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 String username;
final List<String> ips = new ArrayList<>(); final List<String> ips = new ArrayList<>();
@ -55,6 +66,7 @@ public class Command_tempban extends FreedomCommand
username = player.getName(); username = player.getName();
ips.addAll(entry.getIps()); ips.addAll(entry.getIps());
} }
final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName()); final StringBuilder message = new StringBuilder("Temporarily banned " + player.getName());
Date expires = FUtil.parseDateOffset("30m"); Date expires = FUtil.parseDateOffset("30m");
@ -72,7 +84,9 @@ public class Command_tempban extends FreedomCommand
message.append(", Reason: \"").append(reason).append("\""); message.append(", Reason: \"").append(reason).append("\"");
} }
// strike with lightning effect: if (!quiet)
{
// Strike with lightning
final Location targetPos = player.getLocation(); final Location targetPos = player.getLocation();
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
@ -84,6 +98,11 @@ public class Command_tempban extends FreedomCommand
} }
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); Ban ban = Ban.forPlayerName(username, sender, expires, reason);
for (String ip : ips) for (String ip : ips)
@ -92,9 +111,7 @@ public class Command_tempban extends FreedomCommand
} }
plugin.bm.addBan(ban); plugin.bm.addBan(ban);
player.kickPlayer(ban.bakeKickMessage()); player.kickPlayer(ban.bakeKickMessage());
plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason)); plugin.pul.logPunishment(new Punishment(player.getName(), FUtil.getIp(player), sender.getName(), PunishmentType.TEMPBAN, reason));
return true; return true;
} }
} }

View File

@ -9,34 +9,41 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Warns the specified player.", usage = "/<command> <player> <reason>") @CommandParameters(description = "Warns the specified player.", usage = "/<command> [-q] <player> <reason>")
public class Command_warn extends FreedomCommand public class Command_warn extends FreedomCommand
{ {
@Override @Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) 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; 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) if (player == null)
{ {
msg(PLAYER_NOT_FOUND); msg(PLAYER_NOT_FOUND);
return true; return true;
} }
if (sender instanceof Player) if (playerSender == player)
{
if (player.equals(playerSender))
{ {
msg(ChatColor.RED + "Please, don't try to warn yourself."); msg(ChatColor.RED + "Please, don't try to warn yourself.");
return true; return true;
} }
}
if (plugin.al.isAdmin(player)) 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), " "); 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); player.sendTitle(ChatColor.RED + "You've been warned.", ChatColor.YELLOW + "Reason: " + warnReason, 20, 100, 60);
msg(ChatColor.GREEN + "You have successfully warned " + player.getName()); 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(); plugin.pl.getPlayer(player).incrementWarnings();
return true; return true;
} }
} }