Fixed issues brought up in review

This commit is contained in:
Matthew Miller
2019-11-18 19:50:52 +10:00
parent 625be46b30
commit ded86d4872
19 changed files with 76 additions and 41 deletions

View File

@ -29,6 +29,7 @@ import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
@ -76,6 +77,8 @@ public abstract class LocalConfiguration {
public boolean allowSymlinks = false;
public boolean serverSideCUI = true;
public boolean extendedYLimit = false;
public String defaultLocaleName = "default";
public Locale defaultLocale = Locale.getDefault();
protected String[] getDefaultDisallowedBlocks() {
List<BlockType> blockTypes = Lists.newArrayList(

View File

@ -118,7 +118,7 @@ public class BrushCommands {
tool.setBrush(new SphereBrush(), "worldedit.brush.sphere");
}
player.printInfo(TranslatableComponent.of("worldedit.brush.sphere.equip", TextComponent.of((int) radius)));
player.printInfo(TranslatableComponent.of("worldedit.brush.sphere.equip", TextComponent.of(String.format("%.0f", radius))));
}
@Command(

View File

@ -96,7 +96,7 @@ public class GeneralCommands {
session.setBlockChangeLimit(limit);
Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.limit.set", TextComponent.of(limit)));
if (limit != config.defaultChangeLimit) {
component.append(TranslatableComponent.of("worldedit.limit.return-to-default", TextColor.GRAY));
component.append(TextComponent.space()).append(TranslatableComponent.of("worldedit.limit.return-to-default", TextColor.GRAY));
}
actor.printInfo(component);
}
@ -180,7 +180,8 @@ public class GeneralCommands {
}
boolean useServerCui = session.shouldUseServerCUI();
if (drawSelection != null && drawSelection == useServerCui) {
player.printError(TranslatableComponent.of(useServerCui ? "worldedit.drawsel.enabled.already" : "worldedit.drawsel.disabled.already"));
player.printError(TranslatableComponent.of("worldedit.drawsel." + (useServerCui ? "enabled" : "disabled") + ".already"));
return;
}
if (useServerCui) {
@ -284,7 +285,7 @@ public class GeneralCommands {
return;
}
if (blocksOnly && itemsOnly) {
actor.printError(TranslatableComponent.of("worldedit.searchitem.b-and-i"));
actor.printError(TranslatableComponent.of("worldedit.searchitem.either-b-or-i"));
return;
}

View File

@ -39,6 +39,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
@ -119,6 +120,12 @@ public class PropertiesConfiguration extends LocalConfiguration {
allowSymlinks = getBool("allow-symbolic-links", allowSymlinks);
serverSideCUI = getBool("server-side-cui", serverSideCUI);
extendedYLimit = getBool("extended-y-limit", extendedYLimit);
defaultLocaleName = getString("default-locale", defaultLocaleName);
if (defaultLocaleName.equals("default")) {
defaultLocale = Locale.getDefault();
} else {
defaultLocale = Locale.forLanguageTag(defaultLocaleName.replace('_', '-'));
}
LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15));

View File

@ -30,6 +30,7 @@ import org.slf4j.Logger;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
/**
* A less simple implementation of {@link LocalConfiguration}
@ -125,6 +126,13 @@ public class YAMLConfiguration extends LocalConfiguration {
shellSaveType = type.isEmpty() ? null : type;
extendedYLimit = config.getBoolean("compat.extended-y-limit", false);
defaultLocaleName = config.getString("default-locale", defaultLocaleName);
if (defaultLocaleName.equals("default")) {
defaultLocale = Locale.getDefault();
} else {
defaultLocale = Locale.forLanguageTag(defaultLocaleName.replace('_', '-'));
}
}
public void unload() {

View File

@ -27,16 +27,19 @@ public class ResourceLoader {
private ResourceLoader() {
}
private static URL getResourceForgeHack(String location) throws IOException {
return new URL("modjar://worldedit/" + location);
}
public static URL getResource(Class clazz, String name) throws IOException {
URL url = clazz.getResource(name);
if (url == null) {
try {
return new URL("modjar://worldedit/" + clazz.getName().substring(0, clazz.getName().lastIndexOf('.')).replace(".", "/") + "/"
+ name);
return getResourceForgeHack(clazz.getName().substring(0, clazz.getName().lastIndexOf('.')).replace(".", "/")
+ "/" + name);
} catch (Exception e) {
// Not forge.
throw new IOException("Could not find " + name);
}
throw new IOException("Could not find " + name);
}
return url;
}
@ -45,11 +48,10 @@ public class ResourceLoader {
URL url = ResourceLoader.class.getResource("/" + name);
if (url == null) {
try {
return new URL("modjar://worldedit/" + name);
return getResourceForgeHack(name);
} catch (Exception e) {
// Not forge.
throw new IOException("Could not find " + name);
}
throw new IOException("Could not find " + name);
}
return url;
}

View File

@ -30,7 +30,10 @@ import com.sk89q.worldedit.util.formatting.text.renderer.FriendlyComponentRender
import com.sk89q.worldedit.util.io.ResourceLoader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.URL;
import java.nio.charset.StandardCharsets;
@ -81,19 +84,15 @@ public class TranslationManager {
return translations;
}
private Map<String, String> parseTranslationFile(File file) throws IOException {
return filterTranslations(gson.fromJson(Files.toString(file, StandardCharsets.UTF_8), STRING_MAP_TYPE));
}
private Map<String, String> parseTranslationFile(URL file) throws IOException {
return filterTranslations(gson.fromJson(Resources.toString(file, StandardCharsets.UTF_8), STRING_MAP_TYPE));
private Map<String, String> parseTranslationFile(InputStream inputStream) {
return filterTranslations(gson.fromJson(new InputStreamReader(inputStream), STRING_MAP_TYPE));
}
private Optional<Map<String, String>> loadTranslationFile(String filename) {
Map<String, String> baseTranslations;
try {
baseTranslations = parseTranslationFile(ResourceLoader.getResourceRoot("lang/" + filename));
baseTranslations = parseTranslationFile(ResourceLoader.getResourceRoot("lang/" + filename).openStream());
} catch (IOException e) {
// Seem to be missing base. If the user has provided a file use that.
baseTranslations = new HashMap<>();
@ -102,7 +101,7 @@ public class TranslationManager {
File localFile = worldEdit.getWorkingDirectoryFile("lang/" + filename);
if (localFile.exists()) {
try {
baseTranslations.putAll(parseTranslationFile(localFile));
baseTranslations.putAll(parseTranslationFile(new FileInputStream(localFile)));
} catch (IOException e) {
// Failed to parse custom language file. Worth printing.
e.printStackTrace();

View File

@ -37,7 +37,7 @@
"worldedit.drawsel.enabled.already": "Server CUI already enabled.",
"worldedit.limit.too-high": "Your maximum allowable limit is {0}.",
"worldedit.limit.set": "Block change limit set to {0}.",
"worldedit.limit.return-to-default": " (Use //limit to go back to the default.)",
"worldedit.limit.return-to-default": "(Use //limit to go back to the default.)",
"worldedit.timeout.too-high": "Your maximum allowable timeout is {0}ms.",
"worldedit.timeout.set": "Timeout time set to {0} ms.",
"worldedit.timeout.return-to-default": " (Use //timeout to go back to the default.)",
@ -52,7 +52,7 @@
"worldedit.toggleplace.pos1": "Now placing at pos #1.",
"worldedit.toggleplace.player": "Now placing at the block you stand in.",
"worldedit.searchitem.too-short": "Enter a longer search string (len > 2).",
"worldedit.searchitem.b-and-i": "You cannot use both the 'b' and 'i' flags simultaneously.",
"worldedit.searchitem.either-b-or-i": "You cannot use both the 'b' and 'i' flags simultaneously.",
"worldedit.searchitem.searching": "(Please wait... searching items.)",
"worldedit.watchdog.no-hook": "This platform has no watchdog hook.",
"worldedit.watchdog.active.already": "Watchdog hook already active.",
@ -323,5 +323,8 @@
"worldedit.help.command-not-found": "The command '{0}' could not be found.",
"worldedit.help.no-subcommands": "'{0}' has no sub-commands. (Maybe '{1}' is for a parameter?)",
"worldedit.help.subcommand-not-found": "The sub-command '{0}' under '{1}' could not be found."
"worldedit.help.subcommand-not-found": "The sub-command '{0}' under '{1}' could not be found.",
"worldedit.cli.stopping": "Stopping!",
"worldedit.cli.unknown-command": "Unknown command!"
}