diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java index f57181648..76f991837 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java @@ -13,7 +13,7 @@ import java.util.Objects; 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 * multi-threaded use. */ diff --git a/native/src/main/java/com/velocitypowered/natives/util/Natives.java b/native/src/main/java/com/velocitypowered/natives/util/Natives.java index 28110cacd..928b2dd3d 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardCopyOption; public class Natives { @@ -70,7 +69,7 @@ public class Natives { private static Path createTemporaryNativeFilename(String ext) throws IOException { String temporaryFolderPath = System.getProperty("velocity.natives-tmpdir"); if (temporaryFolderPath != null) { - return Files.createTempFile(Paths.get(temporaryFolderPath), "native-", ext); + return Files.createTempFile(Path.of(temporaryFolderPath), "native-", ext); } else { return Files.createTempFile("native-", ext); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java index 64addd7a0..660587cdd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java @@ -21,7 +21,7 @@ import com.velocitypowered.proxy.config.VelocityConfiguration; import java.io.File; import java.io.IOException; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -42,7 +42,7 @@ public class Metrics { private MetricsBase metricsBase; 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; try { config = new MetricsConfig(configFile, defaultEnabled); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 935b75291..f05d60a24 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -67,10 +67,10 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import java.io.IOException; +import java.io.InputStream; import java.net.InetSocketAddress; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.security.AccessController; import java.security.KeyPair; import java.security.PrivilegedAction; @@ -252,8 +252,30 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { FileSystemUtils.visitResources(VelocityServer.class, path -> { logger.info("Loading localizations..."); + final Path langPath = Path.of("lang"); + try { - Files.walk(path).forEach(file -> { + if (!Files.exists(langPath)) { + Files.createDirectory(langPath); + Files.walk(path).forEach(file -> { + if (!Files.isRegularFile(file)) { + 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; } @@ -263,16 +285,11 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { String localeName = filename.replace("messages_", "") .replace("messages", "") .replace('_', '-'); - Locale locale; - if (localeName.isEmpty()) { - locale = Locale.US; - } else { - locale = Locale.forLanguageTag(localeName); - } + Locale locale = localeName.isBlank() + ? Locale.US + : Locale.forLanguageTag(localeName); - translationRegistry.registerAll(locale, - ResourceBundle.getBundle("com/velocitypowered/proxy/l10n/messages", - locale, UTF8ResourceBundleControl.get()), false); + translationRegistry.registerAll(locale, file, false); ClosestLocaleMatcher.INSTANCE.registerKnown(locale); }); } catch (IOException e) { @@ -289,7 +306,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { @SuppressFBWarnings("DM_EXIT") private void doStartupConfigLoad() { try { - Path configPath = Paths.get("velocity.toml"); + Path configPath = Path.of("velocity.toml"); configuration = VelocityConfiguration.read(configPath); if (!configuration.validate()) { @@ -311,7 +328,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { logger.info("Loading plugins..."); try { - Path pluginPath = Paths.get("plugins"); + Path pluginPath = Path.of("plugins"); if (!pluginPath.toFile().exists()) { Files.createDirectory(pluginPath); @@ -363,7 +380,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { * @throws IOException if we can't read {@code velocity.toml} */ public boolean reloadConfiguration() throws IOException { - Path configPath = Paths.get("velocity.toml"); + Path configPath = Path.of("velocity.toml"); VelocityConfiguration newConfiguration = VelocityConfiguration.read(configPath); if (!newConfiguration.validate()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 927631aca..26438a28a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -38,7 +38,6 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.security.SecureRandom; import java.util.HashMap; @@ -219,7 +218,7 @@ public class VelocityConfiguration implements ProxyConfig { } private void loadFavicon() { - Path faviconPath = Paths.get("server-icon.png"); + Path faviconPath = Path.of("server-icon.png"); if (Files.exists(faviconPath)) { try { this.favicon = Favicon.create(faviconPath); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 591308bcb..86b59a8d9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -26,7 +26,6 @@ import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -83,7 +82,7 @@ public class FileSystemUtils { } catch (URISyntaxException e) { throw new IllegalStateException(e); } - consumer.accept(Paths.get(uri)); + consumer.accept(Path.of(uri)); return true; } }