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:
Ursprung
3cb10f6ad4
Commit
acc407a6d5
@ -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.
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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,27 +252,44 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
FileSystemUtils.visitResources(VelocityServer.class, path -> {
|
||||
logger.info("Loading localizations...");
|
||||
|
||||
final Path langPath = Path.of("lang");
|
||||
|
||||
try {
|
||||
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;
|
||||
}
|
||||
|
||||
String filename = com.google.common.io.Files
|
||||
.getNameWithoutExtension(file.getFileName().toString());
|
||||
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()) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren