Merge master, update to texts

This commit is contained in:
Kenzie Togami
2019-04-25 22:11:46 -07:00
63 changed files with 731 additions and 1332 deletions

View File

@ -54,10 +54,9 @@ import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -626,19 +625,18 @@ public class SelectionCommands {
case UNKNOWN:
default:
CommandListBox box = new CommandListBox("Selection modes");
StyledFragment contents = box.getContents();
StyledFragment tip = contents.createFragment(Style.RED);
tip.append("Select one of the modes below:").newLine();
TextComponentProducer contents = box.getContents();
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
box.appendCommand("cuboid", "Select two corners of a cuboid");
box.appendCommand("extend", "Fast cuboid selection mode");
box.appendCommand("poly", "Select a 2D polygon with height");
box.appendCommand("ellipsoid", "Select an ellipsoid");
box.appendCommand("sphere", "Select a sphere");
box.appendCommand("cyl", "Select a cylinder");
box.appendCommand("convex", "Select a convex polyhedral");
box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid");
box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");
box.appendCommand("poly", "Select a 2D polygon with height", "//sel poly");
box.appendCommand("ellipsoid", "Select an ellipsoid", "//sel ellipsoid");
box.appendCommand("sphere", "Select a sphere", "//sel sphere");
box.appendCommand("cyl", "Select a cylinder", "//sel cyl");
box.appendCommand("convex", "Select a convex polyhedral", "//sel convex");
player.printRaw(ColorCodeBuilder.asColorCodes(box));
player.print(box.create());
return;
}

View File

@ -513,5 +513,4 @@ public class UtilityCommands {
PrintCommandHelp.help(command, page, we, actor);
}
}

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.command.argument;
import com.google.common.collect.ImmutableSortedSet;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
@ -48,8 +50,8 @@ public class BooleanConverter implements ArgumentConverter<Boolean> {
}
@Override
public String describeAcceptableArguments() {
return "on|off|true|false";
public Component describeAcceptableArguments() {
return TextComponent.of("on|off|true|false");
}
@Override

View File

@ -22,6 +22,8 @@ package com.sk89q.worldedit.command.argument;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
import org.enginehub.piston.converter.SuccessfulConversion;
@ -30,6 +32,7 @@ import org.enginehub.piston.inject.InjectedValueAccess;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
import static com.sk89q.worldedit.util.formatting.text.Component.space;
public class CommaSeparatedValuesConverter<T> implements ArgumentConverter<T> {
@ -54,14 +57,16 @@ public class CommaSeparatedValuesConverter<T> implements ArgumentConverter<T> {
}
@Override
public String describeAcceptableArguments() {
StringBuilder result = new StringBuilder();
public Component describeAcceptableArguments() {
TextComponent.Builder result = TextComponent.builder("");
if (maximum > -1) {
result.append("up to ").append(maximum).append(' ');
result.append(TextComponent.of("up to "))
.append(Component.of(maximum))
.append(space());
}
result.append("comma separated values of: ")
result.append(TextComponent.of("comma separated values of: "))
.append(delegate.describeAcceptableArguments());
return result.toString();
return result.build();
}
@Override

View File

@ -28,6 +28,8 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.MultiDirection;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
@ -104,9 +106,9 @@ public class DirectionConverter implements ArgumentConverter<BlockVector3> {
}
@Override
public String describeAcceptableArguments() {
return "`me` to use facing direction, or any "
+ (includeDiagonals ? "direction" : "non-diagonal direction");
public Component describeAcceptableArguments() {
return TextComponent.of("`me` to use facing direction, or any "
+ (includeDiagonals ? "direction" : "non-diagonal direction"));
}
@Override

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.command.argument;
import com.sk89q.worldedit.command.util.EntityRemover;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
@ -38,8 +40,10 @@ public class EntityRemoverConverter implements ArgumentConverter<EntityRemover>
}
@Override
public String describeAcceptableArguments() {
return "projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all";
public Component describeAcceptableArguments() {
return TextComponent.of(
"projectiles, items, paintings, itemframes, boats, minecarts, tnt, xp, or all"
);
}
@Override

View File

@ -24,6 +24,8 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
@ -70,7 +72,7 @@ public class EnumConverter<E extends Enum<E>> implements ArgumentConverter<E> {
return new EnumConverter<>(enumClass, lookupKeys, unknownValue);
}
private final String choices;
private final Component choices;
private final ImmutableMap<String, E> map;
@Nullable
private final E unknownValue;
@ -92,15 +94,15 @@ public class EnumConverter<E extends Enum<E>> implements ArgumentConverter<E> {
map.put(key, e);
}
}
this.choices = choices.build()
this.choices = TextComponent.of(choices.build()
.map(choice -> choice.stream().collect(joining("|", "[", "]")))
.collect(joining("|"));
.collect(joining("|")));
this.map = map.build();
this.unknownValue = unknownValue;
}
@Override
public String describeAcceptableArguments() {
public Component describeAcceptableArguments() {
return choices;
}

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.command.argument;
import com.google.common.reflect.TypeToken;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ArgumentConverters;
@ -45,8 +47,8 @@ public class ExpandAmountConverter implements ArgumentConverter<ExpandAmount> {
}
@Override
public String describeAcceptableArguments() {
return "`vert` or " + integerConverter.describeAcceptableArguments();
public Component describeAcceptableArguments() {
return TextComponent.of("`vert` or " + integerConverter.describeAcceptableArguments());
}
@Override

View File

@ -22,11 +22,12 @@ package com.sk89q.worldedit.command.argument;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
@ -71,7 +72,7 @@ public class MaskConverter implements ArgumentConverter<Mask> {
}
@Override
public String describeAcceptableArguments() {
return "any mask";
public Component describeAcceptableArguments() {
return TextComponent.of("any mask");
}
}

View File

@ -27,6 +27,8 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
@ -73,7 +75,7 @@ public class PatternConverter implements ArgumentConverter<Pattern> {
}
@Override
public String describeAcceptableArguments() {
return "any pattern";
public Component describeAcceptableArguments() {
return TextComponent.of("any pattern");
}
}

View File

@ -25,12 +25,13 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector2;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ArgumentConverters;
import org.enginehub.piston.converter.ConversionResult;
import org.enginehub.piston.converter.FailedConversion;
import org.enginehub.piston.converter.SimpleArgumentConverter;
import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
@ -89,8 +90,8 @@ public class VectorConverter<C, T> implements ArgumentConverter<T> {
}
@Override
public String describeAcceptableArguments() {
return "any " + acceptableArguments;
public Component describeAcceptableArguments() {
return TextComponent.of("any " + acceptableArguments);
}
@Override

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.command.argument;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
@ -42,8 +44,8 @@ public class ZonedDateTimeConverter implements ArgumentConverter<ZonedDateTime>
}
@Override
public String describeAcceptableArguments() {
return "any date";
public Component describeAcceptableArguments() {
return TextComponent.of("any date");
}
@Override

View File

@ -23,12 +23,11 @@ import com.google.common.base.Joiner;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.component.Code;
import com.sk89q.worldedit.util.formatting.component.CodeFormat;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager;
@ -116,7 +115,7 @@ public class PrintCommandHelp {
if (subCommands.isEmpty()) {
// Create the message
CommandUsageBox box = new CommandUsageBox(currentCommand, String.join(" ", visited));
actor.printRaw(ColorCodeBuilder.asColorCodes(box));
actor.print(box.create());
} else {
printAllCommands(page, perPage, subCommands.values().stream(), actor, false);
}
@ -134,17 +133,17 @@ public class PrintCommandHelp {
// Box
CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page, pageTotal));
StyledFragment contents = box.getContents();
StyledFragment tip = contents.createFragment(Style.GRAY);
TextComponent.Builder tip = box.getContents().getBuilder().color(TextColor.GRAY);
if (offset >= commands.size()) {
tip.createFragment(Style.RED).append(String.format("There is no page %d (total number of pages is %d).", page, pageTotal)).newLine();
tip.color(TextColor.RED)
.append(TextComponent.of(String.format("There is no page %d (total number of pages is %d).\n", page, pageTotal)));
} else {
List<Command> list = commands.subList(offset, Math.min(offset + perPage, commands.size()));
tip.append("Type ");
tip.append(new Code().append("//help ").append("[<page>] <command...>"));
tip.append(" for more information.").newLine();
tip.append(TextComponent.of("Type "));
tip.append(CodeFormat.wrap("//help [<page>] <command...>"));
tip.append(TextComponent.of(" for more information.\n"));
// Add each command
for (Command mapping : list) {
@ -152,7 +151,7 @@ public class PrintCommandHelp {
}
}
actor.printRaw(ColorCodeBuilder.asColorCodes(box));
actor.print(box.create());
}
private PrintCommandHelp() {

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extension.factory.parser;
import com.google.common.collect.Maps;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEdit;
@ -38,6 +39,7 @@ import com.sk89q.worldedit.internal.registry.InputParser;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -148,7 +150,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
}
}
private static Map<Property<?>, Object> parseProperties(BlockType type, String[] stateProperties) throws NoMatchException {
private static Map<Property<?>, Object> parseProperties(BlockType type, String[] stateProperties, ParserContext context) throws NoMatchException {
Map<Property<?>, Object> blockStates = new HashMap<>();
if (stateProperties.length > 0) { // Block data not yet detected
@ -163,7 +165,14 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
@SuppressWarnings("unchecked")
Property<Object> propertyKey = (Property<Object>) type.getPropertyMap().get(parts[0]);
if (propertyKey == null) {
throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getName());
if (context.getActor() != null) {
context.getActor().print(ErrorFormat.wrap("Unknown property ", parts[0], " for block ", type.getName(),
". Defaulting to base."));
} else {
WorldEdit.logger.warn("Unknown property " + parts[0] + " for block " + type.getName());
// throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getName());
}
return Maps.newHashMap();
}
if (blockStates.containsKey(propertyKey)) {
throw new NoMatchException("Duplicate property " + parts[0]);
@ -222,7 +231,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
typeString = blockAndExtraData[0].substring(0, stateStart);
stateString = blockAndExtraData[0].substring(stateStart + 1, blockAndExtraData[0].length() - 1);
}
if (typeString == null || typeString.isEmpty()) {
if (typeString.isEmpty()) {
throw new InputParseException("Invalid format");
}
String[] stateProperties = EMPTY_STRING_ARRAY;
@ -270,7 +279,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
}
}
blockStates.putAll(parseProperties(blockType, stateProperties));
blockStates.putAll(parseProperties(blockType, stateProperties, context));
if (!context.isPreferringWildcard()) {
// No wildcards allowed => eliminate them. (Start with default state)

View File

@ -23,6 +23,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionOwner;
import com.sk89q.worldedit.util.Identifiable;
import com.sk89q.worldedit.util.auth.Subject;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import java.io.File;
@ -75,6 +76,13 @@ public interface Actor extends Identifiable, SessionOwner, Subject {
*/
void printError(String msg);
/**
* Print a {@link TextComponent}.
*
* @param component The component to print
*/
void print(TextComponent component);
/**
* Returns true if the actor can destroy bedrock.
*

View File

@ -89,6 +89,8 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.command.parametric.ExceptionConverter;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World;
@ -240,97 +242,65 @@ public final class PlatformCommandMananger {
});
}
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandRegistration<CI> registration, CI instance) {
commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
registration,
instance
);
cmd.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"),
TextComponent.of("Sub-command to run."))
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
}
private void registerAllCommands() {
commandManager.register("schematic", cmd -> {
cmd.aliases(ImmutableList.of("schem", "/schematic", "/schem"));
cmd.description("Schematic commands for saving/loading areas");
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
SchematicCommandsRegistration.builder(),
new SchematicCommands(worldEdit)
);
cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.")
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
commandManager.register("snapshot", cmd -> {
cmd.aliases(ImmutableList.of("snap"));
cmd.description("Snapshot commands for saving/loading snapshots");
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
SnapshotCommandsRegistration.builder(),
new SnapshotCommands(worldEdit)
);
cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.")
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
commandManager.register("superpickaxe", cmd -> {
cmd.aliases(ImmutableList.of("pickaxe", "sp"));
cmd.description("Super-pickaxe commands");
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
SuperPickaxeCommandsRegistration.builder(),
new SuperPickaxeCommands(worldEdit)
);
cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.")
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
commandManager.register("brush", cmd -> {
cmd.aliases(ImmutableList.of("br"));
cmd.description("Brushing commands");
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
BrushCommandsRegistration.builder(),
new BrushCommands(worldEdit)
);
cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.")
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
commandManager.register("worldedit", cmd -> {
cmd.aliases(ImmutableList.of("we"));
cmd.description("WorldEdit commands");
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = DefaultCommandManagerService.getInstance()
.newCommandManager();
register(
manager,
WorldEditCommandsRegistration.builder(),
new WorldEditCommands(worldEdit)
);
cmd.addPart(SubCommandPart.builder("action", "Sub-command to run.")
.withCommands(manager.getAllCommands().collect(Collectors.toList()))
.required()
.build());
});
registerSubCommands(
"schematic",
ImmutableList.of("schem", "/schematic", "/schem"),
"Schematic commands for saving/loading areas",
SchematicCommandsRegistration.builder(),
new SchematicCommands(worldEdit)
);
registerSubCommands(
"snapshot",
ImmutableList.of("snap"),
"Snapshot commands for saving/loading snapshots",
SnapshotCommandsRegistration.builder(),
new SnapshotCommands(worldEdit)
);
registerSubCommands(
"superpickaxe",
ImmutableList.of("pickaxe", "sp"),
"Super-pickaxe commands",
SuperPickaxeCommandsRegistration.builder(),
new SuperPickaxeCommands(worldEdit)
);
registerSubCommands(
"brush",
ImmutableList.of("br"),
"Brushing commands",
BrushCommandsRegistration.builder(),
new BrushCommands(worldEdit)
);
registerSubCommands(
"worldedit",
ImmutableList.of("we"),
"WorldEdit commands",
WorldEditCommandsRegistration.builder(),
new WorldEditCommands(worldEdit)
);
register(
commandManager,
BiomeCommandsRegistration.builder(),

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import java.util.UUID;
@ -132,6 +133,11 @@ class PlayerProxy extends AbstractPlayerActor {
basePlayer.printError(msg);
}
@Override
public void print(TextComponent component) {
basePlayer.print(component);
}
@Override
public String[] getGroups() {
return permActor.getGroups();

View File

@ -80,7 +80,7 @@ public class NoiseFilter extends AbstractMask {
*/
public void setDensity(double density) {
checkArgument(density >= 0, "density must be >= 0");
checkArgument(density <= 1, "density must be >= 1");
checkArgument(density <= 1, "density must be <= 1");
this.density = density;
}

View File

@ -78,7 +78,7 @@ public class NoiseFilter2D extends AbstractMask2D {
*/
public void setDensity(double density) {
checkArgument(density >= 0, "density must be >= 0");
checkArgument(density <= 1, "density must be >= 1");
checkArgument(density <= 1, "density must be <= 1");
this.density = density;
}

View File

@ -32,6 +32,7 @@ import com.sk89q.worldedit.internal.expression.runtime.Functions;
import com.sk89q.worldedit.internal.expression.runtime.RValue;
import com.sk89q.worldedit.internal.expression.runtime.ReturnException;
import com.sk89q.worldedit.internal.expression.runtime.Variable;
import com.sk89q.worldedit.session.request.Request;
import java.util.HashMap;
import java.util.List;
@ -142,7 +143,18 @@ public class Expression {
}
private double evaluateRootTimed(int timeout) throws EvaluationException {
Future<Double> result = evalThread.submit(this::evaluateRoot);
Request request = Request.request();
Future<Double> result = evalThread.submit(() -> {
Request local = Request.request();
local.setSession(request.getSession());
local.setWorld(request.getWorld());
local.setEditSession(request.getEditSession());
try {
return Expression.this.evaluateRoot();
} finally {
Request.reset();
}
});
try {
return result.get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {

View File

@ -243,12 +243,7 @@ public class SessionManager {
* @return the key object
*/
protected UUID getKey(SessionKey key) {
String forcedKey = System.getProperty("worldedit.session.uuidOverride");
if (forcedKey != null) {
return UUID.fromString(forcedKey);
} else {
return key.getUniqueId();
}
return key.getUniqueId();
}
/**

View File

@ -48,7 +48,7 @@ public class Location {
* @param extent the extent
*/
public Location(Extent extent) {
this(extent, Vector3.ZERO, Vector3.ZERO);
this(extent, Vector3.ZERO, 0f, 90f);
}
/**
@ -61,7 +61,7 @@ public class Location {
* @param z the Z coordinate
*/
public Location(Extent extent, double x, double y, double z) {
this(extent, Vector3.at(x, y, z), Vector3.ZERO);
this(extent, Vector3.at(x, y, z), 0f, 90f);
}
/**
@ -72,7 +72,7 @@ public class Location {
* @param position the position vector
*/
public Location(Extent extent, Vector3 position) {
this(extent, position, Vector3.ZERO);
this(extent, position, 0f, 90f);
}
/**

View File

@ -1,271 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
import com.google.common.base.Joiner;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class ColorCodeBuilder {
private static final ColorCodeBuilder instance = new ColorCodeBuilder();
private static final Joiner newLineJoiner = Joiner.on("\n");
public static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47;
/**
* Convert a message into color-coded text.
*
* @param message the message
* @return a list of lines
*/
public String[] build(StyledFragment message) {
StringBuilder builder = new StringBuilder();
buildFragment(builder, message, message.getStyle(), new StyleSet());
return builder.toString().split("\r?\n");
}
/**
* Build a fragment.
*
* @param builder the string builder
* @param message the message
* @param parentStyle the parent style
* @param lastStyle the last style
* @return the last style used
*/
private StyleSet buildFragment(StringBuilder builder, StyledFragment message, StyleSet parentStyle, StyleSet lastStyle) {
for (Fragment node : message.getChildren()) {
if (node instanceof StyledFragment) {
StyledFragment fragment = (StyledFragment) node;
lastStyle = buildFragment(
builder, fragment,
parentStyle.extend(message.getStyle()), lastStyle);
} else {
StyleSet style = parentStyle.extend(message.getStyle());
builder.append(getAdditive(style, lastStyle));
builder.append(node);
lastStyle = style;
}
}
return lastStyle;
}
/**
* Get the formatting codes.
*
* @param style the style
* @return the color codes
*/
public static String getFormattingCode(StyleSet style) {
StringBuilder builder = new StringBuilder();
if (style.isBold()) {
builder.append(Style.BOLD);
}
if (style.isItalic()) {
builder.append(Style.ITALIC);
}
if (style.isUnderline()) {
builder.append(Style.UNDERLINE);
}
if (style.isStrikethrough()) {
builder.append(Style.STRIKETHROUGH);
}
return builder.toString();
}
/**
* Get the formatting and color codes.
*
* @param style the style
* @return the color codes
*/
public static String getCode(StyleSet style) {
StringBuilder builder = new StringBuilder();
builder.append(getFormattingCode(style));
if (style.getColor() != null) {
builder.append(style.getColor());
}
return builder.toString();
}
/**
* Get the additional color codes needed to set the given style when the current
* style is the other given one.
*
* @param resetTo the style to reset to
* @param resetFrom the style to reset from
* @return the color codes
*/
public static String getAdditive(StyleSet resetTo, StyleSet resetFrom) {
if (!resetFrom.hasFormatting() && resetTo.hasFormatting()) {
StringBuilder builder = new StringBuilder();
builder.append(getFormattingCode(resetTo));
if (resetFrom.getColor() != resetTo.getColor()) {
builder.append(resetTo.getColor());
}
return builder.toString();
} else if (!resetFrom.hasEqualFormatting(resetTo) ||
(resetFrom.getColor() != null && resetTo.getColor() == null)) {
// Have to set reset code and add back all the formatting codes
return Style.RESET + getCode(resetTo);
} else {
if (resetFrom.getColor() != resetTo.getColor()) {
return String.valueOf(resetTo.getColor());
}
}
return "";
}
/**
* Word wrap the given text and maintain color codes throughout lines.
*
* <p>This is borrowed from Bukkit.</p>
*
* @param rawString the raw string
* @param lineLength the maximum line length
* @return a list of lines
*/
private String[] wordWrap(String rawString, int lineLength) {
// A null string is a single line
if (rawString == null) {
return new String[] {""};
}
// A string shorter than the lineWidth is a single line
if (rawString.length() <= lineLength && !rawString.contains("\n")) {
return new String[] {rawString};
}
char[] rawChars = (rawString + ' ').toCharArray(); // add a trailing space to trigger pagination
StringBuilder word = new StringBuilder();
StringBuilder line = new StringBuilder();
List<String> lines = new LinkedList<>();
int lineColorChars = 0;
for (int i = 0; i < rawChars.length; i++) {
char c = rawChars[i];
// skip chat color modifiers
if (c == Style.COLOR_CHAR) {
word.append(Style.getByChar(rawChars[i + 1]));
lineColorChars += 2;
i++; // Eat the next character as we have already processed it
continue;
}
if (c == ' ' || c == '\n') {
if (line.length() == 0 && word.length() > lineLength) { // special case: extremely long word begins a line
String wordStr = word.toString();
String transformed;
if ((transformed = transform(wordStr)) != null) {
line.append(transformed);
} else {
lines.addAll(Arrays.asList(word.toString().split("(?<=\\G.{" + lineLength + "})")));
}
} else if (line.length() + word.length() - lineColorChars == lineLength) { // Line exactly the correct length...newline
line.append(' ');
line.append(word);
lines.add(line.toString());
line = new StringBuilder();
lineColorChars = 0;
} else if (line.length() + 1 + word.length() - lineColorChars > lineLength) { // Line too long...break the line
String wordStr = word.toString();
String transformed;
if (word.length() > lineLength && (transformed = transform(wordStr)) != null) {
if (line.length() + 1 + transformed.length() - lineColorChars > lineLength) {
lines.add(line.toString());
line = new StringBuilder(transformed);
lineColorChars = 0;
} else {
if (line.length() > 0) {
line.append(' ');
}
line.append(transformed);
}
} else {
for (String partialWord : wordStr.split("(?<=\\G.{" + lineLength + "})")) {
lines.add(line.toString());
line = new StringBuilder(partialWord);
}
lineColorChars = 0;
}
} else {
if (line.length() > 0) {
line.append(' ');
}
line.append(word);
}
word = new StringBuilder();
if (c == '\n') { // Newline forces the line to flush
lines.add(line.toString());
line = new StringBuilder();
}
} else {
word.append(c);
}
}
if(line.length() > 0) { // Only add the last line if there is anything to add
lines.add(line.toString());
}
// Iterate over the wrapped lines, applying the last color from one line to the beginning of the next
if (lines.get(0).isEmpty() || lines.get(0).charAt(0) != Style.COLOR_CHAR) {
lines.set(0, Style.WHITE + lines.get(0));
}
for (int i = 1; i < lines.size(); i++) {
final String pLine = lines.get(i-1);
final String subLine = lines.get(i);
char color = pLine.charAt(pLine.lastIndexOf(Style.COLOR_CHAR) + 1);
if (subLine.isEmpty() || subLine.charAt(0) != Style.COLOR_CHAR) {
lines.set(i, Style.getByChar(color) + subLine);
}
}
return lines.toArray(new String[lines.size()]);
}
/**
* Callback for transforming a word, such as a URL.
*
* @param word the word
* @return the transformed value, or null to do nothing
*/
protected String transform(String word) {
return null;
}
/**
* Convert the given styled fragment into color codes.
*
* @param fragment the fragment
* @return color codes
*/
public static String asColorCodes(StyledFragment fragment) {
return newLineJoiner.join(instance.build(fragment));
}
}

View File

@ -1,92 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
/**
* A fragment of text.
*/
public class Fragment {
private final StringBuilder builder = new StringBuilder();
Fragment() {
}
public Fragment append(String str) {
builder.append(Style.stripColor(str));
return this;
}
public Fragment append(Object obj) {
append(String.valueOf(obj));
return this;
}
public Fragment append(StringBuffer sb) {
append(String.valueOf(sb));
return this;
}
public Fragment append(CharSequence s) {
append(String.valueOf(s));
return this;
}
public Fragment append(boolean b) {
append(String.valueOf(b));
return this;
}
public Fragment append(char c) {
append(String.valueOf(c));
return this;
}
public Fragment append(int i) {
append(String.valueOf(i));
return this;
}
public Fragment append(long lng) {
append(String.valueOf(lng));
return this;
}
public Fragment append(float f) {
append(String.valueOf(f));
return this;
}
public Fragment append(double d) {
append(String.valueOf(d));
return this;
}
public Fragment newLine() {
append("\n");
return this;
}
@Override
public String toString() {
return builder.toString();
}
}

View File

@ -1,276 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.regex.Pattern;
/**
* All supported color values for chat.
*
* <p>From Bukkit.</p>
*/
public enum Style {
/**
* Represents black
*/
BLACK('0', 0x00),
/**
* Represents dark blue
*/
BLUE_DARK('1', 0x1),
/**
* Represents dark green
*/
GREEN_DARK('2', 0x2),
/**
* Represents dark blue (aqua)
*/
CYAN_DARK('3', 0x3),
/**
* Represents dark red
*/
RED_DARK('4', 0x4),
/**
* Represents dark purple
*/
PURPLE_DARK('5', 0x5),
/**
* Represents gold
*/
YELLOW_DARK('6', 0x6),
/**
* Represents gray
*/
GRAY('7', 0x7),
/**
* Represents dark gray
*/
GRAY_DARK('8', 0x8),
/**
* Represents blue
*/
BLUE('9', 0x9),
/**
* Represents green
*/
GREEN('a', 0xA),
/**
* Represents aqua
*/
CYAN('b', 0xB),
/**
* Represents red
*/
RED('c', 0xC),
/**
* Represents light purple
*/
PURPLE('d', 0xD),
/**
* Represents yellow
*/
YELLOW('e', 0xE),
/**
* Represents white
*/
WHITE('f', 0xF),
/**
* Represents magical characters that change around randomly
*/
RANDOMIZE('k', 0x10, true),
/**
* Makes the text bold.
*/
BOLD('l', 0x11, true),
/**
* Makes a line appear through the text.
*/
STRIKETHROUGH('m', 0x12, true),
/**
* Makes the text appear underlined.
*/
UNDERLINE('n', 0x13, true),
/**
* Makes the text italic.
*/
ITALIC('o', 0x14, true),
/**
* Resets all previous chat colors or formats.
*/
RESET('r', 0x15);
/**
* The special character which prefixes all chat color codes. Use this if you need to dynamically
* convert color codes from your custom format.
*/
public static final char COLOR_CHAR = '\u00A7';
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]");
private final int intCode;
private final char code;
private final boolean isFormat;
private final String toString;
private final static Map<Integer, Style> BY_ID = Maps.newHashMap();
private final static Map<Character, Style> BY_CHAR = Maps.newHashMap();
Style(char code, int intCode) {
this(code, intCode, false);
}
Style(char code, int intCode, boolean isFormat) {
this.code = code;
this.intCode = intCode;
this.isFormat = isFormat;
this.toString = new String(new char[] {COLOR_CHAR, code});
}
/**
* Gets the char value associated with this color
*
* @return A char value of this color code
*/
public char getChar() {
return code;
}
@Override
public String toString() {
return toString;
}
/**
* Checks if this code is a format code as opposed to a color code.
*
* @return the if the code is a formatting code
*/
public boolean isFormat() {
return isFormat;
}
/**
* Checks if this code is a color code as opposed to a format code.
*
* @return the if the code is a color
*/
public boolean isColor() {
return !isFormat && this != RESET;
}
/**
* Gets the color represented by the specified color code
*
* @param code Code to check
* @return Associative Style with the given code, or null if it doesn't exist
*/
public static Style getByChar(char code) {
return BY_CHAR.get(code);
}
/**
* Gets the color represented by the specified color code
*
* @param code Code to check
* @return Associative Style with the given code, or null if it doesn't exist
*/
public static Style getByChar(String code) {
checkNotNull(code);
checkArgument(!code.isEmpty(), "Code must have at least one character");
return BY_CHAR.get(code.charAt(0));
}
/**
* Strips the given message of all color codes
*
* @param input String to strip of color
* @return A copy of the input string, without any coloring
*/
public static String stripColor(final String input) {
if (input == null) {
return null;
}
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
}
/**
* Translates a string using an alternate color code character into a string that uses the internal
* ChatColor.COLOR_CODE color code character. The alternate color code character will only be replaced
* if it is immediately followed by 0-9, A-F, a-f, K-O, k-o, R or r.
*
* @param altColorChar The alternate color code character to replace. Ex: &amp;
* @param textToTranslate Text containing the alternate color code character.
* @return Text containing the ChatColor.COLOR_CODE color code character.
*/
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) {
char[] b = textToTranslate.toCharArray();
for (int i = 0; i < b.length - 1; i++) {
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1) {
b[i] = Style.COLOR_CHAR;
b[i+1] = Character.toLowerCase(b[i+1]);
}
}
return new String(b);
}
/**
* Gets the ChatColors used at the end of the given input string.
*
* @param input Input string to retrieve the colors from.
* @return Any remaining ChatColors to pass onto the next line.
*/
public static String getLastColors(String input) {
String result = "";
int length = input.length();
// Search backwards from the end as it is faster
for (int index = length - 1; index > -1; index--) {
char section = input.charAt(index);
if (section == COLOR_CHAR && index < length - 1) {
char c = input.charAt(index + 1);
Style color = getByChar(c);
if (color != null) {
result = color + result;
// Once we find a color or reset we can stop searching
if (color.isColor() || color == RESET) {
break;
}
}
}
}
return result;
}
static {
for (Style color : values()) {
BY_ID.put(color.intCode, color);
BY_CHAR.put(color.code, color);
}
}
}

View File

@ -1,249 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
/**
* Represents set of styles, such as color, bold, etc.
*/
public class StyleSet {
private Boolean bold;
private Boolean italic;
private Boolean underline;
private Boolean strikethrough;
private Style color;
/**
* Create a new style set with no properties set.
*/
public StyleSet() {
}
/**
* Create a new style set with the given styles.
*
* <p>{@link Style#RESET} will be ignored if provided.</p>
*
* @param styles a list of styles
*/
public StyleSet(Style... styles) {
for (Style style : styles) {
if (style.isColor()) {
color = style;
} else if (style == Style.BOLD) {
bold = true;
} else if (style == Style.ITALIC) {
italic = true;
} else if (style == Style.UNDERLINE) {
underline = true;
} else if (style == Style.STRIKETHROUGH) {
strikethrough = true;
}
}
}
/**
* Get whether this style set is bold.
*
* @return true, false, or null if unset
*/
public Boolean getBold() {
return bold;
}
/**
* Get whether the text is bold.
*
* @return true if bold
*/
public boolean isBold() {
return getBold() != null && getBold();
}
/**
* Set whether the text is bold.
*
* @param bold true, false, or null to unset
*/
public void setBold(Boolean bold) {
this.bold = bold;
}
/**
* Get whether this style set is italicized.
*
* @return true, false, or null if unset
*/
public Boolean getItalic() {
return italic;
}
/**
* Get whether the text is italicized.
*
* @return true if italicized
*/
public boolean isItalic() {
return getItalic() != null && getItalic();
}
/**
* Set whether the text is italicized.
*
* @param italic false, or null to unset
*/
public void setItalic(Boolean italic) {
this.italic = italic;
}
/**
* Get whether this style set is underlined.
*
* @return true, false, or null if unset
*/
public Boolean getUnderline() {
return underline;
}
/**
* Get whether the text is underlined.
*
* @return true if underlined
*/
public boolean isUnderline() {
return getUnderline() != null && getUnderline();
}
/**
* Set whether the text is underline.
*
* @param underline false, or null to unset
*/
public void setUnderline(Boolean underline) {
this.underline = underline;
}
/**
* Get whether this style set is stricken through.
*
* @return true, false, or null if unset
*/
public Boolean getStrikethrough() {
return strikethrough;
}
/**
* Get whether the text is stricken through.
*
* @return true if there is strikethrough applied
*/
public boolean isStrikethrough() {
return getStrikethrough() != null && getStrikethrough();
}
/**
* Set whether the text is stricken through.
*
* @param strikethrough false, or null to unset
*/
public void setStrikethrough(Boolean strikethrough) {
this.strikethrough = strikethrough;
}
/**
* Get the color of the text.
*
* @return true, false, or null if unset
*/
public Style getColor() {
return color;
}
/**
* Set the color of the text.
*
* @param color the color
*/
public void setColor(Style color) {
this.color = color;
}
/**
* Return whether text formatting (bold, italics, underline, strikethrough) is set.
*
* @return true if formatting is set
*/
public boolean hasFormatting() {
return getBold() != null || getItalic() != null
|| getUnderline() != null || getStrikethrough() != null;
}
/**
* Return where the text formatting of the given style set is different from
* that assigned to this one.
*
* @param other the other style set
* @return true if there is a difference
*/
public boolean hasEqualFormatting(StyleSet other) {
return getBold() == other.getBold() && getItalic() == other.getItalic()
&& getUnderline() == other.getUnderline() &&
getStrikethrough() == other.getStrikethrough();
}
/**
* Create a new instance with styles inherited from this one but with new styles
* from the given style set.
*
* @param style the style set
* @return a new style set instance
*/
public StyleSet extend(StyleSet style) {
StyleSet newStyle = clone();
if (style.getBold() != null) {
newStyle.setBold(style.getBold());
}
if (style.getItalic() != null) {
newStyle.setItalic(style.getItalic());
}
if (style.getUnderline() != null) {
newStyle.setUnderline(style.getUnderline());
}
if (style.getStrikethrough() != null) {
newStyle.setStrikethrough(style.getStrikethrough());
}
if (style.getColor() != null) {
newStyle.setColor(style.getColor());
}
return newStyle;
}
@Override
public StyleSet clone() {
StyleSet style = new StyleSet();
style.setBold(getBold());
style.setItalic(getItalic());
style.setUnderline(getUnderline());
style.setStrikethrough(getStrikethrough());
style.setColor(getColor());
return style;
}
}

View File

@ -1,150 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting;
import java.util.ArrayList;
import java.util.List;
/**
* A fragment of text that can be styled.
*/
public class StyledFragment extends Fragment {
private final List<Fragment> children = new ArrayList<>();
private StyleSet style;
private Fragment lastText;
public StyledFragment() {
style = new StyleSet();
}
public StyledFragment(StyleSet style) {
this.style = style;
}
public StyledFragment(Style... styles) {
this.style = new StyleSet(styles);
}
public StyleSet getStyle() {
return style;
}
public void setStyles(StyleSet style) {
this.style = style;
}
public List<Fragment> getChildren() {
return children;
}
protected Fragment lastText() {
Fragment text;
if (!children.isEmpty()) {
text = children.get(children.size() - 1);
if (text == lastText) {
return text;
}
}
text = new Fragment();
this.lastText = text;
children.add(text);
return text;
}
public StyledFragment createFragment(Style... styles) {
StyledFragment fragment = new StyledFragment(styles);
append(fragment);
return fragment;
}
public StyledFragment append(StyledFragment fragment) {
children.add(fragment);
return this;
}
@Override
public StyledFragment append(String str) {
lastText().append(str);
return this;
}
@Override
public StyledFragment append(Object obj) {
append(String.valueOf(obj));
return this;
}
@Override
public StyledFragment append(StringBuffer sb) {
append(String.valueOf(sb));
return this;
}
@Override
public StyledFragment append(CharSequence s) {
append(String.valueOf(s));
return this;
}
@Override
public StyledFragment append(boolean b) {
append(String.valueOf(b));
return this;
}
@Override
public StyledFragment append(char c) {
append(String.valueOf(c));
return this;
}
@Override
public StyledFragment append(int i) {
append(String.valueOf(i));
return this;
}
@Override
public StyledFragment append(long lng) {
append(String.valueOf(lng));
return this;
}
@Override
public StyledFragment append(float f) {
append(String.valueOf(f));
return this;
}
@Override
public StyledFragment append(double d) {
append(String.valueOf(d));
return this;
}
@Override
public StyledFragment newLine() {
append("\n");
return this;
}
}

View File

@ -19,19 +19,30 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a fragment representing a command that is to be typed.
*/
public class Code extends StyledFragment {
public class CodeFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Code() {
super(Style.CYAN);
private CodeFormat() {
getBuilder().content("").color(TextColor.AQUA);
}
/**
* Creates a CodeFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static TextComponent wrap(String ... texts) {
CodeFormat code = new CodeFormat();
for (String text: texts) {
code.append(text);
}
return code.create();
}
}

View File

@ -19,7 +19,11 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
public class CommandListBox extends MessageBox {
@ -31,14 +35,28 @@ public class CommandListBox extends MessageBox {
* @param title the title
*/
public CommandListBox(String title) {
super(title);
super(title, new TextComponentProducer());
}
public CommandListBox appendCommand(String alias, String description) {
public CommandListBox appendCommand(String alias, Component description) {
return appendCommand(alias, description, null);
}
public CommandListBox appendCommand(String alias, String description, String insertion) {
return appendCommand(alias, TextComponent.of(description), insertion);
}
public CommandListBox appendCommand(String alias, Component description, String insertion) {
if (!first) {
getContents().newLine();
getContents().newline();
}
getContents().createFragment(Style.YELLOW_DARK).append(alias).append(": ");
TextComponent commandName = TextComponent.of(alias, TextColor.GOLD);
if (insertion != null) {
commandName = commandName
.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, insertion))
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select")));
}
getContents().append(commandName.append(TextComponent.of(": ")));
getContents().append(description);
first = false;
return this;

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandParameters;
@ -35,7 +34,7 @@ import static com.sk89q.worldedit.util.command.CommandUtil.getSubCommands;
/**
* A box to describe usage of a command.
*/
public class CommandUsageBox extends StyledFragment {
public class CommandUsageBox extends TextComponentProducer {
/**
* Create a new usage box.
@ -79,15 +78,14 @@ public class CommandUsageBox extends StyledFragment {
}
}
append(box);
append(box.create());
}
private void attachCommandUsage(Command description, String commandString) {
MessageBox box = new MessageBox("Help for " + commandString);
MessageBox box = new MessageBox("Help for " + commandString,
new TextComponentProducer().append(description.getFullHelp()));
box.getContents().append(description.getFullHelp());
append(box);
append(box.create());
}
}

View File

@ -0,0 +1,51 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a fragment representing an error.
*/
public class ErrorFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
private ErrorFormat() {
getBuilder().content("").color(TextColor.RED);
}
/**
* Creates an ErrorFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static TextComponent wrap(String ... texts) {
ErrorFormat error = new ErrorFormat();
for (String component : texts) {
error.append(component);
}
return error.create();
}
}

View File

@ -19,19 +19,33 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a fragment representing a label.
*/
public class Label extends StyledFragment {
public class LabelFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Label() {
super(Style.YELLOW);
private LabelFormat() {
getBuilder().content("").color(TextColor.YELLOW);
}
/**
* Creates a LabelFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static TextComponent wrap(String ... texts) {
LabelFormat label = new LabelFormat();
for (String component : texts) {
label.append(component);
}
return label.create();
}
}

View File

@ -21,37 +21,39 @@ package com.sk89q.worldedit.util.formatting.component;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
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;
/**
* Makes for a box with a border above and below.
*/
public class MessageBox extends StyledFragment {
public class MessageBox extends TextComponentProducer {
private final StyledFragment contents = new StyledFragment();
private static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47;
private final TextComponentProducer contents;
/**
* Create a new box.
*/
public MessageBox(String title) {
public MessageBox(String title, TextComponentProducer contents) {
checkNotNull(title);
int leftOver = ColorCodeBuilder.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2;
int leftOver = GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2;
int leftSide = (int) Math.floor(leftOver * 1.0/3);
int rightSide = (int) Math.floor(leftOver * 2.0/3);
if (leftSide > 0) {
createFragment(Style.YELLOW).append(createBorder(leftSide));
append(TextComponent.of(createBorder(leftSide), TextColor.YELLOW));
}
append(" ");
append(Component.space());
append(title);
append(" ");
append(Component.space());
if (rightSide > 0) {
createFragment(Style.YELLOW).append(createBorder(rightSide));
append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW));
}
newLine();
append(contents);
newline();
this.contents = contents;
}
private String createBorder(int count) {
@ -63,12 +65,17 @@ public class MessageBox extends StyledFragment {
}
/**
* Get the internal contents.
*
* @return the contents
* Gets the message box contents producer.
*
* @return The contents producer
*/
public StyledFragment getContents() {
public TextComponentProducer getContents() {
return contents;
}
@Override
public TextComponent create() {
append(contents.create());
return super.create();
}
}

View File

@ -19,19 +19,33 @@
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
/**
* Represents a subtle part of the message.
*/
public class Subtle extends StyledFragment {
public class SubtleFormat extends TextComponentProducer {
/**
* Create a new instance.
*/
public Subtle() {
super(Style.GRAY);
private SubtleFormat() {
getBuilder().content("").color(TextColor.GRAY);
}
/**
* Creates a SubtleFormat with the given message.
*
* @param texts The text
* @return The Component
*/
public static TextComponent wrap(String ... texts) {
SubtleFormat subtle = new SubtleFormat();
for (String component : texts) {
subtle.append(component);
}
return subtle.create();
}
}

View File

@ -0,0 +1,68 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
public class TextComponentProducer {
private TextComponent.Builder builder = TextComponent.builder().content("");
public TextComponent.Builder getBuilder() {
return builder;
}
/**
* Adds a component as a child to this Producer.
*
* @param component The component
* @return The producer, for chaining
*/
public TextComponentProducer append(Component component) {
getBuilder().append(component);
return this;
}
/**
* Adds a string as a child to this Producer.
*
* @param string The text
* @return The producer, for chaining
*/
public TextComponentProducer append(String string) {
getBuilder().append(TextComponent.of(string));
return this;
}
/**
* Adds a newline as a child to this Producer.
*
* @return The producer, for chaining
*/
public TextComponentProducer newline() {
getBuilder().append(Component.newline());
return this;
}
public TextComponent create() {
return builder.build();
}
}

View File

@ -93,11 +93,11 @@ public class TrueZipMcRegionChunkStore extends McRegionChunkStore {
} else {
Pattern pattern = Pattern.compile(".*\\.mc[ra]$");
// World pattern
Pattern worldPattern = Pattern.compile(worldName + "\\$");
Pattern worldPattern = Pattern.compile(worldName + "[\\\\/].*");
for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
ZipEntry testEntry = e.nextElement();
// Check for world
if (worldPattern.matcher(worldName).matches()) {
if (worldPattern.matcher(testEntry.getName()).matches()) {
// Check for file
if (pattern.matcher(testEntry.getName()).matches()) {
folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf('/'));