Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e270836
Remove old files
jcxldn Mar 5, 2021
4be641a
Initial idea for config rewrite
jcxldn Mar 5, 2021
c6b66e3
Switch to constructor loading for YamlProvider
jcxldn Mar 5, 2021
5253bff
Add javadocs to Configuration
jcxldn Mar 5, 2021
80054f8
Create YamlProvider test
jcxldn Mar 5, 2021
e862ccf
Move YamlProviderTest into providers pacakge
jcxldn Mar 5, 2021
b8ad0fc
Add initial (in progress) LocaleProvider tests
jcxldn Mar 5, 2021
4559859
Add non-existent directory instanciation test
jcxldn Mar 5, 2021
016c867
Add translate and translateNoColor tests
jcxldn Mar 5, 2021
5f2713a
Create loadAllLocales test (with ignored txt file for testing)
jcxldn Mar 5, 2021
73e5336
Create get tests
jcxldn Mar 5, 2021
8401dd6
Use FileConfiguration instead of Configuration for localeConfig
jcxldn Mar 5, 2021
32b638f
(breaking): Remove LocaleProvider#writeLocaleStream
jcxldn Mar 6, 2021
d95a9c4
Extend save functionality to support FileWriter, File and string inputs
jcxldn Mar 7, 2021
d37eccd
Add more YamlProviderTests for new loading methods
jcxldn Mar 7, 2021
427041c
Add FileConfiguration#reload method
jcxldn Mar 7, 2021
df8ed3d
(bukkit/bungee StartupUtil): Try using YamlProvider instead of remove…
jcxldn Mar 7, 2021
114e2da
Use ConcurrentHashMaps to be thread-safe
jcxldn Mar 13, 2021
d87e293
Use "this" keyword
jcxldn Mar 13, 2021
b8fe82d
Add javadoc to reload function
jcxldn Mar 13, 2021
d67d8df
tests: add async YamlProvider read test
kaylendog Mar 13, 2021
f8f7306
(bukkit/bungee): Add explicit file exists check
jcxldn Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ subprojects {
mapping("java", "SLASHSTAR_STYLE")
exclude "**/*.json" // Exclude JSON to keep the font width data valid
exclude "**/*.md"
exclude "**/*.yml"
exclude "**/*.MockMaker"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
package com.dumbdogdiner.stickyapi.bukkit.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

import javax.annotation.Nullable;

import com.dumbdogdiner.stickyapi.common.configuration.providers.YamlProvider;
import com.dumbdogdiner.stickyapi.common.translation.LocaleProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -60,9 +63,23 @@ public static LocaleProvider setupLocale(@NotNull JavaPlugin plugin, @Nullable L
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.getResource("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.getResource("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.getResource("messages.en_us.yml"));
Comment thread
jcxldn marked this conversation as resolved.

// 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Comment thread
jcxldn marked this conversation as resolved.

// 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment thread
jcxldn marked this conversation as resolved.

This file was deleted.

Loading