Skip to content

Commit

Permalink
remove lang system for commands
Browse files Browse the repository at this point in the history
commands will be included in seperate plugins for each platforms.
NOTE: because of this commands `Modules` will be used as example to access
the API
  • Loading branch information
ham1255 committed Feb 23, 2024
1 parent 6914e7d commit 06b750e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,74 +121,6 @@ public void test(Locale locale) {

}

public static class CommandMessages implements RegistrableMessages {

private final Locale defaultLocale;

// Common
private final Map<Locale, Component> COMMON_PLAYER_NOT_FOUND;
private final Map<Locale, Component> COMMON_PLAYER_NOT_SPECIFIED;
private final Map<Locale, Component> COMMON_COMMAND_NOT_SPECIFIED;

public CommandMessages(Locale defaultLocale) {
this.defaultLocale = defaultLocale;
COMMON_PLAYER_NOT_FOUND = new HashMap<>();
COMMON_COMMAND_NOT_SPECIFIED = new HashMap<>();
COMMON_PLAYER_NOT_SPECIFIED = new HashMap<>();
}

// probably split using :
@Override
public void register(String id, Locale locale, String miniMessage) {
String[] splitId = id.split(":");
//System.out.println(Arrays.toString(splitId) + " " + locale + miniMessage);
switch (splitId[0]) {
case "commands-common" -> {
switch (splitId[1]) {
case "player-not-found" -> COMMON_PLAYER_NOT_FOUND.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
case "player-not-specified" -> COMMON_PLAYER_NOT_SPECIFIED.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
case "command-not-specified" -> COMMON_COMMAND_NOT_SPECIFIED.put(locale, MiniMessage.miniMessage().deserialize(miniMessage));
}
}
case "commands" -> {
switch (splitId[1]) {

}
}
}
}

public Component playerNotFound(Locale locale) {
if (COMMON_PLAYER_NOT_FOUND.containsKey(locale)) return COMMON_PLAYER_NOT_FOUND.get(locale);
return COMMON_PLAYER_NOT_FOUND.get(defaultLocale);
}
public Component playerNotFound() {
return playerNotFound(this.defaultLocale);
}
public Component commandNotSpecified(Locale locale) {
if (COMMON_COMMAND_NOT_SPECIFIED.containsKey(locale)) return COMMON_COMMAND_NOT_SPECIFIED.get(locale);
return COMMON_COMMAND_NOT_SPECIFIED.get(defaultLocale);
}
public Component commandNotSpecified() {
return commandNotSpecified(this.defaultLocale);
}
public Component playerNotSpecified(Locale locale) {
if (COMMON_PLAYER_NOT_SPECIFIED.containsKey(locale)) return COMMON_PLAYER_NOT_SPECIFIED.get(locale);
return COMMON_PLAYER_NOT_SPECIFIED.get(defaultLocale);
}
public Component playerNotSpecified() {
return playerNotSpecified(this.defaultLocale);
}


@Override
public void test(Locale locale) {
if (!(this.COMMON_PLAYER_NOT_FOUND.containsKey(locale) && this.COMMON_PLAYER_NOT_SPECIFIED.containsKey(locale) && this.COMMON_COMMAND_NOT_SPECIFIED.containsKey(locale))) {
throwError(locale, "commands messages");
}
}
}

private final Component redisBungeePrefix;

private final Locale defaultLanguage;
Expand All @@ -197,15 +129,11 @@ public void test(Locale locale) {

private final Messages messages;

private final CommandMessages commandMessages;


public LangConfiguration(Component redisBungeePrefix, Locale defaultLanguage, boolean useClientLanguage, Messages messages, CommandMessages commandMessages) {
public LangConfiguration(Component redisBungeePrefix, Locale defaultLanguage, boolean useClientLanguage, Messages messages) {
this.redisBungeePrefix = redisBungeePrefix;
this.defaultLanguage = defaultLanguage;
this.useClientLanguage = useClientLanguage;
this.messages = messages;
this.commandMessages = commandMessages;
}

public Component redisBungeePrefix() {
Expand All @@ -224,7 +152,4 @@ public Messages messages() {
return messages;
}

public CommandMessages commandMessages() {
return commandMessages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,8 @@ default void loadLangConfig(RedisBungeePlugin<?> plugin, Path dataFolder) throws
messages.register(key.toString(), Locale.forLanguageTag(childKey.toString()), childChildNode.getString());
}));
messages.test(defaultLocale);
LangConfiguration.CommandMessages commandMessages = new LangConfiguration.CommandMessages(defaultLocale);

node.getNode("commands-common").getChildrenMap().forEach((key, childNode) -> childNode.getChildrenMap().forEach((childKey, childChildNode) -> {
commandMessages.register("commands-common:" + key.toString(), Locale.forLanguageTag(childKey.toString()), childChildNode.getString());
}));
node.getNode("commands").getChildrenMap().forEach((key, childNode) -> childNode.getChildrenMap().forEach((childKey, childChildNode) -> childChildNode.getChildrenMap().forEach((childChildKey, childChildChildNode) -> {
commandMessages.register("commands:" + key.toString() + ":" + childKey.toString(), Locale.forLanguageTag(childChildKey.toString()), childChildChildNode.getString());
})));
commandMessages.test(defaultLocale);
onLangConfigLoad(new LangConfiguration(prefix, defaultLocale, useClientLocale, messages, commandMessages));
onLangConfigLoad(new LangConfiguration(prefix, defaultLocale, useClientLocale, messages));
}


Expand Down
56 changes: 0 additions & 56 deletions RedisBungee-API/src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,5 @@ messages:
# placeholder <server> displays server name in the message.
en-us: "<color:green>Connecting you to <server>..."


# commands common messages
commands-common:
player-not-found:
en-us: "<color:red>Player not found."
player-not-specified:
en-us: "<color:red>You must specify a player name."
command-not-specified:
en-us: "<color:red>You must specify a command to be run."

# commands
commands:
glist:
single-player:
en-us: "<color:yellow>1 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."
find:
found:
en-us: "<color:blue><player> is on <server>."
last-seen:
online:
en-us: "<color:green><player> is currently online."
last-seen:
en-us: "<color:blue><player> last seen on <date>."
never-seen:
en-us: "<color:red><player> has never been online."
ip:
connected-from:
en-us: "<color:green><player> is connected from <ip>."
proxy:
connected-to:
en-us: "<color:green><player> is connected to <proxy>."
send-to-all:
sent:
en-us: "<color:green>Sent the command /<command> to all proxies."
# note: server here means a proxy.
server-id:
message:
en-us: "<color:yellow>You are on <color:blue><proxy>."
# Same here too
server-ids:
message:
en-us: "<color:yellow>All server IDs: <proxies>"
plist:
notice:
en-us: "<color:yellow>To see all players online, use /plist <proxy> showall."
not-valid-proxy:
en-us: "<color:red><proxy> is not valid proxy. use /serverids for valid proxies"
single-player:
en-us: "<color:yellow>1 player is currently online on <proxy>."
players:
en-us: "<color:yellow><players> players are currently online on <proxy>."

# DO NOT CHANGE!!!!!
config-version: 1

0 comments on commit 06b750e

Please sign in to comment.