diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 5186aa22..d686bab0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -298,7 +298,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core, Messag // Setup & Load our Configuration files. loadConfigs(); try { - this.messageProvider.setLocale(new Locale(multiverseConfig.getString("locale", "en"))); + this.messageProvider.setLocale(this.config.getLocale()); } catch (IllegalArgumentException e) { this.log(Level.SEVERE, e.getMessage()); this.getServer().getPluginManager().disablePlugin(this); diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java index 289e4d06..c0c5b88b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java @@ -1,10 +1,12 @@ package com.onarandombox.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig; +import com.onarandombox.MultiverseCore.configuration.LocaleSerializor; + import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.Property; import me.main__.util.SerializationConfig.SerializationConfig; - +import java.util.Locale; import java.util.Map; /** @@ -60,6 +62,8 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements private volatile String firstspawnworld; @Property private volatile int teleportcooldown; + @Property(serializor = LocaleSerializor.class) + private volatile Locale locale; public MultiverseCoreConfiguration() { super(); @@ -273,4 +277,14 @@ public class MultiverseCoreConfiguration extends SerializationConfig implements public boolean getUseAsyncChat() { return this.useasyncchat; } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + this.locale = locale; + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java index abd9ace0..a6786f3a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java @@ -1,5 +1,7 @@ package com.onarandombox.MultiverseCore.api; +import java.util.Locale; + import org.bukkit.configuration.serialization.ConfigurationSerializable; /** @@ -145,4 +147,16 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable { * @return useasyncchat. */ boolean getUseAsyncChat(); + + /** + * Sets the locale. + * @param locale The new value. + */ + void setLocale(Locale locale); + + /** + * Gets the locale. + * @return locale + */ + Locale getLocale(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/LocaleSerializor.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocaleSerializor.java new file mode 100644 index 00000000..af165081 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/LocaleSerializor.java @@ -0,0 +1,24 @@ +package com.onarandombox.MultiverseCore.configuration; + +import java.util.Locale; + +import me.main__.util.SerializationConfig.IllegalPropertyValueException; +import me.main__.util.SerializationConfig.Serializor; + +public class LocaleSerializor implements Serializor { + /** + * {@inheritDoc} + */ + @Override + public Locale deserialize(String arg0, Class arg1) throws IllegalPropertyValueException { + return new Locale(arg0); + } + + /** + * {@inheritDoc} + */ + @Override + public String serialize(Locale arg0) { + return arg0.getLanguage(); + } +}