Archiviert
1
0
Dieser Commit ist enthalten in:
Chaoscaot 2020-11-15 11:02:23 +01:00
Ursprung f20be78c59
Commit 6607b736ee
5 geänderte Dateien mit 30 neuen und 44 gelöschten Zeilen

Datei anzeigen

@ -55,9 +55,8 @@ public class BanCommand extends BasicCommand {
banReason.append(args[i]).append(" ");
}
String msg = banReason.toString();
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg);
ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason);
target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gebannt. §f§lGrund: §f" + banReason);
}
public static Timestamp parseTime(CommandSender sender, String arg){

Datei anzeigen

@ -51,8 +51,7 @@ public class MuteCommand extends BasicCommand {
muteReason.append(args[i]).append(" ");
}
String msg = muteReason.toString();
ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason);
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gemuted. Grund: §c" + msg);
target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
ServerTeamchatCommand.sendToTeam(BungeeCore.CHAT_PREFIX + "§c" + target.getUserName() + " wurde von " + sender.getName() + " " + (args[1].equalsIgnoreCase("perma")?"Permanent":"bis zum " + muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " gemuted. §f§lGrund: §f" + muteReason);
}
}

Datei anzeigen

@ -71,8 +71,8 @@ public class WhoisCommand extends BasicCommand {
Team team = Team.get(user.getTeam());
BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName());
BungeeCore.send(player, "§7Bestrafungen: ");
for (Punishment punishment : Punishment.getAllPunishmentsByPlayer(user.getId())) {
BungeeCore.send(player, "§7Strafen: ");
for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) {
BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e"
+ punishment.getStartTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " §c" + punishment.getReason());
}

Datei anzeigen

@ -23,24 +23,22 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
public class Punishment {
public static Punishment getPunishmentByPlayer(int user, PunishmentType type) {
ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE `PunishmentId` IN (SELECT MAX(`PunishmentId`) FROM Punishments WHERE UserId = ? AND Type = ?)", user, type.toDb());
public static Punishment getPunishmentOfPlayer(int user, PunishmentType type) {
ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE EndTime < NOW() AND UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1", user, type.name());
try {
if(!set.next())
return null;
return new Punishment(set);
} catch (SQLException throwable) {
throwable.printStackTrace();
throw new SecurityException("Could not Load Punishments", throwable);
} catch (SQLException e) {
throw new SecurityException("Could not Load Punishments", e);
}
}
public static Map<PunishmentType, Punishment> getPunishmentsByPlayer(int user) {
ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE `PunishmentId` IN (SELECT MAX(`PunishmentId`) FROM Punishments WHERE UserId = ? GROUP BY Type)", user);
public static Map<PunishmentType, Punishment> getPunishmentsOfPlayer(int user) {
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)", user);
try {
Map<PunishmentType, Punishment> punishmentMap = new HashMap<>();
while (set.next()) {
@ -48,30 +46,28 @@ public class Punishment {
punishmentMap.put(punishment.getType(), punishment);
}
return punishmentMap;
} catch (SQLException throwable) {
throwable.printStackTrace();
throw new SecurityException("Could not Load Punishments", throwable);
} catch (SQLException e) {
throw new SecurityException("Could not Load Punishments", e);
}
}
public static Set<Punishment> getAllPunishmentsByPlayer(int user) {
public static List<Punishment> getAllPunishmentsOfPlayer(int user) {
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC", user);
try {
Set<Punishment> punishments = new HashSet<>();
List<Punishment> punishments = new ArrayList<>();
while (set.next()) {
punishments.add(new Punishment(set));
}
return punishments;
} catch (SQLException throwable) {
throwable.printStackTrace();
throw new SecurityException("Could not Load all Punishments", throwable);
} catch (SQLException e) {
throw new SecurityException("Could not Load all Punishments", e);
}
}
public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, Boolean perma) {
SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)",
user, executor, type.toDb(), reason, endTime, perma);
return getPunishmentByPlayer(user, type);
user, executor, type.name(), reason, endTime, perma);
return getPunishmentOfPlayer(user, type);
}
private final Timestamp startTime;
@ -79,15 +75,13 @@ public class Punishment {
private final PunishmentType type;
private final int user;
private final String reason;
private final int id;
private final int punisher;
private final boolean perma;
private Punishment(ResultSet set) throws SQLException {
id = set.getInt("PunishmentId");
user = set.getInt("UserId");
reason = set.getString("Reason");
type = PunishmentType.getTypeFromDB(set.getString("Type"));
type = PunishmentType.valueOf(set.getString("Type"));
startTime = set.getTimestamp("StartTime");
endTime = set.getTimestamp("EndTime");
punisher = set.getInt("Punisher");
@ -114,10 +108,6 @@ public class Punishment {
return reason;
}
public int getId() {
return id;
}
public int getPunisher() {
return punisher;
}
@ -129,13 +119,5 @@ public class Punishment {
public enum PunishmentType {
Ban,
Mute;
public String toDb() {
return name().toLowerCase();
}
public static PunishmentType getTypeFromDB(String str) {
return Arrays.stream(values()).filter(punishmentType -> punishmentType.name().equalsIgnoreCase(str)).collect(Collectors.toList()).get(0);
}
}
}

Datei anzeigen

@ -68,7 +68,7 @@ public class SteamwarUser {
usersById.put(id, this);
usersByName.put(userName.toLowerCase(), this);
usersByUUID.put(uuid, this);
punishments = Punishment.getPunishmentsByPlayer(id);
punishments = Punishment.getPunishmentsOfPlayer(id);
}
public static SteamwarUser getOrCreate(PendingConnection connection){
@ -149,13 +149,19 @@ public class SteamwarUser {
}
public boolean isBanned() {
return punishments.containsKey(Punishment.PunishmentType.Ban) &&
(punishments.get(Punishment.PunishmentType.Ban).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Ban).isPerma());
if(!punishments.containsKey(Punishment.PunishmentType.Ban))
return false;
return isCurrent(punishments.get(Punishment.PunishmentType.Ban));
}
public boolean isMuted(){
return punishments.containsKey(Punishment.PunishmentType.Mute) &&
(punishments.get(Punishment.PunishmentType.Mute).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Mute).isPerma());
if(!punishments.containsKey(Punishment.PunishmentType.Mute))
return false;
return isCurrent(punishments.get(Punishment.PunishmentType.Mute));
}
private boolean isCurrent(Punishment punishment) {
return punishment.isPerma() || punishment.getEndTime().after(new Date());
}
public TextComponent banMessage(){