Skip to content

Commit

Permalink
Refactored the Config File
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Aug 28, 2024
1 parent f904345 commit 9991da2
Show file tree
Hide file tree
Showing 36 changed files with 504 additions and 519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.beanbeanjuice.simpleproxychat.discord.Bot;
import com.beanbeanjuice.simpleproxychat.utility.UpdateChecker;
import com.beanbeanjuice.simpleproxychat.utility.config.Config;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigKey;
import com.beanbeanjuice.simpleproxychat.utility.status.ServerStatusManager;
import de.myzelyam.api.vanish.BungeeVanishAPI;
import litebans.api.Database;
Expand All @@ -28,12 +28,10 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.plugin.PluginManager;
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
import org.bstats.bungeecord.Metrics;

Expand All @@ -43,6 +41,7 @@

public final class SimpleProxyChatBungee extends Plugin implements ISimpleProxyChat {

@Getter private boolean pluginStarting = true;
@Getter private Config config;
@Getter private EpochHelper epochHelper;
@Getter private Bot discordBot;
Expand Down Expand Up @@ -92,15 +91,15 @@ public void onEnable() {
// Send Initial Server Status
discordBot.addRunnableToQueue(() -> {
this.getProxy().getScheduler().schedule(this, () -> {
this.config.overwrite(ConfigDataKey.PLUGIN_STARTING, false);
this.pluginStarting = false;

ServerStatusManager manager = serverListener.getServerStatusManager();
manager.getAllStatusStrings().forEach((string) -> this.getLogger().info(string));
manager.getAllStatusStrings().stream().map(Helper::sanitize).forEach((string) -> this.getLogger().info(string));

if (!config.getAsBoolean(ConfigDataKey.USE_INITIAL_SERVER_STATUS)) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;
if (!config.get(ConfigKey.USE_INITIAL_SERVER_STATUS).asBoolean()) return;
if (!config.get(ConfigKey.DISCORD_PROXY_STATUS_ENABLED).asBoolean()) return;
this.discordBot.sendMessageEmbed(manager.getAllStatusEmbed());
}, config.getAsInteger(ConfigDataKey.SERVER_UPDATE_INTERVAL) * 2L, TimeUnit.SECONDS);
}, config.get(ConfigKey.SERVER_UPDATE_INTERVAL).asInt() * 2L, TimeUnit.SECONDS);
});
}

Expand All @@ -111,11 +110,11 @@ private void startUpdateChecker() {
config,
currentVersion,
(message) -> {
if (!config.getAsBoolean(ConfigDataKey.UPDATE_NOTIFICATIONS)) return;
if (!config.get(ConfigKey.UPDATE_NOTIFICATIONS).asBoolean()) return;

this.getLogger().info(Helper.sanitize(message));

Component minimessage = MiniMessage.miniMessage().deserialize(config.getAsString(ConfigDataKey.PLUGIN_PREFIX) + message);
Component minimessage = MiniMessage.miniMessage().deserialize(config.get(ConfigKey.PLUGIN_PREFIX).asString() + message);
this.getProxy().getPlayers()
.stream()
.filter((player) -> player.hasPermission(Permission.READ_UPDATE_NOTIFICATION.getPermissionNode()))
Expand Down Expand Up @@ -156,12 +155,12 @@ private void hookPlugins() {
}

// Registering the Simple Ban System
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
getLogger().info("LiteBans and AdvancedBan not found. Using the built-in banning system for SimpleProxyChat...");
banHelper = new BanHelper(this.getDataFolder());
banHelper.initialize();
} else {
config.overwrite(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
config.overwrite(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
}
}

Expand All @@ -176,16 +175,16 @@ private void registerListeners() {
}

private void registerCommands() {
this.getProxy().getPluginManager().registerCommand(this, new BungeeReloadCommand(this, config.getAsArrayList(ConfigDataKey.RELOAD_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeChatToggleCommand(this, config.getAsArrayList(ConfigDataKey.CHAT_TOGGLE_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeWhisperCommand(this, config.getAsArrayList(ConfigDataKey.WHISPER_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeReplyCommand(this, config.getAsArrayList(ConfigDataKey.REPLY_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeBroadcastCommand(this, config.getAsArrayList(ConfigDataKey.BROADCAST_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeReloadCommand(this, config.get(ConfigKey.RELOAD_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeChatToggleCommand(this, config.get(ConfigKey.CHAT_TOGGLE_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeWhisperCommand(this, config.get(ConfigKey.WHISPER_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeReplyCommand(this, config.get(ConfigKey.REPLY_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeBroadcastCommand(this, config.get(ConfigKey.BROADCAST_ALIASES).asList().toArray(new String[0])));

// Only enable when needed.
if (config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
this.getProxy().getPluginManager().registerCommand(this, new BungeeBanCommand(this, config.getAsArrayList(ConfigDataKey.BAN_ALIASES).toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeUnbanCommand(this, config.getAsArrayList(ConfigDataKey.UNBAN_ALIASES).toArray(new String[0])));
if (config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
this.getProxy().getPluginManager().registerCommand(this, new BungeeBanCommand(this, config.get(ConfigKey.BAN_ALIASES).asList().toArray(new String[0])));
this.getProxy().getPluginManager().registerCommand(this, new BungeeUnbanCommand(this, config.get(ConfigKey.UNBAN_ALIASES).asList().toArray(new String[0])));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.beanbeanjuice.simpleproxychat.discord.Bot;
import com.beanbeanjuice.simpleproxychat.utility.helper.Helper;
import com.beanbeanjuice.simpleproxychat.utility.config.Config;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigDataKey;
import com.beanbeanjuice.simpleproxychat.utility.config.ConfigKey;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.event.PostOrder;
Expand All @@ -38,9 +38,7 @@
import me.leoko.advancedban.manager.UUIDManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
Expand All @@ -54,6 +52,8 @@ public class SimpleProxyChatVelocity implements ISimpleProxyChat {

private final Metrics.Factory metricsFactory;

@Getter private boolean pluginStarting = true;

@Getter private final ProxyServer proxyServer;
@Getter private final Logger logger;
@Getter private final Config config;
Expand Down Expand Up @@ -118,16 +118,16 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
// Send initial server status.
discordBot.addRunnableToQueue(() -> {
this.getProxyServer().getScheduler().buildTask(this, () -> {
this.config.overwrite(ConfigDataKey.PLUGIN_STARTING, false);
this.pluginStarting = false;

ServerStatusManager manager = serverListener.getServerStatusManager();
manager.getAllStatusStrings().forEach(this.getLogger()::info);
manager.getAllStatusStrings().stream().map(Helper::sanitize).forEach(this.getLogger()::info);

if (!config.getAsBoolean(ConfigDataKey.USE_INITIAL_SERVER_STATUS)) return;
if (!config.getAsBoolean(ConfigDataKey.DISCORD_PROXY_STATUS_ENABLED)) return;
if (!config.get(ConfigKey.USE_INITIAL_SERVER_STATUS).asBoolean()) return;
if (!config.get(ConfigKey.DISCORD_PROXY_STATUS_ENABLED).asBoolean()) return;
discordBot.sendMessageEmbed(manager.getAllStatusEmbed());
})
.delay(config.getAsInteger(ConfigDataKey.SERVER_UPDATE_INTERVAL) * 2L, TimeUnit.SECONDS)
.delay(config.get(ConfigKey.SERVER_UPDATE_INTERVAL).asInt() * 2L, TimeUnit.SECONDS)
.schedule();
});
}
Expand All @@ -141,12 +141,12 @@ private void startUpdateChecker() {
config,
currentVersion,
(message) -> {
if (!config.getAsBoolean(ConfigDataKey.UPDATE_NOTIFICATIONS)) return;
if (!config.get(ConfigKey.UPDATE_NOTIFICATIONS).asBoolean()) return;
this.getLogger().info(Helper.sanitize(message));
this.proxyServer.getAllPlayers()
.stream()
.filter((player) -> player.hasPermission(Permission.READ_UPDATE_NOTIFICATION.getPermissionNode()))
.forEach((player) -> player.sendMessage(Helper.stringToComponent(config.getAsString(ConfigDataKey.PLUGIN_PREFIX) + message)));
.forEach((player) -> player.sendMessage(Helper.stringToComponent(config.get(ConfigKey.PLUGIN_PREFIX).asString() + message)));
}
);

Expand Down Expand Up @@ -185,12 +185,12 @@ private void hookPlugins() {
}

// Registering the Simple Banning System
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
if (!this.isLiteBansEnabled() && !this.isAdvancedBanEnabled() && config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
getLogger().info("LiteBans and AdvancedBan not found. Using the built-in banning system for SimpleProxyChat...");
banHelper = new BanHelper(dataDirectory);
banHelper.initialize();
} else {
config.overwrite(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
config.overwrite(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM, false);
}
}

Expand All @@ -211,37 +211,37 @@ private void registerCommands() {
CommandManager commandManager = proxyServer.getCommandManager();

CommandMeta reloadCommand = commandManager.metaBuilder("spc-reload")
.aliases(config.getAsArrayList(ConfigDataKey.RELOAD_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.RELOAD_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta chatToggleCommand = commandManager.metaBuilder("spc-chat")
.aliases(config.getAsArrayList(ConfigDataKey.CHAT_TOGGLE_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.CHAT_TOGGLE_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta whisperCommand = commandManager.metaBuilder("spc-whisper")
.aliases(config.getAsArrayList(ConfigDataKey.WHISPER_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.WHISPER_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta replyCommand = commandManager.metaBuilder("spc-reply")
.aliases(config.getAsArrayList(ConfigDataKey.REPLY_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.REPLY_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta banCommand = commandManager.metaBuilder("spc-ban")
.aliases(config.getAsArrayList(ConfigDataKey.BAN_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.BAN_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta unbanCommand = commandManager.metaBuilder("spc-unban")
.aliases(config.getAsArrayList(ConfigDataKey.UNBAN_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.UNBAN_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

CommandMeta broadcastCommand = commandManager.metaBuilder("spc-broadcast")
.aliases(config.getAsArrayList(ConfigDataKey.BROADCAST_ALIASES).toArray(new String[0]))
.aliases(config.get(ConfigKey.BROADCAST_ALIASES).asList().toArray(new String[0]))
.plugin(this)
.build();

Expand All @@ -252,7 +252,7 @@ private void registerCommands() {
commandManager.register(broadcastCommand, new VelocityBroadcastCommand(this));

// Only enable if the Simple Banning System is enabled.
if (config.getAsBoolean(ConfigDataKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM)) {
if (config.get(ConfigKey.USE_SIMPLE_PROXY_CHAT_BANNING_SYSTEM).asBoolean()) {
commandManager.register(banCommand, new VelocityBanCommand(this));
commandManager.register(unbanCommand, new VelocityUnbanCommand(this));
}
Expand Down
Loading

0 comments on commit 9991da2

Please sign in to comment.