From 614f5e1c16d849f08438fd777fe045bda3a43bf9 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Thu, 6 Feb 2020 16:33:31 -0500 Subject: [PATCH] Minor changes --- .../fawe/object/exception/FaweException.java | 16 +----- .../java/com/sk89q/worldedit/EditSession.java | 21 ++++--- .../com/sk89q/worldedit/LocalSession.java | 23 ++++---- .../worldedit/command/HistoryCommands.java | 14 ++--- .../worldedit/command/UtilityCommands.java | 55 ++++++++++--------- .../worldedit/function/EntityFunction.java | 1 + 6 files changed, 63 insertions(+), 67 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java index f97d1c65b..2c9b2d728 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/exception/FaweException.java @@ -9,19 +9,9 @@ import java.util.Locale; public class FaweException extends RuntimeException { // DEBUG - public static final FaweException _enableQueue; - public static final FaweException _disableQueue; - - static { - try { - _enableQueue = new FaweException(Extent.class.getDeclaredMethod("enableQueue").toString()); - _disableQueue = new FaweException(Extent.class.getDeclaredMethod("disableQueue").toString()); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - + public static final FaweException _enableQueue = new FaweException("enableQueue"); + public static final FaweException _disableQueue = new FaweException("disableQueue"); + private final Component message; public FaweException(String reason) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 77509df7b..437095ca2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -19,12 +19,6 @@ package com.sk89q.worldedit; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.sk89q.worldedit.regions.Regions.asFlatRegion; -import static com.sk89q.worldedit.regions.Regions.maximumBlockY; -import static com.sk89q.worldedit.regions.Regions.minimumBlockY; - import com.boydti.fawe.FaweCache; import com.boydti.fawe.config.Caption; import com.boydti.fawe.config.Settings; @@ -130,6 +124,10 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -139,11 +137,15 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.worldedit.regions.Regions.asFlatRegion; +import static com.sk89q.worldedit.regions.Regions.maximumBlockY; +import static com.sk89q.worldedit.regions.Regions.minimumBlockY; + import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Range; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * An {@link Extent} that handles history, {@link BlockBag}s, change limits, @@ -338,6 +340,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * chunk batching}. */ public void enableStandardMode() { + setBatchingChunks(true); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 39575a69b..3e40330f2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit; -import static com.google.common.base.Preconditions.checkNotNull; - import com.boydti.fawe.Fawe; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweInputStream; @@ -99,6 +97,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Stores session information. */ @@ -919,6 +919,14 @@ public class LocalSession implements TextureHolder { return selector.getPrimaryPosition(); } + public void setPlaceAtPos1(boolean placeAtPos1) { + this.placeAtPos1 = placeAtPos1; + } + + public boolean isPlaceAtPos1() { + return placeAtPos1; + } + /** * Toggle placement position. * @@ -1086,7 +1094,8 @@ public class LocalSession implements TextureHolder { public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException { if (item.hasBlockType()) { throw new InvalidToolBindException(item, "Blocks can't be used"); - } else if (tool instanceof SelectionWand) { + } + if (tool instanceof SelectionWand) { changeTool(this.wandItem, this.wandItem = item, tool); setDirty(); return; @@ -1118,14 +1127,6 @@ public class LocalSession implements TextureHolder { } } - public void setPlaceAtPos1(boolean placeAtPos1) { - this.placeAtPos1 = placeAtPos1; - } - - public boolean isPlaceAtPos1() { - return placeAtPos1; - } - public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException { ItemType type = item.getType(); if (type.hasBlockType() && type.getBlockType().getMaterial().isAir()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 084f1dc02..7f70d759e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -28,7 +28,6 @@ import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.annotation.Confirm; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; -import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import org.enginehub.piston.annotation.Command; @@ -58,14 +57,14 @@ public class HistoryCommands { @Command( name = "undo", aliases = { "/undo" }, - desc = "Undoes the last action (from history)" + desc = "Undoes the last action (from history)" ) @CommandPermissions({"worldedit.history.undo", "worldedit.history.undo.self"}) public void undo(Player player, LocalSession session, @Confirm(Confirm.Processor.LIMIT) @Arg(desc = "Number of undoes to perform", def = "1") - int times, + int times, @Arg(name = "player", desc = "Undo this player's operations", def = "") - String playerName) throws WorldEditException { + String playerName) throws WorldEditException { times = Math.max(1, times); LocalSession undoSession = session; if (session.hasFastMode()) { @@ -136,13 +135,14 @@ public class HistoryCommands { } @Command( - name = "clearhistory", - aliases = { "/clearhistory" }, - desc = "Clear your history" + name = "clearhistory", + aliases = { "/clearhistory" }, + desc = "Clear your history" ) @CommandPermissions("worldedit.history.clear") public void clearHistory(Actor actor, LocalSession session) { session.clearHistory(); actor.printInfo(TranslatableComponent.of("worldedit.clearhistory.cleared")); } + } 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 d425b6485..76f9b7819 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 @@ -128,7 +128,7 @@ public class UtilityCommands { ) @CommandPermissions("fawe.admin") public void heightmapInterface(Player player, @Arg(name = "min", desc = "int", def = "100") int min, @Arg(name = "max", desc = "int", def = "200") int max) throws IOException { - player.print("Please wait while we generate the minified heightmaps."); + player.print(TextComponent.of("Please wait while we generate the minified heightmaps.")); File srcFolder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP); File webSrc = new File(Fawe.imp().getDirectory(), "web" + File.separator + "heightmap"); @@ -150,7 +150,7 @@ public class UtilityCommands { BufferedImage img = MainUtil.readImage(file); BufferedImage minImg = ImageUtil.getScaledInstance(img, min, min, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); BufferedImage maxImg = max == -1 ? img : ImageUtil.getScaledInstance(img, max, max, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); - player.print("Writing " + name); + player.print(TextComponent.of(String.format("Writing %s", name))); File minFile = new File(minImages, name); File maxFile = new File(maxImages, name); minFile.getParentFile().mkdirs(); @@ -175,9 +175,9 @@ public class UtilityCommands { config.append("// The local source for the image (used in commands)\n"); config.append("var src_local = \"file://\";\n"); File configFile = new File(webSrc, "config.js"); - player.print("Writing " + configFile); + player.print(TextComponent.of(String.format("Writing %s",configFile))); Files.write(configFile.toPath(), config.toString().getBytes()); - player.print("Done! See: `FastAsyncWorldEdit/web/heightmap`"); + player.print(TextComponent.of("Done! See: `FastAsyncWorldEdit/web/heightmap`")); } @Command( @@ -201,9 +201,9 @@ public class UtilityCommands { public int fill(Actor actor, LocalSession session, EditSession editSession, @Arg(desc = "The blocks to fill with") Pattern pattern, - @Range(from=1, to=Integer.MAX_VALUE) @Arg(desc = "The radius to fill in") + @Arg(desc = "The radius to fill in") Expression radiusExp, - @Range(from=1, to=Integer.MAX_VALUE) @Arg(desc = "The depth to fill", def = "1") + @Arg(desc = "The depth to fill", def = "1") int depth, @Arg(desc = "The direction to move", def = "down") @Direction BlockVector3 direction) throws WorldEditException, EvaluationException { @@ -612,10 +612,10 @@ public class UtilityCommands { @CommandPermissions("worldedit.remove") @Logging(PLACEMENT) public int remove(Actor actor, - @Arg(desc = "The type of entity to remove") - EntityRemover remover, - @Arg(desc = "The radius of the cuboid to remove from") - int radius) throws WorldEditException { + @Arg(desc = "The type of entity to remove") + EntityRemover remover, + @Arg(desc = "The radius of the cuboid to remove from") + int radius) throws WorldEditException { if (radius < -1) { actor.printError(TranslatableComponent.of("worldedit.remove.explain-all")); return 0; @@ -627,7 +627,7 @@ public class UtilityCommands { } private int killMatchingEntities(Integer radius, Actor actor, Supplier func) throws IncompleteRegionException, - MaxChangedBlocksException { + MaxChangedBlocksException { List visitors = new ArrayList<>(); LocalSession session = we.getSessionManager().get(actor); @@ -653,22 +653,6 @@ public class UtilityCommands { return killed; } - @Command( - name = "/help", - desc = "Displays help for WorldEdit commands" - ) - @CommandPermissions("worldedit.help") - public void help(Actor actor, - @Switch(name = 's', desc = "List sub-commands of the given command, if applicable") - boolean listSubCommands, - @ArgFlag(name = 'p', desc = "The page to retrieve", def = "1") - int page, - @Arg(desc = "The command to retrieve help for", def = "", variable = true) - List command) throws WorldEditException { - PrintCommandHelp.help(command, page, listSubCommands, - we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "//help"); - } - private DecimalFormat formatForLocale(Locale locale) { DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(locale); format.applyPattern("#,##0.#####"); @@ -699,6 +683,23 @@ public class UtilityCommands { }, (Component) null); } + @Command( + name = "/help", + desc = "Displays help for WorldEdit commands" + ) + @CommandPermissions("worldedit.help") + public void help(Actor actor, + @Switch(name = 's', desc = "List sub-commands of the given command, if applicable") + boolean listSubCommands, + @ArgFlag(name = 'p', desc = "The page to retrieve", def = "1") + int page, + @Arg(desc = "The command to retrieve help for", def = "", variable = true) + List command) throws WorldEditException { + PrintCommandHelp.help(command, page, listSubCommands, + we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "//help"); + } + + @Command( name = "/confirm", desc = "Confirm a command" diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/EntityFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/EntityFunction.java index 6bbb669f0..9ce9915fa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/EntityFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/EntityFunction.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Entity; +import java.util.function.Predicate; /** * Applies a function to entities.