mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-05 04:48:02 +00:00
remove all old messages code, new lang file
This commit is contained in:
parent
f6e1ca65bf
commit
e897a60976
@ -352,7 +352,7 @@ public abstract class AbstractRedisBungeeAPI {
|
||||
* @since 0.8.0
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public void kickPlayer(String playerName, String message) {
|
||||
kickPlayer(getUuidFromName(playerName), message);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public interface ConfigLoader {
|
||||
boolean reconnectToLastServer = node.getNode("reconnect-to-last-server").getBoolean();
|
||||
boolean handleMotd = node.getNode("handle-motd").getBoolean(true);
|
||||
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)), kickWhenOnline, reconnectToLastServer, handleMotd);
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, kickWhenOnline, reconnectToLastServer, handleMotd);
|
||||
Summoner<?> summoner;
|
||||
RedisBungeeMode redisBungeeMode;
|
||||
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
||||
@ -137,30 +137,6 @@ public interface ConfigLoader {
|
||||
|
||||
void onConfigLoad(RedisBungeeConfiguration configuration, Summoner<?> summoner, RedisBungeeMode mode);
|
||||
|
||||
default ImmutableMap<RedisBungeeConfiguration.MessageType, String> getMessagesFromPath(Path path) throws IOException {
|
||||
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(path).build();
|
||||
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||
HashMap<RedisBungeeConfiguration.MessageType, String> messages = new HashMap<>();
|
||||
messages.put(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION, node.getNode("logged-in-other-location").getString("§cLogged in from another location."));
|
||||
messages.put(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN, node.getNode("already-logged-in").getString("§cYou are already logged in!"));
|
||||
return ImmutableMap.copyOf(messages);
|
||||
}
|
||||
|
||||
default Path createMessagesFile(Path dataFolder) throws IOException {
|
||||
if (Files.notExists(dataFolder)) {
|
||||
Files.createDirectory(dataFolder);
|
||||
}
|
||||
Path file = dataFolder.resolve("messages.yml");
|
||||
if (Files.notExists(file)) {
|
||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream("messages.yml")) {
|
||||
Files.createFile(file);
|
||||
assert in != null;
|
||||
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
default Path createConfigFile(Path dataFolder) throws IOException {
|
||||
if (Files.notExists(dataFolder)) {
|
||||
Files.createDirectory(dataFolder);
|
||||
|
@ -13,18 +13,13 @@ package com.imaginarycode.minecraft.redisbungee.api.config;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
|
||||
public class RedisBungeeConfiguration {
|
||||
|
||||
public enum MessageType {
|
||||
LOGGED_IN_OTHER_LOCATION,
|
||||
ALREADY_LOGGED_IN
|
||||
}
|
||||
|
||||
private final ImmutableMap<MessageType, String> messages;
|
||||
public static final int CONFIG_VERSION = 2;
|
||||
private final String proxyId;
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
@ -36,9 +31,8 @@ public class RedisBungeeConfiguration {
|
||||
private final boolean handleMotd;
|
||||
|
||||
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages, boolean kickWhenOnline, boolean handleReconnectToLastServer, boolean handleMotd) {
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, boolean kickWhenOnline, boolean handleReconnectToLastServer, boolean handleMotd) {
|
||||
this.proxyId = proxyId;
|
||||
this.messages = messages;
|
||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||
for (String s : exemptAddresses) {
|
||||
addressBuilder.add(InetAddresses.forString(s));
|
||||
@ -67,10 +61,6 @@ public class RedisBungeeConfiguration {
|
||||
return overrideBungeeCommands;
|
||||
}
|
||||
|
||||
public String getMessage(MessageType messageType) {
|
||||
return this.messages.get(messageType);
|
||||
}
|
||||
|
||||
public boolean kickWhenOnline() {
|
||||
return kickWhenOnline;
|
||||
}
|
||||
|
34
RedisBungee-API/src/main/resources/lang.yml
Normal file
34
RedisBungee-API/src/main/resources/lang.yml
Normal file
@ -0,0 +1,34 @@
|
||||
# this config file is for messages / Languages
|
||||
# Note 1: use MiniMessage format https://docs.advntr.dev/minimessage/format.html for colors etc... Legacy chat color is not supported.
|
||||
# Mote 2: Language codes that are used is ISO 639-1, here is full list https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
|
||||
|
||||
|
||||
# example:
|
||||
# Format:
|
||||
# message_id:
|
||||
# <2 char language code>: "MiniMessage color and your text."
|
||||
# lets assume we want to add arabic language.
|
||||
# logged-in-other-location:
|
||||
# en: "<color:red>You logged in from another location!"
|
||||
# ar: "<color:red>لقد اتصلت من مكان اخر"
|
||||
|
||||
|
||||
# Prefix if ever used.
|
||||
redis-bungee-prefix: "<color:red>[<color:yellow>Redis<color:red>Bungee]"
|
||||
|
||||
# en is English, Which is the default language used when a language for a message isn't defined.
|
||||
# Warning: if en or set default language wasn't defined in the config for all messages, plugin will not load.
|
||||
|
||||
# set the default language
|
||||
default-language: en
|
||||
|
||||
# send language based on client sent settings
|
||||
# https://minecraft.fandom.com/wiki/Language
|
||||
use-client-language: true
|
||||
|
||||
|
||||
logged-in-other-location:
|
||||
en: "<color:red>You logged in from another location!"
|
||||
|
||||
already-logged-in:
|
||||
en: "<color:red>You are already logged in!"
|
@ -1,5 +0,0 @@
|
||||
# this config file is for messages for players and command messages
|
||||
# Note this uses MiniMessage format https://docs.advntr.dev/minimessage/format.html
|
||||
|
||||
logged-in-other-location: "<color:red>You logged in from another location!"
|
||||
already-logged-in: "<color:red>You are already logged in!"
|
@ -16,6 +16,7 @@ import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfigurati
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PlayerLeftNetworkEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@ -73,12 +74,12 @@ public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer, Po
|
||||
// check if online
|
||||
if (getLastOnline(event.getConnection().getUniqueId()) == 0) {
|
||||
if (plugin.configuration().kickWhenOnline()) {
|
||||
kickPlayer(event.getConnection().getUniqueId(),MiniMessage.miniMessage().deserialize( plugin.configuration().getMessage(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION)));
|
||||
kickPlayer(event.getConnection().getUniqueId(), Component.empty());
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3);
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason(BungeeComponentSerializer.get().serialize(MiniMessage.miniMessage().deserialize( plugin.configuration().getMessage(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN))));
|
||||
event.setCancelReason(BUNGEECORD_SERIALIZER.serialize(Component.empty()));
|
||||
event.completeIntent((Plugin) plugin);
|
||||
}
|
||||
} else {
|
||||
|
@ -24,6 +24,7 @@ import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
import com.velocitypowered.api.event.connection.PostLoginEvent;
|
||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
@ -68,15 +69,15 @@ public class VelocityPlayerDataManager extends PlayerDataManager<Player, PostLog
|
||||
|
||||
@Subscribe
|
||||
public void onLoginEvent(LoginEvent event, Continuation continuation) {
|
||||
System.out.println(event.getPlayer().getPlayerSettings().getLocale().getDisplayLanguage());
|
||||
// check if online
|
||||
if (getLastOnline(event.getPlayer().getUniqueId()) == 0) {
|
||||
if (plugin.configuration().kickWhenOnline()) {
|
||||
|
||||
kickPlayer(event.getPlayer().getUniqueId(), MiniMessage.miniMessage().deserialize(plugin.configuration().getMessage(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION)));
|
||||
kickPlayer(event.getPlayer().getUniqueId(), Component.empty());
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(continuation::resume, TimeUnit.SECONDS, 3);
|
||||
} else {
|
||||
event.setResult(ResultedEvent.ComponentResult.denied( MiniMessage.miniMessage().deserialize(plugin.configuration().getMessage(RedisBungeeConfiguration.MessageType.ALREADY_LOGGED_IN))));
|
||||
event.setResult(ResultedEvent.ComponentResult.denied(Component.empty()));
|
||||
continuation.resume();
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user