Skip to content

Instantly share code, notes, and snippets.

@stuntguy3000
Created December 2, 2014 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuntguy3000/cbfe8ceb8bcc13e9a2b3 to your computer and use it in GitHub Desktop.
Save stuntguy3000/cbfe8ceb8bcc13e9a2b3 to your computer and use it in GitHub Desktop.
Language system
public class Lang {
public static String CLASS_ARCHER = "Archer";
public static String CLASS_ASSASSIN = "Assassin";
public static String CLASS_MAGE = "Mage";
public static String CLASS_NOT_PICKED = "&cYou need to select a class!";
public static String CLASS_WARRIOR = "Warrior";
public static String COMMAND_CLASS_CANNOT_CHANGE = "&cYou cannot change your class!";
public static String COMMAND_CLASS_CHOSEN = "&7You have chosen the &e%s&7 class.";
public static String COMMAND_CLASS_NOT_FOUND = "&cThe specified class does not exist!";
public static String COMMAND_CLASS_VIEW = "&7Your class is &e%s&7.";
public static String COMMAND_SKILL_VIEW = "&7You have &e%s &7point%s.";
public static String COMMAND_SYNTAX = "&7Command Syntax: /%s";
public static String GENERAL_PREFIX = "&8[&3Classes&8] &7";
public static String formulate(String message, Object... vars) {
return ChatColor.translateAlternateColorCodes('&', Lang.GENERAL_PREFIX + String.format(message, vars));
}
public static String formulateConsole(String message, Object... vars) {
return ChatColor.stripColor(Lang.GENERAL_PREFIX + String.format(message, vars)).replaceAll("[^\\x00-\\x7f]", "").trim().replaceAll(" +", " ");
}
public static String formulateRaw(String message, Object... vars) {
return ChatColor.translateAlternateColorCodes('&', String.format(message, vars));
}
public static void load() throws IllegalAccessException, NoSuchFieldException, IOException {
YamlConfiguration config = ConfigHandler.getConfig(ConfigHandler.ConfigType.LANG);
Lang messageInstance = new Lang();
for (Field field : messageInstance.getClass().getFields()) {
if (!config.contains(field.getName())) {
config.set(field.getName(), field.get(messageInstance.getClass()));
}
}
for (String message : config.getKeys(false)) {
try {
Field field = Lang.class.getDeclaredField(message);
field.setAccessible(true);
field.set(null, config.getString(message));
} catch (NoSuchFieldException ex) {
config.set(message, null);
config.save(ConfigHandler.getFile(ConfigHandler.ConfigType.LANG));
}
}
try {
config.save(ConfigHandler.getFile(ConfigHandler.ConfigType.LANG));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment