SteamWar/BungeeCore
Archiviert
13
2

Reworked Ban and Mute

Dieser Commit ist enthalten in:
Chaoscaot 2020-11-14 23:23:49 +01:00
Ursprung 8c3df0e1dd
Commit 986b53fbf8
10 geänderte Dateien mit 189 neuen und 57 gelöschten Zeilen

Datei anzeigen

@ -54,7 +54,7 @@ public class BungeeCore extends Plugin {
public static final String SERVER_TEAMCHAT_PREFIX = "§8STC §e";
public static final String TEAMCHAT_PREFIX = "§8TC §e";
public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy");
public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("HH:mm dd.MM.yyyy");
public static String CHAT_PREFIX;
public static String WORLD_FOLDER;

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp;
import java.text.ParseException;
@ -56,12 +57,12 @@ public class BanCommand extends BasicCommand {
}
String msg = banReason.toString();
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gebannt. Grund: §c" + msg);
target.ban(banTime, msg);
target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
}
public static Timestamp parseTime(CommandSender sender, String arg){
if(arg.equalsIgnoreCase("perma")) {
return Timestamp.from(Instant.ofEpochSecond(946674800));
return Timestamp.from(Instant.ofEpochSecond(946684800));
}else{
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy_HH:mm");
try{

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import java.sql.Timestamp;
import java.time.Instant;
public class MuteCommand extends BasicCommand {
@ -52,6 +53,6 @@ public class MuteCommand extends BasicCommand {
}
String msg = muteReason.toString();
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " gemuted. Grund: §c" + msg);
target.mute(muteTime, msg);
target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp;
import java.util.Date;
@ -44,6 +45,6 @@ public class UnbanCommand extends BasicCommand {
return;
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "Du hast " + target.getUserName() + " entbannt.");
target.ban(Timestamp.from(new Date().toInstant()), "");
target.ban(Timestamp.from(new Date().toInstant()), "Unban", SteamwarUser.get(sender.getName()).getId(), false);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
import net.md_5.bungee.api.CommandSender;
@ -70,11 +71,10 @@ public class WhoisCommand extends BasicCommand {
Team team = Team.get(user.getTeam());
BungeeCore.send(player, "§7Team§8: §e" + team.getTeamName());
if(user.isBanned()){
player.sendMessage(user.banMessage());
}
if(user.isMuted()){
player.sendMessage(user.muteMessage());
BungeeCore.send(player, "§7Bestrafungen: ");
for (Punishment punishment : Punishment.getAllPunishmentsByPlayer(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

@ -47,6 +47,15 @@ public class BanListener extends BasicListener {
List<BannedUserIPs> ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress());
if(!ips.isEmpty()){
if(ips.stream().anyMatch(bannedUserIPs -> bannedUserIPs.getUserID() == user.getId())) {
ips.forEach(bannedUserIPs -> {
if(bannedUserIPs.getUserID() == user.getId())
bannedUserIPs.remove();
});
ips.removeIf(bannedUserIPs -> bannedUserIPs.getUserID() == user.getId());
if(ips.isEmpty())
return;
}
StringBuilder potentialBan = new StringBuilder();
potentialBan.append(BungeeCore.CHAT_PREFIX);
potentialBan.append("§cMögliche Bannumgehung durch §r");

Datei anzeigen

@ -74,7 +74,7 @@ class Utils {
if(max == ModType.YELLOW)
player.disconnect(BungeeCore.stringToText("§7Deaktiviere den Mod §e" + mods.get(0).getModName() + "§7, um weiter auf §eSteam§8War §7spielen zu können."));
else{
user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung des Mods " + mods.get(0).getModName());
user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung des Mods " + mods.get(0).getModName(), 0, false);
BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen des Mods " + mods.get(0).getModName() + " gebannt.");
}
}else{
@ -84,7 +84,7 @@ class Utils {
if(max == ModType.YELLOW)
player.disconnect(BungeeCore.stringToText("§7Deaktiviere die Mods\n§e" + sb.toString() + "§7um weiter auf §eSteam§8War §7spielen zu können."));
else{
user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung der Mods\n" + sb.toString());
user.ban(Timestamp.from(Instant.now().plus(7, ChronoUnit.DAYS)), "Versuchte Benutzung der Mods\n" + sb.toString(), 0, false);
BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch wegen der Mods " + sb.toString() + " gebannt.");
}
}

Datei anzeigen

@ -78,4 +78,8 @@ public class BannedUserIPs {
public java.sql.Timestamp getTimestamp() {
return timestamp;
}
public void remove() {
SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", userID);
}
}

Datei anzeigen

@ -0,0 +1,141 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.sql;
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());
try {
if(!set.next())
return null;
return new Punishment(set);
} catch (SQLException throwable) {
throwable.printStackTrace();
throw new SecurityException("Could not Load Punishments", throwable);
}
}
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);
try {
Map<PunishmentType, Punishment> punishmentMap = new HashMap<>();
while (set.next()) {
Punishment punishment = new Punishment(set);
punishmentMap.put(punishment.getType(), punishment);
}
return punishmentMap;
} catch (SQLException throwable) {
throwable.printStackTrace();
throw new SecurityException("Could not Load Punishments", throwable);
}
}
public static Set<Punishment> getAllPunishmentsByPlayer(int user) {
ResultSet set = SQL.select("SELECT * FROM Punishments WHERE UserId = ? ORDER BY `PunishmentId` DESC", user);
try {
Set<Punishment> punishments = new HashSet<>();
while (set.next()) {
punishments.add(new Punishment(set));
}
return punishments;
} catch (SQLException throwable) {
throwable.printStackTrace();
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) {
SQL.update("INSERT INTO Punishments (UserId, Punisher, Type, Reason, EndTime, Perma) VALUES (?, ?, ?, ?, ?, ?)",
user, executor, type.toDb(), reason, endTime, perma);
return getPunishmentByPlayer(user, type);
}
private final Timestamp startTime;
private final Timestamp endTime;
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"));
startTime = set.getTimestamp("StartTime");
endTime = set.getTimestamp("EndTime");
punisher = set.getInt("Punisher");
perma = set.getBoolean("Perma");
}
public Timestamp getStartTime() {
return startTime;
}
public Timestamp getEndTime() {
return endTime;
}
public PunishmentType getType() {
return type;
}
public int getUser() {
return user;
}
public String getReason() {
return reason;
}
public int getId() {
return id;
}
public int getPunisher() {
return punisher;
}
public boolean isPerma() {
return perma;
}
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

@ -32,7 +32,6 @@ import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -43,16 +42,12 @@ public class SteamwarUser {
private final UUID uuid;
private String userName;
private UserGroup userGroup;
private Timestamp banTime;
private String banReason;
private int team;
private Timestamp muteTime;
private String muteReason;
private Map<Punishment.PunishmentType, Punishment> punishments;
private static final Map<String, SteamwarUser> usersByName = new HashMap<>();
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
private static final Timestamp PERMA_BAN = Timestamp.from(Instant.ofEpochSecond(946684800));
private static final InetAddress LIXFEL_DE;
static {
@ -69,14 +64,11 @@ public class SteamwarUser {
uuid = UUID.fromString(rs.getString("UUID"));
userName = rs.getString("UserName");
userGroup = UserGroup.getUsergroup(rs.getString("UserGroup"));
banTime = rs.getTimestamp("BanTime");
banReason = rs.getString("BanReason");
team = rs.getInt("Team");
muteTime = rs.getTimestamp("MuteTime");
muteReason = rs.getString("MuteReason");
usersById.put(id, this);
usersByName.put(userName.toLowerCase(), this);
usersByUUID.put(uuid, this);
punishments = Punishment.getPunishmentsByPlayer(id);
}
public static SteamwarUser getOrCreate(PendingConnection connection){
@ -157,47 +149,32 @@ public class SteamwarUser {
}
public boolean isBanned() {
if (banTime == null) {
return false;
} else if (banTime.after(new Date()) || banTime.before(PERMA_BAN)) {
return true;
} else {
SQL.update("UPDATE UserData SET BanTime = NULL, BanReason = '' WHERE id = ?", id);
SQL.update("DELETE FROM BannedUserIPs WHERE UserID = ?", id);
banTime = null;
banReason = "";
return false;
}
return punishments.containsKey(Punishment.PunishmentType.Ban) &&
(punishments.get(Punishment.PunishmentType.Ban).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Ban).isPerma());
}
public boolean isMuted(){
if(muteTime == null){
return false;
}else if(muteTime.after(new Date()) || muteTime.before(PERMA_BAN)){
return true;
}else{
SQL.update("UPDATE UserData SET MuteTime = NULL, MuteReason = '' WHERE id = ?", id);
muteTime = null;
muteReason = "";
return false;
}
return punishments.containsKey(Punishment.PunishmentType.Mute) &&
(punishments.get(Punishment.PunishmentType.Mute).getEndTime().after(new Date()) || punishments.get(Punishment.PunishmentType.Mute).isPerma());
}
public TextComponent banMessage(){
if (banTime.before(PERMA_BAN)) {
return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + banReason);
Punishment punishment = punishments.get(Punishment.PunishmentType.Ban);
if (punishment.isPerma()) {
return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gebannt. §r§lGrund§r: §c" + punishment.getReason());
} else {
return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " +
banTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gebannt. §r§lGrund§r: §c" + banReason);
punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gebannt. §r§lGrund§r: §c" + punishment.getReason());
}
}
public TextComponent muteMessage(){
if (muteTime.before(PERMA_BAN)) {
return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gemuted. §r§lGrund§r: §c" + muteReason);
Punishment punishment = punishments.get(Punishment.PunishmentType.Mute);
if (punishment.isPerma()) {
return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + "§cDu bist permanent gemuted. §r§lGrund§r: §c" + punishment.getReason());
} else {
return BungeeCore.stringToText(BungeeCore.CHAT_PREFIX + " Du bist bis zum " +
muteTime.toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gemuted. §r§lGrund§r: §c" + muteReason);
punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " gemuted. §r§lGrund§r: §c" + punishment.getReason());
}
}
@ -205,10 +182,9 @@ public class SteamwarUser {
BannedUserIPs.banIP(this, ip);
}
public void ban(Timestamp time, String banReason){
SQL.update("UPDATE UserData SET BanTime = ?, BanReason = ? WHERE id = ?", time, banReason, id);
banTime = time;
this.banReason = banReason;
public void ban(Timestamp time, String banReason, int from, boolean perma){
punishments.remove(Punishment.PunishmentType.Ban);
punishments.put(Punishment.PunishmentType.Ban, Punishment.createPunishment(id, from, Punishment.PunishmentType.Ban, banReason, time, perma));
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
if(player != null){
@ -218,10 +194,9 @@ public class SteamwarUser {
updateBanIP("");
}
public void mute(Timestamp time, String muteReason){
SQL.update("UPDATE UserData SET MuteTime = ?, MuteReason = ? WHERE id = ?", time, muteReason, id);
muteTime = time;
this.muteReason = muteReason;
public void mute(Timestamp time, String muteReason, int from, boolean perma){
punishments.remove(Punishment.PunishmentType.Mute);
punishments.put(Punishment.PunishmentType.Mute, Punishment.createPunishment(id, from, Punishment.PunishmentType.Mute, muteReason, time, perma));
}
private static SteamwarUser dbInit(ResultSet rs){