mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Locale no longer requires Plan as variable (Still requires Mock, TODO)
This commit is contained in:
parent
1821217530
commit
be21756611
@ -174,7 +174,7 @@ public class Plan extends BukkitPlugin implements IPlan {
|
||||
throw new PlanEnableException("Something went wrong saving the downloaded GeoLite2 Geolocation database", e);
|
||||
}
|
||||
|
||||
new Locale(this).loadLocale();
|
||||
new Locale().loadLocale();
|
||||
|
||||
theme = new Theme();
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class PlanBungee extends BungeePlugin implements IPlan {
|
||||
}
|
||||
variableHolder = new ServerVariableHolder(getProxy());
|
||||
|
||||
new Locale(this).loadLocale();
|
||||
new Locale().loadLocale();
|
||||
|
||||
theme = new Theme();
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
package main.java.com.djrapitops.plan.settings.locale;
|
||||
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.config.Config;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.settings.ColorScheme;
|
||||
import com.djrapitops.plugin.settings.DefaultMessages;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.settings.Permissions;
|
||||
import main.java.com.djrapitops.plan.settings.Settings;
|
||||
import main.java.com.djrapitops.plan.systems.store.FileSystem;
|
||||
import main.java.com.djrapitops.plan.systems.store.config.ConfigSystem;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.LocaleEntryComparator;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.StringLengthComparator;
|
||||
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
|
||||
@ -34,12 +37,10 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class Locale {
|
||||
|
||||
private final IPlan plugin;
|
||||
private final Map<Msg, Message> messages;
|
||||
|
||||
public Locale(IPlan plugin) {
|
||||
public Locale() {
|
||||
LocaleHolder.setLocale(this);
|
||||
this.plugin = plugin;
|
||||
messages = new EnumMap<>(Msg.class);
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ public class Locale {
|
||||
if (Settings.WRITE_NEW_LOCALE.isTrue()) {
|
||||
writeNewDefaultLocale();
|
||||
}
|
||||
File localeFile = new File(plugin.getDataFolder(), "locale.txt");
|
||||
File localeFile = FileSystem.getLocaleFile();
|
||||
if (localeFile.exists()) {
|
||||
loadFromFile(localeFile);
|
||||
} else if (locale.equals("DEFAULT")) {
|
||||
@ -83,7 +84,6 @@ public class Locale {
|
||||
}
|
||||
|
||||
private void writeNewDefaultLocale() throws IOException {
|
||||
|
||||
Optional<String> key = messages.keySet().stream()
|
||||
.map(Msg::getIdentifier)
|
||||
.sorted(new StringLengthComparator())
|
||||
@ -96,9 +96,11 @@ public class Locale {
|
||||
.sorted(new LocaleEntryComparator())
|
||||
.map(entry -> getSpacedIdentifier(entry.getKey().getIdentifier(), length) + "|| " + entry.getValue().toString())
|
||||
.collect(Collectors.toList());
|
||||
Files.write(new File(plugin.getDataFolder(), "locale.txt").toPath(), lines, StandardCharsets.UTF_8);
|
||||
plugin.getMainConfig().set(Settings.WRITE_NEW_LOCALE.getPath(), false);
|
||||
plugin.getMainConfig().save();
|
||||
Files.write(FileSystem.getLocaleFile().toPath(), lines, StandardCharsets.UTF_8);
|
||||
|
||||
Config config = ConfigSystem.getInstance().getConfig();
|
||||
config.set(Settings.WRITE_NEW_LOCALE.getPath(), false);
|
||||
config.save();
|
||||
}
|
||||
|
||||
private String getSpacedIdentifier(String identifier, int length) {
|
||||
@ -110,13 +112,15 @@ public class Locale {
|
||||
}
|
||||
|
||||
private void loadDefault() {
|
||||
// TODO Move to Msg as DefaultMessages
|
||||
|
||||
String analysis = "Analysis | ";
|
||||
String prefix = "[Plan] ";
|
||||
String green = "§a";
|
||||
String yellow = "§e";
|
||||
String red = "§c";
|
||||
String arrowsRight = DefaultMessages.ARROWS_RIGHT.parse();
|
||||
ColorScheme cs = plugin.getColorScheme();
|
||||
ColorScheme cs = MiscUtils.getIPlan().getColorScheme();
|
||||
String mCol = cs.getMainColor();
|
||||
String sCol = cs.getSecondaryColor();
|
||||
String tCol = cs.getTertiaryColor();
|
||||
@ -310,7 +314,7 @@ public class Locale {
|
||||
|
||||
private void loadFromResource(String fileName) {
|
||||
try {
|
||||
loadFromContents(FileUtil.lines(plugin, fileName), fileName);
|
||||
loadFromContents(FileSystem.readFromResource(fileName), fileName);
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.error("Could not find file inside the jar: " + fileName);
|
||||
Log.info("Using Locale: Default (EN)");
|
||||
|
@ -45,6 +45,10 @@ public class FileSystem implements SubSystem {
|
||||
return getInstance().configFile;
|
||||
}
|
||||
|
||||
public static File getLocaleFile() {
|
||||
return new File(getInstance().dataFolder, "locale.txt");
|
||||
}
|
||||
|
||||
public static List<String> readFromResource(String fileName) throws IOException {
|
||||
return FileUtil.lines(MiscUtils.getIPlan(), fileName);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.utilities.comparators;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Compares Strings and sorts them by length
|
||||
* Compares Strings and sorts them by length (Longest fist).
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 3.6.2
|
||||
|
@ -51,7 +51,7 @@ public class TestInit {
|
||||
* Does not load any messages from anywhere because that would cause exceptions.
|
||||
*/
|
||||
public static void initEmptyLocale() {
|
||||
new Locale(null);
|
||||
new Locale();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +62,7 @@ public class TestInit {
|
||||
* @param plan Mocked Plan
|
||||
*/
|
||||
public static void initLocale(Plan plan) {
|
||||
new Locale(plan).loadLocale();
|
||||
new Locale().loadLocale();
|
||||
}
|
||||
|
||||
public static TestInit init() throws Exception {
|
||||
@ -139,7 +139,7 @@ public class TestInit {
|
||||
when(planMock.getServerInfoManager()).thenReturn(bukkitServerInfoManager);
|
||||
ColorScheme cs = new ColorScheme(ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK);
|
||||
when(planMock.getColorScheme()).thenReturn(cs);
|
||||
initLocale(planMock);
|
||||
initLocale(null);
|
||||
|
||||
RunnableFactory.activateTestMode();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user