From 944c8c552161b7781db80d507d70fcab5adf01f8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 23 Nov 2019 05:15:48 +0000 Subject: [PATCH] Fixes #255 compass exceptipn --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 13 --- .../fawe/object/brush/CommandBrush.java | 4 +- .../{PlayerWrapper.java => AsyncPlayer.java} | 32 +++--- .../wrappers/LocationMaskedPlayerWrapper.java | 103 +++++++++++++++++- .../fawe/wrappers/SilentPlayerWrapper.java | 4 +- .../platform/PlatformCommandManager.java | 41 +------ .../extension/platform/PlatformManager.java | 12 +- .../extension/platform/PlayerProxy.java | 3 - 8 files changed, 131 insertions(+), 81 deletions(-) rename worldedit-core/src/main/java/com/boydti/fawe/wrappers/{PlayerWrapper.java => AsyncPlayer.java} (90%) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index d061f468c..1aa189540 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -21,9 +21,6 @@ package com.sk89q.worldedit.bukkit; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.Fawe; -import com.boydti.fawe.wrappers.PlayerWrapper; -import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; @@ -37,22 +34,12 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockState; 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.entity.EntityType; -import com.sk89q.worldedit.world.entity.EntityTypes; import com.sk89q.worldedit.world.gamemode.GameMode; -import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; -import com.sk89q.worldedit.world.item.ItemTypes; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java index 0a1e610db..ff341ec9f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java @@ -2,7 +2,7 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.util.StringMan; import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper; -import com.boydti.fawe.wrappers.PlayerWrapper; +import com.boydti.fawe.wrappers.AsyncPlayer; import com.boydti.fawe.wrappers.SilentPlayerWrapper; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; @@ -42,7 +42,7 @@ public class CommandBrush implements Brush { position = position.add(face.getDirection().toBlockPoint()); } player.setSelection(selector); - PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position.toVector3()))); + AsyncPlayer wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position.toVector3()))); List cmds = StringMan.split(replaced, ';'); for (String cmd : cmds) { CommandEvent event = new CommandEvent(wePlayer, cmd); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/AsyncPlayer.java similarity index 90% rename from worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java rename to worldedit-core/src/main/java/com/boydti/fawe/wrappers/AsyncPlayer.java index 00cb5cd27..8f1abc76c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/AsyncPlayer.java @@ -17,16 +17,16 @@ import com.sk89q.worldedit.util.TargetBlock; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; -public class PlayerWrapper extends PlayerProxy { - public PlayerWrapper(Player parent) { +public class AsyncPlayer extends PlayerProxy { + public AsyncPlayer(Player parent) { super(parent); } - public static PlayerWrapper wrap(Player parent) { - if (parent instanceof PlayerWrapper) { - return (PlayerWrapper) parent; + public static AsyncPlayer wrap(Player parent) { + if (parent instanceof AsyncPlayer) { + return (AsyncPlayer) parent; } - return new PlayerWrapper(parent); + return new AsyncPlayer(parent); } @Override @@ -162,23 +162,23 @@ public class PlayerWrapper extends PlayerProxy { } catch (RuntimeException e) { caught = e; } - TaskManager.IMP.sync(new RunnableVal() { - @Override - public void run(Object value) { - setPosition(Vector3.at(x + 0.5, y, z + 0.5)); - } - }); + setPosition(Vector3.at(x + 0.5, y, z + 0.5)); if (caught != null) { throw caught; } } + @Override + public void setPosition(Vector3 pos, float pitch, float yaw) { + Fawe.get().getQueueHandler().sync(() -> super.setPosition(pos, pitch, yaw)); + } + @Override public Location getBlockTrace(int range, boolean useLastBlock) { return TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Location value) { - TargetBlock tb = new TargetBlock(PlayerWrapper.this, range, 0.2D); + TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); this.value = useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock(); } }); @@ -189,7 +189,7 @@ public class PlayerWrapper extends PlayerProxy { return TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Location value) { - TargetBlock tb = new TargetBlock(PlayerWrapper.this, range, 0.2D); + TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); this.value = useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace(); } }); @@ -200,7 +200,7 @@ public class PlayerWrapper extends PlayerProxy { return TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Location value) { - TargetBlock tb = new TargetBlock(PlayerWrapper.this, range, 0.2D); + TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D); this.value = tb.getSolidTargetBlock(); } }); @@ -215,7 +215,7 @@ public class PlayerWrapper extends PlayerProxy { public boolean passThroughForwardWall(int range) { return TaskManager.IMP.sync(() -> { int searchDist = 0; - TargetBlock hitBlox = new TargetBlock(PlayerWrapper.this, range, 0.2); + TargetBlock hitBlox = new TargetBlock(AsyncPlayer.this, range, 0.2); Extent world = getLocation().getExtent(); Location block; boolean firstBlock = true; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/LocationMaskedPlayerWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/LocationMaskedPlayerWrapper.java index d60ee83b2..dc15ca7d6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/LocationMaskedPlayerWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/LocationMaskedPlayerWrapper.java @@ -1,10 +1,19 @@ package com.boydti.fawe.wrappers; +import com.boydti.fawe.Fawe; +import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.EditSessionBuilder; +import com.boydti.fawe.util.TaskManager; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.block.BlockTypes; -public class LocationMaskedPlayerWrapper extends PlayerWrapper { +public class LocationMaskedPlayerWrapper extends AsyncPlayer { private final boolean allowTeleport; private Location position; @@ -23,11 +32,101 @@ public class LocationMaskedPlayerWrapper extends PlayerWrapper { return position; } + private void update() { + this.position = super.getLocation(); + } + @Override public void setPosition(Vector3 pos, float pitch, float yaw) { - this.position = new Location(position.getExtent(), pos, pitch, yaw); if (allowTeleport) { super.setPosition(pos, pitch, yaw); + update(); + } + } + + @Override + public void findFreePosition(Location searchPos) { + if (allowTeleport) { + super.setPosition(searchPos); + update(); + } + } + + @Override + public void setOnGround(Location searchPos) { + if (allowTeleport) { + super.setPosition(searchPos); + update(); + } + } + + @Override + public void findFreePosition() { + if (allowTeleport) { + super.findFreePosition(); + update(); + } + } + + @Override + public boolean ascendLevel() { + if (allowTeleport) { + super.ascendLevel(); + update(); + } + return true; + } + + @Override + public boolean descendLevel() { + if (allowTeleport) { + super.descendLevel(); + update(); + } + return true; + } + + @Override + public boolean ascendToCeiling(int clearance) { + if (allowTeleport) { + super.ascendToCeiling(clearance); + update(); + } + return true; + } + + @Override + public boolean ascendToCeiling(int clearance, boolean alwaysGlass) { + if (allowTeleport) { + super.ascendToCeiling(clearance, alwaysGlass); + update(); + } + return true; + } + + @Override + public boolean ascendUpwards(int distance) { + if (allowTeleport) { + super.ascendUpwards(distance); + update(); + } + return true; + } + + @Override + public boolean ascendUpwards(int distance, boolean alwaysGlass) { + if (allowTeleport) { + super.ascendUpwards(distance, alwaysGlass); + update(); + } + return true; + } + + @Override + public void floatAt(int x, int y, int z, boolean alwaysGlass) { + if (allowTeleport) { + super.floatAt(x, y, z, alwaysGlass); + update(); } } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/SilentPlayerWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/SilentPlayerWrapper.java index 2e8b51979..d99f25891 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/SilentPlayerWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/SilentPlayerWrapper.java @@ -3,12 +3,10 @@ package com.boydti.fawe.wrappers; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.formatting.text.Component; -import java.awt.*; - /** * Avoids printing any messages */ -public class SilentPlayerWrapper extends PlayerWrapper { +public class SilentPlayerWrapper extends AsyncPlayer { public SilentPlayerWrapper(Player parent) { super(parent); } 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 5fd21ebba..235fa0f60 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 @@ -337,44 +337,6 @@ public final class PlatformCommandManager { globalInjectedValues.injectValue(Key.of(InjectedValueAccess.class), Optional::of); } - private Actor wrapActor(Actor actor, InjectedValueStore context) { - if (actor instanceof Player) { - final Set failedPermissions = new LinkedHashSet<>(); - Player player = (Player) actor; - Player unwrapped = PlayerProxy.unwrap(player); - actor = new LocationMaskedPlayerWrapper(unwrapped, unwrapped.getLocation(), true) { - @Override - public boolean hasPermission(String permission) { - if (!super.hasPermission(permission)) { - failedPermissions.add(permission); - return false; - } - return true; - } - @Override - public void checkPermission(String permission) throws AuthorizationException { - try { - super.checkPermission(permission); - } catch (AuthorizationException e) { - failedPermissions.add(permission); - throw e; - } - } - }; - context.injectValue(Key.of(CommandPermissions.class), i -> Optional.of(new CommandPermissions() { - @Override - public Class annotationType() { - return CommandPermissions.class; - } - @Override - public String[] value() { - return failedPermissions.toArray(new String[0]); - } - })); - } - return actor; - } - private void registerSubCommands(String name, List aliases, String desc, CommandManager commandManager, Consumer> handlerInstance) { @@ -815,9 +777,8 @@ public final class PlatformCommandManager { getCommandManager(), actor, "//help"); } - private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor tmp, Event event) { + private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor, Event event) { InjectedValueStore store = MapBackedValueStore.create(); - Actor actor = wrapActor(tmp, store); store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor)); if (actor instanceof Player) { store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index f4a90859c..12de47f9a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -21,6 +21,8 @@ package com.sk89q.worldedit.extension.platform; import static com.google.common.base.Preconditions.checkNotNull; +import com.boydti.fawe.wrappers.AsyncPlayer; +import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.object.brush.visualization.VirtualWorld; import com.boydti.fawe.object.exception.FaweException; @@ -267,13 +269,19 @@ public class PlatformManager { if (cuiActor == null) { cuiActor = player; } - - return (T) new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld())); + if (player == permActor && player == cuiActor) { + return (T) proxyFawe(player); + } + return (T) proxyFawe(new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld()))); } else { return base; } } + private T proxyFawe(T player) { + return (T) new LocationMaskedPlayerWrapper(player, player.getLocation(), true); + } + /** * Get the command manager. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index a71b2b314..5c2e83573 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.extension.platform; import static com.google.common.base.Preconditions.checkNotNull; -import com.boydti.fawe.wrappers.PlayerWrapper; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; @@ -34,7 +33,6 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -44,7 +42,6 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import javax.annotation.Nullable; import java.util.UUID; -import java.util.function.Supplier; public class PlayerProxy extends AbstractPlayerActor {