mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-01 23:56:40 +00:00
- Start the indefinite ban system, currently working with manually adding to the configuration.
- /plex reload reloads the indefinite bans - Fixed bug where AdminChat showed up with symbols still and not colorized in adminchat
This commit is contained in:
@ -49,6 +49,11 @@ public class Punishment
|
||||
DATE_FORMAT.format(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
||||
}
|
||||
|
||||
public static Component generateIndefBanMessage(String type)
|
||||
{
|
||||
return PlexUtils.messageComponent("indefBanMessage", type, banUrl);
|
||||
}
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
||||
|
@ -2,9 +2,12 @@ package dev.plex.punishment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@ -12,6 +15,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
@ -21,6 +25,7 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
@ -28,6 +33,77 @@ import redis.clients.jedis.Jedis;
|
||||
|
||||
public class PunishmentManager extends PlexBase
|
||||
{
|
||||
private final List<String> bannedIPs = Lists.newArrayList();
|
||||
private final List<String> bannedUsernames = Lists.newArrayList();
|
||||
private final List<UUID> bannedUUIDs = Lists.newArrayList();
|
||||
|
||||
public void mergeIndefiniteBans()
|
||||
{
|
||||
this.bannedUsernames.clear();
|
||||
this.bannedIPs.clear();
|
||||
this.bannedUUIDs.clear();
|
||||
|
||||
this.bannedUUIDs.addAll(Plex.get().indefBans.getStringList("uuids").stream().filter(string ->
|
||||
{
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(string);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}).map(UUID::fromString).toList());
|
||||
|
||||
this.bannedIPs.addAll(Plex.get().indefBans.getStringList("ips"));
|
||||
this.bannedUsernames.addAll(Plex.get().indefBans.getStringList("usernames"));
|
||||
|
||||
PlexLog.log("Loaded {0} UUID(s), {1} IP(s), and {2} username(s) into the indefinite banned list", this.bannedUUIDs.size(), this.bannedIPs.size(), this.bannedUsernames.size());
|
||||
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
PlexLog.log("Resetting redis indefinite bans lists and asynchronously uploading from configuration");
|
||||
Plex.get().getRedisConnection().runAsync(jedis -> {
|
||||
jedis.set("indefbanned-uuids", new Gson().toJson(this.bannedUUIDs));
|
||||
jedis.set("indefbanned-ips", new Gson().toJson(this.bannedIPs));
|
||||
jedis.set("indefbanned-users", new Gson().toJson(this.bannedUsernames));
|
||||
this.bannedIPs.clear();
|
||||
this.bannedUsernames.clear();
|
||||
this.bannedUUIDs.clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIndefUUIDBanned(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
List<UUID> uuids = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbanned-uuids"), new TypeToken<List<UUID>>(){}.getType());
|
||||
return uuids.contains(uuid);
|
||||
}
|
||||
return this.bannedUUIDs.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean isIndefIPBanned(String ip)
|
||||
{
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
List<String> ips = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbanned-ips"), new TypeToken<List<String>>(){}.getType());
|
||||
return ips.contains(ip);
|
||||
}
|
||||
return this.bannedIPs.contains(ip);
|
||||
}
|
||||
|
||||
public boolean isIndefUserBanned(String username)
|
||||
{
|
||||
if (Plex.get().getRedisConnection().isEnabled())
|
||||
{
|
||||
List<String> users = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbanned-users"), new TypeToken<List<String>>(){}.getType());
|
||||
return users.contains(username);
|
||||
}
|
||||
return this.bannedUsernames.contains(username);
|
||||
}
|
||||
|
||||
public void insertPunishment(PunishedPlayer player, Punishment punishment)
|
||||
{
|
||||
File file = player.getPunishmentsFile();
|
||||
@ -123,7 +199,7 @@ public class PunishmentManager extends PlexBase
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
|
||||
}
|
||||
@ -195,12 +271,6 @@ public class PunishmentManager extends PlexBase
|
||||
|
||||
private void issuePunishment(PunishedPlayer player, Punishment punishment)
|
||||
{
|
||||
/*if (punishment.getType() == PunishmentType.BAN)
|
||||
{
|
||||
// Ban ban = new Ban(punishment.getPunished(), (punishment.getPunisher() == null ? null : punishment.getPunisher()), "", punishment.getReason(), punishment.getEndDate());
|
||||
// Plex.get().getBanManager().executeBan(ban);
|
||||
}
|
||||
else*/
|
||||
if (punishment.getType() == PunishmentType.FREEZE)
|
||||
{
|
||||
player.setFrozen(true);
|
||||
|
Reference in New Issue
Block a user