Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-24 15:20:25 +01:00
Re-use patterns in MinecraftTranslationRegistry
Dieser Commit ist enthalten in:
Ursprung
c1e66f306c
Commit
d602d820dd
@ -44,6 +44,7 @@ import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||
import org.geysermc.connector.metrics.Metrics;
|
||||
import org.geysermc.connector.network.ConnectorServerEventHandler;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||
import org.geysermc.connector.registry.BlockRegistries;
|
||||
import org.geysermc.connector.registry.Registries;
|
||||
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
|
||||
@ -150,6 +151,7 @@ public class GeyserConnector {
|
||||
Registries.init();
|
||||
|
||||
ItemTranslator.init();
|
||||
MessageTranslator.init();
|
||||
LocaleUtils.init();
|
||||
|
||||
ResourcePack.loadPacks();
|
||||
|
@ -270,4 +270,8 @@ public class MessageTranslator {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,10 @@ package org.geysermc.connector.network.translators.chat;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.geysermc.connector.utils.LocaleUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
@ -42,18 +41,21 @@ import java.util.regex.Pattern;
|
||||
* Used in MessageTranslator.java as part of the KyoriPowered/Adventure library
|
||||
*/
|
||||
public class MinecraftTranslationRegistry implements Translator {
|
||||
private final Pattern stringReplacement = Pattern.compile("%s");
|
||||
private final Pattern positionalStringReplacement = Pattern.compile("%([0-9]+)\\$s");
|
||||
|
||||
@Override
|
||||
public @Nonnull Key name() {
|
||||
return Key.key("geyser", "minecraft_translations");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable MessageFormat translate(@NonNull String key, @NonNull Locale locale) {
|
||||
public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull Locale locale) {
|
||||
// Get the locale string
|
||||
String localeString = LocaleUtils.getLocaleString(key, locale.toString());
|
||||
|
||||
// Replace the `%s` with numbered inserts `{0}`
|
||||
Pattern p = Pattern.compile("%s");
|
||||
Pattern p = stringReplacement;
|
||||
Matcher m = p.matcher(localeString);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int i = 0;
|
||||
@ -63,7 +65,7 @@ public class MinecraftTranslationRegistry implements Translator {
|
||||
m.appendTail(sb);
|
||||
|
||||
// Replace the `%x$s` with numbered inserts `{x}`
|
||||
p = Pattern.compile("%([0-9]+)\\$s");
|
||||
p = positionalStringReplacement;
|
||||
m = p.matcher(sb.toString());
|
||||
sb = new StringBuffer();
|
||||
while (m.find()) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren