Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5
Rewrite the configuration package (very basic for now)#98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e2708364be641ac6b66e35253bff80054f8e862ccfb8ad0fc4559859016c8675f2713a73e53368401dd632b638fd95a9c4d37eccd427041cdf8ed3d114e2dad87e293b8fe82dd67d8dff8f7306File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,8 +5,11 @@ | ||
| package com.dumbdogdiner.stickyapi.bungeecord.util; | ||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.InputStream; | ||
| import com.dumbdogdiner.stickyapi.annotation.Untested; | ||
| import com.dumbdogdiner.stickyapi.common.configuration.providers.YamlProvider; | ||
| import com.dumbdogdiner.stickyapi.common.translation.LocaleProvider; | ||
| import org.jetbrains.annotations.NotNull; | ||
| @@ -67,10 +70,23 @@ public static LocaleProvider setupLocale(@NotNull Plugin plugin, @Nullable Local | ||
| if (!localeEnabled) { | ||
| plugin.getLogger() | ||
| .severe("Failed to configure default locale file - perhaps you deleted it? Will create a new one."); | ||
| // FIXME: This is horrible and needs to be improved | ||
| try { | ||
| localeProvider.writeLocaleStream(plugin.getResourceAsStream("messages.en_us.yml"), "messages.en_us.yml", | ||
| true); | ||
| // Step 1: Make sure the locale file exists (returns null if not found) | ||
| InputStream localeFile = plugin.getResourceAsStream("messages.en_us.yml"); | ||
| // Step 1.5: Throw an exception if the file doesn't exist | ||
| if (localeFile == null) | ||
| throw new FileNotFoundException("The locale file was not found in our embedded resources!"); | ||
| // Step 2:Load the yml from plugin.getResource (the internal .jar resource) | ||
| YamlProvider embeddedMessagesResource = new YamlProvider(plugin.getResourceAsStream("messages.en_us.yml")); | ||
jcxldn marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Step 3: Create a File instance representing our output dir in the plugin's data folder | ||
| File outputLocation = new File(localeProvider.getLocaleFolder(), "messages.en_us.yml"); | ||
| // outputLocation should now be something like [..]/plugins/[..]/locale/messages.en_us.yml | ||
| // Step 4: write the embedded messages resource to the plugin data dir | ||
| embeddedMessagesResource.save(outputLocation); | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| plugin.getLogger().severe("Something went horribly wrong while saving the default locale."); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,90 +4,22 @@ | ||
| */ | ||
| package com.dumbdogdiner.stickyapi.common.configuration; | ||
| import java.util.Map; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| /** | ||
| * Represents a source of configurable options and settings | ||
| * Base interface for a configuration. | ||
| */ | ||
| public interface Configuration extends ConfigurationSection { | ||
| /** | ||
| * Sets the default value of the given path as provided. | ||
| * <p> | ||
| * If no source {@link Configuration} was provided as a default collection, then | ||
| * a new {@link MemoryConfiguration} will be created to hold the new default | ||
| * value. | ||
| * <p> | ||
| * If value is null, the value will be removed from the default Configuration | ||
| * source. | ||
| * | ||
| * @param path Path of the value to set. | ||
| * @param value Value to set the default to. | ||
| * @throws IllegalArgumentException Thrown if path is null. | ||
| */ | ||
| @Override | ||
| public void addDefault(@NotNull String path, @Nullable Object value); | ||
| /** | ||
| * Sets the default values of the given paths as provided. | ||
| * <p> | ||
| * If no source {@link Configuration} was provided as a default collection, then | ||
| * a new {@link MemoryConfiguration} will be created to hold the new default | ||
| * values. | ||
| * | ||
| * @param defaults A map of Path{@literal ->}Values to add to defaults. | ||
| * @throws IllegalArgumentException Thrown if defaults is null. | ||
| */ | ||
| public void addDefaults(@NotNull Map<String, Object> defaults); | ||
| public interface Configuration { | ||
| /** | ||
| * Sets the default values of the given paths as provided. | ||
| * <p> | ||
| * If no source {@link Configuration} was provided as a default collection, then | ||
| * a new {@link MemoryConfiguration} will be created to hold the new default | ||
| * value. | ||
| * <p> | ||
| * This method will not hold a reference to the specified Configuration, nor | ||
| * will it automatically update if that Configuration ever changes. If you | ||
| * require this, you should set the default source with | ||
| * {@link #setDefaults(com.dumbdogdiner.stickyapi.common.configuration.Configuration)}. | ||
| * | ||
| * @param defaults A configuration holding a list of defaults to copy. | ||
| * @throws IllegalArgumentException Thrown if defaults is null or this. | ||
| * Gets the given string from the path, returning the given default value if not found. | ||
| * @param path The path of the string to get | ||
| * @param def The default value if the path is not found or is not a string | ||
| * @return The requested string. | ||
| */ | ||
| public void addDefaults(@NotNull Configuration defaults); | ||
| /** | ||
| * Sets the source of all default values for this {@link Configuration}. | ||
| * <p> | ||
| * If a previous source was set, or previous default values were defined, then | ||
| * they will not be copied to the new source. | ||
| * | ||
| * @param defaults New source of default values for this configuration. | ||
| * @throws IllegalArgumentException Thrown if defaults is null or this. | ||
| */ | ||
| public void setDefaults(@NotNull Configuration defaults); | ||
| /** | ||
| * Gets the source {@link Configuration} for this configuration. | ||
| * <p> | ||
| * If no configuration source was set, but default values were added, then a | ||
| * {@link MemoryConfiguration} will be returned. If no source was set and no | ||
| * defaults were set, then this method will return null. | ||
| * | ||
| * @return Configuration source for default values, or null if none exist. | ||
| */ | ||
| @Nullable | ||
| public Configuration getDefaults(); | ||
| public String getString(String path, String def); | ||
| /** | ||
| * Gets the {@link ConfigurationOptions} for this {@link Configuration}. | ||
| * <p> | ||
| * All setters through this method are chainable. | ||
| * | ||
| * @return Options for this configuration | ||
| * Gets the given string from the path. | ||
| * @param path The path of the string to get | ||
| * @return The requested string, or null. | ||
| */ | ||
| @NotNull | ||
| public ConfigurationOptions options(); | ||
| } | ||
| public String getString(String path); | ||
| } | ||
jcxldn marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.