diff --git a/src/main/java/net/knarcraft/stargatecommand/StargateCommand.java b/src/main/java/net/knarcraft/stargatecommand/StargateCommand.java index 6f6dbe1..48b22d7 100644 --- a/src/main/java/net/knarcraft/stargatecommand/StargateCommand.java +++ b/src/main/java/net/knarcraft/stargatecommand/StargateCommand.java @@ -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
The configuration to load
+ */ + 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 * diff --git a/src/main/java/net/knarcraft/stargatecommand/property/Icon.java b/src/main/java/net/knarcraft/stargatecommand/property/Icon.java index 0e9c78c..821ad65 100644 --- a/src/main/java/net/knarcraft/stargatecommand/property/Icon.java +++ b/src/main/java/net/knarcraft/stargatecommand/property/Icon.java @@ -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 defaultIconThe default value used unless another is specified
+ * @param placeholderThe placeholder this icon should replace
+ * @param configNodeThe config node used to specify this icon
*/ - 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 + * + * @returnThe config node used to specify this icon
+ */ + public String getConfigNode() { + return this.configNode; + } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..818cf4f --- /dev/null +++ b/src/main/resources/config.yml @@ -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: "⚊" \ No newline at end of file diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index a53b9ce..7021839 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -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" \ No newline at end of file