+ added language system back in
This commit is contained in:
parent
24f8d0dcec
commit
9bc84f9d6e
@ -6,6 +6,7 @@ import eu.univento.commons.player.ban.BanReason;
|
||||
import eu.univento.commons.player.friend.FriendData;
|
||||
import eu.univento.commons.player.kick.KickData;
|
||||
import eu.univento.commons.player.kick.KickReason;
|
||||
import eu.univento.commons.player.language.Language;
|
||||
import eu.univento.commons.player.mute.MuteData;
|
||||
import eu.univento.commons.player.mute.MuteReason;
|
||||
import eu.univento.commons.player.rank.Group;
|
||||
@ -47,6 +48,10 @@ public class DatabasePlayer {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public Language getLanguage() {
|
||||
return Language.getLanguage(Locale.forLanguageTag(getSettings().getLanguage()));
|
||||
}
|
||||
|
||||
public CompletableFuture<PlayerSettings> getSettingsFromDatabase() {
|
||||
CompletableFuture<PlayerSettings> future = new CompletableFuture<>();
|
||||
getObjectFromDatabase("Settings").whenComplete((entries, throwable) -> {
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2017 univento.eu - All rights reserved
|
||||
* You are not allowed to use, distribute or modify this code
|
||||
*/
|
||||
|
||||
package eu.univento.commons.player.language;
|
||||
|
||||
import eu.univento.commons.Commons;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.sql.ResultSet;
|
||||
import io.vertx.ext.sql.SQLConnection;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author joethei
|
||||
* @version 0.1
|
||||
*/
|
||||
public class Language {
|
||||
|
||||
private static ArrayList<Language> languages = new ArrayList<>();
|
||||
|
||||
static {
|
||||
languages.add(new Language(Locale.GERMAN));
|
||||
languages.add(new Language(Locale.ENGLISH));
|
||||
languages.add(new Language(Locale.ITALIAN));
|
||||
}
|
||||
|
||||
@Getter private Locale locale;
|
||||
private LinkedHashMap<String, String> translations = new LinkedHashMap<>();
|
||||
|
||||
private Language(Locale locale) {
|
||||
this.locale = locale;
|
||||
Commons.getCommons().getDatabaseManager().getMySQL().getClient().getConnection(res -> {
|
||||
if(res.succeeded()) {
|
||||
SQLConnection connection = res.result();
|
||||
connection.query("SELECT identifier, " + locale.getISO3Language() + " FROM translations;", result -> {
|
||||
if(result.succeeded()) {
|
||||
ResultSet rs = result.result();
|
||||
for(JsonObject json : rs.getRows()) {
|
||||
translations.put(json.getString("translations"), json.getString(locale.getISO3Language()));
|
||||
}
|
||||
|
||||
}else result.cause().printStackTrace();
|
||||
});
|
||||
}else res.cause().printStackTrace();
|
||||
});
|
||||
}
|
||||
|
||||
public static Language getLanguage(Locale locale) {
|
||||
for(Language language : languages) {
|
||||
if(language.getLocale().equals(locale)) return language;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMessage(MessageConstant constant) {
|
||||
return getWord(constant.getName());
|
||||
}
|
||||
|
||||
public String getWord(String constant) {
|
||||
return translations.get(constant);
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package eu.univento.commons.utils;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/**
|
||||
* @author joethei, Alex Gitelman
|
||||
* @version 1.0
|
||||
@ -37,4 +39,25 @@ public class Strings {
|
||||
// e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
|
||||
return Integer.signum(vals1.length - vals2.length);
|
||||
}
|
||||
|
||||
public static String[] remove(String[] array, String element) {
|
||||
if (array.length > 0) {
|
||||
int index = -1;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i].equals(element)) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
String[] copy = (String[]) Array.newInstance(array.getClass().getComponentType(), array.length - 1);
|
||||
if (copy.length > 0) {
|
||||
System.arraycopy(array, 0, copy, 0, index);
|
||||
System.arraycopy(array, index + 1, copy, index, copy.length - index);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user