Add a language file and system.

This commit is contained in:
graywolf336 2013-12-23 14:31:27 -06:00
parent 845e219d5d
commit ab0c236711
6 changed files with 91 additions and 24 deletions

View File

@ -1,18 +1,19 @@
[Jail 3.0](http://ci.graywolf336.com/job/Jail/) [Jail 3.0](http://ci.graywolf336.com/job/Jail/)
==== ====
This plugins adds Jail to your Minecraft server. Admins can define several jails and then jail/unjail people or jail them on time basis. Plugin also offers wide variety of protections, so players won't escape out of your jail. This plugins adds Jail to your Minecraft server. Admins can define several jails and then jail/unjail people or jail them on time basis. Plugin also offers wide variety of protections, so players won't escape out of your jail.
[![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/) [![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/)
ToDo ToDo
=== ===
* About everything * About everything
Done Done
=== ===
* Muted Prisoners are now muted * Muted Prisoners are now muted
* New command system, internally we handle commands a lot better * New command system, internally we handle commands a lot better
* Delete commands are now remove * Delete commands are now remove
* Language system
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
==== ====

View File

@ -43,14 +43,14 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.7.2-R0.1-SNAPSHOT</version> <version>1.7.2-R0.3-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.1-SNAPSHOT</version> <version>1.7.2-R0.3-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>

View File

@ -12,6 +12,7 @@ import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.beans.Prisoner;
import com.graywolf336.jail.beans.SimpleLocation; import com.graywolf336.jail.beans.SimpleLocation;
import com.graywolf336.jail.enums.LangString;
/** /**
* Handles all the saving and loading of the plugin's data. * Handles all the saving and loading of the plugin's data.
@ -23,7 +24,7 @@ import com.graywolf336.jail.beans.SimpleLocation;
*/ */
public class JailIO { public class JailIO {
private JailMain pl; private JailMain pl;
private FileConfiguration flat; private FileConfiguration flat, lang;
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
public JailIO(JailMain plugin) { public JailIO(JailMain plugin) {
@ -39,6 +40,60 @@ public class JailIO {
} }
} }
/** Loads the language file from disk, if there is none then we save the default one. */
public void loadLanguage() {
String language = pl.getConfig().getString("system.language");
boolean save = false;
File langFile = new File(pl.getDataFolder(), language + ".yml");
//File or folder already exists, let's check
if(langFile.exists()) {
if(langFile.isFile()) {
lang = YamlConfiguration.loadConfiguration(langFile);
}else {
pl.getLogger().severe("The language file can not be a folder, please double check your setup. Because of that, we are reverting back to English as the language.");
lang = YamlConfiguration.loadConfiguration(pl.getResource("en.yml"));
save = true;
}
}else {
pl.getLogger().info("Loading the default language of: en");
pl.getLogger().info("If you wish to change this, please rename 'en.yml' to whatever you wish and set the config value to the name of the file.");
lang = YamlConfiguration.loadConfiguration(pl.getResource("en.yml"));
save = true;
}
//If we have flagged to save the language file, let's save it as en.yml as this flag usually means they didn't have it loaded.
if(save) {
try {
lang.save(new File(pl.getDataFolder(), "en.yml"));
} catch (IOException e) {
pl.getLogger().severe("Unable to save the language file: " + e.getMessage());
}
}
}
/** Returns the message in the language, no variables are replaced.*/
public String getLanguageString(LangString langString) {
return getLanguageString(langString, new String[] {});
}
/**
* Returns the message in the language, with the provided variables being replaced.
*
* @param langString Which {@link LangString} we should be getting to send.
* @param variables All the variables to replace, in order from 0 to however many.
* @return The message as a colorful message.
*/
public String getLanguageString(LangString langString, String... variables) {
String message = lang.getString("language." + langString.toString().toLowerCase());
for (int i = 0; i < variables.length; i++) {
message = message.replaceAll("%" + i + "%", variables[i]);
}
return Util.getColorfulMessage(message);
}
/** /**
* Prepares the storage engine to be used. * Prepares the storage engine to be used.
*/ */

View File

@ -22,6 +22,7 @@ public class JailMain extends JavaPlugin {
jm = new JailManager(this); jm = new JailManager(this);
io = new JailIO(this); io = new JailIO(this);
io.loadLanguage();
io.prepareStorage(); io.prepareStorage();
io.loadJails(); io.loadJails();

View File

@ -0,0 +1,10 @@
package com.graywolf336.jail.enums;
public enum LangString {
/** The message sent when players are jailed without a reason. */
JAILED,
/** The message sent when players are jailed with a reason. */
JAILEDWITHREASON,
/** The message sent when players are released from jail. */
UNJAILED;
}

View File

@ -1,4 +1,4 @@
Messages: language:
Jailed: "&cYou've been jailed!" jailed: "&cYou've been jailed!"
JailedWithReason: "&cYou've been jailed for: %s" jailedwithreason: "&cYou've been jailed for: %s"
UnJailed: "&2You have been released! Please respect the server rules." unjailed: "&2You have been released! Please respect the server rules."