Skip to content

Commit

Permalink
Support per-actor locales on platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Mar 16, 2022
1 parent 6263124 commit 0b78f2e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import revxrsal.commands.bukkit.BukkitCommandActor;
import revxrsal.commands.bukkit.exception.SenderNotConsoleException;
import revxrsal.commands.bukkit.exception.SenderNotPlayerException;
import revxrsal.commands.locales.Locales;

import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.UUID;

import static revxrsal.commands.util.Preconditions.notNull;
Expand Down Expand Up @@ -82,4 +84,12 @@ else if (isConsole())
@Override public CommandHandler getCommandHandler() {
return handler;
}

@Override public @NotNull Locale getLocale() {
if (isPlayer()) {
Locale locale = Locales.get(requirePlayer().getLocale());
return locale == null ? BukkitCommandActor.super.getLocale() : locale;
}
return BukkitCommandActor.super.getLocale();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import revxrsal.commands.bungee.BungeeCommandActor;
import revxrsal.commands.bungee.exception.SenderNotPlayerException;

import java.util.Locale;
import java.util.UUID;

import static revxrsal.commands.util.Strings.colorize;
Expand Down Expand Up @@ -62,4 +63,10 @@ public BungeeActor(CommandSender sender, CommandHandler handler) {
@Override public CommandHandler getCommandHandler() {
return handler;
}

@Override public @NotNull Locale getLocale() {
if (isPlayer())
return requirePlayer().getLocale();
return BungeeCommandActor.super.getLocale();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import revxrsal.commands.sponge.exception.SenderNotConsoleException;
import revxrsal.commands.sponge.exception.SenderNotPlayerException;

import java.util.Locale;
import java.util.UUID;

import static revxrsal.commands.util.Strings.colorize;
Expand Down Expand Up @@ -75,6 +76,12 @@ public SpongeActor(CommandSource source, CommandHandler handler) {
return (ConsoleSource) source;
}

@Override public @NotNull Locale getLocale() {
if (isPlayer())
return requirePlayer().getLocale();
return SpongeCommandActor.super.getLocale();
}

@Override public void reply(@NotNull Text message) {
source.sendMessage(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import revxrsal.commands.velocity.exception.SenderNotConsoleException;
import revxrsal.commands.velocity.exception.SenderNotPlayerException;

import java.util.Locale;
import java.util.UUID;

import static revxrsal.commands.util.Preconditions.notNull;
Expand Down Expand Up @@ -61,11 +62,16 @@ public VelocityActor(CommandSource source, ProxyServer server, CommandHandler ha
source.sendMessage(component);
}


@Override public void reply(@NotNull ComponentLike component) {
source.sendMessage(component);
}

@Override public @NotNull Locale getLocale() {
if (isPlayer())
return requirePlayer().getPlayerSettings().getLocale();
return VelocityCommandActor.super.getLocale();
}

@Override public @NotNull ProxyServer getServer() {
return server;
}
Expand Down

0 comments on commit 0b78f2e

Please sign in to comment.