Prevents editing of dangerous and unimplemented config values

This commit is contained in:
2022-05-30 16:17:22 +02:00
parent fb080c21c4
commit 1bfa91a98b
7 changed files with 117 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
package net.knarcraft.stargatecommand;
import net.TheDgtl.Stargate.api.StargateAPI;
import net.TheDgtl.Stargate.config.ConfigurationOption;
import net.knarcraft.stargatecommand.command.CommandStarGateCommand;
import net.knarcraft.stargatecommand.command.StargateCommandTabCompleter;
import org.bukkit.command.PluginCommand;
@@ -8,14 +9,23 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
/**
* The main class for the Stargate-Command add-on
*/
@SuppressWarnings("unused")
public class StargateCommand extends JavaPlugin {
private List<ConfigurationOption> bannedConfigOptions;
@Override
public void onEnable() {
//Initialize the list of banned configuration options
if (bannedConfigOptions == null) {
initializeBannedConfigOptions();
}
//Get the Stargate API
ServicesManager servicesManager = this.getServer().getServicesManager();
RegisteredServiceProvider<StargateAPI> stargateProvider = servicesManager.getRegistration(StargateAPI.class);
@@ -25,8 +35,8 @@ public class StargateCommand extends JavaPlugin {
//Register commands
PluginCommand stargateCommand = this.getCommand("stargateCommand");
if (stargateCommand != null) {
stargateCommand.setExecutor(new CommandStarGateCommand(stargateAPI));
stargateCommand.setTabCompleter(new StargateCommandTabCompleter());
stargateCommand.setExecutor(new CommandStarGateCommand(stargateAPI, bannedConfigOptions));
stargateCommand.setTabCompleter(new StargateCommandTabCompleter(bannedConfigOptions));
}
} else {
throw new IllegalStateException("Unable to hook into Stargate. Make sure the Stargate plugin is installed " +
@@ -39,4 +49,32 @@ public class StargateCommand extends JavaPlugin {
//Currently, nothing needs to be disabled
}
/**
* Initializes the list of banned configuration options
*
* <p>The banned configuration options are those options that should never be updated manually, and the ones deemed
* too risky to be updated on a running Stargate instance.</p>
*/
private void initializeBannedConfigOptions() {
bannedConfigOptions = new ArrayList<>();
bannedConfigOptions.add(ConfigurationOption.CONFIG_VERSION);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_DATABASE);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_USERNAME);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_ADDRESS);
bannedConfigOptions.add(ConfigurationOption.DATABASE_NAME);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_INSTANCE_NAME);
bannedConfigOptions.add(ConfigurationOption.USING_REMOTE_DATABASE);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_DRIVER);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_PASSWORD);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_PORT);
bannedConfigOptions.add(ConfigurationOption.BUNGEE_USE_SSL);
bannedConfigOptions.add(ConfigurationOption.SHOW_HIKARI_CONFIG);
for (ConfigurationOption option : ConfigurationOption.values()) {
//Configuration options with a null description are unimplemented and should not be used
if (option.getDescription() == null) {
bannedConfigOptions.add(option);
}
}
}
}