Fixing...
Dieser Commit ist enthalten in:
Ursprung
f20be78c59
Commit
6607b736ee
@ -55,9 +55,8 @@ public class BanCommand extends BasicCommand {
|
|||||||
banReason.append(args[i]).append(" ");
|
banReason.append(args[i]).append(" ");
|
||||||
}
|
}
|
||||||
String msg = banReason.toString();
|
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"));
|
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){
|
public static Timestamp parseTime(CommandSender sender, String arg){
|
||||||
|
@ -51,8 +51,7 @@ public class MuteCommand extends BasicCommand {
|
|||||||
muteReason.append(args[i]).append(" ");
|
muteReason.append(args[i]).append(" ");
|
||||||
}
|
}
|
||||||
String msg = muteReason.toString();
|
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"));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ public class WhoisCommand extends BasicCommand {
|
|||||||
Team team = Team.get(user.getTeam());
|
Team team = Team.get(user.getTeam());
|
||||||
BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName());
|
BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName());
|
||||||
|
|
||||||
BungeeCore.send(player, "§7Bestrafungen: ");
|
BungeeCore.send(player, "§7Strafen: ");
|
||||||
for (Punishment punishment : Punishment.getAllPunishmentsByPlayer(user.getId())) {
|
for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) {
|
||||||
BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e"
|
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());
|
+ punishment.getStartTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " §c" + punishment.getReason());
|
||||||
}
|
}
|
||||||
|
@ -23,24 +23,22 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Punishment {
|
public class Punishment {
|
||||||
|
|
||||||
public static Punishment getPunishmentByPlayer(int user, PunishmentType type) {
|
public static Punishment getPunishmentOfPlayer(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());
|
ResultSet set = SQL.select("SELECT * FROM `Punishments` WHERE EndTime < NOW() AND UserId = ? AND Type = ? ORDER BY PunishmentId DESC LIMIT 1", user, type.name());
|
||||||
try {
|
try {
|
||||||
if(!set.next())
|
if(!set.next())
|
||||||
return null;
|
return null;
|
||||||
return new Punishment(set);
|
return new Punishment(set);
|
||||||
} catch (SQLException throwable) {
|
} catch (SQLException e) {
|
||||||
throwable.printStackTrace();
|
throw new SecurityException("Could not Load Punishments", e);
|
||||||
throw new SecurityException("Could not Load Punishments", throwable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<PunishmentType, Punishment> getPunishmentsByPlayer(int 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);
|
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE PunishmentId IN (SELECT MAX(PunishmentId) FROM Punishments WHERE UserId = ? GROUP BY Type)", user);
|
||||||
try {
|
try {
|
||||||
Map<PunishmentType, Punishment> punishmentMap = new HashMap<>();
|
Map<PunishmentType, Punishment> punishmentMap = new HashMap<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
@ -48,30 +46,28 @@ public class Punishment {
|
|||||||
punishmentMap.put(punishment.getType(), punishment);
|
punishmentMap.put(punishment.getType(), punishment);
|
||||||
}
|
}
|
||||||
return punishmentMap;
|
return punishmentMap;
|
||||||
} catch (SQLException throwable) {
|
} catch (SQLException e) {
|
||||||
throwable.printStackTrace();
|
throw new SecurityException("Could not Load Punishments", e);
|
||||||
throw new SecurityException("Could not Load Punishments", throwable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC", user);
|
||||||
try {
|
try {
|
||||||
Set<Punishment> punishments = new HashSet<>();
|
List<Punishment> punishments = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
punishments.add(new Punishment(set));
|
punishments.add(new Punishment(set));
|
||||||
}
|
}
|
||||||
return punishments;
|
return punishments;
|
||||||
} catch (SQLException throwable) {
|
} catch (SQLException e) {
|
||||||
throwable.printStackTrace();
|
throw new SecurityException("Could not Load all Punishments", e);
|
||||||
throw new SecurityException("Could not Load all Punishments", throwable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Punishment createPunishment(int user, int executor, PunishmentType type, String reason, Timestamp endTime, Boolean perma) {
|
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 (?, ?, ?, ?, ?, ?)",
|
SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
user, executor, type.toDb(), reason, endTime, perma);
|
user, executor, type.name(), reason, endTime, perma);
|
||||||
return getPunishmentByPlayer(user, type);
|
return getPunishmentOfPlayer(user, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Timestamp startTime;
|
private final Timestamp startTime;
|
||||||
@ -79,15 +75,13 @@ public class Punishment {
|
|||||||
private final PunishmentType type;
|
private final PunishmentType type;
|
||||||
private final int user;
|
private final int user;
|
||||||
private final String reason;
|
private final String reason;
|
||||||
private final int id;
|
|
||||||
private final int punisher;
|
private final int punisher;
|
||||||
private final boolean perma;
|
private final boolean perma;
|
||||||
|
|
||||||
private Punishment(ResultSet set) throws SQLException {
|
private Punishment(ResultSet set) throws SQLException {
|
||||||
id = set.getInt("PunishmentId");
|
|
||||||
user = set.getInt("UserId");
|
user = set.getInt("UserId");
|
||||||
reason = set.getString("Reason");
|
reason = set.getString("Reason");
|
||||||
type = PunishmentType.getTypeFromDB(set.getString("Type"));
|
type = PunishmentType.valueOf(set.getString("Type"));
|
||||||
startTime = set.getTimestamp("StartTime");
|
startTime = set.getTimestamp("StartTime");
|
||||||
endTime = set.getTimestamp("EndTime");
|
endTime = set.getTimestamp("EndTime");
|
||||||
punisher = set.getInt("Punisher");
|
punisher = set.getInt("Punisher");
|
||||||
@ -114,10 +108,6 @@ public class Punishment {
|
|||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPunisher() {
|
public int getPunisher() {
|
||||||
return punisher;
|
return punisher;
|
||||||
}
|
}
|
||||||
@ -129,13 +119,5 @@ public class Punishment {
|
|||||||
public enum PunishmentType {
|
public enum PunishmentType {
|
||||||
Ban,
|
Ban,
|
||||||
Mute;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class SteamwarUser {
|
|||||||
usersById.put(id, this);
|
usersById.put(id, this);
|
||||||
usersByName.put(userName.toLowerCase(), this);
|
usersByName.put(userName.toLowerCase(), this);
|
||||||
usersByUUID.put(uuid, this);
|
usersByUUID.put(uuid, this);
|
||||||
punishments = Punishment.getPunishmentsByPlayer(id);
|
punishments = Punishment.getPunishmentsOfPlayer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SteamwarUser getOrCreate(PendingConnection connection){
|
public static SteamwarUser getOrCreate(PendingConnection connection){
|
||||||
@ -149,13 +149,19 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBanned() {
|
public boolean isBanned() {
|
||||||
return punishments.containsKey(Punishment.PunishmentType.Ban) &&
|
if(!punishments.containsKey(Punishment.PunishmentType.Ban))
|
||||||
(punishments.get(Punishment.PunishmentType.Ban).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Ban).isPerma());
|
return false;
|
||||||
|
return isCurrent(punishments.get(Punishment.PunishmentType.Ban));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMuted(){
|
public boolean isMuted(){
|
||||||
return punishments.containsKey(Punishment.PunishmentType.Mute) &&
|
if(!punishments.containsKey(Punishment.PunishmentType.Mute))
|
||||||
(punishments.get(Punishment.PunishmentType.Mute).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Mute).isPerma());
|
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(){
|
public TextComponent banMessage(){
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren