Now saving the Locale in the new config

This commit is contained in:
main() 2012-10-16 20:38:55 +02:00
parent 322acbc636
commit 7031e9e58b
4 changed files with 54 additions and 2 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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<Locale, String> {
/**
* {@inheritDoc}
*/
@Override
public Locale deserialize(String arg0, Class<Locale> arg1) throws IllegalPropertyValueException {
return new Locale(arg0);
}
/**
* {@inheritDoc}
*/
@Override
public String serialize(Locale arg0) {
return arg0.getLanguage();
}
}