From ca8b161e4cf7460d53077fa5d2ab6215298a1864 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 31 Dec 2016 17:23:01 +1100 Subject: [PATCH] Fix fake player inter world teleport --- .../com/boydti/fawe/wrappers/FakePlayer.java | 10 ++++ .../boydti/fawe/wrappers/PlayerWrapper.java | 53 +++++++++++++++++-- .../extension/platform/CommandManager.java | 2 +- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java b/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java index 3817da9d..19b6b25a 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java @@ -45,6 +45,13 @@ public class FakePlayer extends LocalPlayer { private World world; private Location pos; + public static FakePlayer wrap(String name, UUID uuid, Actor parent) { + if (parent.getUniqueId().toString().equals("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be")) { + return getConsole(); + } + return new FakePlayer(name, uuid, parent); + } + public FakePlayer(String name, UUID uuid, Actor parent) { this.name = name; this.uuid = uuid == null ? UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)) : uuid; @@ -150,6 +157,9 @@ public class FakePlayer extends LocalPlayer { @Override public void setPosition(Vector pos, float pitch, float yaw) { + if (pos instanceof WorldVector) { + this.world = ((WorldVector) pos).getWorld(); + } this.pos = new Location(world, pos, yaw, pitch); } diff --git a/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java b/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java index ba568325..13570c10 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java @@ -80,14 +80,61 @@ public class PlayerWrapper extends AbstractPlayerActor { TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Boolean value) { - parent.findFreePosition(searchPos); + World world = searchPos.getWorld(); + int x = searchPos.getBlockX(); + int y = Math.max(0, searchPos.getBlockY()); + int origY = y; + int z = searchPos.getBlockZ(); + + byte free = 0; + + while (y <= world.getMaxY() + 2) { + if (BlockType.canPassThrough(world.getBlock(new Vector(x, y, z)))) { + ++free; + } else { + free = 0; + } + + if (free == 2) { + if (y - 1 != origY) { + final Vector pos = new Vector(x, y - 2, z); + final int id = world.getBlockType(pos); + final int data = world.getBlockData(pos); + setPosition(new WorldVector((LocalWorld) world, x + 0.5, y - 2 + BlockType.centralTopLimit(id, data), z + 0.5)); + } + + return; + } + + ++y; + } } }); } @Override - public void setOnGround(WorldVector searchPos) { - parent.setOnGround(searchPos); + public void setOnGround(final WorldVector searchPos) { + TaskManager.IMP.sync(new RunnableVal() { + @Override + public void run(Boolean value) { + World world = searchPos.getWorld(); + int x = searchPos.getBlockX(); + int y = Math.max(0, searchPos.getBlockY()); + int z = searchPos.getBlockZ(); + + while (y >= 0) { + final Vector pos = new Vector(x, y, z); + final int id = world.getBlockType(pos); + final int data = world.getBlockData(pos); + if (!BlockType.canPassThrough(id, data)) { + setPosition(new WorldVector((LocalWorld) world, x + 0.5, y + BlockType.centralTopLimit(id, data), z + 0.5)); + return; + } + + --y; + } + } + }); } @Override diff --git a/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 6208a10a..ff22752f 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -260,7 +260,7 @@ public final class CommandManager { return; } if (!actor.isPlayer()) { - actor = new FakePlayer(actor.getName(), actor.getUniqueId(), actor); + actor = FakePlayer.wrap(actor.getName(), actor.getUniqueId(), actor); } final LocalSession session = worldEdit.getSessionManager().get(actor); LocalConfiguration config = worldEdit.getConfiguration();