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 config;
public Config messages; public Config messages;
public Config indefBans; public Config indefBans;
public Config commands;
public Config toggles; public Config toggles;
public File modulesFolder; public File modulesFolder;
private StorageType storageType = StorageType.SQLITE; private StorageType storageType = StorageType.SQLITE;
@@ -80,7 +79,6 @@ public class Plex extends JavaPlugin
config = new Config(this, "config.yml"); config = new Config(this, "config.yml");
messages = new Config(this, "messages.yml"); messages = new Config(this, "messages.yml");
indefBans = new Config(this, "indefbans.yml"); indefBans = new Config(this, "indefbans.yml");
commands = new Config(this, "commands.yml");
toggles = new Config(this, "toggles.yml"); toggles = new Config(this, "toggles.yml");
build.load(this); build.load(this);
@@ -106,7 +104,6 @@ public class Plex extends JavaPlugin
// Don't add default entries to these files // Don't add default entries to these files
indefBans.load(false); indefBans.load(false);
commands.load(false);
sqlConnection = new SQLConnection(); sqlConnection = new SQLConnection();
redisConnection = new RedisConnection(); redisConnection = new RedisConnection();
@@ -201,13 +198,8 @@ public class Plex extends JavaPlugin
PlexLog.log("Started " + serviceManager.serviceCount() + " services."); PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
reloadPlayers(); reloadPlayers();
PlexLog.debug("Registered Bukkit -> BungeeCord Plugin Messaging Channel"); PlexLog.debug("Registered Bukkit -> Proxy Plugin Messaging Channel");
PlexLog.debug("Velocity Support? " + BungeeUtil.isVelocity()); PlexLog.debug("Proxy enabled? " + Bukkit.getServerConfig().isProxyEnabled());
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.");
}
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
moduleManager.enableModules(); moduleManager.enableModules();
@@ -51,8 +51,6 @@ public class PlexCMD extends PlexCommand
plugin.indefBans.load(false); plugin.indefBans.load(false);
plugin.getPunishmentManager().mergeIndefiniteBans(); plugin.getPunishmentManager().mergeIndefiniteBans();
send(sender, "Reloaded indefinite bans"); send(sender, "Reloaded indefinite bans");
plugin.commands.load();
send(sender, "Reloaded blocked commands file");
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
{ {
throw new RuntimeException("Vault is required to run on the server if you use permissions!"); 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 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) @EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncChatEvent event) public void onChat(AsyncChatEvent event)
@@ -24,7 +24,7 @@ import org.bukkit.projectiles.ProjectileSource;
public class TogglesListener extends PlexListener public class TogglesListener extends PlexListener
{ {
List<String> commands = plugin.commands.getStringList("block_on_mute"); List<String> commands = plugin.config.getStringList("block_on_mute");
@EventHandler @EventHandler
public void onExplosionPrime(ExplosionPrimeEvent event) public void onExplosionPrime(ExplosionPrimeEvent event)
@@ -10,20 +10,9 @@ import org.bukkit.entity.Player;
public class BungeeUtil 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) public static void kickPlayer(Player player, Component message)
{ {
if (PROXIED_SERVER) if (Bukkit.getServerConfig().isProxyEnabled())
{ {
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("KickPlayer"); out.writeUTF("KickPlayer");
@@ -1,9 +1,16 @@
package dev.plex.util; package dev.plex.util;
import dev.plex.Plex; import dev.plex.Plex;
import java.util.Locale; 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.apache.commons.lang3.math.NumberUtils;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.GameRules;
import org.bukkit.Registry;
import org.bukkit.World; import org.bukkit.World;
public class GameRuleUtil public class GameRuleUtil
@@ -24,34 +31,53 @@ public class GameRuleUtil
} }
} }
private static void readGameRules(World world, String s)
{
String[] parts = s.split(";");
if (parts.length != 2)
{
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") @SuppressWarnings("unchecked")
private static <T> void readGameRules(World world, String s) 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)
{ {
String gameRule = s.split(";")[0]; @SuppressWarnings("unchecked")
T value = (T) s.split(";")[1]; GameRule<Integer> intRule = (GameRule<Integer>) rule;
GameRule<T> rule = (GameRule<T>) GameRule.getByName(gameRule); try
if (rule != null && check(value).getClass().equals(rule.getType()))
{ {
world.setGameRule(rule, value); Integer value = Integer.parseInt(valueString);
PlexLog.debug("Setting game rule " + gameRule + " for world " + world.getName() + " with value " + value); 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 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;
}
} }
-7
View File
@@ -1,7 +0,0 @@
# These commands will be blocked when a player is muted or when chat is toggled off.
block_on_mute:
- me
- say
- msg
- reply
- mail
+8
View File
@@ -172,6 +172,14 @@ blocked_entities:
- "ENDER_DRAGON" - "ENDER_DRAGON"
- "MINECART_TNT" - "MINECART_TNT"
# These commands will be blocked when a player is muted or when chat is toggled off.
block_on_mute:
- me
- say
- msg
- reply
- mail
# Limit entities per chunk # Limit entities per chunk
entity_limit: entity_limit:
# Is the mob limit enabled? # Is the mob limit enabled?