3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-19 09:20:08 +01:00

Fixed issues brought up in review

Dieser Commit ist enthalten in:
Matthew Miller 2019-11-18 19:50:52 +10:00
Ursprung 625be46b30
Commit ded86d4872
19 geänderte Dateien mit 76 neuen und 41 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extent.Extent;
@ -98,7 +99,7 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements
@Override
public Locale getLocale() {
return Locale.US;
return WorldEdit.getInstance().getConfiguration().defaultLocale;
}
@Override

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.bukkit.util.CommandInspector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -53,7 +54,7 @@ class BukkitCommandInspector implements CommandInspector {
public String getShortText(Command command) {
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
if (mapping.isPresent()) {
return reduceToText(mapping.get().getDescription(), Locale.US);
return reduceToText(mapping.get().getDescription(), WorldEdit.getInstance().getConfiguration().defaultLocale);
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return "Help text not available";
@ -64,7 +65,7 @@ class BukkitCommandInspector implements CommandInspector {
public String getFullText(Command command) {
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
if (mapping.isPresent()) {
return reduceToText(mapping.get().getFullHelp(), Locale.US);
return reduceToText(mapping.get().getFullHelp(), WorldEdit.getInstance().getConfiguration().defaultLocale);
} else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return "Help text not available";

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.auth.AuthorizationException;
@ -114,7 +115,7 @@ public class BukkitCommandSender extends AbstractNonPlayerActor {
@Override
public Locale getLocale() {
return Locale.US;
return WorldEdit.getInstance().getConfiguration().defaultLocale;
}
@Override

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
@ -170,8 +171,8 @@ public class BukkitServerInterface implements MultiUserPlatform {
command.getAliases().stream()
).toArray(String[]::new);
// TODO Handle localisation correctly
return new CommandInfo(reduceToText(command.getUsage(), Locale.US),
reduceToText(command.getDescription(), Locale.US), aliases,
return new CommandInfo(reduceToText(command.getUsage(), WorldEdit.getInstance().getConfiguration().defaultLocale),
reduceToText(command.getDescription(), WorldEdit.getInstance().getConfiguration().defaultLocale), aliases,
inspector, permissionsArray);
}).collect(Collectors.toList()));
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.cli;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
@ -141,7 +142,7 @@ public class CLICommandSender implements Actor {
@Override
public Locale getLocale() {
return Locale.getDefault();
return WorldEdit.getInstance().getConfiguration().defaultLocale;
}
@Override

Datei anzeigen

@ -32,7 +32,7 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockState;
@ -238,13 +238,13 @@ public class CLIWorldEdit {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.equals("stop")) {
commandSender.printInfo(TextComponent.of("Stopping!"));
commandSender.printInfo(TranslatableComponent.of("worldedit.cli.stopping"));
break;
}
CommandEvent event = new CommandEvent(commandSender, line);
WorldEdit.getInstance().getEventBus().post(event);
if (!event.isCancelled()) {
commandSender.printError(TextComponent.of("Unknown command!"));
commandSender.printError(TranslatableComponent.of("worldedit.cli.unknown-command"));
} else {
saveAllWorlds(false);
}

Datei anzeigen

@ -95,20 +95,20 @@ if (project.hasProperty(crowdinApiKey)) {
apiKey = "${project.property(crowdinApiKey)}"
projectId = "worldedit-core"
files = arrayOf(
object {
var name = "strings.json"
var source = "$projectDir/src/main/resources/lang/strings.json"
}
object {
var name = "strings.json"
var source = "${file("src/main/resources/lang/strings.json")}"
}
)
}
tasks.named<DownloadTranslationsTask>("crowdinDownload") {
apiKey = "${project.property(crowdinApiKey)}"
destination = "$projectDir/src/main/resources/lang"
destination = "${file("build/resources/main/lang")}"
projectId = "worldedit-core"
}
tasks.named("processResources").configure {
tasks.named("classes").configure {
dependsOn("crowdinDownload")
}
}

Datei anzeigen

@ -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(

Datei anzeigen

@ -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(

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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));

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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!"
}

Datei anzeigen

@ -26,6 +26,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(ServerPlayerEntity.class)
public interface AccessorServerPlayerEntity {
@Accessor("clientLanguage")
@Accessor
String getClientLanguage();
}

Datei anzeigen

@ -27,7 +27,6 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.sponge;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionKey;
@ -144,7 +145,7 @@ public class SpongeCommandSender implements Actor {
@Override
public Locale getLocale() {
return Locale.US;
return WorldEdit.getInstance().getConfiguration().defaultLocale;
}
@Override

Datei anzeigen

@ -34,6 +34,7 @@ import org.slf4j.Logger;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
public class ConfigurateConfiguration extends LocalConfiguration {
@ -131,5 +132,11 @@ public class ConfigurateConfiguration extends LocalConfiguration {
shellSaveType = type.equals("") ? null : type;
extendedYLimit = node.getNode("compat", "extended-y-limit").getBoolean(false);
defaultLocaleName = node.getNode("default-locale").getString(defaultLocaleName);
if (defaultLocaleName.equals("default")) {
defaultLocale = Locale.getDefault();
} else {
defaultLocale = Locale.forLanguageTag(defaultLocaleName.replace('_', '-'));
}
}
}