Start getting rid of legacy strings

This commit is contained in:
Telesphoreo 2022-03-17 17:16:17 -05:00
parent 8f7fed5835
commit 3c0b79ba06
14 changed files with 198 additions and 129 deletions

View File

@ -23,18 +23,18 @@ import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.UpdateChecker;
import dev.plex.world.CustomWorld;
import java.io.File;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.UUID;
@Getter
@Setter
public class Plex extends JavaPlugin {
public class Plex extends JavaPlugin
{
private static Plex plugin;
public Config config;
public Config messages;
@ -63,19 +63,24 @@ public class Plex extends JavaPlugin {
private String system;
public static Plex get() {
public static Plex get()
{
return plugin;
}
@Override
public void onLoad() {
public void onLoad()
{
plugin = this;
config = new Config(this, "config.yml");
messages = new Config(this, "messages.yml");
indefBans = new Config(this, "indefbans.yml");
modulesFolder = new File(this.getDataFolder() + File.separator + "modules");
if (!modulesFolder.exists()) modulesFolder.mkdir();
if (!modulesFolder.exists())
{
modulesFolder.mkdir();
}
sqlConnection = new SQLConnection();
mongoConnection = new MongoConnection();
@ -87,19 +92,24 @@ public class Plex extends JavaPlugin {
}
@Override
public void onEnable() {
public void onEnable()
{
config.load();
messages.load();
// Don't add default entries to indefinite ban file
indefBans.load(false);
moduleManager.enableModules();
system = config.getString("commands.permissions");
try {
try
{
PlexUtils.testConnections();
PlexLog.log("Connected to " + storageType.name().toUpperCase());
} catch (Exception e) {
}
catch (Exception e)
{
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
e.printStackTrace();
}
@ -111,16 +121,22 @@ public class Plex extends JavaPlugin {
Metrics metrics = new Metrics(this, 14143);
PlexLog.log("Enabled Metrics");
if (redisConnection.isEnabled()) {
if (redisConnection.isEnabled())
{
redisConnection.getJedis();
PlexLog.log("Connected to Redis!");
} else {
}
else
{
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
}
if (storageType == StorageType.MONGODB) {
if (storageType == StorageType.MONGODB)
{
mongoPlayerData = new MongoPlayerData();
} else {
}
else
{
sqlPlayerData = new SQLPlayerData();
}
@ -148,24 +164,28 @@ public class Plex extends JavaPlugin {
}
@Override
public void onDisable() {
public void onDisable()
{
Bukkit.getOnlinePlayers().forEach(player ->
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
if (plugin.getRankManager().isAdmin(plexPlayer)) {
if (plugin.getRankManager().isAdmin(plexPlayer))
{
plugin.getAdminList().removeFromCache(UUID.fromString(plexPlayer.getUuid()));
}
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
} else if (sqlPlayerData != null) //sql checking
}
else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer);
}
});
if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected()) {
if (redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
{
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server!");
redisConnection.getJedis().close();
}
@ -173,21 +193,25 @@ public class Plex extends JavaPlugin {
moduleManager.disableModules();
}
private void generateWorlds() {
private void generateWorlds()
{
PlexLog.log("Generating any worlds if needed...");
for (String key : config.getConfigurationSection("worlds").getKeys(false)) {
for (String key : config.getConfigurationSection("worlds").getKeys(false))
{
CustomWorld.generateConfigFlatWorld(key);
}
PlexLog.log("Finished with world generation!");
}
private void reloadPlayers() {
private void reloadPlayers()
{
Bukkit.getOnlinePlayers().forEach(player ->
{
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId()));
if (plugin.getRankManager().isAdmin(plexPlayer)) {
if (plugin.getRankManager().isAdmin(plexPlayer))
{
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid()));
admin.setRank(plexPlayer.getRankFromString());

View File

@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import dev.morphia.Datastore;
import dev.morphia.query.Query;
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;

View File

@ -19,6 +19,7 @@ import java.util.Arrays;
import java.util.UUID;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
@ -90,9 +91,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
* Executes the command
*
* @param sender The sender of the command
* @param playerSender The player who executed the command (null if command source is console or if command source is any but console executed)
* @param playerSender The player who executed the command (null if CommandSource is console or if CommandSource is any but console executed)
* @param args A Kyori Component to send to the sender (can be null)
* @return
*/
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
@ -165,9 +165,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Checks if the string given is a command string
* Checks if the String given is a matching command
*
* @param label The string to check
* @param label The String to check
* @return true if the string is a command name or alias
*/
private boolean matches(String label)
@ -202,9 +202,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Sends a message to an audience
* Sends a message to an Audience
*
* @param audience The audience to send the message to
* @param audience The Audience to send the message to
* @param s The message to send
*/
protected void send(Audience audience, String s)
@ -213,10 +213,10 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Sends a message to an audience
* Sends a message to an Audience
*
* @param audience The audience to send the message to
* @param component The component to send
* @param audience The Audience to send the message to
* @param component The Component to send
*/
protected void send(Audience audience, Component component)
{
@ -226,7 +226,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
/**
* Checks whether a sender has enough permissions or is high enough a rank
*
* @param sender A command sender
* @param sender A CommandSender
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
@ -415,7 +415,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
*
* @param s The message entry
* @param objects Any objects to replace in order
* @return A Kyori component
* @return A Kyori Component
*/
protected Component messageComponent(String s, Object... objects)
{
@ -435,25 +435,25 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Converts usage to a component
* Converts usage to a Component
*
* @return A Kyori component stating the usage
* @return A Kyori Component stating the usage
*/
protected Component usage()
{
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + this.getUsage());
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(this.getUsage()).color(NamedTextColor.GRAY));
}
/**
* Converts usage to a component
* Converts usage to a Component
* <p>
* s The usage to convert
*
* @return A Kyori component stating the usage
* @return A Kyori Component stating the usage
*/
protected Component usage(String s)
{
return componentFromString(ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s);
return Component.text("Correct Usage: ").color(NamedTextColor.YELLOW).append(componentFromString(s).color(NamedTextColor.GRAY));
}
protected Player getNonNullPlayer(String name)
@ -498,21 +498,21 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
}
/**
* Converts a string to a legacy Kyori component
* Converts a String to a legacy Kyori Component
*
* @param s The string to convert
* @param s The String to convert
* @return A Kyori component
*/
protected Component componentFromString(String s)
{
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
}
/**
* Converts a string to a mini message kyori component
* Converts a String to a MiniMessage Component
*
* @param s The string to convert
* @return A Kyori component
* @param s The String to convert
* @return A Kyori Component
*/
protected Component mmString(String s)
{

View File

@ -7,20 +7,15 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.player.PunishedPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
public class LockupCMD extends PlexCommand

View File

@ -15,7 +15,6 @@ import java.util.Arrays;
import java.util.List;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@ -9,18 +9,16 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.module.PlexModule;
import dev.plex.module.PlexModuleFile;
import dev.plex.rank.enums.Rank;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.stream.Collectors;
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
public class PlexCMD extends PlexCommand
@ -31,10 +29,11 @@ public class PlexCMD extends PlexCommand
{
if (args.length == 0)
{
send(sender, ChatColor.LIGHT_PURPLE + "Plex - A new freedom plugin.");
send(sender, ChatColor.LIGHT_PURPLE + "Plugin version: " + plugin.getDescription().getVersion());
send(sender, ChatColor.LIGHT_PURPLE + "Authors: " + ChatColor.GOLD + "Telesphoreo, Taahh");
return componentFromString(ChatColor.LIGHT_PURPLE + "Run " + ChatColor.GOLD + "/plex modules" + ChatColor.LIGHT_PURPLE + " to see a list of modules.");
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion()));
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
return null;
}
if (args[0].equalsIgnoreCase("reload"))
{
@ -49,6 +48,7 @@ public class PlexCMD extends PlexCommand
plugin.getRankManager().importDefaultRanks();
send(sender, "Imported ranks");
send(sender, "Plex successfully reloaded.");
return null;
}
else if (args[0].equalsIgnoreCase("redis"))
{
@ -61,12 +61,13 @@ public class PlexCMD extends PlexCommand
send(sender, "Set test to 123. Now outputting key test...");
send(sender, plugin.getRedisConnection().getJedis().get("test"));
plugin.getRedisConnection().getJedis().close();
return null;
}
if (args[0].equalsIgnoreCase("modules"))
else if (args[0].equalsIgnoreCase("modules"))
{
if (args.length == 1)
{
return MiniMessage.miniMessage().deserialize("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
return mmString("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
}
if (args[1].equalsIgnoreCase("reload"))
{
@ -74,6 +75,7 @@ public class PlexCMD extends PlexCommand
plugin.getModuleManager().loadAllModules();
plugin.getModuleManager().loadModules();
plugin.getModuleManager().enableModules();
return null;
}
}
else
@ -86,6 +88,14 @@ public class PlexCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return ImmutableList.of("reload", "redis");
if (args.length == 0)
{
return ImmutableList.of("reload", "redis", "modules");
}
if (args[0].equalsIgnoreCase("modules"))
{
return ImmutableList.of("reload");
}
return Collections.emptyList();
}
}

View File

@ -2,16 +2,16 @@ package dev.plex.config;
import dev.plex.Plex;
import dev.plex.util.PlexLog;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* Creates a custom Config object
*/
public class Config extends YamlConfiguration {
public class Config extends YamlConfiguration
{
/**
* The plugin instance
*/
@ -38,12 +38,14 @@ public class Config extends YamlConfiguration {
* @param plugin The plugin instance
* @param name The file name
*/
public Config(Plex plugin, String name) {
public Config(Plex plugin, String name)
{
this.plugin = plugin;
this.file = new File(plugin.getDataFolder(), name);
this.name = name;
if (!file.exists()) {
if (!file.exists())
{
saveDefault();
}
}
@ -56,17 +58,22 @@ public class Config extends YamlConfiguration {
/**
* Loads the configuration file
*/
public void load(boolean loadFromFile) {
try {
if (loadFromFile) {
public void load(boolean loadFromFile)
{
try
{
if (loadFromFile)
{
YamlConfiguration externalYamlConfig = YamlConfiguration.loadConfiguration(file);
InputStreamReader internalConfigFileStream = new InputStreamReader(Plex.get().getResource(name), StandardCharsets.UTF_8);
YamlConfiguration internalYamlConfig = YamlConfiguration.loadConfiguration(internalConfigFileStream);
// Gets all the keys inside the internal file and iterates through all of it's key pairs
for (String string : internalYamlConfig.getKeys(true)) {
for (String string : internalYamlConfig.getKeys(true))
{
// Checks if the external file contains the key already.
if (!externalYamlConfig.contains(string)) {
if (!externalYamlConfig.contains(string))
{
// If it doesn't contain the key, we set the key based off what was found inside the plugin jar
externalYamlConfig.setComments(string, internalYamlConfig.getComments(string));
externalYamlConfig.set(string, internalYamlConfig.get(string));
@ -74,14 +81,17 @@ public class Config extends YamlConfiguration {
added = true;
}
}
if (added) {
if (added)
{
externalYamlConfig.save(file);
PlexLog.log("Saving new file...");
added = false;
}
}
super.load(file);
} catch (Exception ex) {
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
@ -89,10 +99,14 @@ public class Config extends YamlConfiguration {
/**
* Saves the configuration file
*/
public void save() {
try {
public void save()
{
try
{
super.save(file);
} catch (Exception ex) {
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
@ -100,7 +114,8 @@ public class Config extends YamlConfiguration {
/**
* Moves the configuration file from the plugin's resources folder to the data folder (plugins/Plex/)
*/
private void saveDefault() {
private void saveDefault()
{
plugin.saveResource(name, false);
}
}

View File

@ -4,10 +4,6 @@ import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.module.exception.ModuleLoadException;
import dev.plex.util.PlexLog;
import lombok.Getter;
import org.apache.logging.log4j.LogManager;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
@ -18,18 +14,26 @@ import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
import org.apache.logging.log4j.LogManager;
import org.bukkit.configuration.file.YamlConfiguration;
@Getter
public class ModuleManager {
public class ModuleManager
{
private final List<PlexModule> modules = Lists.newArrayList();
public void loadAllModules() {
public void loadAllModules()
{
this.modules.clear();
PlexLog.debug(String.valueOf(Plex.get().getModulesFolder().listFiles().length));
Arrays.stream(Plex.get().getModulesFolder().listFiles()).forEach(file -> {
if (file.getName().endsWith(".jar")) {
try {
Arrays.stream(Plex.get().getModulesFolder().listFiles()).forEach(file ->
{
if (file.getName().endsWith(".jar"))
{
try
{
URLClassLoader loader = new URLClassLoader(
new URL[]{file.toURI().toURL()},
Plex.class.getClassLoader()
@ -54,42 +58,54 @@ public class ModuleManager {
String version = internalModuleConfig.getString("version", "1.0");
PlexModuleFile plexModuleFile = new PlexModuleFile(name, main, description, version);
Class<? extends PlexModule> module = (Class<? extends PlexModule>) Class.forName(main, true, loader);
Class<? extends PlexModule> module = (Class<? extends PlexModule>)Class.forName(main, true, loader);
PlexModule plexModule = module.getConstructor().newInstance();
plexModule.setPlex(Plex.get());
plexModule.setPlexModuleFile(plexModuleFile);
plexModule.setDataFolder(new File(Plex.get().getModulesFolder() + File.separator + plexModuleFile.getName()));
if (!plexModule.getDataFolder().exists()) plexModule.getDataFolder().mkdir();
if (!plexModule.getDataFolder().exists())
{
plexModule.getDataFolder().mkdir();
}
plexModule.setLogger(LogManager.getLogger(plexModuleFile.getName()));
modules.add(plexModule);
} catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
}
catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e)
{
e.printStackTrace();
}
}
});
}
public void loadModules() {
this.modules.forEach(module -> {
public void loadModules()
{
this.modules.forEach(module ->
{
PlexLog.log("Loading module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
module.load();
});
}
public void enableModules() {
this.modules.forEach(module -> {
public void enableModules()
{
this.modules.forEach(module ->
{
PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
module.enable();
});
}
public void disableModules() {
this.modules.forEach(module -> {
public void disableModules()
{
this.modules.forEach(module ->
{
PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
module.getCommands().stream().toList().forEach(plexCommand -> {
module.getCommands().stream().toList().forEach(plexCommand ->
{
module.unregisterCommand(plexCommand);
Plex.get().getServer().getCommandMap().getKnownCommands().remove(plexCommand.getName());
plexCommand.getAliases().forEach(alias -> Plex.get().getServer().getCommandMap().getKnownCommands().remove(alias));
@ -99,12 +115,17 @@ public class ModuleManager {
});
}
public void unloadModules() {
public void unloadModules()
{
this.disableModules();
this.modules.forEach(module -> {
try {
this.modules.forEach(module ->
{
try
{
((URLClassLoader)module.getClass().getClassLoader()).close();
} catch (IOException e) {
}
catch (IOException e)
{
e.printStackTrace();
}
});

View File

@ -4,17 +4,14 @@ import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.listener.PlexListener;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.event.HandlerList;
import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.apache.logging.log4j.Logger;
import org.bukkit.event.HandlerList;
@Getter
@Setter(AccessLevel.MODULE)
@ -31,11 +28,17 @@ public abstract class PlexModule
private File dataFolder;
private Logger logger;
public void load() {}
public void load()
{
}
public void enable() {}
public void enable()
{
}
public void disable() {}
public void disable()
{
}
public void registerListener(PlexListener listener)
{

View File

@ -30,6 +30,7 @@ public class Punishment
private boolean customTime;
private boolean active; // Field is only for bans
private LocalDateTime endDate;
public Punishment(UUID punished, UUID punisher)
{
this.punished = punished;

View File

@ -7,7 +7,6 @@ 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;
@ -15,7 +14,6 @@ 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;
@ -24,11 +22,9 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Data;
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;
@ -41,7 +37,8 @@ public class PunishmentManager extends PlexBase
public void mergeIndefiniteBans()
{
this.indefiniteBans.clear();
Plex.get().indefBans.getKeys(false).forEach(key -> {
Plex.get().indefBans.getKeys(false).forEach(key ->
{
IndefiniteBan ban = new IndefiniteBan();
ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips"));
ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users"));
@ -54,7 +51,8 @@ public class PunishmentManager extends PlexBase
if (Plex.get().getRedisConnection().isEnabled())
{
PlexLog.log("Asynchronously uploading all indefinite bans to Redis");
Plex.get().getRedisConnection().runAsync(jedis -> {
Plex.get().getRedisConnection().runAsync(jedis ->
{
jedis.set("indefbans", new Gson().toJson(indefiniteBans));
});
}
@ -65,7 +63,9 @@ public class PunishmentManager extends PlexBase
if (Plex.get().getRedisConnection().isEnabled())
{
PlexLog.debug("Checking if UUID is banned in Redis");
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>(){}.getType());
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
{
}.getType());
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
}
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
@ -76,7 +76,9 @@ public class PunishmentManager extends PlexBase
if (Plex.get().getRedisConnection().isEnabled())
{
PlexLog.debug("Checking if IP is banned in Redis");
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>(){}.getType());
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
{
}.getType());
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
}
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
@ -87,7 +89,9 @@ public class PunishmentManager extends PlexBase
if (Plex.get().getRedisConnection().isEnabled())
{
PlexLog.debug("Checking if username is banned in Redis");
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>(){}.getType());
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
{
}.getType());
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
}
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));

View File

@ -4,13 +4,13 @@ import dev.plex.services.AbstractService;
public class UpdateCheckerService extends AbstractService
{
private boolean newVersion = false;
public UpdateCheckerService()
{
super(true, true);
}
private boolean newVersion = false;
@Override
public void run()
{

View File

@ -5,7 +5,6 @@ import com.mongodb.client.MongoClients;
import dev.morphia.Datastore;
import dev.morphia.Morphia;
import dev.morphia.mapping.MapperOptions;
import dev.plex.Plex;
import dev.plex.PlexBase;
import dev.plex.player.PlexPlayer;

View File

@ -2,9 +2,8 @@ package dev.plex.storage;
import dev.plex.PlexBase;
import dev.plex.util.PlexLog;
import redis.clients.jedis.Jedis;
import java.util.function.Consumer;
import redis.clients.jedis.Jedis;
public class RedisConnection extends PlexBase
{