From 9816eb3102f0dd178d56030be2d87b4d39414d39 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 23 Jul 2019 16:26:18 -0400 Subject: [PATCH] More work on commands --- config/checkstyle/import-control.xml | 6 +- .../com/boydti/fawe/bukkit/BukkitCommand.java | 4 +- .../boydti/fawe/bukkit/chat/FancyMessage.java | 64 ++--- .../bukkit/BukkitServerInterface.java | 5 +- .../com/boydti/fawe/command/CFICommand.java | 2 +- .../com/boydti/fawe/command/CFICommands.java | 271 +++++++++--------- .../main/java/com/boydti/fawe/config/BBC.java | 36 +-- .../com/boydti/fawe/object/FawePlayer.java | 13 +- .../fawe/object/brush/InspectBrush.java | 5 +- .../com/boydti/fawe/util/chat/Message.java | 41 +-- .../worldedit/command/BrushCommands.java | 8 +- .../command/BrushOptionsCommands.java | 15 +- .../sk89q/worldedit/command/ListFilters.java | 15 +- .../worldedit/command/SchematicCommands.java | 195 +++++++------ .../worldedit/command/SelectionCommands.java | 10 +- .../worldedit/command/UtilityCommands.java | 55 ++-- 16 files changed, 349 insertions(+), 396 deletions(-) diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index a291b5ad5..1ef3e6098 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -1,6 +1,7 @@ + "-//Checkstyle//DTD ImportControl Configuration 1.4//EN" + "https://checkstyle.org/dtds/import_control_1_4.dtd"> + @@ -9,6 +10,7 @@ + diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java index 7904a62f7..ed7490872 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/BukkitCommand.java @@ -13,12 +13,12 @@ public class BukkitCommand implements CommandExecutor { private final FaweCommand cmd; - public BukkitCommand(final FaweCommand cmd) { + public BukkitCommand(FaweCommand cmd) { this.cmd = cmd; } @Override - public boolean onCommand(@NotNull final CommandSender sender, final Command cmd, final String label, final String[] args) { + public boolean onCommand(@NotNull CommandSender sender, Command cmd, String label, String[] args) { final FawePlayer plr = Fawe.imp().wrap(sender); if (!sender.hasPermission(this.cmd.getPerm()) && !sender.isOp()) { BBC.NO_PERM.send(plr, this.cmd.getPerm()); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java index 2151f1408..3590e58f2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/FancyMessage.java @@ -54,7 +54,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< } private List messageParts; - private int index = 0; + private int index; private String jsonString; private boolean dirty; @@ -78,11 +78,11 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * * @param firstPartText The existing text in the message. */ - public FancyMessage(final String firstPartText) { + public FancyMessage(String firstPartText) { this(rawText(firstPartText)); } - private FancyMessage(final TextualComponent firstPartText) { + private FancyMessage(TextualComponent firstPartText) { messageParts = new ArrayList<>(); messageParts.add(new MessagePart(firstPartText)); index = messageParts.size(); @@ -165,7 +165,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< } } if (text.length() - last > 0) { - append(text.substring(last, text.length())); + append(text.substring(last)); colors.forEach(this::color); } index++; @@ -206,7 +206,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * represent formatters. */ public FancyMessage style(ChatColor... styles) { - for (final ChatColor style : styles) { + for (ChatColor style : styles) { if (!style.isFormat()) { color(style); } @@ -224,7 +224,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param path The path of the file on the client filesystem. * @return This builder instance. */ - public FancyMessage file(final String path) { + public FancyMessage file(String path) { onClick("open_file", path); return this; } @@ -237,7 +237,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param url The URL of the page to open when the link is clicked. * @return This builder instance. */ - public FancyMessage link(final String url) { + public FancyMessage link(String url) { onClick("open_url", url); return this; } @@ -252,7 +252,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param command The text to display in the chat bar of the client. * @return This builder instance. */ - public FancyMessage suggest(final String command) { + public FancyMessage suggest(String command) { onClick("suggest_command", command); return this; } @@ -267,7 +267,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param command The text to append to the chat bar of the client. * @return This builder instance. */ - public FancyMessage insert(final String command) { + public FancyMessage insert(String command) { onCurrent(m -> m.insertionData = command); dirty = true; return this; @@ -282,7 +282,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param command The text to display in the chat bar of the client. * @return This builder instance. */ - public FancyMessage command(final String command) { + public FancyMessage command(String command) { onClick("run_command", command); return this; } @@ -297,7 +297,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * hovering. * @return This builder instance. */ - public FancyMessage tooltip(final String text) { + public FancyMessage tooltip(String text) { onHover("show_text", new JsonString(text)); return this; } @@ -313,8 +313,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * tooltip are created. * @return This builder instance. */ - public FancyMessage tooltip(final Iterable lines) { - tooltip(com.boydti.fawe.bukkit.chat.ArrayWrapper.toArray(lines, String.class)); + public FancyMessage tooltip(Iterable lines) { + tooltip(ArrayWrapper.toArray(lines, String.class)); return this; } @@ -327,7 +327,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param lines The lines of text which will be displayed to the client upon hovering. * @return This builder instance. */ - public FancyMessage tooltip(final String... lines) { + public FancyMessage tooltip(String... lines) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < lines.length; i++) { builder.append(lines[i]); @@ -420,9 +420,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * tooltip are created. * @return This builder instance. */ - public FancyMessage formattedTooltip(final Iterable lines) { - return formattedTooltip( - com.boydti.fawe.bukkit.chat.ArrayWrapper.toArray(lines, FancyMessage.class)); + public FancyMessage formattedTooltip(Iterable lines) { + return formattedTooltip(ArrayWrapper.toArray(lines, FancyMessage.class)); } /** @@ -433,7 +432,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * message. * @return This builder instance. */ - public FancyMessage translationReplacements(final String... replacements) { + public FancyMessage translationReplacements(String... replacements) { for (String str : replacements) { latest().translationReplacements.add(new JsonString(str)); } @@ -466,7 +465,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * message. * @return This builder instance. */ - public FancyMessage translationReplacements(final FancyMessage... replacements) { + public FancyMessage translationReplacements(FancyMessage... replacements) { Collections.addAll(latest().translationReplacements, replacements); dirty = true; @@ -482,9 +481,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * message. * @return This builder instance. */ - public FancyMessage translationReplacements(final Iterable replacements) { + public FancyMessage translationReplacements(Iterable replacements) { return translationReplacements( - com.boydti.fawe.bukkit.chat.ArrayWrapper.toArray(replacements, FancyMessage.class)); + ArrayWrapper.toArray(replacements, FancyMessage.class)); } /** @@ -495,11 +494,11 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param text The text which will populate the new message component. * @return This builder instance. */ - public FancyMessage then(final String text) { + public FancyMessage then(String text) { return then(rawText(text)); } - private FancyMessage append(final String text) { + private FancyMessage append(String text) { if (!latest().hasText()) { throw new IllegalStateException("previous message part has no text"); } @@ -519,7 +518,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param text The text which will populate the new message component. * @return This builder instance. */ - public FancyMessage then(final TextualComponent text) { + public FancyMessage then(TextualComponent text) { if (!latest().hasText()) { throw new IllegalStateException("previous message part has no text"); } @@ -552,7 +551,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< latest().writeJson(writer); } else { writer.beginObject().name("text").value("").name("extra").beginArray(); - for (final MessagePart part : this) { + for (MessagePart part : this) { part.writeJson(writer); } writer.endArray().endObject(); @@ -644,7 +643,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< int minorVersion = Integer.parseInt(split[1]); int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R - if (minorVersion < 8 || (minorVersion == 8 && revisionVersion == 1)) { + if (minorVersion < 8 || minorVersion == 8 && revisionVersion == 1) { chatSerializerClazz = Reflection.getNMSClass("ChatSerializer"); } else { chatSerializerClazz = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer"); @@ -694,9 +693,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< * @param senders The command senders who will receive the message. * @see #send(CommandSender) */ - public void send(final Iterable senders) { + public void send(Iterable senders) { String string = toJSONString(); - for (final CommandSender sender : senders) { + for (CommandSender sender : senders) { send(sender, string); } } @@ -742,7 +741,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< return messageParts.get(messageParts.size() - 1); } - private void onClick(final String name, final String data) { + private void onClick(String name, String data) { onCurrent(m -> { m.clickActionName = name; m.clickActionData = data; @@ -750,7 +749,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< dirty = true; } - private void onHover(final String name, final JsonRepresentedObject data) { + private void onHover(String name, JsonRepresentedObject data) { onCurrent(m -> { m.hoverActionName = name; m.hoverActionData = data; @@ -759,6 +758,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< } // Doc copied from interface + @Override public Map serialize() { HashMap map = new HashMap<>(); map.put("messageParts", messageParts); @@ -784,6 +784,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< /** * Internally called method. Not for API consumption. */ + @Override @NotNull public Iterator iterator() { return messageParts.iterator(); @@ -830,8 +831,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable< .add(MessagePart.stylesToNames.inverse().get(entry.getKey())); } } else if (entry.getKey().equals("color")) { - component.color = ChatColor - .valueOf(entry.getValue().getAsString().toUpperCase()); + component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase()); } else if (entry.getKey().equals("clickEvent")) { JsonObject object = entry.getValue().getAsJsonObject(); component.clickActionName = object.get("action").getAsString(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index 67fd7c1fa..8c90a1bfe 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -85,7 +85,10 @@ public class BukkitServerInterface implements MultiUserPlatform { @Override public boolean isValidMobType(String type) { - final EntityType entityType = EntityType.fromName(type); + if (!type.startsWith("minecraft:")) { + return false; + } + final EntityType entityType = EntityType.fromName(type.substring(10)); return entityType != null && entityType.isAlive(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java index 0e4490070..7b3dfb6a5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommand.java @@ -56,7 +56,7 @@ public class CFICommand extends CommandProcessor { hmCmd = Commands.getAlias(CFICommands.class, "heightmap") + " " + settings.imageArg; } - CFICommands.msg("What do you want to use as the base?").newline() + TextComponent.of("What do you want to use as the base?").newline() .text("[HeightMap]").cmdTip(hmCmd).text(" - A heightmap like ") .text("[this]").linkTip("http://i.imgur.com/qCd30MR.jpg") .newline() diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java index 7f01081d8..60787f493 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java @@ -1,6 +1,8 @@ package com.boydti.fawe.command; import static com.boydti.fawe.util.image.ImageUtil.load; +import static com.sk89q.worldedit.command.MethodCommands.getArguments; +import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline; import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; @@ -18,7 +20,6 @@ import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TextureUtil; -import com.boydti.fawe.util.chat.Message; import com.boydti.fawe.util.image.ImageUtil; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.EmptyClipboardException; @@ -44,19 +45,13 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import org.enginehub.piston.annotation.Command; -import org.enginehub.piston.annotation.CommandContainer; -import org.enginehub.piston.annotation.param.Arg; -import org.enginehub.piston.annotation.param.Switch; -import org.enginehub.piston.exception.StopExecutionException; -import org.enginehub.piston.inject.InjectedValueAccess; - -import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.io.ByteArrayOutputStream; @@ -76,6 +71,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.IntStream; import javax.imageio.ImageIO; +import org.checkerframework.checker.nullness.qual.NonNull; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; @@ -83,9 +79,6 @@ import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.exception.StopExecutionException; import org.enginehub.piston.inject.InjectedValueAccess; -import static com.boydti.fawe.util.image.ImageUtil.load; -import static com.sk89q.worldedit.command.MethodCommands.*; - @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class CFICommands { @@ -161,16 +154,17 @@ public class CFICommands { public void brush(FawePlayer fp) { CFISettings settings = assertSettings(fp); settings.popMessages(fp); - Message msg; + @NonNull Builder msg; if (settings.getGenerator().getImageViewer() != null) { - msg = msg("CFI supports using brushes during creation").newline() - .text(" - Place the map on a wall of item frames").newline() - .text(" - Use any WorldEdit brush on the item frames").newline() - .text(" - Example: ").text("Video").linkTip("https://goo.gl/PK4DMG").newline(); + msg = TextComponent.builder("CFI supports using brushes during creation").append(newline()) + .append(" - Place the map on a wall of item frames").append(newline()) + .append(" - Use any WorldEdit brush on the item frames").append(newline()) + .append(" - Example: ").append(TextComponent.of("Video").clickEvent(ClickEvent.openUrl("https://goo.gl/PK4DMG"))).append(newline()); } else { - msg = msg("This is not supported with your platform/version").newline(); + msg = TextComponent.builder("This is not supported with your platform/version").append(newline()); } - msg.text("< [Back]").cmdTip(alias()).send(fp); + //TODO msg.text("< [Back]").cmdTip(alias()).send(fp); + fp.toWorldEditPlayer().print(msg.build()); } @Command( @@ -360,7 +354,7 @@ public class CFICommands { floor(fp, BlockTypes.SNOW.getDefaultState().with(PropertyKey.LAYERS, 7), image, mask, disableWhiteOnly); main(fp, BlockTypes.SNOW_BLOCK, image, mask, disableWhiteOnly); smooth(fp, 1, 8, image, mask, disableWhiteOnly); - msg("Added snow!").send(fp); + TextComponent.of("Added snow!").send(fp); assertSettings(fp).resetComponent(); component(fp); } @@ -389,15 +383,15 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void paletteblocks(FawePlayer fp, Player player, LocalSession session, @Arg(name = "arg", desc = "String", def = "") String arg) throws EmptyClipboardException, InputParseException, FileNotFoundException { if (arg == null) { - msg("What blocks do you want to color with?").newline() + TextComponent.of("What blocks do you want to color with?").append(newline()) .text("[All]").cmdTip(alias() + " PaletteBlocks *").text(" - All available blocks") - .newline() + .append(newline()) .text("[Clipboard]").cmdTip(alias() + " PaletteBlocks #clipboard").text(" - The blocks in your clipboard") - .newline() + .append(newline()) .text("[List]").suggestTip(alias() + " PaletteBlocks stone,gravel").text(" - A comma separated list of blocks") - .newline() + .append(newline()) .text("[Complexity]").cmdTip(alias() + " Complexity").text(" - Block textures within a complexity range") - .newline() + .append(newline()) .text("< [Back]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "coloring")) .send(fp); return; @@ -511,7 +505,7 @@ public class CFICommands { } else { gen.addSchems(load(imageMask), mask, multi.getHolders(), rarity, distance, rotate); } - msg("Added schematics!").send(fp); + TextComponent.of("Added schematics!").send(fp); populate(fp); } @@ -533,7 +527,7 @@ public class CFICommands { } else { gen.setBiome(biome); } - msg("Set biome!").send(fp); + TextComponent.of("Set biome!").send(fp); assertSettings(fp).resetComponent(); component(fp); } @@ -545,7 +539,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void caves(FawePlayer fp) throws WorldEditException { assertSettings(fp).getGenerator().addCaves(); - msg("Added caves!").send(fp); + TextComponent.of("Added caves!").send(fp); populate(fp); } @@ -557,7 +551,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void ore(FawePlayer fp, Mask mask, Pattern pattern, int size, int frequency, int rariry, int minY, int maxY) throws WorldEditException { assertSettings(fp).getGenerator().addOre(mask, pattern, size, frequency, rariry, minY, maxY); - msg("Added ore!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Added ore!")); populate(fp); } @@ -568,7 +562,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void ores(FawePlayer fp, Mask mask) throws WorldEditException { assertSettings(fp).getGenerator().addDefaultOres(mask); - msg("Added ores!").send(fp); + fp.toWorldEditPlayer().print(TextComponent.of("Added ores!")); populate(fp); } @@ -585,7 +579,8 @@ public class CFICommands { } else { gen.setHeights(Integer.parseInt(arg)); } - msg("Set height!").send(fp); + fp.toWorldEditPlayer().print("Set Height!"); + TextComponent.of("Set height!").send(fp); component(fp); } @@ -597,7 +592,7 @@ public class CFICommands { public void waterId(FawePlayer fp, BlockStateHolder block) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setWaterId(block.getBlockType().getInternalId()); - msg("Set water id!").send(fp); + TextComponent.of("Set water id!").send(fp); settings.resetComponent(); component(fp); } @@ -611,7 +606,7 @@ public class CFICommands { public void baseId(FawePlayer fp, BlockStateHolder block) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setBedrockId(block.getBlockType().getInternalId()); - msg("Set base id!").send(fp); + TextComponent.of("Set base id!").send(fp); settings.resetComponent(); component(fp); } @@ -625,7 +620,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void worldthickness(FawePlayer fp, int height) throws WorldEditException { assertSettings(fp).getGenerator().setWorldThickness(height); - msg("Set world thickness!").send(fp); + TextComponent.of("Set world thickness!").send(fp); component(fp); } @@ -638,7 +633,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void floorthickness(FawePlayer fp, int height) throws WorldEditException { assertSettings(fp).getGenerator().setFloorThickness(height); - msg("Set floor thickness!").send(fp); + TextComponent.of("Set floor thickness!").send(fp); component(fp); } @@ -650,7 +645,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void update(FawePlayer fp) throws WorldEditException { assertSettings(fp).getGenerator().update(); - msg("Chunks refreshed!").send(fp); + TextComponent.of("Chunks refreshed!").send(fp); mainMenu(fp); } @@ -662,7 +657,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void tp(FawePlayer fp) throws WorldEditException { HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); - msg("Teleporting...").send(fp); + TextComponent.of("Teleporting...").send(fp); Vector3 origin = gen.getOrigin(); Player player = fp.getPlayer(); player.setPosition(origin.subtract(16, 0, 16)); @@ -680,7 +675,7 @@ public class CFICommands { @CommandPermissions("worldedit.anvil.cfi") public void waterheight(FawePlayer fp, int height) throws WorldEditException { assertSettings(fp).getGenerator().setWaterHeight(height); - msg("Set water height!").send(fp); + TextComponent.of("Set water height!").send(fp); component(fp); } @@ -694,7 +689,7 @@ public class CFICommands { public void glass(FawePlayer fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setColorWithGlass(load(image)); - msg("Set color with glass!").send(fp); + TextComponent.of("Set color with glass!").send(fp); settings.resetColoring(); mainMenu(fp); } @@ -719,7 +714,7 @@ public class CFICommands { gen.setColor(load(image)); } settings.resetColoring(); - msg("Set color with blocks!").send(fp); + TextComponent.of("Set color with blocks!").send(fp); mainMenu(fp); } @@ -735,7 +730,7 @@ public class CFICommands { public void blockbiome(FawePlayer fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setBlockAndBiomeColor(load(image), mask, load(imageMask), !disableWhiteOnly); - msg("Set color with blocks and biomes!").send(fp); + TextComponent.of("Set color with blocks and biomes!").send(fp); settings.resetColoring(); mainMenu(fp); } @@ -751,7 +746,7 @@ public class CFICommands { public void biomecolor(FawePlayer fp, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) throws WorldEditException { CFISettings settings = assertSettings(fp); settings.getGenerator().setBiomeColor(load(image)); - msg("Set color with biomes!").send(fp); + TextComponent.of("Set color with biomes!").send(fp); settings.resetColoring(); mainMenu(fp); } @@ -804,15 +799,16 @@ public class CFICommands { int biomePriority = gen.getBiomePriority(); - Message msg = msg(">> Current Settings <<").newline() - .text("Randomization ").text("[" + (Boolean.toString(rand).toUpperCase()) + "]").cmdTip(alias() + " randomization " + (!rand)) - .newline() - .text("Mask ").text("[" + mask + "]").cmdTip(alias() + " mask") - .newline() - .text("Blocks ").text("[" + blocks + "]").tooltip(blockList).command(alias() + " paletteBlocks") - .newline() - .text("BiomePriority ").text("[" + biomePriority + "]").cmdTip(alias() + " biomepriority") - .newline(); + //TODO fix this so it can execute commands and show tooltips. + @NonNull Builder builder = TextComponent.builder(">> Current Settings <<").append(newline()) + .append("Randomization ").append("[" + Boolean.toString(rand).toUpperCase() + "]")//.cmdTip(alias() + " randomization " + (!rand)) + .append(newline()) + .append("Mask ").append("[" + mask + "]")//.cmdTip(alias() + " mask") + .append(newline()) + .append("Blocks ").append("[" + blocks + "]")//.tooltip(blockList).command(alias() + " paletteBlocks") + .append(newline()) + .append("BiomePriority ").append("[" + biomePriority + "]")//.cmdTip(alias() + " biomepriority") + .append(newline()); if (settings.image != null) { StringBuilder colorArgs = new StringBuilder(); @@ -827,19 +823,20 @@ public class CFICommands { colorArgs.append(" -w"); } - msg.text("Image: ") - .text("[" + settings.imageArg + "]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "image")) - .newline().newline() - .text("&cLet's Color: ") - .cmdOptions(alias() + " ", colorArgs.toString(), "Biomes", "Blocks", "BlockAndBiome", "Glass") - .newline(); + builder.append("Image: ") + .append("[" + settings.imageArg + "]")//.cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "image")) + .append(newline()).append(newline()) + .append("Let's Color: ") + //.cmdOptions(alias() + " ", colorArgs.toString(), "Biomes", "Blocks", "BlockAndBiome", "Glass") + .append(newline()); } else { - msg.newline().text("You can color a world using an image like ") - .text("[This]").linkTip("http://i.imgur.com/vJYinIU.jpg").newline() - .text("&cYou MUST provide an image: ") - .text("[None]").cmdTip(alias() + " " + Commands.getAlias(Command.class, "image")).newline(); + builder.append(newline()).append("You can color a world using an image like ") + .append(TextComponent.of("[This]").clickEvent(ClickEvent.openUrl("http://i.imgur.com/vJYinIU.jpg"))).append(newline()) + .append("You MUST provide an image: ") + .append("[None]");//.cmdTip(alias() + " " + Commands.getAlias(Command.class, "image")).append(newline()); } - msg.text("< [Back]").cmdTip(alias()).send(fp); + builder.append("< [Back]");//.cmdTip(alias()).send(fp); + fp.toWorldEditPlayer().print(builder.build()); } @Command( @@ -859,12 +856,12 @@ public class CFICommands { StringBuilder cmd = new StringBuilder(alias() + " mask "); - msg(">> Current Settings <<").newline() - .text("Image Mask ").text("[" + settings.imageMaskArg + "]").suggestTip(cmd + "http://") - .newline() - .text("WorldEdit Mask ").text("[" + settings.maskArg + "]").suggestTip(cmd + "") - .newline() - .text("< [Back]").cmdTip(alias() + " " + settings.getCategory()).send(fp); + TextComponent.of(">> Current Settings <<").append(newline()) + .text("Image Mask ").text("[" + settings.imageMaskArg + "]").suggestTip(cmd + "http://") + .append(newline()) + .text("WorldEdit Mask ").text("[" + settings.maskArg + "]").suggestTip(cmd + "") + .append(newline()) + .text("< [Back]").cmdTip(alias() + " " + settings.getCategory()).send(fp); } @Command( @@ -884,9 +881,9 @@ public class CFICommands { if (pattern != null) { settings.getCategory().accept(fp); } else { - msg(">> Current Settings <<").newline() + TextComponent.of(">> Current Settings <<").append(newline()) .text("Pattern ").text("[Click Here]").suggestTip(cmd + " stone") - .newline() + .append(newline()) .text("< [Back]").cmdTip(alias() + " " + settings.getCategory()).send(fp); } } @@ -922,11 +919,13 @@ public class CFICommands { StringBuilder cmd = new StringBuilder(alias() + " image "); if (image == null) { - msg("Please provide an image:").newline() - .text("From a URL: ").text("[Click Here]").suggestTip(cmd + "http://") - .newline() - .text("From a file: ").text("[Click Here]").suggestTip(cmd + "file://") - .send(fp); + TextComponent build = TextComponent.builder("Please provide an image:") + .append(newline()) + .append("From a URL: ").append("[Click Here]")//TODO .suggestTip(cmd + "http://") + .append(newline()) + .append("From a file: ").append("[Click Here]")//TODO .suggestTip(cmd + "file://") + .build(); + fp.toWorldEditPlayer().print(build); } else { if (settings.hasGenerator()) { coloring(fp); @@ -947,11 +946,14 @@ public class CFICommands { CFISettings settings = assertSettings(fp); settings.popMessages(fp); settings.setCategory(this::populate); - msg("What would you like to populate?").newline() - .text("(You will need to type these commands)").newline() - .cmdOptions(alias() + " ", "", "Ores", "Ore", "Caves", "Schematics", "Smooth") - .newline().text("< [Back]").cmdTip(alias()) - .send(fp); + TextComponent build = TextComponent.builder("What would you like to populate?") + .append(newline()) + .append("(You will need to type these commands)").append(newline()) + //TODO .cmdOptions(alias() + " ", "", "Ores", "Ore", "Caves", "Schematics", "Smooth") + .append(newline()) + .append(TextComponent.of("< [Back]").clickEvent(ClickEvent.runCommand(alias()))) + .build(); + fp.toWorldEditPlayer().print(build); } @Command( @@ -991,50 +993,51 @@ public class CFICommands { String waterHeight = Commands.getAlias(CFICommands.class, "waterheight"); String snow = Commands.getAlias(CFICommands.class, "snow"); - Message msg = msg(">> Current Settings <<").newline() - .text("Mask ").text("[" + mask + "]").cmdTip(alias() + " mask") - .newline() - .text("Pattern ").text("[" + pattern + "]").cmdTip(alias() + " pattern") - .newline() - .newline() - .text(">> Components <<") - .newline() - .text("[Height]").suggestTip(alias() + " " + alias("height") + " 120").text(" - Terrain height for whole map") - .newline() - .text("[WaterHeight]").suggestTip(alias() + " " + alias("waterheight") + " 60").text(" - Sea level for whole map") - .newline() - .text("[FloorThickness]").suggestTip(alias() + " " + alias("floorthickness") + " 60").text(" - Floor thickness of entire map") - .newline() - .text("[WorldThickness]").suggestTip(alias() + " " + alias("worldthickness") + " 60").text(" - World thickness of entire map") - .newline() - .text("[Snow]").suggestTip(alias() + " " + alias("snow") + maskArgs).text(" - Set snow in the masked areas") - .newline(); - - if (pattern != null) { - String disabled = "You must specify a pattern"; - msg - .text("[&cWaterId]").tooltip(disabled).newline() - .text("[&cBedrockId]").tooltip(disabled).newline() - .text("[&cFloor]").tooltip(disabled).newline() - .text("[&cMain]").tooltip(disabled).newline() - .text("[&cColumn]").tooltip(disabled).newline() - .text("[&cOverlay]").tooltip(disabled).newline(); - } else { - StringBuilder compArgs = new StringBuilder(); - compArgs.append(" " + settings.patternArg + maskArgs); - - msg - .text("[WaterId]").cmdTip(alias() + " waterId " + pattern).text(" - Water id for whole map").newline() - .text("[BedrockId]").cmdTip(alias() + " baseId " + pattern).text(" - Bedrock id for whole map").newline() - .text("[Floor]").cmdTip(alias() + " floor" + compArgs).text(" - Set the floor in the masked areas").newline() - .text("[Main]").cmdTip(alias() + " main" + compArgs).text(" - Set the main block in the masked areas").newline() - .text("[Column]").cmdTip(alias() + " column" + compArgs).text(" - Set the columns in the masked areas").newline() - .text("[Overlay]").cmdTip(alias() + " overlay" + compArgs).text(" - Set the overlay in the masked areas").newline(); - } - - msg.newline() - .text("< [Back]").cmdTip(alias()) - .send(fp); + //TODO +// Message msg = TextComponent.builder(">> Current Settings <<").append(newline()) +// .append("Mask ").append("[" + mask + "]").cmdTip(alias() + " mask") +// .append(newline()) +// .append("Pattern ").append("[" + pattern + "]").cmdTip(alias() + " pattern") +// .append(newline()) +// .append(newline()) +// .append(">> Components <<") +// .append(newline()) +// .append("[Height]").suggestTip(alias() + " " + alias("height") + " 120").text(" - Terrain height for whole map") +// .append(newline()) +// .text("[WaterHeight]").suggestTip(alias() + " " + alias("waterheight") + " 60").text(" - Sea level for whole map") +// .append(newline()) +// .text("[FloorThickness]").suggestTip(alias() + " " + alias("floorthickness") + " 60").text(" - Floor thickness of entire map") +// .append(newline()) +// .text("[WorldThickness]").suggestTip(alias() + " " + alias("worldthickness") + " 60").text(" - World thickness of entire map") +// .append(newline()) +// .text("[Snow]").suggestTip(alias() + " " + alias("snow") + maskArgs).text(" - Set snow in the masked areas") +// .append(newline()); +// +// if (pattern != null) { +// String disabled = "You must specify a pattern"; +// msg +// .text("[&cWaterId]").tooltip(disabled).append(newline()) +// .text("[&cBedrockId]").tooltip(disabled).append(newline()) +// .text("[&cFloor]").tooltip(disabled).append(newline()) +// .text("[&cMain]").tooltip(disabled).append(newline()) +// .text("[&cColumn]").tooltip(disabled).append(newline()) +// .text("[&cOverlay]").tooltip(disabled).append(newline()); +// } else { +// StringBuilder compArgs = new StringBuilder(); +// compArgs.append(" " + settings.patternArg + maskArgs); +// +// msg +// .text("[WaterId]").cmdTip(alias() + " waterId " + pattern).text(" - Water id for whole map").append(newline()) +// .text("[BedrockId]").cmdTip(alias() + " baseId " + pattern).text(" - Bedrock id for whole map").append(newline()) +// .text("[Floor]").cmdTip(alias() + " floor" + compArgs).text(" - Set the floor in the masked areas").append(newline()) +// .text("[Main]").cmdTip(alias() + " main" + compArgs).text(" - Set the main block in the masked areas").append(newline()) +// .text("[Column]").cmdTip(alias() + " column" + compArgs).text(" - Set the columns in the masked areas").append(newline()) +// .text("[Overlay]").cmdTip(alias() + " overlay" + compArgs).text(" - Set the overlay in the masked areas").append(newline()); +// } +// +// msg.append(newline()) +// .text("< [Back]").cmdTip(alias()) +// .send(fp); } private static CFISettings assertSettings(FawePlayer fp) { @@ -1180,18 +1183,14 @@ public class CFICommands { return Commands.getAlias(CFICommands.class, command); } - protected static Message msg(String text) { - return new Message().newline() - .text(BBC.getPrefix()) - .text(text); - } - + @SuppressWarnings("unused") protected static void mainMenu(FawePlayer fp) { - msg("What do you want to do now?").newline() - .cmdOptions(alias() + " ", "", "Coloring", "Component", "Populate", "Brush") - .newline().text("<> [View]").command(alias() + " " + Commands.getAlias(CFICommands.class, "download")).tooltip("View full resolution image") - .newline().text(">< [Cancel]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "cancel")) - .newline().text("&2>> [Done]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "done")) - .send(fp); + //TODO +// msg("What do you want to do now?").append(newline()) +// .cmdOptions(alias() + " ", "", "Coloring", "Component", "Populate", "Brush") +// .append(newline()).text("<> [View]").command(alias() + " " + Commands.getAlias(CFICommands.class, "download")).tooltip("View full resolution image") +// .append(newline()).text(">< [Cancel]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "cancel")) +// .append(newline()).text("&2>> [Done]").cmdTip(alias() + " " + Commands.getAlias(CFICommands.class, "done")) +// .send(fp); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java b/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java index a155318d7..fb23187e2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java @@ -6,11 +6,9 @@ import com.boydti.fawe.configuration.file.YamlConfiguration; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RunnableVal3; import com.boydti.fawe.util.StringMan; -import com.boydti.fawe.util.chat.Message; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.sk89q.worldedit.extension.platform.Actor; - import java.io.File; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -369,7 +367,7 @@ public enum BBC { private static final HashMap replacements = new HashMap<>(); static { - for (final char letter : "1234567890abcdefklmnor".toCharArray()) { + for (char letter : "1234567890abcdefklmnor".toCharArray()) { replacements.put("&" + letter, "\u00a7" + letter); } replacements.put("\\\\n", "\n"); @@ -394,17 +392,13 @@ public enum BBC { * * @param defaultMessage default */ - BBC(final String defaultMessage, final String category) { + BBC(String defaultMessage, String category) { this.defaultMessage = defaultMessage; this.translatedMessage = defaultMessage; this.category = category.toLowerCase(); } - public String f(final Object... args) { - return format(args); - } - - public String format(final Object... args) { + public String format(Object... args) { String m = this.translatedMessage; for (int i = args.length - 1; i >= 0; i--) { if (args[i] == null) { @@ -418,7 +412,7 @@ public enum BBC { return m; } - public static void load(final File file) { + public static void load(File file) { try { if (!file.exists()) { file.getParentFile().mkdirs(); @@ -430,13 +424,13 @@ public enum BBC { final HashSet allNames = new HashSet<>(); final HashSet allCats = new HashSet<>(); final HashSet toRemove = new HashSet<>(); - for (final BBC c : all) { + for (BBC c : all) { allNames.add(c.name()); allCats.add(c.category.toLowerCase()); } final EnumSet captions = EnumSet.noneOf(BBC.class); boolean changed = false; - for (final String key : keys) { + for (String key : keys) { final Object value = yml.get(key); if (value instanceof MemorySection) { continue; @@ -456,11 +450,11 @@ public enum BBC { toRemove.add(key); } } - for (final String remove : toRemove) { + for (String remove : toRemove) { changed = true; yml.set(remove, null); } - for (final BBC caption : all) { + for (BBC caption : all) { if (!captions.contains(caption)) { changed = true; yml.set(caption.category + "." + caption.name().toLowerCase(), caption.defaultMessage); @@ -470,7 +464,7 @@ public enum BBC { if (changed) { yml.save(file); } - } catch (final Exception e) { + } catch (Exception e) { e.printStackTrace(); } } @@ -501,10 +495,6 @@ public enum BBC { return this.translatedMessage; } - public Message m(Object... args) { - return new Message(this, args); - } - public String original() { return defaultMessage; } @@ -518,7 +508,7 @@ public enum BBC { return index == 0 ? this : others[index - 1]; } - public void send(Object actor, final Object... args) { + public void send(Object actor, Object... args) { if (isEmpty()) { return; } @@ -536,10 +526,10 @@ public enum BBC { } public static String getPrefix() { - return (PREFIX.isEmpty() ? "" : PREFIX.s() + " "); + return PREFIX.isEmpty() ? "" : PREFIX.s() + " "; } - public void send(final FawePlayer player, final Object... args) { + public void send(FawePlayer player, Object... args) { if (isEmpty()) { return; } @@ -549,7 +539,7 @@ public enum BBC { player.sendMessage((PREFIX.isEmpty() ? "" : PREFIX.s() + " ") + this.format(args)); } } - public void send(final Actor player, final Object... args) { + public void send(Actor player, Object... args) { if (isEmpty()) { return; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 54d7607cf..8ecf06f30 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -159,7 +159,8 @@ public abstract class FawePlayer extends Metadatable { if (times > limit) { setConfirmTask(task, context, command); String volume = ""; - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(0, times, command, volume)); + throw new RegionOperationException( + BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.format(0, times, command, volume)); } } task.run(); @@ -171,7 +172,9 @@ public abstract class FawePlayer extends Metadatable { if (radius > 448) { setConfirmTask(task, context, command); long volume = (long) (Math.PI * ((double) radius * radius)); - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(0, radius, command, NumberFormat.getNumberInstance().format(volume))); + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM + .format(0, radius, command, + NumberFormat.getNumberInstance().format(volume))); } } } @@ -188,7 +191,8 @@ public abstract class FawePlayer extends Metadatable { setConfirmTask(task, context, command); BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); long volume = (long) base.getX() * base.getZ() * base.getY() * times; - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(min, max, command, NumberFormat.getNumberInstance().format(volume))); + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM + .format(min, max, command, NumberFormat.getNumberInstance().format(volume))); } } } @@ -205,7 +209,8 @@ public abstract class FawePlayer extends Metadatable { setConfirmTask(task, context, command); BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); long volume = (long) base.getX() * base.getZ() * base.getY(); - throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(min, max, command, NumberFormat.getNumberInstance().format(volume))); + throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM + .format(min, max, command, NumberFormat.getNumberInstance().format(volume))); } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index a5d3ab0b9..ce7c8e4f4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -60,11 +60,12 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { public boolean perform(final Player player, LocalSession session, boolean rightClick) { if (!session.isToolControlEnabled() || !player.hasPermission("worldedit.tool.inspect")) { - player.print(BBC.getPrefix() + BBC.NO_PERM.f("worldedit.tool.inspect")); + player.print(BBC.getPrefix() + BBC.NO_PERM.format("worldedit.tool.inspect")); return false; } if (!Settings.IMP.HISTORY.USE_DATABASE) { - player.print(BBC.getPrefix() + BBC.SETTING_DISABLE.f("history.use-database (Import with /frb #import )")); + player.print(BBC.getPrefix() + BBC.SETTING_DISABLE + .format("history.use-database (Import with /frb #import )")); return false; } BlockVector3 target = getTarget(player, rightClick).toBlockPoint(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java index d42460e4b..e62f02945 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/chat/Message.java @@ -3,9 +3,8 @@ package com.boydti.fawe.util.chat; import com.boydti.fawe.Fawe; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FawePlayer; - import com.sk89q.worldedit.extension.platform.Actor; - +import java.io.Serializable; import java.util.Objects; public class Message { @@ -24,10 +23,6 @@ public class Message { active = !(Fawe.get().getChatManager() instanceof PlainChatManager); } - public Message(BBC caption, Object... args) { - this(BBC.getPrefix() + caption.format(args)); - } - public Message(String text) { this(); text(text); @@ -41,13 +36,6 @@ public class Message { return (T) (this.builder = manager.builder()); } - public Message activeText(String text) { - if (active) { - text(text); - } - return this; - } - public boolean supportsInteraction() { return active; } @@ -56,7 +44,7 @@ public class Message { return text(caption.format(args)); } - public Message text(java.io.Serializable text) { + public Message text(Serializable text) { Fawe.get().getChatManager().text(this, BBC.color(Objects.toString(text))); return this; } @@ -76,14 +64,10 @@ public class Message { } public Message command(String command) { - Fawe.get().getChatManager().command(this, ("/") + command); + Fawe.get().getChatManager().command(this, "/" + command); return this; } - public Message prefix() { - return text(BBC.getPrefix()); - } - public Message newline() { return text("\n"); } @@ -98,8 +82,8 @@ public class Message { public Message cmdOptions(String prefix, String suffix, String... options) { for (int i = 0; i < options.length; i++) { - if (i != 0) text(" &8|&7 "); - text("&7[&a" + options[i] + "&7]") + if (i != 0) text(" | "); + text("[" + options[i] + "]") .cmdTip(prefix + options[i] + suffix); } return this; @@ -114,11 +98,6 @@ public class Message { return this; } - public Message color(String color) { - Fawe.get().getChatManager().color(this, BBC.color(color)); - return this; - } - public void send(Actor player) { send(FawePlayer.wrap(player)); } @@ -129,19 +108,19 @@ public class Message { public Message paginate(String baseCommand, int page, int totalPages) { if (!active) { - return text(BBC.PAGE_FOOTER.f(baseCommand, page + 1)); + return text(BBC.PAGE_FOOTER.format(baseCommand, page + 1)); } if (page < totalPages && page > 1) { // Back | Next - this.text("&f<<").command(baseCommand + " " + (page - 1)).text("&8 | ").text("&f>>") + this.text("<<").command(baseCommand + " " + (page - 1)).text(" | ").text(">>") .command(baseCommand + " " + (page + 1)); } else if (page <= 1 && totalPages > page) { // Next - this.text("&8 -").text(" | ").text("&f>>") + this.text(" -").text(" | ").text(">>") .command(baseCommand + " " + (page + 1)); } else if (page == totalPages && totalPages > 1) { // Back - this.text("&f<<").command(baseCommand + " " + (page - 1)).text("&8 | ").text("- "); + this.text("<<").command(baseCommand + " " + (page - 1)).text(" | ").text("- "); } else { - this.text("&8 - | - "); + this.text(" - | - "); } return this; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 0b59cecf2..89343bab9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -124,8 +124,6 @@ import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.inject.InjectedValueAccess; import org.enginehub.piston.inject.Key; -import static com.sk89q.worldedit.command.MethodCommands.*; - /** * Commands to set brush shape. */ @@ -254,7 +252,7 @@ public class BrushCommands { @Arg(desc = "The radius to sample for blending", def = "25") Expression radius, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - player.print(BBC.BRUSH_SPLINE.f(radius)); + player.print(BBC.BRUSH_SPLINE.format(radius)); return set(session, context, new SplineBrush(player, session)) .setSize(radius) @@ -310,7 +308,7 @@ public class BrushCommands { public BrushSettings surfaceSpline(Player player, LocalSession session, Pattern fill, @Arg(desc = "The radius to sample for blending", def = "0") Expression radius, @Arg(name = "tension", desc = "double", def = "0") double tension, @Arg(name = "bias", desc = "double", def = "0") double bias, @Arg(name = "continuity", desc = "double", def = "0") double continuity, @Arg(name = "quality", desc = "double", def = "10") double quality, InjectedValueAccess context) throws WorldEditException { - player.print(BBC.BRUSH_SPLINE.f(radius)); + player.print(BBC.BRUSH_SPLINE.format(radius)); worldEdit.checkMaxBrushRadius(radius); return set(session, context, new SurfaceSpline(tension, bias, continuity, quality)) @@ -795,7 +793,7 @@ public class BrushCommands { @CommandPermissions("worldedit.brush.copy") public BrushSettings copy(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Switch(name = 'r', desc = "Apply random rotation on paste") boolean randomRotate, @Switch(name = 'a', desc = "Apply auto view based rotation on paste") boolean autoRotate, InjectedValueAccess context) throws WorldEditException { worldEdit.checkMaxBrushRadius(radius); - player.print(BBC.BRUSH_COPY.f(radius)); + player.print(BBC.BRUSH_COPY.format(radius)); return set(session, context, new CopyPastaBrush(player, session, randomRotate, autoRotate)) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java index 35e5054e1..f01b507dd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushOptionsCommands.java @@ -43,6 +43,7 @@ import java.util.zip.GZIPInputStream; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; +import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.inject.InjectedValueAccess; @@ -138,7 +139,7 @@ public class BrushOptionsCommands { ) @CommandPermissions("worldedit.brush.list") public void list(Actor actor, InjectedValueAccess args, - @Switch(name = 'p', desc = "Prints the requested page") + @ArgFlag(name = 'p', desc = "Prints the requested page", def = "0") int page) throws WorldEditException { String baseCmd = Commands.getAlias(BrushCommands.class, "brush") + " " + Commands.getAlias(BrushOptionsCommands.class, "loadbrush"); File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes"); @@ -349,7 +350,7 @@ public class BrushOptionsCommands { throws WorldEditException { BrushTool tool = session.getBrushTool(player, false); if (tool == null) { - player.print(BBC.BRUSH_NONE.f()); + player.print(BBC.BRUSH_NONE.s()); return; } if (mask == null) { @@ -381,7 +382,7 @@ public class BrushOptionsCommands { Arguments arguments) throws WorldEditException { BrushTool tool = session.getBrushTool(player, false); if (tool == null) { - player.print(BBC.BRUSH_NONE.f()); + player.print(BBC.BRUSH_NONE.s()); return; } if (mask == null) { @@ -409,7 +410,7 @@ public class BrushOptionsCommands { Arguments arguments) throws WorldEditException { BrushTool tool = session.getBrushTool(player, false); if (tool == null) { - player.print(BBC.BRUSH_NONE.f()); + player.print(BBC.BRUSH_NONE.s()); return; } if (transform == null) { @@ -438,7 +439,7 @@ public class BrushOptionsCommands { Arguments arguments) throws WorldEditException { BrushTool tool = session.getBrushTool(player, false); if (tool == null) { - player.print(BBC.BRUSH_NONE.f()); + player.print(BBC.BRUSH_NONE.s()); return; } if (pattern == null) { @@ -465,7 +466,7 @@ public class BrushOptionsCommands { range = Math.max(0, Math.min(256, range)); BrushTool tool = session.getBrushTool(player, false); if (tool == null) { - player.print(BBC.BRUSH_NONE.f()); + player.print(BBC.BRUSH_NONE.s()); return; } tool.setRange(range); @@ -485,7 +486,7 @@ public class BrushOptionsCommands { worldEdit.checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player, false); if (tool == null) { - player.print(BBC.BRUSH_NONE.f()); + player.print(BBC.BRUSH_NONE.s()); return; } BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java index fee888e32..9c6113657 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ListFilters.java @@ -1,24 +1,19 @@ package com.sk89q.worldedit.command; import com.boydti.fawe.Fawe; -import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.StringMan; -import com.sk89q.worldedit.command.util.CommandPermissions; -import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import org.enginehub.piston.annotation.Command; -import org.enginehub.piston.annotation.CommandContainer; -import org.enginehub.piston.annotation.param.Arg; -import org.enginehub.piston.exception.StopExecutionException; - import java.io.File; -import java.io.IOException; import java.util.Locale; import java.util.UUID; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.enginehub.piston.annotation.Command; +import org.enginehub.piston.annotation.CommandContainer; +import org.enginehub.piston.exception.StopExecutionException; +//TODO This class breaks compilation @CommandContainer public class ListFilters { public class Filter { @@ -81,7 +76,7 @@ public class ListFilters { } @Command( - name = "", + name = "*", //TODO originally this was left blank but doing so causes a major compilation error desc = "wildcard" ) public Filter wildcard(Actor actor, File root, String arg) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index c898b6e23..c474241f9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -19,25 +19,16 @@ package com.sk89q.worldedit.command; -import static com.boydti.fawe.util.ReflectionUtils.as; import static com.google.common.base.Preconditions.checkNotNull; import com.boydti.fawe.config.BBC; -import com.boydti.fawe.config.Commands; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FawePlayer; -import com.boydti.fawe.object.RunnableVal3; import com.boydti.fawe.object.clipboard.MultiClipboardHolder; import com.boydti.fawe.object.clipboard.URIClipboardHolder; import com.boydti.fawe.object.clipboard.remap.ClipboardRemapper; import com.boydti.fawe.object.schematic.MinecraftStructure; -import com.boydti.fawe.object.schematic.StructureFormat; - import com.boydti.fawe.util.MainUtil; -import com.boydti.fawe.util.chat.Message; -import com.sk89q.worldedit.command.util.AsyncCommandBuilder; -import org.enginehub.piston.inject.InjectedValueAccess; -import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -51,7 +42,6 @@ import com.sk89q.worldedit.event.extent.PlayerSaveClipboardEvent; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; @@ -59,7 +49,6 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.formatting.component.CodeFormat; import com.sk89q.worldedit.util.formatting.component.ErrorFormat; import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.component.SchematicPaginationBox; @@ -87,7 +76,6 @@ import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.Callable; - import java.util.regex.Pattern; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; @@ -95,6 +83,7 @@ import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.Switch; import org.enginehub.piston.exception.StopExecutionException; +import org.enginehub.piston.inject.InjectedValueAccess; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -218,7 +207,8 @@ public class SchematicCommands { @Arg(desc = "Format name.", def = "sponge") String formatName) throws FilenameException { LocalConfiguration config = worldEdit.getConfiguration(); - ClipboardFormat format = formatName == null ? null : ClipboardFormats.findByAlias(formatName); + + ClipboardFormat format = ClipboardFormats.findByAlias(formatName); InputStream in = null; try { URI uri; @@ -228,19 +218,15 @@ public class SchematicCommands { return; } UUID uuid = UUID.fromString(filename.substring(4)); - URL base = new URL(Settings.IMP.WEB.URL); - URL url = new URL(base, "uploads/" + uuid + "." + format.getPrimaryFileExtension()); - ReadableByteChannel rbc = Channels.newChannel(url.openStream()); - in = Channels.newInputStream(rbc); + URL webUrl = new URL(Settings.IMP.WEB.URL); + URL url = new URL(webUrl, "uploads/" + uuid + "." + format.getPrimaryFileExtension()); + ReadableByteChannel byteChannel = Channels.newChannel(url.openStream()); + in = Channels.newInputStream(byteChannel); uri = url.toURI(); } else { - if (!player.hasPermission("worldedit.schematic.load") && !player.hasPermission("worldedit.clipboard.load")) { - BBC.NO_PERM.send(player, "worldedit.clipboard.load"); - return; - } - File working = worldEdit.getWorkingDirectoryFile(config.saveDir); - File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(working, player.getUniqueId().toString()) : working; - File f; + File saveDir = worldEdit.getWorkingDirectoryFile(config.saveDir); + File dir = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS ? new File(saveDir, player.getUniqueId().toString()) : saveDir; + File file; if (filename.startsWith("#")) { String[] extensions; if (format != null) { @@ -248,9 +234,9 @@ public class SchematicCommands { } else { extensions = ClipboardFormats.getFileExtensionArray(); } - f = player.openFileOpenDialog(extensions); - if (f == null || !f.exists()) { - player.printError("Schematic " + filename + " does not exist! (" + f + ")"); + file = player.openFileOpenDialog(extensions); + if (file == null || !file.exists()) { + player.printError("Schematic " + filename + " does not exist! (" + file + ")"); return; } } else { @@ -262,27 +248,27 @@ public class SchematicCommands { String extension = filename.substring(filename.lastIndexOf('.') + 1); format = ClipboardFormats.findByExtension(extension); } - f = MainUtil.resolve(dir, filename, format, false); + file = MainUtil.resolve(dir, filename, format, false); } - if (f == null || !f.exists()) { + if (file == null || !file.exists()) { if (!filename.contains("../")) { dir = this.worldEdit.getWorkingDirectoryFile(config.saveDir); - f = MainUtil.resolve(dir, filename, format, false); + file = MainUtil.resolve(dir, filename, format, false); } } - if (f == null || !f.exists() || !MainUtil.isInSubDirectory(working, f)) { - player.printError("Schematic " + filename + " does not exist! (" + (f != null && f.exists()) + "|" + f + "|" + (f != null && !MainUtil.isInSubDirectory(working, f)) + ")"); + if (file == null || !file.exists() || !MainUtil.isInSubDirectory(saveDir, file)) { + player.printError("Schematic " + filename + " does not exist! (" + (file != null && file.exists()) + "|" + file + "|" + (file != null && !MainUtil.isInSubDirectory(saveDir, file)) + ")"); return; } if (format == null) { - format = ClipboardFormats.findByFile(f); + format = ClipboardFormats.findByFile(file); if (format == null) { - BBC.CLIPBOARD_INVALID_FORMAT.send(player, f.getName()); + BBC.CLIPBOARD_INVALID_FORMAT.send(player, file.getName()); return; } } - in = new FileInputStream(f); - uri = f.toURI(); + in = new FileInputStream(file); + uri = file.toURI(); } format.hold(player, uri, in); BBC.SCHEMATIC_LOADED.send(player, filename); @@ -418,7 +404,8 @@ public class SchematicCommands { continue; } if (Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS && (!MainUtil.isInSubDirectory(dir, destFile) || !MainUtil.isInSubDirectory(dir, source)) && !player.hasPermission("worldedit.schematic.delete.other")) { - BBC.SCHEMATIC_MOVE_FAILED.send(player, destFile, BBC.NO_PERM.f("worldedit.schematic.move.other")); + BBC.SCHEMATIC_MOVE_FAILED.send(player, destFile, + BBC.NO_PERM.format("worldedit.schematic.move.other")); continue; } try { @@ -522,7 +509,7 @@ public class SchematicCommands { " -f restricts by format\n" ) @CommandPermissions("worldedit.schematic.show") - public void show(Player player, InjectedValueAccess args, @Switch(name='f', desc = "TODO") String formatName) { + public void show(Player player, InjectedValueAccess args, @Switch(name='f', desc = "") String formatName) { FawePlayer fp = FawePlayer.wrap(player); if (args.argsLength() == 0) { if (fp.getSession().getVirtualWorld() != null) fp.setVirtualWorld(null); @@ -586,66 +573,65 @@ public class SchematicCommands { public void list(FawePlayer fp, Actor actor, InjectedValueAccess args, @ArgFlag(name = 'p', desc = "Page to view.", def = "1") int page, - @Switch(name = 'f', desc = "Restricts by format.") - String formatName) throws WorldEditException { - LocalConfiguration config = worldEdit.getConfiguration(); - File dir = worldEdit.getWorkingDirectoryFile(config.saveDir); + @Switch(name = 'd', desc = "Sort by date, oldest first") + boolean oldFirst, + @Switch(name = 'n', desc = "Sort by date, newest first") + boolean newFirst, + @Switch(name = 'f', desc = "Restricts by format.") + String formatName, + @Arg(name = "filter", desc = "Filter for schematics", def = "all") + String filter) throws WorldEditException { + if (oldFirst && newFirst) { + throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest.")); + } + final String saveDir = worldEdit.getConfiguration().saveDir; + final int sortType = oldFirst ? -1 : newFirst ? 1 : 0; - String schemCmd = "/" + Commands.getAlias(SchematicCommands.class, "schematic"); - String loadSingle = schemCmd + " " + Commands.getAlias(SchematicCommands.class, "load"); - String loadMulti = schemCmd + " " + Commands.getAlias(SchematicCommands.class, "loadall"); - String unload = schemCmd + " " + Commands.getAlias(SchematicCommands.class, "unload"); - String delete = schemCmd + " " + Commands.getAlias(SchematicCommands.class, "delete"); - String list = schemCmd + " " + Commands.getAlias(SchematicCommands.class, "list"); - String showCmd = schemCmd + " " + Commands.getAlias(SchematicCommands.class, "show"); + final String pageCommand = actor.isPlayer() + ? "//schem list -p %page%" + (sortType == -1 ? " -d" : sortType == 1 ? " -n" : "") : null; - URIClipboardHolder multi = as(URIClipboardHolder.class, fp.getSession().getExistingClipboard()); + WorldEditAsyncCommandBuilder.createAndSendMessage(actor, + new SchematicListTask(saveDir, sortType, page, pageCommand, filter, formatName), "(Please wait... gathering schematic list.)"); - final boolean hasShow = actor.hasPermission("worldedit.schematic.show"); - UtilityCommands.list(dir, actor, args, page, -1, formatName, Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS, new RunnableVal3() { - @Override - public void run(Message msg, URI uri, String relFilePath) { - boolean isDir = false; - boolean loaded = multi != null && multi.contains(uri); - - String name = relFilePath; - String uriStr = uri.toString(); - if (uriStr.startsWith("file:/")) { - File file = new File(uri.getPath()); - name = file.getName(); - try { - if (!MainUtil.isInSubDirectory(dir, file)) { - throw new RuntimeException(new CommandException("Invalid path")); - } - } catch (IOException ignore) {} - if (file.isDirectory()) { - isDir = true; - } else if (name.indexOf('.') != -1) { - name = name.substring(0, name.lastIndexOf('.')); - } - } // url - - msg.text(" - "); - - if (msg.supportsInteraction()) { - if (loaded) { - msg.text("[-]").command(unload + " " + relFilePath).tooltip("Unload"); - } else { - msg.text("[+]").command(loadMulti + " " + relFilePath).tooltip("Add to clipboard"); - } - if (!isDir) msg.text("[X]").suggest("/" + delete + " " + relFilePath).tooltip("Delete"); - else if (hasShow) msg.text("[O]").command(showCmd + " " + args.getJoinedStrings(0) + " " + relFilePath).tooltip("Show"); - msg.text(name); - if (isDir) { - msg.command(list + " " + relFilePath).tooltip("List"); - } else { - msg.command(loadSingle + " " + relFilePath).tooltip("Load"); - } - } else { - msg.text(name); - } - } - }); +// UtilityCommands.list(dir, actor, args, page, -1, formatName, Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS, new RunnableVal3() { +// @Override +// public void run(Message msg, URI uri, String relFilePath) { +// boolean isDir = false; +// boolean loaded = multi != null && multi.contains(uri); +// +// String name = relFilePath; +// String uriStr = uri.toString(); +// if (uriStr.startsWith("file:/")) { +// File file1 = new File(uri.getPath()); +// name = file1.getName(); +// try { +// if (!MainUtil.isInSubDirectory(dir, file1)) { +// throw new RuntimeException(new CommandException("Invalid path")); +// } +// } catch (IOException ignore) {} +// if (file1.isDirectory()) { +// isDir = true; +// } else if (name.indexOf('.') != -1) { +// name = name.substring(0, name.lastIndexOf('.')); +// } +// } // url +// +// msg.text(" - "); +// +// if (loaded) { +// msg.text("[-]").command(unload + " " + relFilePath).tooltip("Unload"); +// } else { +// msg.text("[+]").command(loadMulti + " " + relFilePath).tooltip("Add to clipboard"); +// } +// if (!isDir) msg.text("[X]").suggest("/" + delete + " " + relFilePath).tooltip("Delete"); +// msg.text(name); +// if (isDir) { +// msg.command(list + " " + relFilePath).tooltip("List"); +// } else { +// msg.command(loadSingle + " " + relFilePath).tooltip("Load"); +// } +// } +// }); } private static class SchematicLoadTask implements Callable { @@ -734,18 +720,24 @@ public class SchematicCommands { private final int page; private final File rootDir; private final String pageCommand; + private final String filter; + private String formatName; - SchematicListTask(String prefix, int sortType, int page, String pageCommand) { + SchematicListTask(String prefix, int sortType, int page, String pageCommand, + String filter, String formatName) { this.prefix = prefix; this.sortType = sortType; this.page = page; this.rootDir = WorldEdit.getInstance().getWorkingDirectoryFile(prefix); this.pageCommand = pageCommand; + this.filter = filter; + this.formatName = formatName; } @Override public Component call() throws Exception { - List fileList = allFiles(rootDir); + ClipboardFormat format = ClipboardFormats.findByAlias(formatName); + List fileList = getFiles(rootDir,filter,format); if (fileList == null || fileList.isEmpty()) { return ErrorFormat.wrap("No schematics found."); @@ -776,13 +768,18 @@ public class SchematicCommands { } } - private static List allFiles(File root) { + //TODO filtering for directories, global, and private scheamtics needs to be reimplemented here + private static List getFiles(File root, String filter, ClipboardFormat format) { File[] files = root.listFiles(); if (files == null) return null; + //Only get the files that match the format parameter + if (format != null) { + files = Arrays.stream(files).filter(format::isFormat).toArray(File[]::new); + } List fileList = new ArrayList<>(); for (File f : files) { if (f.isDirectory()) { - List subFiles = allFiles(f); + List subFiles = getFiles(f, filter, format); if (subFiles == null) continue; // empty subdir fileList.addAll(subFiles); } else { 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 0d23ae5e6..5dbd8db1e 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 @@ -554,7 +554,7 @@ public class SelectionCommands { newSelector = new Polygonal2DRegionSelector(oldSelector); player.print(BBC.SEL_2D_POLYGON.s()); Optional limit = ActorSelectorLimits.forActor(player).getPolygonVertexLimit(); - limit.ifPresent(integer -> player.print(BBC.SEL_MAX.f(integer))); + limit.ifPresent(integer -> player.print(BBC.SEL_MAX.format(integer))); break; } case ELLIPSOID: @@ -575,14 +575,14 @@ public class SelectionCommands { newSelector = new ConvexPolyhedralRegionSelector(oldSelector); player.print(BBC.SEL_CONVEX_POLYHEDRAL.s()); Optional limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit(); - limit.ifPresent(integer -> player.print(BBC.SEL_MAX.f(integer))); + limit.ifPresent(integer -> player.print(BBC.SEL_MAX.format(integer))); break; } case POLYHEDRAL: newSelector = new PolyhedralRegionSelector(player.getWorld()); player.print(BBC.SEL_CONVEX_POLYHEDRAL.s()); Optional limit = ActorSelectorLimits.forActor(player).getPolyhedronVertexLimit(); - limit.ifPresent(integer -> player.print(BBC.SEL_MAX.f(integer))); + limit.ifPresent(integer -> player.print(BBC.SEL_MAX.format(integer))); player.print(BBC.SEL_LIST.s()); break; case FUZZY: @@ -591,8 +591,8 @@ public class SelectionCommands { mask = new IdMask(world); } newSelector = new FuzzyRegionSelector(player, editSession, mask); - player.print(BBC.SEL_FUZZY.f()); - player.print(BBC.SEL_LIST.f()); + player.print(BBC.SEL_FUZZY.s()); + player.print(BBC.SEL_LIST.s()); break; case LIST: default: diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index b0aa3d5b7..671d26ae1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -188,14 +188,11 @@ public class UtilityCommands { @Arg(desc = "The blocks to fill with") Pattern pattern, @Arg(desc = "The radius to fill in") - double radius, + @Range(min = 1) double radius, @Arg(desc = "The depth to fill", def = "1") - int depth, - @Arg(desc = "Direction to fill", def = "down") - BlockVector3 direction) throws WorldEditException { - radius = Math.max(1, radius); + @Range(min = 1) int depth, + @Arg(desc = "Direction to fill", def = "down") BlockVector3 direction) throws WorldEditException { we.checkMaxRadius(radius); - depth = Math.max(1, depth); BlockVector3 pos = session.getPlacementPosition(player); int affected = editSession.fillDirection(pos, pattern, radius, depth, direction); @@ -284,10 +281,9 @@ public class UtilityCommands { @Arg(desc = "The blocks to fill with") Pattern pattern, @Arg(desc = "The radius to fill in") - double radius, + @Range(min = 1) double radius, @Arg(desc = "The depth to fill", def = "") - Integer depth) throws WorldEditException { - radius = Math.max(1, radius); + @Range(min = 1) Integer depth) throws WorldEditException { we.checkMaxRadius(radius); depth = depth == null ? Integer.MAX_VALUE : Math.max(1, depth); we.checkMaxRadius(radius); @@ -306,10 +302,9 @@ public class UtilityCommands { @Logging(PLACEMENT) public int drain(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius to drain") - double radius, + @Range(min = 0) double radius, @Switch(name = 'w', desc = "Also un-waterlog blocks") boolean waterlogged) throws WorldEditException { - radius = Math.max(0, radius); we.checkMaxRadius(radius); int affected = editSession.drainArea( session.getPlacementPosition(player), radius, waterlogged); @@ -326,8 +321,7 @@ public class UtilityCommands { @Logging(PLACEMENT) public int fixLava(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius to fix in") - double radius) throws WorldEditException { - radius = Math.max(0, radius); + @Range(min = 0) double radius) throws WorldEditException { we.checkMaxRadius(radius); int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.LAVA); player.print(affected + " block(s) have been changed."); @@ -360,14 +354,10 @@ public class UtilityCommands { @Logging(PLACEMENT) public int removeAbove(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The apothem of the square to remove from", def = "1") - int size, + @Range(min = 1) int size, @Arg(desc = "The maximum height above you to remove from", def = "") Integer height) throws WorldEditException { - size = Math.max(1, size); we.checkMaxRadius(size); - World world = player.getWorld(); - height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1); - int affected = editSession.removeAbove(session.getPlacementPosition(player), size, height); BBC.VISITOR_BLOCK.send(player, affected); return affected; @@ -382,10 +372,9 @@ public class UtilityCommands { @Logging(PLACEMENT) public int removeBelow(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The apothem of the square to remove from", def = "1") - int size, + @Range(min =1) int size, @Arg(desc = "The maximum height below you to remove from", def = "") Integer height) throws WorldEditException { - size = Math.max(1, size); we.checkMaxRadius(size); World world = player.getWorld(); height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1); @@ -406,8 +395,7 @@ public class UtilityCommands { @Arg(desc = "The mask of blocks to remove") Mask mask, @Arg(desc = "The radius of the square to remove from", def = "50") - int radius) throws WorldEditException { - radius = Math.max(1, radius); + @Range(min=1) int radius) throws WorldEditException { we.checkMaxRadius(radius); int affected = editSession.removeNear(session.getPlacementPosition(player), mask, radius); @@ -424,12 +412,11 @@ public class UtilityCommands { @Logging(PLACEMENT) public int replaceNear(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the square to remove in") - int radius, + @Range(min=1) int radius, @Arg(desc = "The mask matching blocks to remove", def = "") Mask from, @Arg(desc = "The pattern of blocks to replace with") Pattern to) throws WorldEditException { - radius = Math.max(1, radius); we.checkMaxRadius(radius); BlockVector3 base = session.getPlacementPosition(player); @@ -455,8 +442,7 @@ public class UtilityCommands { @Logging(PLACEMENT) public int snow(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the circle to snow in", def = "10") - double size) throws WorldEditException { - size = Math.max(1, size); + @Range(min=1) double size) throws WorldEditException { we.checkMaxRadius(size); int affected = editSession.simulateSnow(session.getPlacementPosition(player), size); @@ -473,12 +459,11 @@ public class UtilityCommands { @Logging(PLACEMENT) public int thaw(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the circle to thaw in", def = "10") - double size) throws WorldEditException { - size = Math.max(1, size); + @Range(min=1) double size) throws WorldEditException { we.checkMaxRadius(size); int affected = editSession.thaw(session.getPlacementPosition(player), size); - player.print(affected + " surface(s) thawed."); + player.print(affected + " surfaces thawed."); return affected; } @@ -491,10 +476,9 @@ public class UtilityCommands { @Logging(PLACEMENT) public int green(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the circle to convert in", def = "10") - double size, + @Range(min=1) double size, @Switch(name = 'f', desc = "Also convert coarse dirt") boolean convertCoarse) throws WorldEditException { - size = Math.max(1, size); we.checkMaxRadius(size); final boolean onlyNormalDirt = !convertCoarse; @@ -512,12 +496,12 @@ public class UtilityCommands { @Logging(PLACEMENT) public void extinguish(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The radius of the square to remove in", def = "") - Integer radius) throws WorldEditException { + @Range(min=1) Integer radius) throws WorldEditException { LocalConfiguration config = we.getConfiguration(); int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40; - int size = radius != null ? Math.max(1, radius) : defaultRadius; + int size = radius != null ? radius : defaultRadius; we.checkMaxRadius(size); Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE); @@ -673,8 +657,7 @@ public class UtilityCommands { return; } WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> { - double result = expression.evaluate( - new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); + double result = expression.evaluateTimeout(WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result); return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE)); }, null); @@ -804,7 +787,7 @@ public class UtilityCommands { page = args.getInteger(--len); } for (int i = 0; i < len; i++) { - String arg = args.getString(i); + String arg = ""; switch (arg.toLowerCase()) { case "me": case "mine":