mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +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:
parent
fea21195da
commit
8550240754
@ -35,6 +35,7 @@ public class Plex extends JavaPlugin
|
||||
private static Plex plugin;
|
||||
public Config config;
|
||||
public Config messages;
|
||||
public Config indefBans;
|
||||
private StorageType storageType = StorageType.SQLITE;
|
||||
|
||||
private SQLConnection sqlConnection;
|
||||
@ -64,6 +65,7 @@ public class Plex extends JavaPlugin
|
||||
plugin = this;
|
||||
config = new Config(this, "config.yml");
|
||||
messages = new Config(this, "messages.yml");
|
||||
indefBans = new Config(this, "indefbans.yml");
|
||||
|
||||
sqlConnection = new SQLConnection();
|
||||
mongoConnection = new MongoConnection();
|
||||
@ -75,6 +77,7 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
config.load();
|
||||
messages.load();
|
||||
indefBans.load();
|
||||
system = config.getString("commands.permissions");
|
||||
|
||||
try
|
||||
@ -122,6 +125,7 @@ public class Plex extends JavaPlugin
|
||||
PlexLog.log("Rank Manager initialized");
|
||||
|
||||
punishmentManager = new PunishmentManager();
|
||||
punishmentManager.mergeIndefiniteBans();
|
||||
// banManager = new BanManager();
|
||||
PlexLog.log("Punishment System initialized");
|
||||
|
||||
|
@ -31,12 +31,20 @@ public class PlexCMD extends PlexCommand
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
|
||||
|
||||
Plex.get().config.load();
|
||||
send(sender, "Reloaded config file");
|
||||
|
||||
Plex.get().messages.load();
|
||||
send(sender, "Reloaded messages file");
|
||||
|
||||
Plex.get().indefBans.load();
|
||||
Plex.get().getPunishmentManager().mergeIndefiniteBans();
|
||||
send(sender, "Reloaded indefinite bans");
|
||||
|
||||
Plex.get().getRankManager().importDefaultRanks();
|
||||
send(sender, "Imported ranks");
|
||||
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("redis"))
|
||||
|
@ -13,6 +13,27 @@ public class BanListener extends PlexListener
|
||||
@EventHandler
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
if (plugin.getPunishmentManager().isIndefUUIDBanned(event.getUniqueId()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateIndefBanMessage("UUID"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isIndefIPBanned(event.getAddress().getHostAddress()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateIndefBanMessage("IP"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isIndefUserBanned(event.getName()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||
Punishment.generateIndefBanMessage("username"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
||||
{
|
||||
PunishedPlayer player = PlayerCache.getPunishedPlayer(event.getUniqueId());
|
||||
|
@ -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);
|
||||
|
@ -4,42 +4,12 @@ import dev.plex.PlexBase;
|
||||
import dev.plex.util.PlexLog;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RedisConnection extends PlexBase
|
||||
{
|
||||
private Jedis jedis;
|
||||
|
||||
/*public JedisPool openPool()
|
||||
{
|
||||
JedisPoolConfig jedisConfig = new JedisPoolConfig();
|
||||
//jedisConfig.setMaxIdle(10);
|
||||
//jedisConfig.setMaxTotal(100);
|
||||
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(RedisConnection.class.getClassLoader());
|
||||
this.pool = new JedisPool(jedisConfig, plugin.config.getString("data.side.hostname"),
|
||||
plugin.config.getInt("data.side.port"));
|
||||
Thread.currentThread().setContextClassLoader(previous);
|
||||
PlexLog.log("Connected to Redis!");
|
||||
return pool;
|
||||
}
|
||||
|
||||
public Jedis getJedis()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.jedis = pool.getResource();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PlexLog.error("An error occurred with Redis.");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (plugin.config.getBoolean("data.side.auth"))
|
||||
{
|
||||
jedis.auth(plugin.config.getString("data.side.password"));
|
||||
}
|
||||
return jedis;
|
||||
}*/
|
||||
|
||||
public Jedis getJedis()
|
||||
{
|
||||
try
|
||||
@ -60,6 +30,16 @@ public class RedisConnection extends PlexBase
|
||||
return jedis;
|
||||
}
|
||||
|
||||
public void runAsync(Consumer<Jedis> jedisConsumer)
|
||||
{
|
||||
new Thread(() -> {
|
||||
try (Jedis jedis = getJedis())
|
||||
{
|
||||
jedisConsumer.accept(jedis);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public final boolean isEnabled()
|
||||
{
|
||||
return plugin.config.getBoolean("data.side.enabled");
|
||||
|
@ -8,18 +8,39 @@ public class PlexLog extends PlexBase
|
||||
{
|
||||
private static final boolean debugEnabled = plugin.config.getBoolean("debug");
|
||||
|
||||
public static void log(String message)
|
||||
public static void log(String message, Object... strings)
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
}
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.YELLOW + "[Plex] " + ChatColor.GRAY + "%s", message));
|
||||
}
|
||||
|
||||
public static void error(String message)
|
||||
public static void error(String message, Object... strings)
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
}
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error] " + ChatColor.GOLD + "%s", message));
|
||||
}
|
||||
|
||||
public static void debug(String message)
|
||||
public static void debug(String message, Object... strings)
|
||||
{
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
if (message.contains("{" + i + "}"))
|
||||
{
|
||||
message = message.replace("{" + i + "}", strings[i].toString());
|
||||
}
|
||||
}
|
||||
if (debugEnabled)
|
||||
{
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.DARK_PURPLE + "[Plex Debug] " + ChatColor.GOLD + "%s", message));
|
||||
|
@ -158,7 +158,7 @@ public class PlexUtils extends PlexBase
|
||||
|
||||
public static Component messageComponent(String entry, Object... objects)
|
||||
{
|
||||
return MiniMessage.miniMessage().parse(messageString(entry, objects));
|
||||
return MiniMessage.miniMessage().parse(LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(messageString(entry, objects))));
|
||||
}
|
||||
|
||||
public static String messageString(String entry, Object... objects)
|
||||
|
13
src/main/resources/indefbans.yml
Normal file
13
src/main/resources/indefbans.yml
Normal file
@ -0,0 +1,13 @@
|
||||
# Plex Indefinite Bans File
|
||||
# Players with their UUID / IP / Usernames in here will be indefinitely banned until removed
|
||||
|
||||
# List of permanently banned UUIDs
|
||||
# If you want to get someone's UUID, use https://api.ashcon.app/mojang/v2/user/<username>
|
||||
uuids: []
|
||||
|
||||
# List of permanently banned IP addresses
|
||||
ips: []
|
||||
|
||||
# List of permanently banned UUIDs
|
||||
# If you want to get someone's username, use https://api.ashcon.app/mojang/v2/user/<uuid>, or just remember it
|
||||
usernames: []
|
@ -15,6 +15,7 @@
|
||||
# 3. Expiry
|
||||
# 4. Punisher
|
||||
banMessage: "<red>You have been banned! You may appeal at <gold><v>.\n<red>Reason: <gold><v>\n<red>End date: <gold><v>\n<red>Banned by: <gold><v>"
|
||||
indefBanMessage: "<red>Your <v> is currently banned! You may appeal at <gold><v>."
|
||||
test: "this is a test message!"
|
||||
# 1. The command sender's username
|
||||
variableTest: "variable test with <v>!"
|
||||
|
Loading…
Reference in New Issue
Block a user