Reorganize commands.yml, fix all deprecated code

This commit is contained in:
2025-12-25 19:26:39 -05:00
parent 39f79a931f
commit 03dc254cc8
8 changed files with 62 additions and 56 deletions
+2 -10
View File
@@ -43,7 +43,6 @@ public class Plex extends JavaPlugin
public Config config;
public Config messages;
public Config indefBans;
public Config commands;
public Config toggles;
public File modulesFolder;
private StorageType storageType = StorageType.SQLITE;
@@ -80,7 +79,6 @@ public class Plex extends JavaPlugin
config = new Config(this, "config.yml");
messages = new Config(this, "messages.yml");
indefBans = new Config(this, "indefbans.yml");
commands = new Config(this, "commands.yml");
toggles = new Config(this, "toggles.yml");
build.load(this);
@@ -106,7 +104,6 @@ public class Plex extends JavaPlugin
// Don't add default entries to these files
indefBans.load(false);
commands.load(false);
sqlConnection = new SQLConnection();
redisConnection = new RedisConnection();
@@ -201,13 +198,8 @@ public class Plex extends JavaPlugin
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
reloadPlayers();
PlexLog.debug("Registered Bukkit -> BungeeCord Plugin Messaging Channel");
PlexLog.debug("Velocity Support? " + BungeeUtil.isVelocity());
PlexLog.debug("BungeeCord Support? " + BungeeUtil.isBungeeCord());
if (BungeeUtil.isBungeeCord() && BungeeUtil.isVelocity())
{
PlexLog.warn("It seems you have both velocity and bungeecord configuration options enabled! When running Velocity, you do NOT need to enable bungeecord.");
}
PlexLog.debug("Registered Bukkit -> Proxy Plugin Messaging Channel");
PlexLog.debug("Proxy enabled? " + Bukkit.getServerConfig().isProxyEnabled());
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
moduleManager.enableModules();
@@ -51,8 +51,6 @@ public class PlexCMD extends PlexCommand
plugin.indefBans.load(false);
plugin.getPunishmentManager().mergeIndefiniteBans();
send(sender, "Reloaded indefinite bans");
plugin.commands.load();
send(sender, "Reloaded blocked commands file");
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
{
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
@@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class MuteListener extends PlexListener
{
List<String> commands = plugin.commands.getStringList("block_on_mute");
List<String> commands = plugin.config.getStringList("block_on_mute");
@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncChatEvent event)
@@ -24,7 +24,7 @@ import org.bukkit.projectiles.ProjectileSource;
public class TogglesListener extends PlexListener
{
List<String> commands = plugin.commands.getStringList("block_on_mute");
List<String> commands = plugin.config.getStringList("block_on_mute");
@EventHandler
public void onExplosionPrime(ExplosionPrimeEvent event)
@@ -10,20 +10,9 @@ import org.bukkit.entity.Player;
public class BungeeUtil
{
public static final boolean PROXIED_SERVER = isBungeeCord() || isVelocity();
public static boolean isBungeeCord()
{
return Bukkit.spigot().getSpigotConfig().getBoolean("settings.bungeecord");
}
public static boolean isVelocity()
{
return Bukkit.spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled") && !Bukkit.spigot().getPaperConfig().getString("settings.velocity-support.secret", "").isEmpty();
}
public static void kickPlayer(Player player, Component message)
{
if (PROXIED_SERVER)
if (Bukkit.getServerConfig().isProxyEnabled())
{
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("KickPlayer");
@@ -1,9 +1,16 @@
package dev.plex.util;
import dev.plex.Plex;
import java.util.Locale;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.key.Key;
import org.apache.commons.lang3.math.NumberUtils;
import org.bukkit.GameRule;
import org.bukkit.GameRules;
import org.bukkit.Registry;
import org.bukkit.World;
public class GameRuleUtil
@@ -24,34 +31,53 @@ public class GameRuleUtil
}
}
@SuppressWarnings("unchecked")
private static <T> void readGameRules(World world, String s)
private static void readGameRules(World world, String s)
{
String gameRule = s.split(";")[0];
T value = (T) s.split(";")[1];
GameRule<T> rule = (GameRule<T>) GameRule.getByName(gameRule);
if (rule != null && check(value).getClass().equals(rule.getType()))
String[] parts = s.split(";");
if (parts.length != 2)
{
world.setGameRule(rule, value);
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value);
PlexLog.error("Invalid game rule format: " + s);
return;
}
String gameRuleName = parts[0];
String valueString = parts[1];
Registry<GameRule<?>> gameRuleRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.GAME_RULE);
GameRule<?> rule = gameRuleRegistry.get(Key.key("minecraft", gameRuleName));
if (rule == null)
{
PlexLog.error(String.format("Unknown game rule: %s", gameRuleName));
return;
}
if (rule.getType() == Boolean.class)
{
@SuppressWarnings("unchecked")
GameRule<Boolean> boolRule = (GameRule<Boolean>) rule;
Boolean value = Boolean.parseBoolean(valueString);
world.setGameRule(boolRule, value);
PlexLog.debug("Setting game rule " + gameRuleName + " for world " + world.getName() + " with value " + value);
}
else if (rule.getType() == Integer.class)
{
@SuppressWarnings("unchecked")
GameRule<Integer> intRule = (GameRule<Integer>) rule;
try
{
Integer value = Integer.parseInt(valueString);
world.setGameRule(intRule, value);
PlexLog.debug("Setting game rule " + gameRuleName + " for world " + world.getName() + " with value " + value);
}
catch (NumberFormatException e)
{
PlexLog.error(String.format("Invalid integer value '%s' for game rule %s", valueString, gameRuleName));
}
}
else
{
PlexLog.error(String.format("Failed to set game rule %s for world %s with value %s!", gameRule, world.getName().toLowerCase(Locale.ROOT), value));
PlexLog.error(String.format("Unknown game rule type for %s: %s", gameRuleName, rule.getType()));
}
}
public static <T> Object check(T value)
{
if (value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("false"))
{
return Boolean.parseBoolean(value.toString());
}
if (NumberUtils.isCreatable(value.toString()))
{
return Integer.parseInt(value.toString());
}
return value;
}
}