Add a language file and system.
This commit is contained in:
parent
845e219d5d
commit
ab0c236711
35
README.md
35
README.md
@ -1,18 +1,19 @@
|
||||
[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.
|
||||
|
||||
[![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/)
|
||||
|
||||
ToDo
|
||||
===
|
||||
* About everything
|
||||
|
||||
Done
|
||||
===
|
||||
* Muted Prisoners are now muted
|
||||
* New command system, internally we handle commands a lot better
|
||||
* Delete commands are now remove
|
||||
|
||||
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
|
||||
[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.
|
||||
|
||||
[![Build Status](http://ci.graywolf336.com/job/Jail/badge/icon)](http://ci.graywolf336.com/job/Jail/)
|
||||
|
||||
ToDo
|
||||
===
|
||||
* About everything
|
||||
|
||||
Done
|
||||
===
|
||||
* Muted Prisoners are now muted
|
||||
* New command system, internally we handle commands a lot better
|
||||
* Delete commands are now remove
|
||||
* Language system
|
||||
|
||||
[Jail 3.0 JavaDoc](http://ci.graywolf336.com/job/Jail/javadoc)
|
||||
====
|
4
pom.xml
4
pom.xml
@ -43,14 +43,14 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.7.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.7.2-R0.3-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.7.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.7.2-R0.3-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
|
@ -12,6 +12,7 @@ import com.graywolf336.jail.beans.Cell;
|
||||
import com.graywolf336.jail.beans.Jail;
|
||||
import com.graywolf336.jail.beans.Prisoner;
|
||||
import com.graywolf336.jail.beans.SimpleLocation;
|
||||
import com.graywolf336.jail.enums.LangString;
|
||||
|
||||
/**
|
||||
* Handles all the saving and loading of the plugin's data.
|
||||
@ -23,7 +24,7 @@ import com.graywolf336.jail.beans.SimpleLocation;
|
||||
*/
|
||||
public class JailIO {
|
||||
private JailMain pl;
|
||||
private FileConfiguration flat;
|
||||
private FileConfiguration flat, lang;
|
||||
private int storage; //0 = flatfile, 1 = sqlite, 2 = mysql
|
||||
|
||||
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.
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ public class JailMain extends JavaPlugin {
|
||||
|
||||
jm = new JailManager(this);
|
||||
io = new JailIO(this);
|
||||
io.loadLanguage();
|
||||
io.prepareStorage();
|
||||
io.loadJails();
|
||||
|
||||
|
10
src/main/java/com/graywolf336/jail/enums/LangString.java
Normal file
10
src/main/java/com/graywolf336/jail/enums/LangString.java
Normal 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;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
Messages:
|
||||
Jailed: "&cYou've been jailed!"
|
||||
JailedWithReason: "&cYou've been jailed for: %s"
|
||||
UnJailed: "&2You have been released! Please respect the server rules."
|
||||
language:
|
||||
jailed: "&cYou've been jailed!"
|
||||
jailedwithreason: "&cYou've been jailed for: %s"
|
||||
unjailed: "&2You have been released! Please respect the server rules."
|
Loading…
Reference in New Issue
Block a user