From 227ac22d153235d43efea8a7236fc67695c0110c Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 30 Jun 2016 22:11:58 +1000 Subject: [PATCH] Fix data for id=9 --- .../fawe/bukkit/logging/LoggingExtent.java | 1 - .../main/java/com/boydti/fawe/FaweCache.java | 1 - .../boydti/fawe/example/CharFaweChunk.java | 1 - .../com/boydti/fawe/object/FawePlayer.java | 4 + .../clipboard/MemoryOptimizedClipboard.java | 1 - .../com/boydti/fawe/wrappers/FakePlayer.java | 238 ++++++++++++++++++ .../com/sk89q/worldedit/CuboidClipboard.java | 1 - .../boydti/fawe/forge/v0/ForgeChunk_All.java | 1 - 8 files changed, 242 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/logging/LoggingExtent.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/logging/LoggingExtent.java index b77e8b4a..84470695 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/logging/LoggingExtent.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/logging/LoggingExtent.java @@ -96,7 +96,6 @@ public class LoggingExtent extends AbstractDelegateExtent { case 58: case 60: case 7: - case 9: case 11: case 73: case 74: diff --git a/core/src/main/java/com/boydti/fawe/FaweCache.java b/core/src/main/java/com/boydti/fawe/FaweCache.java index fa0b5541..1861038f 100644 --- a/core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/core/src/main/java/com/boydti/fawe/FaweCache.java @@ -281,7 +281,6 @@ public class FaweCache { case 58: case 60: case 7: - case 9: case 11: case 73: case 74: diff --git a/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java b/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java index 780c27ea..1f6c86ec 100644 --- a/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java +++ b/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java @@ -232,7 +232,6 @@ public abstract class CharFaweChunk extends FaweChunk { case 58: case 60: case 7: - case 9: case 73: case 79: case 80: diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index e81be950..1fa209fd 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -11,6 +11,7 @@ import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; +import com.boydti.fawe.wrappers.FakePlayer; import com.boydti.fawe.wrappers.PlayerWrapper; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EmptyClipboardException; @@ -58,6 +59,9 @@ public abstract class FawePlayer { if (obj == null) { return null; } + if (obj instanceof FakePlayer) { + return ((FakePlayer) obj).toFawePlayer(); + } if (obj instanceof Player) { Player actor = (Player) obj; if (obj.getClass().getSimpleName().equals("PlayerProxy")) { diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index 67493273..f989ea77 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -251,7 +251,6 @@ public class MemoryOptimizedClipboard extends FaweClipboard { case 58: case 60: case 7: - case 9: case 11: case 73: case 74: diff --git a/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java b/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java new file mode 100644 index 00000000..59178f65 --- /dev/null +++ b/core/src/main/java/com/boydti/fawe/wrappers/FakePlayer.java @@ -0,0 +1,238 @@ +package com.boydti.fawe.wrappers; + +import com.boydti.fawe.Fawe; +import com.boydti.fawe.object.FaweLocation; +import com.boydti.fawe.object.FawePlayer; +import com.google.common.base.Charsets; +import com.sk89q.worldedit.LocalPlayer; +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldVector; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.event.platform.CommandEvent; +import com.sk89q.worldedit.extension.platform.CommandManager; +import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.session.SessionKey; +import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.World; +import java.util.UUID; +import javax.annotation.Nullable; + +/** + * Only really useful for executing commands from console
+ * - The API itself doesn't any fake player anywhere + */ +public class FakePlayer extends LocalPlayer { + private static FakePlayer CONSOLE; + + public static FakePlayer getConsole() { + if (CONSOLE == null) { + CONSOLE = new FakePlayer("#CONSOLE", null); + } + return CONSOLE; + } + + private final String name; + private final UUID uuid; + private World world; + private Location pos; + + public FakePlayer(String name, UUID uuid) { + this.name = name; + this.uuid = uuid == null ? UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)) : uuid; + this.world = WorldEdit.getInstance().getServer().getWorlds().get(0); + this.pos = new Location(world, 0, 0, 0); + } + + private FawePlayer fp; + + public FawePlayer toFawePlayer() { + if (fp == null) { + fp = new FawePlayer(this) { + @Override + public void sendTitle(String head, String sub) {} + + @Override + public void resetTitle() {} + + @Override + public String getName() { + return name; + } + + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public boolean hasPermission(String perm) { + return FakePlayer.this.hasPermission(perm) || (Boolean) getMeta("perm." + perm, false); + } + + @Override + public void setPermission(String perm, boolean flag) { + setMeta("perm." + perm, true); + } + + @Override + public void sendMessage(String message) { + FakePlayer.this.print(message); + } + + @Override + public void executeCommand(String substring) { + CommandManager.getInstance().handleCommand(new CommandEvent(FakePlayer.this, substring)); + } + + @Override + public FaweLocation getLocation() { + Location loc = FakePlayer.this.getLocation(); + return new FaweLocation(loc.getExtent().toString(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + } + + @Override + public Player getPlayer() { + return FakePlayer.this; + } + }; + } + return fp; + } + + @Override + public World getWorld() { + return world; + } + + @Override + public int getItemInHand() { + return 0; + } + + @Override + public void giveItem(int type, int amount) {} + + @Override + public BlockBag getInventoryBlockBag() { + return null; + } + + @Override + public WorldVector getPosition() { + return new WorldVector(pos); + } + + @Override + public double getPitch() { + return pos.getPitch(); + } + + @Override + public double getYaw() { + return pos.getYaw(); + } + + @Override + public void setPosition(Vector pos, float pitch, float yaw) { + this.pos = new Location(world, pos, yaw, pitch); + } + + @Nullable + @Override + public BaseEntity getState() { + return null; + } + + @Override + public Location getLocation() { + return pos; + } + + @Override + public String getName() { + return name; + } + + @Override + public void printRaw(String msg) { + Fawe.debug(msg); + } + + @Override + public void printDebug(String msg) { + Fawe.debug(msg); + } + + @Override + public void print(String msg) { + Fawe.debug(msg); + } + + @Override + public void printError(String msg) { + Fawe.debug(msg); + } + + private FakeSessionKey key; + + @Override + public SessionKey getSessionKey() { + if (key == null) { + key = new FakeSessionKey(uuid, name); + } + return key; + } + + @Nullable + @Override + public T getFacet(Class cls) { + return null; + } + + @Override + public UUID getUniqueId() { + return uuid; + } + + @Override + public String[] getGroups() { + return new String[0]; + } + + @Override + public boolean hasPermission(String permission) { + return true; + } + + private static class FakeSessionKey implements SessionKey { + private final UUID uuid; + private final String name; + private FakeSessionKey(UUID uuid, String name) { + this.uuid = uuid; + this.name = name; + } + + @Override + public UUID getUniqueId() { + return uuid; + } + + @Nullable + @Override + public String getName() { + return name; + } + + @Override + public boolean isActive() { + return true; + } + + @Override + public boolean isPersistent() { + return true; + } + } +} diff --git a/core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index cc361178..46adb5cb 100644 --- a/core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -295,7 +295,6 @@ public class CuboidClipboard { case 58: case 60: case 7: - case 9: case 11: case 73: case 74: diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java index 535823fb..17d37ccc 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeChunk_All.java @@ -88,7 +88,6 @@ public class ForgeChunk_All extends CharFaweChunk { case 58: case 60: case 7: - case 9: case 73: case 79: case 80: