1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Fail safe for corrupted data in locale and translatable word files

This commit is contained in:
Zrips 2017-05-11 13:09:18 +03:00
parent 89d6e78551
commit e7b52d2ecf
5 changed files with 192 additions and 170 deletions

View File

@ -510,6 +510,7 @@ public class Jobs extends JavaPlugin {
* @throws IOException
*/
public static void reload() throws IOException {
if (saveTask != null) {
saveTask.shutdown();
saveTask = null;

View File

@ -53,6 +53,7 @@ import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.dao.JobsDAOData;
import com.gamingmesh.jobs.economy.PointsData;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.stuff.PerformCommands;
public class PlayerManager {
@ -786,6 +787,7 @@ public class PlayerManager {
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer())));
return boost;
}

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.LocaleReader;
@ -17,6 +18,12 @@ public class LanguageManager {
this.plugin = plugin;
}
List<String> languages = new ArrayList<String>();
public List<String> getLanguages() {
return languages;
}
/**
* Method to load the language file configuration
*
@ -25,7 +32,7 @@ public class LanguageManager {
synchronized void load() {
// Just copying default language files, except en, that one will be generated
List<String> languages = new ArrayList<String>();
languages = new ArrayList<String>();
languages.add("cs");
languages.add("cz");
languages.add("de");
@ -48,6 +55,13 @@ public class LanguageManager {
for (String lang : languages) {
File f = new File(plugin.getDataFolder(), "locale" + File.separator + "messages_" + lang + ".yml");
// Fail safe if file get corrupted and being created with corrupted data, we need to recreate it
if ((f.length() / 1024) > 1024) {
f.delete();
f = new File(plugin.getDataFolder(), "locale" + File.separator + "messages_" + lang + ".yml");
}
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
@ -142,12 +156,10 @@ public class LanguageManager {
c.get("command.limit.output.reachedpointslimit2", "&eYou can check your limit with &2/jobs limit &ecommand");
c.get("command.limit.output.notenabled", "&eMoney limit is not enabled");
c.get("command.resetlimit.help.info", "Resets players payment limits");
c.get("command.resetlimit.help.args", "[playername]");
c.get("command.resetlimit.output.reseted", "&ePayment limits have been reset for: &2%playername%");
c.get("command.help.output.info", "Type /jobs [cmd] ? for more information about a command.");
c.get("command.help.output.usage", "Usage: %usage%");
c.get("command.help.output.title", "&e-------&e ======= &6Jobs &e======= &e-------");
@ -175,7 +187,6 @@ public class LanguageManager {
c.get("command.blockinfo.output.data", " &eBlock data: &6%blockdata%");
c.get("command.blockinfo.output.usage", " &eUsage: &6%first% &eor &6%second%");
c.get("command.iteminfo.help.info", "Shows item information you holding.");
c.get("command.iteminfo.help.args", "");
c.get("command.iteminfo.output.name", " &eItem name: &6%itemname%");
@ -355,7 +366,6 @@ public class LanguageManager {
c.get("command.gtop.output.next", "&2|&e Next Page >>>>");
c.get("command.gtop.output.show", "&2Show from &e[from] &2until &e[until] &2global top list");
c.get("command.area.help.info", "Modify restricted areas.");
c.get("command.area.help.args", "add/remove/info/list");
c.get("command.area.help.addUsage", "&eUsage: &6/Jobs area add [areaName] [bonus]");

View File

@ -14,6 +14,7 @@ import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.LocaleReader;
import com.gamingmesh.jobs.container.NameList;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
public class NameTranslatorManager {
@ -179,7 +180,7 @@ public class NameTranslatorManager {
langFile.saveDefaultConfig();
}
languages.add("en");
languages.addAll(Jobs.getLanguageManager().getLanguages());
File customLocaleFile = new File(plugin.getDataFolder(), "TranslatableWords" + File.separator + "Words_" + Jobs.getGCManager().localeString + ".yml");
if (!customLocaleFile.exists() && !Jobs.getGCManager().localeString.equalsIgnoreCase("en"))
@ -188,6 +189,14 @@ public class NameTranslatorManager {
for (String lang : languages) {
File f = new File(plugin.getDataFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
// Fail safe if file get corrupted and being created with corrupted data, we need to recreate it
if ((f.length() / 1024) > 1024) {
f.delete();
f = new File(plugin.getDataFolder(), "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
}
Bukkit.getServer().getConsoleSender().sendMessage(lang + " " + (f.length() / 1024));
YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
CommentedYamlConfiguration writer = new CommentedYamlConfiguration();