Prevents editing of dangerous and unimplemented config values
This commit is contained in:
26
README.md
26
README.md
@@ -1,31 +1,37 @@
|
||||
> Please visit [our discord](https://discord.gg/mTaHuK6BVa) for all updates and support!
|
||||
|
||||
# Description
|
||||
|
||||
Stargate-Command is an addon for Stargate which adds additional useful commands to the vanilla Stargate experience.
|
||||
|
||||
#### Features:
|
||||
|
||||
* The ability to edit the config file through commands, and automated reloading of changed values
|
||||
|
||||
## Dependencies
|
||||
|
||||
[The most recent version of Stargate (> 1.0.0.4)](https://www.spigotmc.org/resources/stargate.87978/)
|
||||
|
||||
# Permissions
|
||||
|
||||
### Nodes
|
||||
|
||||
```
|
||||
stargate.command.config - Gives access to the `/sgc config` command
|
||||
```
|
||||
|
||||
# Changes
|
||||
|
||||
[Version 0.1.0]
|
||||
|
||||
- Full takeover removing old functionality, and, for now, replacing it with config editing
|
||||
[Version 0.0.4]
|
||||
- Fix for Bukkit's direction fix
|
||||
[Version 0.0.3]
|
||||
- Added /sgc owner <player> command
|
||||
- Now requires at least Stargate v0.7.8.0
|
||||
[Version 0.0.2]
|
||||
- Fix an issue with dialing on a specific network
|
||||
- Change permission checks to use Stargate, this allows proper permission debugging
|
||||
[Version 0.0.1]
|
||||
- Initial Release
|
||||
[Version 0.0.4]
|
||||
- Fix for Bukkit's direction fix
|
||||
[Version 0.0.3]
|
||||
- Added /sgc owner <player> command
|
||||
- Now requires at least Stargate v0.7.8.0
|
||||
[Version 0.0.2]
|
||||
- Fix an issue with dialing on a specific network
|
||||
- Change permission checks to use Stargate, this allows proper permission debugging
|
||||
[Version 0.0.1]
|
||||
- Initial Release
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command represents the config command for changing config values
|
||||
@@ -19,16 +20,19 @@ import java.util.Arrays;
|
||||
public class CommandConfig implements CommandExecutor {
|
||||
|
||||
private final ConfigurationAPI configurationAPI;
|
||||
private final List<ConfigurationOption> bannedConfigOptions;
|
||||
|
||||
/**
|
||||
* Instantiates a new instance of the config command
|
||||
*
|
||||
* @param configurationAPI <p>A reference to the Stargate API</p>
|
||||
* @param configurationAPI <p>A reference to the Stargate API</p>
|
||||
* @param bannedConfigOptions <p>A list of config options that shouldn't be available</p>
|
||||
*/
|
||||
public CommandConfig(ConfigurationAPI configurationAPI) {
|
||||
public CommandConfig(ConfigurationAPI configurationAPI, List<ConfigurationOption> bannedConfigOptions) {
|
||||
super();
|
||||
|
||||
this.configurationAPI = configurationAPI;
|
||||
this.bannedConfigOptions = bannedConfigOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +49,9 @@ public class CommandConfig implements CommandExecutor {
|
||||
ConfigurationOption selectedOption;
|
||||
try {
|
||||
selectedOption = ConfigurationOption.valueOf(args[0].toUpperCase());
|
||||
if (bannedConfigOptions.contains(selectedOption)) {
|
||||
return true;
|
||||
}
|
||||
} catch (IllegalArgumentException exception) {
|
||||
commandSender.sendMessage("Invalid configuration option specified");
|
||||
return true;
|
||||
@@ -215,10 +222,12 @@ public class CommandConfig implements CommandExecutor {
|
||||
* @param sender <p>The command sender to display the config list to</p>
|
||||
*/
|
||||
private void displayConfigValues(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Stargate" + ChatColor.GOLD + "Config values:");
|
||||
sender.sendMessage(ChatColor.GREEN + "Stargate " + ChatColor.GOLD + "Config values:");
|
||||
|
||||
for (ConfigurationOption option : ConfigurationOption.values()) {
|
||||
sender.sendMessage(getOptionDescription(option));
|
||||
if (!bannedConfigOptions.contains(option)) {
|
||||
sender.sendMessage(getOptionDescription(option));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
package net.knarcraft.stargatecommand.command;
|
||||
|
||||
import net.TheDgtl.Stargate.api.StargateAPI;
|
||||
import net.TheDgtl.Stargate.config.ConfigurationOption;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This command represents any command which starts with stargate-command (sgc)
|
||||
*/
|
||||
public class CommandStarGateCommand implements CommandExecutor {
|
||||
|
||||
private final StargateAPI stargateAPI;
|
||||
private final List<ConfigurationOption> bannedConfigOptions;
|
||||
|
||||
public CommandStarGateCommand(StargateAPI stargateAPI) {
|
||||
/**
|
||||
* Instantiates a new Stargate-command command
|
||||
*
|
||||
* @param stargateAPI <p>A reference to the Stargate API</p>
|
||||
* @param bannedConfigOptions <p>A list of config options that shouldn't be available</p>
|
||||
*/
|
||||
public CommandStarGateCommand(StargateAPI stargateAPI, List<ConfigurationOption> bannedConfigOptions) {
|
||||
this.stargateAPI = stargateAPI;
|
||||
this.bannedConfigOptions = bannedConfigOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,7 +35,8 @@ public class CommandStarGateCommand implements CommandExecutor {
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("config")) {
|
||||
String[] subArgs = (String[]) ArrayUtils.remove(args, 0);
|
||||
return new CommandConfig(stargateAPI.getConfigurationAPI()).onCommand(commandSender, command, s, subArgs);
|
||||
return new CommandConfig(stargateAPI.getConfigurationAPI(), bannedConfigOptions).onCommand(
|
||||
commandSender, command, s, subArgs);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -16,11 +16,21 @@ import java.util.List;
|
||||
*/
|
||||
public class ConfigTabCompleter implements TabCompleter {
|
||||
|
||||
private final List<ConfigurationOption> bannedConfigOptions;
|
||||
private List<String> booleans;
|
||||
private List<String> integers;
|
||||
private List<String> chatColors;
|
||||
private List<String> doubles;
|
||||
|
||||
/**
|
||||
* Instantiates a new config tab completer
|
||||
*
|
||||
* @param bannedConfigOptions <p>A list of config options that shouldn't be available</p>
|
||||
*/
|
||||
public ConfigTabCompleter(List<ConfigurationOption> bannedConfigOptions) {
|
||||
this.bannedConfigOptions = bannedConfigOptions;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@@ -32,6 +42,9 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
ConfigurationOption selectedOption;
|
||||
try {
|
||||
selectedOption = ConfigurationOption.valueOf(args[0].toUpperCase());
|
||||
if (bannedConfigOptions.contains(selectedOption)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -39,7 +52,9 @@ public class ConfigTabCompleter implements TabCompleter {
|
||||
} else {
|
||||
List<String> configOptionNames = new ArrayList<>();
|
||||
for (ConfigurationOption option : ConfigurationOption.values()) {
|
||||
configOptionNames.add(option.name());
|
||||
if (!bannedConfigOptions.contains(option)) {
|
||||
configOptionNames.add(option.name());
|
||||
}
|
||||
}
|
||||
return filterMatching(configOptionNames, args[0]);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.knarcraft.stargatecommand.command;
|
||||
|
||||
import net.TheDgtl.Stargate.config.ConfigurationOption;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -11,8 +12,22 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tab completer for the main /sgc command
|
||||
*/
|
||||
public class StargateCommandTabCompleter implements TabCompleter {
|
||||
|
||||
private final List<ConfigurationOption> bannedConfigOptions;
|
||||
|
||||
/**
|
||||
* Instantiates a new Stargate-command tab completer
|
||||
*
|
||||
* @param bannedConfigOptions <p>A list of config options that shouldn't be available</p>
|
||||
*/
|
||||
public StargateCommandTabCompleter(List<ConfigurationOption> bannedConfigOptions) {
|
||||
this.bannedConfigOptions = bannedConfigOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command,
|
||||
@NotNull String s, @NotNull String[] args) {
|
||||
@@ -27,7 +42,7 @@ public class StargateCommandTabCompleter implements TabCompleter {
|
||||
return matchingCommands;
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("config")) {
|
||||
String[] subArgs = (String[]) ArrayUtils.remove(args, 0);
|
||||
return new ConfigTabCompleter().onTabComplete(commandSender, command, s, subArgs);
|
||||
return new ConfigTabCompleter(bannedConfigOptions).onTabComplete(commandSender, command, s, subArgs);
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ main: net.knarcraft.stargatecommand.StargateCommand
|
||||
version: 0.1.0
|
||||
description: Command addon for the Stargate plugin for Bukkit
|
||||
author: EpicKnarvik97
|
||||
depend: [Stargate]
|
||||
depend: [ Stargate ]
|
||||
api-version: 1.18
|
||||
commands:
|
||||
stargatecommand:
|
||||
aliases:
|
||||
aliases:
|
||||
- sgc
|
||||
description: The root command for all added commands
|
||||
usage: |
|
||||
|
||||
Reference in New Issue
Block a user