From 80d7b0582f4673695b61d1841af6cda4bc2391a2 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Mon, 9 Dec 2019 20:07:57 +0100 Subject: [PATCH] i18n upstream merge --- .gitignore | 3 ++ .../sk89q/worldedit/bukkit/BukkitPlayer.java | 3 +- .../sk89q/worldedit/LocalConfiguration.java | 10 ++++- .../worldedit/command/SelectionCommands.java | 8 ++-- .../worldedit/command/WorldEditCommands.java | 2 +- .../command/util/AsyncCommandBuilder.java | 4 +- .../worldedit/function/factory/Deform.java | 23 +++++------ .../function/operation/ForwardExtentCopy.java | 38 ++++++++----------- .../function/operation/Operation.java | 15 ++++++++ .../function/visitor/BreadthFirstSearch.java | 4 +- .../function/visitor/EntityVisitor.java | 3 +- .../function/visitor/FlatRegionVisitor.java | 3 +- .../function/visitor/RegionVisitor.java | 3 +- .../worldedit/regions/RegionSelector.java | 24 ++++++------ .../util/PropertiesConfiguration.java | 8 +--- .../worldedit/util/YAMLConfiguration.java | 8 +--- .../util/formatting/WorldEditText.java | 2 +- .../util/formatting/component/TextUtils.java | 10 +++++ .../worldedit/util/io/ResourceLoader.java | 22 +++++------ .../util/translation/TranslationManager.java | 34 +++++++---------- .../src/main/resources/lang/.gitignore | 1 - .../src/main/resources/lang/strings.json | 1 - .../sk89q/worldedit/forge/ForgePlayer.java | 3 +- .../config/ConfigurateConfiguration.java | 8 +--- 24 files changed, 121 insertions(+), 119 deletions(-) delete mode 100644 worldedit-core/src/main/resources/lang/.gitignore diff --git a/.gitignore b/.gitignore index b33e539e0..abbab0e31 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ todo.txt mvn/* docs/ *.sh +# i18n +worldedit-core/src/main/resources/lang/* +!worldedit-core/src/main/resources/lang/strings.json diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 751d915c5..e25697834 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.bukkit; import com.boydti.fawe.Fawe; import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.config.Caption; +import com.sk89q.worldedit.util.formatting.component.TextUtils; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.RunnableVal; @@ -280,7 +281,7 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public Locale getLocale() { - return Locale.forLanguageTag(player.getLocale().replace('_', '-')); + return TextUtils.getLocaleByMinecraftTag(player.getLocale()); } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java index 7725376f6..49a7f39df 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalConfiguration.java @@ -24,6 +24,7 @@ import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.BlockMaskBuilder; +import com.sk89q.worldedit.util.formatting.component.TextUtils; import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -210,5 +211,12 @@ public abstract class LocalConfiguration { return item; } - + public void setDefaultLocaleName(String localeName) { + this.defaultLocaleName = localeName; + if (localeName.equals("default")) { + this.defaultLocale = Locale.getDefault(); + } else { + this.defaultLocale = TextUtils.getLocaleByMinecraftTag(localeName); + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index d28f4d8bb..9a0d08b61 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -312,7 +312,7 @@ public class SelectionCommands { ) @CommandPermissions("worldedit.wand.toggle") public void toggleWand(Player player) { - player.print(TextComponent.of("The selection wand is now a normal tool. You can disable it with ") + player.printInfo(TextComponent.of("The selection wand is now a normal tool. You can disable it with ") .append(TextComponent.of("/none", TextColor.AQUA).clickEvent( ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/none"))) .append(TextComponent.of(" and rebind it to any item with ")) @@ -383,7 +383,7 @@ public class SelectionCommands { session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.print(TranslatableComponent.of("worldedit.shift.shifted")); + actor.printInfo(TranslatableComponent.of("worldedit.shift.shifted")); } catch (RegionOperationException e) { actor.printError(TextComponent.of(e.getMessage())); } @@ -406,7 +406,7 @@ public class SelectionCommands { region.expand(getChangesForEachDir(amount, onlyHorizontal, onlyVertical)); session.getRegionSelector(world).learnChanges(); session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.print(TranslatableComponent.of("worldedit.outset.outset")); + actor.printInfo(TranslatableComponent.of("worldedit.outset.outset")); } @Command( @@ -426,7 +426,7 @@ public class SelectionCommands { region.contract(getChangesForEachDir(amount, onlyHorizontal, onlyVertical)); session.getRegionSelector(world).learnChanges(); session.getRegionSelector(world).explainRegionAdjust(actor, session); - actor.print(TranslatableComponent.of("worldedit.inset.inset")); + actor.printInfo(TranslatableComponent.of("worldedit.inset.inset")); } private BlockVector3[] getChangesForEachDir(int amount, boolean onlyHorizontal, boolean onlyVertical) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 45d415c28..138f5bee3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -186,7 +186,7 @@ public class WorldEditCommands { actor.printInfo(TranslatableComponent.of("worldedit.timezone.set", TextComponent.of(tz.getDisplayName( TextStyle.FULL, actor.getLocale() )))); - actor.print(TranslatableComponent.of("worldedit.timezone.current", + actor.printInfo(TranslatableComponent.of("worldedit.timezone.current", TextComponent.of(dateFormat.withLocale(actor.getLocale()).format(ZonedDateTime.now(tz))))); } catch (ZoneRulesException e) { actor.printError(TranslatableComponent.of("worldedit.timezone.invalid")); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java index 7760d1bb9..4543ac224 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java @@ -166,13 +166,13 @@ public final class AsyncCommandBuilder { message = converted.getRichMessage(); } } - sender.print(failure.append(TextComponent.of(": ")).append(message)); + sender.printError(failure.append(TextComponent.of(": ")).append(message)); } } else { throw orig; } } catch (Throwable unknown) { - sender.print(failure.append(TextComponent.of(": Unknown error. Please see console."))); + sender.printError(failure.append(TextComponent.of(": Unknown error. Please see console."))); logger.error("Uncaught exception occurred in task: " + description, orig); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index 2aca7cd7d..9bb608bba 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -19,10 +19,7 @@ package com.sk89q.worldedit.function.factory; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; - -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -42,8 +39,8 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; -import java.util.Collection; -import java.util.List; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; public class Deform implements Contextual { @@ -160,6 +157,12 @@ public class Deform implements Contextual { session == null ? WorldEdit.getInstance().getConfiguration().calculationTimeout : session.getTimeout()); } + public enum Mode { + RAW_COORD, + OFFSET, + UNIT_CUBE + } + private static final class DeformOperation implements Operation { private final Extent destination; private final Region region; @@ -195,16 +198,10 @@ public class Deform implements Contextual { @Override public Iterable getStatusMessages() { - return Lists.newArrayList(TranslatableComponent.of("worldedit.operation.deform.expression", + return ImmutableList.of(TranslatableComponent.of("worldedit.operation.deform.expression", TextComponent.of(expression).color(TextColor.GRAY))); } } - public enum Mode { - RAW_COORD, - OFFSET, - UNIT_CUBE - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 1c3f68a20..8b46bb04e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -19,54 +19,49 @@ package com.sk89q.worldedit.function.operation; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - import com.boydti.fawe.object.extent.BlockTranslateExtent; import com.boydti.fawe.object.extent.PositionTransformExtent; import com.boydti.fawe.object.function.block.BiomeCopy; import com.boydti.fawe.object.function.block.CombinedBlockCopy; import com.boydti.fawe.object.function.block.SimpleBlockCopy; import com.boydti.fawe.util.MaskTraverser; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.metadata.EntityProperties; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.CombinedRegionFunction; -import com.sk89q.worldedit.function.FlatRegionFunction; -import com.sk89q.worldedit.function.FlatRegionMaskingFilter; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.RegionMaskTestFunction; -import com.sk89q.worldedit.function.biome.ExtentBiomeCopy; import com.sk89q.worldedit.function.RegionMaskingFilter; import com.sk89q.worldedit.function.entity.ExtentEntityCopy; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; -import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.visitor.EntityVisitor; +import com.sk89q.worldedit.function.visitor.FlatRegionVisitor; import com.sk89q.worldedit.function.visitor.IntersectRegionFunction; import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.function.visitor.FlatRegionVisitor; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.FlatRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.entity.EntityTypes; -import java.util.Collections; import com.sk89q.worldedit.util.formatting.text.Component; -import java.util.List; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.world.entity.EntityTypes; -import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.stream.Collectors; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Makes a copy of a portion of one extent to another extent or another point. * @@ -428,15 +423,14 @@ public class ForwardExtentCopy implements Operation { @Override public Iterable getStatusMessages() { - List messages = new ArrayList<>(); - messages.add(TranslatableComponent.of("worldedit.operation.affected.block", - TextComponent.of(affectedBlocks)).color(TextColor.GRAY)); - messages.add(TranslatableComponent.of("worldedit.operation.affected.biome", - TextComponent.of(affectedBiomeCols)).color(TextColor.GRAY)); - messages.add(TranslatableComponent.of("worldedit.operation.affected.entity", - TextComponent.of(affectedEntities)).color(TextColor.GRAY)); - - return messages; + return ImmutableList.of( + TranslatableComponent.of("worldedit.operation.affected.block", + TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), + TranslatableComponent.of("worldedit.operation.affected.biome", + TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), + TranslatableComponent.of("worldedit.operation.affected.entity", + TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) + ); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java index 5ae25eb2b..c21f2a6f7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/Operation.java @@ -19,12 +19,15 @@ package com.sk89q.worldedit.function.operation; +import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -35,6 +38,11 @@ import java.util.stream.Collectors; */ public interface Operation { + /** + * This is an internal field, and should not be touched. + */ + Set warnedDeprecatedClasses = new HashSet<>(); + /** * Complete the next step. If this method returns true, then the method may * be called again in the future, or possibly never. If this method @@ -76,6 +84,13 @@ public interface Operation { // TODO Remove legacy code WorldEdit 8.0.0 List oldMessages = new ArrayList<>(); addStatusMessages(oldMessages); + if (oldMessages.size() > 0) { + String className = getClass().getName(); + if (!warnedDeprecatedClasses.contains(className)) { + WorldEdit.logger.warn("An operation is using the old status message API. This will be removed in further versions. Class: " + className); + warnedDeprecatedClasses.add(className); + } + } return oldMessages.stream().map(TextComponent::of).collect(Collectors.toList()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 10efa0c9b..e85b7a4f1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.visitor; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.object.collection.BlockVectorSet; @@ -279,7 +279,7 @@ public abstract class BreadthFirstSearch implements Operation { @Override public Iterable getStatusMessages() { - return Lists.newArrayList(TranslatableComponent.of( + return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.block", TextComponent.of(getAffected()) ).color(TextColor.GRAY)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java index bdfb9dcc0..9d4405ca2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.visitor; +import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import static com.google.common.base.Preconditions.checkNotNull; @@ -84,7 +85,7 @@ public class EntityVisitor implements Operation { @Override public Iterable getStatusMessages() { - return Lists.newArrayList(TranslatableComponent.of( + return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.entity", TextComponent.of(getAffected()) ).color(TextColor.GRAY)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index ba43aca0b..799f69bb1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.visitor; +import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.google.common.collect.Lists; @@ -83,7 +84,7 @@ public class FlatRegionVisitor implements Operation { @Override public Iterable getStatusMessages() { - return Lists.newArrayList(TranslatableComponent.of( + return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.column", TextComponent.of(getAffected()) ).color(TextColor.GRAY)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index 89f4123b2..309da923a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.visitor; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; @@ -95,7 +96,7 @@ public class RegionVisitor implements Operation { @Override public Iterable getStatusMessages() { - return Lists.newArrayList(TranslatableComponent.of( + return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.block", TextComponent.of(getAffected()) ).color(TextColor.GRAY)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index 72a7f170c..2e257ce69 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -20,22 +20,21 @@ package com.sk89q.worldedit.regions; import com.google.common.collect.Lists; - import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.world.World; +import javax.annotation.Nullable; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import javax.annotation.Nullable; - /** * Region selectors create {@link Region}s from a series of "selected points." * They are used, for example, to allow users to create a {@link CuboidRegion} @@ -77,8 +76,8 @@ public interface RegionSelector { /** * Tell the player information about his/her primary selection. * - * @param actor the actor - * @param session the session + * @param actor the actor + * @param session the session * @param position position */ void explainPrimarySelection(Actor actor, LocalSession session, BlockVector3 position); @@ -86,8 +85,8 @@ public interface RegionSelector { /** * Tell the player information about his/her secondary selection. * - * @param actor the actor - * @param session the session + * @param actor the actor + * @param session the session * @param position position */ void explainSecondarySelection(Actor actor, LocalSession session, BlockVector3 position); @@ -96,7 +95,7 @@ public interface RegionSelector { * The the player information about the region's changes. This may resend * all the defining region information if needed. * - * @param actor the actor + * @param actor the actor * @param session the session */ void explainRegionAdjust(Actor actor, LocalSession session); @@ -157,13 +156,13 @@ public interface RegionSelector { /** * Get lines of information about the selection. - * + * * @return a list of lines describing the region */ @Deprecated default List getInformationLines() { return Lists.newArrayList(); - }; + } /** * Get lines of information about the selection. @@ -172,12 +171,13 @@ public interface RegionSelector { */ default List getSelectionInfoLines() { return getInformationLines().stream() - .map(TextComponent::of) + .map(line -> TextComponent.of(line, TextColor.LIGHT_PURPLE)) .collect(Collectors.toList()); } /** * Get the vertices + * * @return * @throws IncompleteRegionException */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java index fce840b40..d09c30d3a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/PropertiesConfiguration.java @@ -39,7 +39,6 @@ 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; @@ -123,12 +122,7 @@ 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('_', '-')); - } + setDefaultLocaleName(getString("default-locale", defaultLocaleName)); LocalSession.MAX_HISTORY_SIZE = Math.max(15, getInt("history-size", 15)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java index 9a3dc841f..6cc54bdf3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/YAMLConfiguration.java @@ -30,7 +30,6 @@ import org.slf4j.Logger; import java.io.IOException; import java.util.HashSet; -import java.util.Locale; /** * A less simple implementation of {@link LocalConfiguration} @@ -128,12 +127,7 @@ public class YAMLConfiguration extends LocalConfiguration { 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('_', '-')); - } + setDefaultLocaleName(config.getString("default-locale", defaultLocaleName)); } public void unload() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java index 1e2b0728e..e448926fc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java @@ -35,7 +35,7 @@ public class WorldEditText { } public static Component format(Component component, Locale locale) { - return CONFIG_HOLDER.replace(WorldEdit.getInstance().getTranslationManager().convertText(component, locale)); + return WorldEdit.getInstance().getTranslationManager().convertText(CONFIG_HOLDER.replace(component), locale); } public static String reduceToText(Component component, Locale locale) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextUtils.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextUtils.java index f604d322a..8540ed3b1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextUtils.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.util.List; +import java.util.Locale; public class TextUtils { @@ -46,4 +47,13 @@ public class TextUtils { } return builder.build(); } + /** + * Gets a Java Locale object by the Minecraft locale tag. + * + * @param locale The Minecraft locale tag + * @return A Java locale + */ + public static Locale getLocaleByMinecraftTag(String locale) { + return Locale.forLanguageTag(locale.replace('_', '-')); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java index 0ce49b115..e3aaca134 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/io/ResourceLoader.java @@ -28,18 +28,18 @@ public class ResourceLoader { } private static URL getResourceForgeHack(String location) throws IOException { - return new URL("modjar://worldedit/" + location); + try { + return new URL("modjar://worldedit/" + location); + } catch (Exception e) { + throw new IOException("Could not find " + location); + } } public static URL getResource(Class clazz, String name) throws IOException { URL url = clazz.getResource(name); if (url == null) { - try { - return getResourceForgeHack(clazz.getName().substring(0, clazz.getName().lastIndexOf('.')).replace(".", "/") - + "/" + name); - } catch (Exception e) { - throw new IOException("Could not find " + name); - } + return getResourceForgeHack(clazz.getName().substring(0, clazz.getName().lastIndexOf('.')).replace(".", "/") + + "/" + name); } return url; } @@ -47,12 +47,8 @@ public class ResourceLoader { public static URL getResourceRoot(String name) throws IOException { URL url = ResourceLoader.class.getResource("/" + name); if (url == null) { - try { - return getResourceForgeHack(name); - } catch (Exception e) { - throw new IOException("Could not find " + name); - } + return getResourceForgeHack(name); } return url; } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java index 46984ce82..656430038 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java @@ -19,8 +19,7 @@ package com.sk89q.worldedit.util.translation; -import com.google.common.io.Files; -import com.google.common.io.Resources; +import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -29,21 +28,14 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.renderer.FriendlyComponentRenderer; 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.io.*; import java.lang.reflect.Type; -import java.net.URL; -import java.nio.charset.StandardCharsets; import java.text.MessageFormat; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Locale; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +import static java.util.stream.Collectors.toMap; + /** * Handles translations for the plugin. @@ -62,7 +54,7 @@ public class TranslationManager { private static final Gson gson = new GsonBuilder().create(); private static final Type STRING_MAP_TYPE = new TypeToken>() {}.getType(); - private final Map> translationMap = new HashMap<>(); + private final Map> translationMap = new ConcurrentHashMap<>(); private final FriendlyComponentRenderer friendlyComponentRenderer = FriendlyComponentRenderer.from( (locale, key) -> new MessageFormat(getTranslationMap(locale).getOrDefault(key, key), locale)); private Locale defaultLocale = Locale.ENGLISH; @@ -80,8 +72,10 @@ public class TranslationManager { } private Map filterTranslations(Map translations) { - translations.entrySet().removeIf(entry -> entry.getValue().isEmpty()); - return translations; + return translations.entrySet().stream() + .filter(e -> !e.getValue().isEmpty()) + .map(e -> Maps.immutableEntry(e.getKey(), e.getValue().replace("'", "''"))) + .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); } private Map parseTranslationFile(InputStream inputStream) { @@ -95,7 +89,7 @@ public class TranslationManager { 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<>(); + baseTranslations = new ConcurrentHashMap<>(); } File localFile = worldEdit.getWorkingDirectoryFile("lang/" + filename); @@ -117,7 +111,7 @@ public class TranslationManager { } checkedLocales.add(locale); // Make a copy of the default language file - Map baseTranslations = new HashMap<>(); + Map baseTranslations = new ConcurrentHashMap<>(); if (!locale.equals(defaultLocale)) { baseTranslations.putAll(getTranslationMap(defaultLocale)); } diff --git a/worldedit-core/src/main/resources/lang/.gitignore b/worldedit-core/src/main/resources/lang/.gitignore deleted file mode 100644 index 0a00d7014..000000000 --- a/worldedit-core/src/main/resources/lang/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*/ \ No newline at end of file diff --git a/worldedit-core/src/main/resources/lang/strings.json b/worldedit-core/src/main/resources/lang/strings.json index 6eb93906b..fc90b4189 100644 --- a/worldedit-core/src/main/resources/lang/strings.json +++ b/worldedit-core/src/main/resources/lang/strings.json @@ -13,7 +13,6 @@ "fawe.worldedit.history.find.element": "&8 - &2{0}: {1} &7ago &3{2}m &6{3} &c/{4}", "fawe.worldedit.history.find.hover": "{0} blocks changed, click for more info", - "fawe.info.lighting.propagate.selection": "Lighting has been propogated in {0} chunks. (Note: To remove light use //removelight)", "fawe.info.updated.lighting.selection": "Lighting has been updated in {0} chunks. (It may take a second for the packets to send)", "fawe.info.set.region": "Selection set to your current allowed region", diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java index 0ac91396e..551a83f67 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.WorldEditText; +import com.sk89q.worldedit.util.formatting.component.TextUtils; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; @@ -209,7 +210,7 @@ public class ForgePlayer extends AbstractPlayerActor { @Override public Locale getLocale() { - return Locale.forLanguageTag(player.language.replace('_', '-')); + return TextUtils.getLocaleByMinecraftTag(player.language); } @Override diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java index e9808c99e..350a7c9a6 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/config/ConfigurateConfiguration.java @@ -34,7 +34,6 @@ import org.slf4j.Logger; import java.io.IOException; import java.util.HashSet; -import java.util.Locale; public class ConfigurateConfiguration extends LocalConfiguration { @@ -131,11 +130,6 @@ 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('_', '-')); - } + setDefaultLocaleName(node.getNode("default-locale").getString(defaultLocaleName)); } }