Makes visualizer icons configurable #2

This commit is contained in:
2022-06-02 15:49:00 +02:00
parent ff1dbaedc4
commit a5484578f5
4 changed files with 68 additions and 14 deletions

View File

@@ -6,7 +6,10 @@ import net.knarcraft.stargatecommand.command.CommandStarGateCommand;
import net.knarcraft.stargatecommand.command.StargateCommandTabCompleter;
import net.knarcraft.stargatecommand.formatting.Translator;
import net.knarcraft.stargatecommand.listener.StargateListener;
import net.knarcraft.stargatecommand.manager.IconManager;
import net.knarcraft.stargatecommand.property.Icon;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;
@@ -31,6 +34,12 @@ public class StargateCommand extends JavaPlugin {
initializeBannedConfigOptions();
}
instance = this;
FileConfiguration configuration = this.getConfig();
this.saveDefaultConfig();
configuration.options().copyDefaults(true);
loadConfiguration(configuration);
Translator.loadLanguages("en");
//Get the Stargate API
ServicesManager servicesManager = this.getServer().getServicesManager();
@@ -66,6 +75,21 @@ public class StargateCommand extends JavaPlugin {
return instance;
}
/**
* Loads all configuration values from the given configuration
*
* @param fileConfiguration <p>The configuration to load</p>
*/
private void loadConfiguration(FileConfiguration fileConfiguration) {
//Load all icons from config
for (Icon icon : Icon.values()) {
String iconString = fileConfiguration.getString(icon.getConfigNode());
if (iconString != null) {
IconManager.registerIconString(icon, iconString);
}
}
}
/**
* Initializes the list of banned configuration options
*

View File

@@ -8,54 +8,58 @@ public enum Icon {
/**
* The icon used to mark a Stargate as hidden
*/
HIDDEN("", "{icon_h}"),
HIDDEN("", "{icon_h}", "icon.hiddenIcon"),
/**
* The icon used to mark a Stargate as not hidden
*/
NOT_HIDDEN("", "{icon_nh}"),
NOT_HIDDEN("", "{icon_nh}", "icon.notHiddenIcon"),
/**
* The icon used to mark a Stargate as always on/open
*/
ALWAYS_ON("", "{icon_a}"),
ALWAYS_ON("", "{icon_a}", "icon.alwaysOpenIcon"),
/**
* The icon used to mark a Stargate as not always on/open
*/
NOT_ALWAYS_ON("", "{icon_na}"),
NOT_ALWAYS_ON("", "{icon_na}", "icon.notAlwaysOpenIcon"),
/**
* The icon used to mark a Stargate as random
*/
RANDOM("", "{icon_r}"),
RANDOM("", "{icon_r}", "icon.randomIcon"),
/**
* The icon used to mark a Stargate as not random
*/
NOT_RANDOM("", "{icon_nr}"),
NOT_RANDOM("", "{icon_nr}", "icon.notRandomIcon"),
/**
* The icon used as a rightwards arrow between two items
*/
ARROW_RIGHT("->", "{icon_arrow_right}"),
ARROW_RIGHT("->", "{icon_arrow_right}", "icon.arrowRightIcon"),
/**
* The icon used to replace the space character for any names with spaces
*/
SPACE_REPLACEMENT("", "{icon_space}");
SPACE_REPLACEMENT("", "{icon_space}", "icon.spaceReplacementIcon");
private final String defaultIcon;
private final String placeholder;
private final String configNode;
/**
* Instantiates a new icon
*
* @param defaultIcon <p>The default value used unless another is specified</p>
* @param placeholder <p>The placeholder this icon should replace</p>
* @param configNode <p>The config node used to specify this icon</p>
*/
Icon(String defaultIcon, String placeholder) {
Icon(String defaultIcon, String placeholder, String configNode) {
this.defaultIcon = defaultIcon;
this.placeholder = placeholder;
this.configNode = configNode;
}
/**
@@ -76,4 +80,13 @@ public enum Icon {
return this.placeholder;
}
/**
* Gets the config node used to specify this icon
*
* @return <p>The config node used to specify this icon</p>
*/
public String getConfigNode() {
return this.configNode;
}
}

View File

@@ -0,0 +1,17 @@
icon:
# The "icon" used to mark a Stargate as hidden when visualizing the network
hiddenIcon: "⇒"
# The "icon" used to mark a Stargate as not hidden when visualizing the network
notHiddenIcon: "⇄"
# The "icon" used to mark a Stargate as always open when visualizing the network
alwaysOpenIcon: "⬛"
# The "icon" used to mark a Stargate as not always open when visualizing the network
notAlwaysOpenIcon: "⬜"
# The "icon" used to mark a Stargate as random open when visualizing the network
randomIcon: "↯"
# The "icon" used to mark a Stargate as not random open when visualizing the network
notRandomIcon: "↠"
# The "icon" used for a right arrow. Used to display a Stargate's destination during visualization
arrowRightIcon: "->"
# The "icon" used to replace any spaces in Stargate or network names
spaceReplacementIcon: "⚊"

View File

@@ -10,14 +10,14 @@ en:
CONFIG_VALUES_HEADER: "&aStargate &6Config values:"
CONFIG_OPTION_DESCRIPTION: "&6{name}&r - &a{description}&8 (Default: &7{value}&8)"
COMMAND_PLAYER_ONLY: "This command can only be used by players"
COMMAND_DIAL_ARGUMENTS: "You need to provide a network name and a portal name to dial"
COMMAND_DIAL_ARGUMENTS: "You need to provide a network name and a Stargate name to dial"
INVALID_NETWORK_GIVEN: "Invalid network specified in input"
INVALID_PORTAL_GIVEN: "Invalid portal specified in input"
PORTAL_NO_ACCESS: "You don't have access to the selected portal"
NO_PORTAL_IN_SIGHT: "You need to look at a portal to use this command"
INVALID_PORTAL_GIVEN: "Invalid Stargate specified in input"
PORTAL_NO_ACCESS: "You don't have access to the selected Stargate"
NO_PORTAL_IN_SIGHT: "You need to look at a Stargate to use this command"
DIAL_SUCCESSFUL: "Your Stargate has been prepared"
COMMAND_VISUALIZER_ARGUMENTS: "A network must be provided to visualize"
COMMAND_VISUALIZER_FORMAT: "Symbol explanation: \n&6{icon_h}&r = hidden, &6{icon_nh}&r = not hidden\n&6{icon_a}&r = always open, &6{icon_na}&r = not always open\n&6{icon_r}&r = random destination, &6{icon_nr}&r = non-random destination\n&6{icon_arrow_right}&r = fixed portal going to the specified portal\n|\nAll portals in network &a{network}&r:"
COMMAND_VISUALIZER_FORMAT: "Symbol explanation: \n&6{icon_h}&r = hidden, &6{icon_nh}&r = not hidden\n&6{icon_a}&r = always open, &6{icon_na}&r = not always open\n&6{icon_r}&r = random destination, &6{icon_nr}&r = non-random destination\n&6{icon_arrow_right}&r = fixed Stargate going to the specified Stargate\n|\nAll Stargates in network &a{network}&r:"
COMMAND_VISUALIZER_PORTAL_FORMAT: "&6{icons} &a{portal}&r{fixed}"
COMMAND_VISUALIZER_FIXED_FORMAT: " {icon_arrow_right} &a{portal}"
COMMAND_INFO_FORMAT: "Stargate info:\n|- &6Name&r: &a{portal}&r\n|- &6Destination&r: &a{destination}&r\n|- &6Network&r: &a{network}&r\n|- &6Owner&r: &a{owner}&r\n|- &6Flags&r: &a{flags}&r"