mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-04-08 16:10:26 +00:00
Language system implementation, commands still not translatable yet, finish up configs system
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.api;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.events.EventsPlatform;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||
@@ -54,6 +55,8 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
RedisBungeeConfiguration configuration();
|
||||
|
||||
LangConfiguration langConfiguration();
|
||||
|
||||
Summoner<?> getSummoner();
|
||||
|
||||
RedisBungeeMode getRedisBungeeMode();
|
||||
|
||||
@@ -1,4 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2013-present RedisBungee contributors
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class LangConfiguration {
|
||||
|
||||
|
||||
public static class Messages {
|
||||
|
||||
private final Map<Locale, Component> LOGGED_IN_FROM_OTHER_LOCATION;
|
||||
private final Map<Locale, Component> ALREADY_LOGGED_IN;
|
||||
private final Map<Locale, String> SERVER_CONNECTING;
|
||||
private final Map<Locale, String> SERVER_NOT_FOUND;
|
||||
|
||||
private final Locale defaultLocale;
|
||||
|
||||
public Messages(Locale defaultLocale) {
|
||||
LOGGED_IN_FROM_OTHER_LOCATION = new HashMap<>();
|
||||
ALREADY_LOGGED_IN = new HashMap<>();
|
||||
SERVER_CONNECTING = new HashMap<>();
|
||||
SERVER_NOT_FOUND = new HashMap<>();
|
||||
this.defaultLocale = defaultLocale;
|
||||
}
|
||||
|
||||
public void register(String id, Locale locale, String miniMessage) {
|
||||
switch (id) {
|
||||
case "server-not-found" -> SERVER_NOT_FOUND.put(locale, miniMessage);
|
||||
case "server-connecting" -> SERVER_CONNECTING.put(locale, miniMessage);
|
||||
case "logged-in-other-location" -> LOGGED_IN_FROM_OTHER_LOCATION.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
|
||||
case "already-logged-in" -> ALREADY_LOGGED_IN.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
|
||||
}
|
||||
}
|
||||
|
||||
public Component alreadyLoggedIn(Locale locale) {
|
||||
if (ALREADY_LOGGED_IN.containsKey(locale)) return ALREADY_LOGGED_IN.get(locale);
|
||||
return ALREADY_LOGGED_IN.get(defaultLocale);
|
||||
}
|
||||
|
||||
// there is no way to know whats client locale during login so just default to use default locale MESSAGES.
|
||||
public Component alreadyLoggedIn() {
|
||||
return this.alreadyLoggedIn(this.defaultLocale);
|
||||
}
|
||||
|
||||
public Component loggedInFromOtherLocation(Locale locale) {
|
||||
if (LOGGED_IN_FROM_OTHER_LOCATION.containsKey(locale)) return LOGGED_IN_FROM_OTHER_LOCATION.get(locale);
|
||||
return LOGGED_IN_FROM_OTHER_LOCATION.get(defaultLocale);
|
||||
}
|
||||
|
||||
// there is no way to know what's client locale during login so just default to use default locale MESSAGES.
|
||||
public Component loggedInFromOtherLocation() {
|
||||
return this.loggedInFromOtherLocation(this.defaultLocale);
|
||||
}
|
||||
|
||||
public Component serverConnecting(Locale locale, String server) {
|
||||
String miniMessage;
|
||||
if (SERVER_CONNECTING.containsKey(locale)) {
|
||||
miniMessage = SERVER_CONNECTING.get(locale);
|
||||
} else {
|
||||
miniMessage = SERVER_CONNECTING.get(defaultLocale);
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(miniMessage, Placeholder.parsed("server", server));
|
||||
}
|
||||
|
||||
public Component serverConnecting(String server) {
|
||||
return this.serverConnecting(this.defaultLocale, server);
|
||||
}
|
||||
|
||||
public Component serverNotFound(Locale locale, String server) {
|
||||
String miniMessage;
|
||||
if (SERVER_NOT_FOUND.containsKey(locale)) {
|
||||
miniMessage = SERVER_NOT_FOUND.get(locale);
|
||||
} else {
|
||||
miniMessage = SERVER_NOT_FOUND.get(defaultLocale);
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(miniMessage, Placeholder.parsed("server", server));
|
||||
}
|
||||
|
||||
public Component serverNotFound(String server) {
|
||||
return this.serverNotFound(this.defaultLocale, server);
|
||||
}
|
||||
|
||||
|
||||
// tests locale if set CORRECTLY or just throw if not
|
||||
public void test(Locale locale) {
|
||||
if (!(LOGGED_IN_FROM_OTHER_LOCATION.containsKey(locale) && ALREADY_LOGGED_IN.containsKey(locale) && SERVER_CONNECTING.containsKey(locale) && SERVER_NOT_FOUND.containsKey(locale))) {
|
||||
throw new IllegalStateException("Language system in `messages` found missing entries for " + locale.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private final Component redisBungeePrefix;
|
||||
|
||||
private final Locale defaultLanguage;
|
||||
|
||||
private final boolean useClientLanguage;
|
||||
|
||||
private final Messages messages;
|
||||
|
||||
|
||||
public LangConfiguration(Component redisBungeePrefix, Locale defaultLanguage, boolean useClientLanguage, Messages messages) {
|
||||
this.redisBungeePrefix = redisBungeePrefix;
|
||||
this.defaultLanguage = defaultLanguage;
|
||||
this.useClientLanguage = useClientLanguage;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public Component redisBungeePrefix() {
|
||||
return redisBungeePrefix;
|
||||
}
|
||||
|
||||
public Locale defaultLanguage() {
|
||||
return defaultLanguage;
|
||||
}
|
||||
|
||||
public boolean useClientLanguage() {
|
||||
return useClientLanguage;
|
||||
}
|
||||
|
||||
public Messages messages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public interface ConfigLoader extends GenericConfigLoader {
|
||||
|
||||
int CONFIG_VERSION = 2;
|
||||
|
||||
@Override
|
||||
default void loadConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws IOException {
|
||||
Path configFile = createConfigFile(dataFolder, "config.yml", "config.yml");
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2013-present RedisBungee contributors
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config.loaders;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public interface GenericConfigLoader {
|
||||
|
||||
// CHANGES on every reboot
|
||||
String RANDOM_OLD = "backup-" + Instant.now().getEpochSecond();
|
||||
|
||||
default void loadConfig(RedisBungeePlugin<?> plugin, File dataFolder) throws IOException {
|
||||
loadConfig(plugin, dataFolder.toPath());
|
||||
}
|
||||
|
||||
|
||||
void loadConfig(RedisBungeePlugin<?> plugin, Path path) throws IOException;
|
||||
|
||||
default Path createConfigFile(Path dataFolder, String configFile, @Nullable String defaultResourceID) throws IOException {
|
||||
if (Files.notExists(dataFolder)) {
|
||||
Files.createDirectory(dataFolder);
|
||||
|
||||
@@ -1,4 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2013-present RedisBungee contributors
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
*
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
|
||||
package com.imaginarycode.minecraft.redisbungee.api.config.loaders;
|
||||
|
||||
public interface LangConfigLoader {
|
||||
import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
|
||||
import com.imaginarycode.minecraft.redisbungee.api.config.LangConfiguration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
|
||||
public interface LangConfigLoader extends GenericConfigLoader {
|
||||
|
||||
int CONFIG_VERSION = 1;
|
||||
|
||||
default void loadLangConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws IOException {
|
||||
Path configFile = createConfigFile(dataFolder, "lang.yml", "lang.yml");
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||
if (node.getNode("config-version").getInt(0) != CONFIG_VERSION) {
|
||||
handleOldConfig(dataFolder, "lang.yml", "lang.yml");
|
||||
node = yamlConfigurationFileLoader.load();
|
||||
}
|
||||
// MINI message serializer
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
Component prefix = miniMessage.deserialize(node.getNode("prefix").getString("<color:red>[<color:yellow>Redis<color:red>Bungee]"));
|
||||
Locale defaultLocale = Locale.forLanguageTag(node.getNode("default-locale").getString("en-us"));
|
||||
System.out.println(node.getNode("default-locale").getString());
|
||||
boolean useClientLocale = node.getNode("use-client-locale").getBoolean(true);
|
||||
LangConfiguration.Messages messages = new LangConfiguration.Messages(defaultLocale);
|
||||
node.getNode("messages").getChildrenMap().forEach((key, childNode) -> childNode.getChildrenMap().forEach((childKey, childChildNode) -> {
|
||||
messages.register(key.toString(), Locale.forLanguageTag(childKey.toString()), childChildNode.getString());
|
||||
}));
|
||||
messages.test(defaultLocale);
|
||||
onLangConfigLoad(new LangConfiguration(prefix, defaultLocale, useClientLocale, messages));
|
||||
}
|
||||
|
||||
|
||||
void onLangConfigLoad(LangConfiguration langConfiguration);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -61,9 +61,8 @@ compatibility-max-connections: 3
|
||||
# if this disabled override-bungee-commands will be ignored
|
||||
register-commands: false
|
||||
|
||||
|
||||
# THIS IS BUNGEECORD ONLY OPTION!
|
||||
# Whether or not RedisBungee should install its version of regular BungeeCord commands.
|
||||
# Whether RedisBungee should install its version of regular BungeeCord commands.
|
||||
# Often, the RedisBungee commands are desired, but in some cases someone may wish to
|
||||
# override the commands using another plugin.
|
||||
#
|
||||
@@ -75,23 +74,24 @@ register-commands: false
|
||||
# ignored on velocity
|
||||
override-bungee-commands: false
|
||||
|
||||
# A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic
|
||||
# restart scripts.
|
||||
exempt-ip-addresses: []
|
||||
|
||||
# restore old login behavior before 0.9.0 update
|
||||
# enabled by default
|
||||
# when true: when player login and there is old player with same uuid it will get disconnected as result and new player will login
|
||||
# when true: when player login and there is old player with same uuid it will get disconnected as result and new player will log in
|
||||
# when false: when a player login but login will fail because old player is still connected.
|
||||
kick-when-online: true
|
||||
|
||||
# enabled by default
|
||||
# this option tells redis-bungee handle motd and set online count, when motd is requested
|
||||
# this option tells RedisBungee handle motd and set online count, when motd is requested
|
||||
# you can disable this when you want to handle motd yourself, use RedisBungee api to get total players when needed :)
|
||||
handle-motd: true
|
||||
|
||||
# A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic
|
||||
# restart scripts.
|
||||
# Ignored if handle-motd is disabled.
|
||||
exempt-ip-addresses: []
|
||||
|
||||
# disabled by default
|
||||
# Redis-bungee will attempt to connect player to last server that was stored.
|
||||
# RedisBungee will attempt to connect player to last server that was stored.
|
||||
reconnect-to-last-server: false
|
||||
|
||||
# Config version DO NOT CHANGE!!!!
|
||||
|
||||
@@ -1,71 +1,80 @@
|
||||
# this config file is for messages / Languages
|
||||
# Note 1: use MiniMessage format https://docs.advntr.dev/minimessage/format.html
|
||||
# use MiniMessage format https://docs.advntr.dev/minimessage/format.html
|
||||
# for colors etc... Legacy chat color is not supported.
|
||||
|
||||
# Note 2:
|
||||
# Language codes used in minecraft from the minecraft wiki
|
||||
|
||||
# example: en_us for american english and ar_sa for arabic
|
||||
# example: en-us for american english and ar-sa for arabic
|
||||
|
||||
# all codes can be obtained from link below
|
||||
# from the colum Locale Code -> In-game
|
||||
# NOTE: minecraft wiki shows languages like this `en_us` in config it should be `en-us`
|
||||
# https://minecraft.wiki/w/Language
|
||||
|
||||
# example:
|
||||
# lets assume we want to add arabic language.
|
||||
# errors:
|
||||
# messages:
|
||||
# logged-in-other-location:
|
||||
# en_us: "<color:red>You logged in from another location!"
|
||||
# ar_sa: "<color:red>لقد اتصلت من مكان اخر"
|
||||
# en-us: "<color:red>You logged in from another location!"
|
||||
# ar-sa: "<color:red>لقد اتصلت من مكان اخر"
|
||||
|
||||
|
||||
# RedisBungee Prefix if ever used.
|
||||
redis-bungee-prefix: "<color:red>[<color:yellow>Redis<color:red>Bungee]"
|
||||
prefix: "<color:red>[<color:yellow>Redis<color:red>Bungee]"
|
||||
|
||||
# us_en is american English, Which is the default language used when a language for a message isn't defined.
|
||||
# Warning: IF THE set default language wasn't defined in the config for all messages, plugin will not load.
|
||||
|
||||
# set the default language
|
||||
default-language: en_us
|
||||
# en-us is american English, Which is the default language used when a language for a message isn't defined.
|
||||
# Warning: IF THE set default locale wasn't defined in the config for all messages, plugin will not load.
|
||||
# set the Default locale
|
||||
default-locale: en-us
|
||||
|
||||
# send language based on client sent settings
|
||||
# if you don't have languages configured for client it will
|
||||
# default to language that has been set above
|
||||
use-client-language: true
|
||||
# if you don't have languages configured For client Language
|
||||
# it will default to language that has been set above
|
||||
# NOTE: due minecraft protocol not sending player settings during login,
|
||||
# some of the messages like logged-in-other-location will
|
||||
# skip translation and use default locale that has been set in default-locale.
|
||||
use-client-locale: true
|
||||
|
||||
# messages
|
||||
# messages that are used during login, and connecting to Last server
|
||||
messages:
|
||||
logged-in-other-location:
|
||||
en_us: "<color:red>You logged in from another location!"
|
||||
ar_sa: "<color:red>لقد اتصلت من مكان اخر"
|
||||
en-us: "<color:red>You logged in from another location!"
|
||||
ar-sa: "<color:red>لقد اتصلت من مكان اخر"
|
||||
already-logged-in:
|
||||
en_us: "<color:red>You are already logged in!"
|
||||
ar_sa: "<color:red>انت متصل بالفعل"
|
||||
en-us: "<color:red>You are already logged in!"
|
||||
ar-sa: "<color:red>انت متصل بالفعل"
|
||||
server-not-found:
|
||||
# placeholder <server> displays server name in the message.
|
||||
en_us: "<color:red>unable to connect you to the last server, because server <server> was not found."
|
||||
ar_sa: "<color:red>فشل الاتصال بالخادم السابق لان الخادم غير موجود (<server>)"
|
||||
server-found:
|
||||
en-us: "<color:red>unable to connect you to the last server, because server <server> was not found."
|
||||
ar-sa: "<color:red>فشل الاتصال بالخادم السابق لان الخادم غير موجود (<server>)"
|
||||
server-connecting:
|
||||
# placeholder <server> displays server name in the message.
|
||||
en_us: "<color:green>Connecting you to <server>..."
|
||||
ar_sa: "<color:green>جاري الاتصال بخادم <server>"
|
||||
en-us: "<color:green>Connecting you to <server>..."
|
||||
ar-sa: "<color:green>جاري الاتصال بخادم <server>"
|
||||
|
||||
# commands common messages:
|
||||
|
||||
# commands common messages
|
||||
commands-common:
|
||||
player-not-found:
|
||||
en_us: "<color:red>Player not found."
|
||||
ar_sa: "<color:red>اللاعب غير موجود"
|
||||
en-us: "<color:red>Player not found."
|
||||
ar-sa: "<color:red>اللاعب غير موجود"
|
||||
player-not-specified:
|
||||
en_us: "<color:red>You must specify a player name."
|
||||
ar_sa: "<color:red>أدخل اسم اللاعب مطلوب"
|
||||
en-us: "<color:red>You must specify a player name."
|
||||
ar-sa: "<color:red>أدخل اسم اللاعب مطلوب"
|
||||
command-not-specified:
|
||||
en_us: "<color:red>You must specify a command to be run."
|
||||
ar_sa: "<color:red>ادخل الأمر المطلوب"
|
||||
en-us: "<color:red>You must specify a command to be run."
|
||||
ar-sa: "<color:red>ادخل الأمر المطلوب"
|
||||
|
||||
# commands
|
||||
commands:
|
||||
glist:
|
||||
single-player:
|
||||
en-us: "<color:yellow><players> player is currently online"
|
||||
players:
|
||||
en-us: "<color:yellow><players> players are currently online"
|
||||
notice:
|
||||
en-us: "<color:yellow>To see all players online, use /glist showall."
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# DO NOT CHANGE!!!!!
|
||||
config-version: 1
|
||||
Reference in New Issue
Block a user