mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-01 00:10:12 +01:00
Added Locale grab from github
- initLocale() checks for locale files and checks for external locale if setting is not default/files are not found
This commit is contained in:
parent
eed828f894
commit
dbd8dded42
@ -9,6 +9,12 @@ import com.djrapitops.plan.database.databases.*;
|
|||||||
import com.djrapitops.plan.data.cache.*;
|
import com.djrapitops.plan.data.cache.*;
|
||||||
import com.djrapitops.plan.data.listeners.*;
|
import com.djrapitops.plan.data.listeners.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
import main.java.com.djrapitops.plan.ui.webserver.WebSocketServer;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -60,17 +66,9 @@ public class Plan extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
File dataFolder = getDataFolder();
|
getDataFolder().mkdirs();
|
||||||
dataFolder.mkdirs();
|
|
||||||
|
|
||||||
File localeFile = new File(dataFolder, "locale.txt");
|
initLocale();
|
||||||
if (localeFile.exists()) {
|
|
||||||
Phrase.loadLocale(localeFile);
|
|
||||||
}
|
|
||||||
File htmlLocale = new File(dataFolder, "htmlLocale.txt");
|
|
||||||
if (htmlLocale.exists()) {
|
|
||||||
Html.loadLocale(htmlLocale);
|
|
||||||
}
|
|
||||||
|
|
||||||
databases = new HashSet<>();
|
databases = new HashSet<>();
|
||||||
databases.add(new MySQLDB(this));
|
databases.add(new MySQLDB(this));
|
||||||
@ -313,4 +311,59 @@ public class Plan extends JavaPlugin {
|
|||||||
public int getBootAnalysisTaskID() {
|
public int getBootAnalysisTaskID() {
|
||||||
return bootAnalysisTaskID;
|
return bootAnalysisTaskID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initLocale() {
|
||||||
|
String locale = Settings.LOCALE.toString().toUpperCase();
|
||||||
|
File localeFile = new File(getDataFolder(), "locale.txt");
|
||||||
|
File htmlLocale = new File(getDataFolder(), "htmlLocale.txt");
|
||||||
|
boolean skipLoc = false;
|
||||||
|
boolean skipHtmlLoc = false;
|
||||||
|
String usingLocale = "";
|
||||||
|
if (localeFile.exists()) {
|
||||||
|
Phrase.loadLocale(localeFile);
|
||||||
|
skipLoc = true;
|
||||||
|
usingLocale = "locale.txt";
|
||||||
|
}
|
||||||
|
if (htmlLocale.exists()) {
|
||||||
|
Html.loadLocale(htmlLocale);
|
||||||
|
skipHtmlLoc = true;
|
||||||
|
}
|
||||||
|
if (!locale.equals("DEFAULT")) {
|
||||||
|
try {
|
||||||
|
if (!skipLoc) {
|
||||||
|
URL localeURL = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/localization/locale_" + locale + ".txt");
|
||||||
|
InputStream inputStream = localeURL.openStream();
|
||||||
|
OutputStream outputStream = new FileOutputStream(localeFile);
|
||||||
|
int read = 0;
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
while ((read = inputStream.read(bytes)) != -1) {
|
||||||
|
outputStream.write(bytes, 0, read);
|
||||||
|
}
|
||||||
|
Phrase.loadLocale(localeFile);
|
||||||
|
usingLocale = locale;
|
||||||
|
localeFile.delete();
|
||||||
|
}
|
||||||
|
if (!skipHtmlLoc) {
|
||||||
|
URL localeURL = new URL("https://raw.githubusercontent.com/Rsl1122/Plan-PlayerAnalytics/master/Plan/localization/htmlLocale_" + locale + ".txt");
|
||||||
|
InputStream inputStream = localeURL.openStream();
|
||||||
|
OutputStream outputStream = new FileOutputStream(htmlLocale);
|
||||||
|
int read = 0;
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
while ((read = inputStream.read(bytes)) != -1) {
|
||||||
|
outputStream.write(bytes, 0, read);
|
||||||
|
}
|
||||||
|
Html.loadLocale(htmlLocale);
|
||||||
|
htmlLocale.delete();
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
logError("Attempted using locale that doesn't exist.");
|
||||||
|
usingLocale = "Default: EN";
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
usingLocale = "Default: EN";
|
||||||
|
}
|
||||||
|
log("Using locale: " + usingLocale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,10 @@ public enum Settings {
|
|||||||
DEM_TRIGGERS("Customization.DemographicsTriggers.Trigger"),
|
DEM_TRIGGERS("Customization.DemographicsTriggers.Trigger"),
|
||||||
DEM_FEMALE("Customization.DemographicsTriggers.Female"),
|
DEM_FEMALE("Customization.DemographicsTriggers.Female"),
|
||||||
DEM_MALE("Customization.DemographicsTriggers.Male"),
|
DEM_MALE("Customization.DemographicsTriggers.Male"),
|
||||||
DEM_IGNORE("Customization.DemographicsTriggers.IgnoreWhen"),;
|
DEM_IGNORE("Customization.DemographicsTriggers.IgnoreWhen"),
|
||||||
|
LOCALE("Settings.Locale");
|
||||||
|
|
||||||
private String configPath;
|
private final String configPath;
|
||||||
|
|
||||||
private Settings(String path) {
|
private Settings(String path) {
|
||||||
this.configPath = path;
|
this.configPath = path;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
Settings:
|
Settings:
|
||||||
|
Locale: default
|
||||||
Data:
|
Data:
|
||||||
GatherLocations: true
|
GatherLocations: true
|
||||||
Analysis:
|
Analysis:
|
||||||
|
Loading…
Reference in New Issue
Block a user