From ccd8f2c2a901cb6043af13a1dda2e3069268f581 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Wed, 9 Oct 2019 20:43:28 -0400 Subject: [PATCH] Attempt to fix command execution. --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 2 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 14 ++---- .../worldedit/bukkit/WorldEditPlugin.java | 9 +--- .../com/boydti/fawe/command/FaweBinding.java | 16 ------- .../worldedit/command/SelectionCommands.java | 12 ++--- .../command/util/SuggestionHelper.java | 1 + .../platform/AbstractNonPlayerActor.java | 5 ++ .../platform/PlatformCommandManager.java | 6 +-- .../platform/binding/AnnotatedBindings.java | 48 ------------------- .../command/CommandLoggingHandler.java | 19 ++++++-- 10 files changed, 33 insertions(+), 99 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/command/FaweBinding.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/AnnotatedBindings.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index e5452b80b..0cce4ed2f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -83,7 +83,7 @@ public class FaweBukkit implements IFawe, Listener { } if (PaperLib.isPaper() && Settings.IMP.EXPERIMENTAL.DYNAMIC_CHUNK_RENDERING > 1) { new RenderListener(plugin); - } + }in if (Bukkit.getPluginManager().getPlugin("PlotSquared") != null) { try { WEManager.IMP.managers.add(new PlotSquaredFeature()); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 3016dc15c..928d0dd88 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -31,7 +31,6 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; -import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.math.BlockVector3; @@ -177,15 +176,8 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public void setPosition(Vector3 pos, float pitch, float yaw) { - if (pos instanceof com.sk89q.worldedit.util.Location) { - com.sk89q.worldedit.util.Location loc = (com.sk89q.worldedit.util.Location) pos; - Extent extent = loc.getExtent(); - if (extent instanceof World) { - org.bukkit.World world = Bukkit.getWorld(((World) extent).getName()); - player.teleport(new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch)); - } - } - player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw, pitch)); + player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), + pos.getZ(), yaw, pitch)); } @Override @@ -264,7 +256,7 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public boolean isAllowedToFly() { return player.getAllowFlight(); - } + } @Override public void setFlying(boolean flying) { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index 0a50892f4..a247b6389 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -224,13 +224,6 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter } } -// // Register 1.13 Material ids with LegacyMapper -// LegacyMapper legacyMapper = LegacyMapper.getInstance(); -// for (Material m : Material.values()) { -// if (!m.isLegacy() && m.isBlock()) { -// legacyMapper.register(m.getId(), 0, BukkitAdapter.adapt(m).getDefaultState()); -// } -// } // Enable metrics new Metrics(this); PaperLib.suggestPaper(this); @@ -465,7 +458,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter // code of WorldEdit expects it String[] split = new String[args.length + 1]; System.arraycopy(args, 0, split, 1, args.length); - split[0] = commandLabel; + split[0] = "/" + commandLabel; CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/FaweBinding.java b/worldedit-core/src/main/java/com/boydti/fawe/command/FaweBinding.java deleted file mode 100644 index 89d3d9321..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/FaweBinding.java +++ /dev/null @@ -1,16 +0,0 @@ -//package com.boydti.fawe.command; -// -//import com.sk89q.worldedit.WorldEdit; -//import com.sk89q.worldedit.util.command.parametric.BindingHelper; -// -//public class FaweBinding extends BindingHelper { -// private final WorldEdit worldEdit; -// -// public FaweBinding(WorldEdit worldEdit) { -// this.worldEdit = worldEdit; -// } -// -// public WorldEdit getWorldEdit() { -// return worldEdit; -// } -//} 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 4e8727206..80ef774a8 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 @@ -116,7 +116,7 @@ public class SelectionCommands { } if (!session.getRegionSelector(world).selectPrimary(pos.toBlockPoint(), ActorSelectorLimits.forActor(actor))) { - BBC.SELECTOR_ALREADY_SET.send(actor); + actor.print(BBC.SELECTOR_ALREADY_SET.s()); return; } @@ -144,7 +144,7 @@ public class SelectionCommands { } if (!session.getRegionSelector(world).selectSecondary(pos.toBlockPoint(), ActorSelectorLimits.forActor(actor))) { - BBC.SELECTOR_ALREADY_SET.send(actor); + actor.print(BBC.SELECTOR_ALREADY_SET.s()); return; } @@ -163,14 +163,14 @@ public class SelectionCommands { if (pos != null) { if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toBlockPoint(), ActorSelectorLimits.forActor(player))) { - BBC.SELECTOR_ALREADY_SET.send(player); + player.print(BBC.SELECTOR_ALREADY_SET.s()); return; } session.getRegionSelector(player.getWorld()) .explainPrimarySelection(player, session, pos.toBlockPoint()); } else { - BBC.NO_BLOCK.send(player); + player.print(BBC.NO_BLOCK.s()); } } @@ -185,14 +185,14 @@ public class SelectionCommands { if (pos != null) { if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toBlockPoint(), ActorSelectorLimits.forActor(player))) { - BBC.SELECTOR_ALREADY_SET.send(player); + player.print(BBC.SELECTOR_ALREADY_SET.s()); return; } session.getRegionSelector(player.getWorld()) .explainSecondarySelection(player, session, pos.toBlockPoint()); } else { - BBC.NO_BLOCK.send(player); + player.print(BBC.NO_BLOCK.s()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java index 268b2cd3d..57990087f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/SuggestionHelper.java @@ -29,6 +29,7 @@ import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; + import java.util.Arrays; import java.util.HashSet; import java.util.List; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java index 856e9b418..19820255d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractNonPlayerActor.java @@ -114,14 +114,17 @@ public abstract class AbstractNonPlayerActor implements Actor { * @param value * @return previous value */ + @Override public final void setMeta(String key, Object value) { this.meta.put(key, value); } + @Override public final T getAndSetMeta(String key, T value) { return (T) this.meta.put(key, value); } + @Override public final boolean hasMeta() { return !meta.isEmpty(); } @@ -133,6 +136,7 @@ public abstract class AbstractNonPlayerActor implements Actor { * @param key * @return */ + @Override public final V getMeta(String key) { return (V) this.meta.get(key); } @@ -144,6 +148,7 @@ public abstract class AbstractNonPlayerActor implements Actor { * * @param key */ + @Override public final V deleteMeta(String key) { return (V) this.meta.remove(key); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 57d6e71ae..3aaa08794 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -541,7 +541,6 @@ public final class PlatformCommandManager { Request.reset(); Actor actor = event.getActor(); String args = event.getArguments(); - System.out.println(1); TaskManager.IMP.taskNow(() -> { int space0 = args.indexOf(' '); String arg0 = space0 == -1 ? args : args.substring(0, space0); @@ -596,8 +595,7 @@ public final class PlatformCommandManager { } public void handleCommandTask(ThrowableSupplier task, InjectedValueAccess context, @Nullable LocalSession session, CommandEvent event) { - Request.reset(); - Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("No player")); + Actor actor = event.getActor(); long start = System.currentTimeMillis(); @@ -662,7 +660,7 @@ public final class PlatformCommandManager { long time = System.currentTimeMillis() - start; if (time > 1000) { - BBC.ACTION_COMPLETE.send(actor, time / 1000D); + BBC.ACTION_COMPLETE.send(event.getActor(), time / 1000D); } worldEdit.flushBlockBag(actor, editSession); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/AnnotatedBindings.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/AnnotatedBindings.java deleted file mode 100644 index 8768cbdda..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/AnnotatedBindings.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.sk89q.worldedit.extension.platform.binding; - -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.extension.input.InputParseException; -import com.sk89q.worldedit.internal.annotation.Validate; - -import java.lang.annotation.Annotation; - -public class AnnotatedBindings extends Bindings { - - private final WorldEdit worldEdit; - - public AnnotatedBindings(WorldEdit worldEdit) { - this.worldEdit = worldEdit; - } - - @Validate() - public String getText(String argument, Validate modifier) { - return validate(argument, modifier); - } - - /** - * Validate a string value using relevant modifiers. - * - * @param string the string - * @param modifiers the list of modifiers to scan - * @throws InputParseException on a validation error - */ - private static String validate(String string, Annotation... modifiers) { - if (string != null) { - for (Annotation modifier : modifiers) { - if (modifier instanceof Validate) { - Validate validate = (Validate) modifier; - - if (!validate.value().isEmpty()) { - if (!string.matches(validate.value())) { - throw new InputParseException( - String.format( - "The given text doesn't match the right format (technically speaking, the 'format' is %s)", - validate.value())); - } - } - } - } - } - return string; - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index fbdbc09ef..927b195c4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -29,6 +29,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import org.enginehub.piston.CommandParameters; +import org.enginehub.piston.exception.CommandException; import org.enginehub.piston.gen.CommandCallListener; import org.enginehub.piston.inject.Key; @@ -72,15 +73,23 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable logMode = loggingAnnotation.value(); } - Optional playerOpt = parameters.injectedValue(Key.of(Actor.class)); - Optional worldOpt = parameters.injectedValue(Key.of(World.class)); + Optional actorOpt = parameters.injectedValue(Key.of(Actor.class)); - if (!playerOpt.isPresent() || !worldOpt.isPresent()) { + if (!actorOpt.isPresent()) { return; } + Actor actor = actorOpt.get(); - Actor actor = playerOpt.get(); - World world = worldOpt.get(); + World world; + try { + Optional worldOpt = parameters.injectedValue(Key.of(World.class)); + if (!worldOpt.isPresent()) { + return; + } + world = worldOpt.get(); + } catch (CommandException ex) { + return; + } builder.append("WorldEdit: ").append(actor.getName()); builder.append(" (in \"").append(world.getName()).append("\")");