13
0
geforkt von Mirrors/Velocity

Added ability to customize translations (#692)

* Added ability to customize translations

* Removed remaining usage of `Paths#get`

As of java 11 its replacement `Path#of` was created, which is called when using `Paths#get`, besides, according to documentation, it mentions that it can be deprecated at any time

And fix a minor typo in LegacyChannelIdentifier
Dieser Commit ist enthalten in:
4drian3d 2022-04-15 23:38:44 -05:00 committet von GitHub
Ursprung 3cb10f6ad4
Commit acc407a6d5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
6 geänderte Dateien mit 37 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -13,7 +13,7 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin * Represents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin
* messages, please see {@link MinecraftChannelIdentifier}. This class is immutable and safe for * messages, please see {@link MinecraftChannelIdentifier}. This class is immutable and safe for
* multi-threaded use. * multi-threaded use.
*/ */

Datei anzeigen

@ -29,7 +29,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
public class Natives { public class Natives {
@ -70,7 +69,7 @@ public class Natives {
private static Path createTemporaryNativeFilename(String ext) throws IOException { private static Path createTemporaryNativeFilename(String ext) throws IOException {
String temporaryFolderPath = System.getProperty("velocity.natives-tmpdir"); String temporaryFolderPath = System.getProperty("velocity.natives-tmpdir");
if (temporaryFolderPath != null) { if (temporaryFolderPath != null) {
return Files.createTempFile(Paths.get(temporaryFolderPath), "native-", ext); return Files.createTempFile(Path.of(temporaryFolderPath), "native-", ext);
} else { } else {
return Files.createTempFile("native-", ext); return Files.createTempFile("native-", ext);
} }

Datei anzeigen

@ -21,7 +21,7 @@ import com.velocitypowered.proxy.config.VelocityConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Paths; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -42,7 +42,7 @@ public class Metrics {
private MetricsBase metricsBase; private MetricsBase metricsBase;
private Metrics(Logger logger, int serviceId, boolean defaultEnabled) { private Metrics(Logger logger, int serviceId, boolean defaultEnabled) {
File configFile = Paths.get("plugins").resolve("bStats").resolve("config.txt").toFile(); File configFile = Path.of("plugins", "bStats", "config.txt").toFile();
MetricsConfig config; MetricsConfig config;
try { try {
config = new MetricsConfig(configFile, defaultEnabled); config = new MetricsConfig(configFile, defaultEnabled);

Datei anzeigen

@ -67,10 +67,10 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessController; import java.security.AccessController;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
@ -252,27 +252,44 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
FileSystemUtils.visitResources(VelocityServer.class, path -> { FileSystemUtils.visitResources(VelocityServer.class, path -> {
logger.info("Loading localizations..."); logger.info("Loading localizations...");
final Path langPath = Path.of("lang");
try { try {
if (!Files.exists(langPath)) {
Files.createDirectory(langPath);
Files.walk(path).forEach(file -> { Files.walk(path).forEach(file -> {
if (!Files.isRegularFile(file)) { if (!Files.isRegularFile(file)) {
return; return;
} }
try {
Path langFile = langPath.resolve(file.getFileName().toString());
if (!Files.exists(langFile)) {
try (InputStream is = Files.newInputStream(file)) {
Files.copy(is, langFile);
}
}
} catch (IOException e) {
logger.error("Encountered an I/O error whilst loading translations", e);
}
});
}
Files.walk(langPath).forEach(file -> {
if (!Files.isRegularFile(file)) {
return;
}
String filename = com.google.common.io.Files String filename = com.google.common.io.Files
.getNameWithoutExtension(file.getFileName().toString()); .getNameWithoutExtension(file.getFileName().toString());
String localeName = filename.replace("messages_", "") String localeName = filename.replace("messages_", "")
.replace("messages", "") .replace("messages", "")
.replace('_', '-'); .replace('_', '-');
Locale locale; Locale locale = localeName.isBlank()
if (localeName.isEmpty()) { ? Locale.US
locale = Locale.US; : Locale.forLanguageTag(localeName);
} else {
locale = Locale.forLanguageTag(localeName);
}
translationRegistry.registerAll(locale, translationRegistry.registerAll(locale, file, false);
ResourceBundle.getBundle("com/velocitypowered/proxy/l10n/messages",
locale, UTF8ResourceBundleControl.get()), false);
ClosestLocaleMatcher.INSTANCE.registerKnown(locale); ClosestLocaleMatcher.INSTANCE.registerKnown(locale);
}); });
} catch (IOException e) { } catch (IOException e) {
@ -289,7 +306,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
@SuppressFBWarnings("DM_EXIT") @SuppressFBWarnings("DM_EXIT")
private void doStartupConfigLoad() { private void doStartupConfigLoad() {
try { try {
Path configPath = Paths.get("velocity.toml"); Path configPath = Path.of("velocity.toml");
configuration = VelocityConfiguration.read(configPath); configuration = VelocityConfiguration.read(configPath);
if (!configuration.validate()) { if (!configuration.validate()) {
@ -311,7 +328,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
logger.info("Loading plugins..."); logger.info("Loading plugins...");
try { try {
Path pluginPath = Paths.get("plugins"); Path pluginPath = Path.of("plugins");
if (!pluginPath.toFile().exists()) { if (!pluginPath.toFile().exists()) {
Files.createDirectory(pluginPath); Files.createDirectory(pluginPath);
@ -363,7 +380,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
* @throws IOException if we can't read {@code velocity.toml} * @throws IOException if we can't read {@code velocity.toml}
*/ */
public boolean reloadConfiguration() throws IOException { public boolean reloadConfiguration() throws IOException {
Path configPath = Paths.get("velocity.toml"); Path configPath = Path.of("velocity.toml");
VelocityConfiguration newConfiguration = VelocityConfiguration.read(configPath); VelocityConfiguration newConfiguration = VelocityConfiguration.read(configPath);
if (!newConfiguration.validate()) { if (!newConfiguration.validate()) {

Datei anzeigen

@ -38,7 +38,6 @@ import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.HashMap; import java.util.HashMap;
@ -219,7 +218,7 @@ public class VelocityConfiguration implements ProxyConfig {
} }
private void loadFavicon() { private void loadFavicon() {
Path faviconPath = Paths.get("server-icon.png"); Path faviconPath = Path.of("server-icon.png");
if (Files.exists(faviconPath)) { if (Files.exists(faviconPath)) {
try { try {
this.favicon = Favicon.create(faviconPath); this.favicon = Favicon.create(faviconPath);

Datei anzeigen

@ -26,7 +26,6 @@ import java.nio.file.FileSystem;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -83,7 +82,7 @@ public class FileSystemUtils {
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
consumer.accept(Paths.get(uri)); consumer.accept(Path.of(uri));
return true; return true;
} }
} }