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