Skip to content

Commit

Permalink
Fix some bugs from T9N PR (#538)
Browse files Browse the repository at this point in the history
* Use printInfo/printError to keep colors right

* Escape quotes before they go in the map
  • Loading branch information
octylFractal authored and me4502 committed Dec 9, 2019
1 parent 679b00b commit 7831eed
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void wand(Player player, LocalSession session,
)
@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 "))
Expand Down Expand Up @@ -373,7 +373,7 @@ public void shift(Actor actor, World world, LocalSession session,

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()));
}
Expand All @@ -396,7 +396,7 @@ public void outset(Actor actor, World world, LocalSession session,
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(
Expand All @@ -416,7 +416,7 @@ public void inset(Actor actor, World world, LocalSession session,
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void tz(Actor actor, LocalSession session,
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ private T runTask() {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;

import java.util.List;
Expand Down Expand Up @@ -58,23 +59,23 @@ public interface RegionSelector {

/**
* Called when the first point is selected.
*
*
* @param position the position
* @return true if something changed
*/
boolean selectPrimary(BlockVector3 position, SelectorLimits limits);

/**
* Called when the second point is selected.
*
*
* @param position the position
* @return true if something changed
*/
boolean selectSecondary(BlockVector3 position, SelectorLimits limits);

/**
* Tell the player information about his/her primary selection.
*
*
* @param actor the actor
* @param session the session
* @param position position
Expand All @@ -101,37 +102,37 @@ public interface RegionSelector {

/**
* Get the primary position.
*
*
* @return the primary position
* @throws IncompleteRegionException thrown if a region has not been fully defined
*/
BlockVector3 getPrimaryPosition() throws IncompleteRegionException;

/**
* Get the selection.
*
*
* @return the created region
* @throws IncompleteRegionException thrown if a region has not been fully defined
*/
Region getRegion() throws IncompleteRegionException;

/**
* Get the region even if it's not fully defined.
*
*
* @return an incomplete region object that is incomplete
*/
Region getIncompleteRegion();

/**
* Returns whether the region has been fully defined.
*
*
* @return true if a selection is available
*/
boolean isDefined();

/**
* Get the number of blocks inside the region.
*
*
* @return number of blocks, or -1 if undefined
*/
int getArea();
Expand All @@ -148,14 +149,14 @@ public interface RegionSelector {

/**
* Get a lowercase name of this region selector type.
*
*
* @return a lower case name of the type
*/
String getTypeName();

/**
* Get lines of information about the selection.
*
*
* @return a list of lines describing the region
*/
@Deprecated
Expand All @@ -170,7 +171,7 @@ default List<String> getInformationLines() {
*/
default List<Component> getSelectionInfoLines() {
return getInformationLines().stream()
.map(TextComponent::of)
.map(line -> TextComponent.of(line, TextColor.LIGHT_PURPLE))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.sk89q.worldedit.util.translation;

import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
Expand All @@ -41,6 +42,8 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import static java.util.stream.Collectors.toMap;

/**
* Handles translations for the plugin.
*
Expand Down Expand Up @@ -76,8 +79,10 @@ public void setDefaultLocale(Locale defaultLocale) {
}

private Map<String, String> filterTranslations(Map<String, String> 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<String, String> parseTranslationFile(InputStream inputStream) {
Expand Down

0 comments on commit 7831eed

Please sign in to comment.