1
0

Merge pull request 'Update PunishmentCommand' (#394) from CommandPunishment into master

Reviewed-on: SteamWar/BungeeCore#394
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-06-16 13:22:34 +02:00
Commit 5c534305d9

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -34,65 +35,67 @@ import java.util.Date;
public class PunishmentCommand { public class PunishmentCommand {
public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) { public PunishmentCommand(String command, Punishment.PunishmentType punishmentType) {
new BasicCommand(command, "bungeecore.ban") { new SWCommand(command, "bungeecore.ban") {
@Override @Register(description = "PUNISHMENT_USAGE")
public void execute(CommandSender sender, String[] args) { public void genericCommand(ProxiedPlayer player, String toPunish, String date, String... message) {
if (punishmentType.isNeedsAdmin() && !SteamwarUser.get((ProxiedPlayer) sender).getUserGroup().isAdminGroup()) { if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player).getUserGroup().isAdminGroup()) {
return;
}
if (args.length < 3) {
Message.send("PUNISHMENT_USAGE", sender, command);
return; return;
} }
SteamwarUser target = unsafeUser(sender, args[0]); SteamwarUser target = unsafeUser(player, toPunish);
if (target == null) if (target == null)
return; return;
Timestamp banTime = parseTime(sender, args[1]); Timestamp banTime = parseTime(player, date);
if (banTime == null) if (banTime == null)
return; return;
StringBuilder reason = new StringBuilder(); boolean isPerma = date.equalsIgnoreCase("perma");
for (int i = 2; i < args.length; i++) { String msg = String.join(" ", message);
reason.append(args[i]).append(" "); target.punish(punishmentType, banTime, msg, SteamwarUser.get(player.getName()).getId(), isPerma);
} Message.team(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), player.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg);
boolean isPerma = args[1].equalsIgnoreCase("perma");
String msg = reason.toString();
target.punish(punishmentType, banTime, msg, SteamwarUser.get(sender.getName()).getId(), isPerma);
Message.team(punishmentType.getTeamMessage(), new Message("PREFIX"), target.getUserName(), sender.getName(), new Message((isPerma ? "PUNISHMENT_PERMA" : "PUNISHMENT_UNTIL"), banTime), msg);
} }
}; };
if (punishmentType.getUnpunishmentMessage() == null) { if (punishmentType.getUnpunishmentMessage() == null) {
return; return;
} }
String antiCommand = "un" + command; String antiCommand = "un" + command;
new BasicCommand(antiCommand, "bungeecore.ban") { new SWCommand(antiCommand, "bungeecore.ban") {
@Override @Register(description = "PUNISHMENT_USAGE")
public void execute(CommandSender sender, String[] args) { public void genericCommand(ProxiedPlayer player, String toUnpunish) {
if (punishmentType.isNeedsAdmin() && !SteamwarUser.get((ProxiedPlayer) sender).getUserGroup().isAdminGroup()) { if (punishmentType.isNeedsAdmin() && !SteamwarUser.get(player).getUserGroup().isAdminGroup()) {
return;
}
if (args.length < 1) {
Message.send("UNPUNISHMENT_USAGE", sender, antiCommand);
return; return;
} }
SteamwarUser target = existingUser(sender, args[0]); SteamwarUser target = existingUser(player, toUnpunish);
if (target == null) if (target == null)
return; return;
if (!target.isPunished(punishmentType)) { if (!target.isPunished(punishmentType)) {
Message.send(punishmentType.getUsageNotPunished(), sender); Message.send(punishmentType.getUsageNotPunished(), player);
return; return;
} }
Message.send(punishmentType.getUnpunishmentMessage(), sender, target.getUserName()); Message.send(punishmentType.getUnpunishmentMessage(), player, target.getUserName());
target.punish(punishmentType, Timestamp.from(new Date().toInstant()), antiCommand, SteamwarUser.get(sender.getName()).getId(), false); target.punish(punishmentType, Timestamp.from(new Date().toInstant()), antiCommand, SteamwarUser.get(player.getName()).getId(), false);
} }
}; };
} }
protected SteamwarUser existingUser(CommandSender sender, String arg){
SteamwarUser target = SteamwarUser.get(arg);
if(target == null)
Message.send("UNKNOWN_PLAYER", sender);
return target;
}
protected SteamwarUser unsafeUser(CommandSender sender, String arg){
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg);
if(target == null)
Message.send("UNKNOWN_PLAYER", sender);
return target;
}
public static Timestamp parseTime(CommandSender sender, String arg) { public static Timestamp parseTime(CommandSender sender, String arg) {
if (arg.equalsIgnoreCase("perma")) { if (arg.equalsIgnoreCase("perma")) {
return Punishment.PERMA_TIME; return Punishment.PERMA_TIME;