From bc92e43be0b30eece2d9e85638f7953832784093 Mon Sep 17 00:00:00 2001 From: Wyatt Childers Date: Sun, 6 Jul 2014 20:13:27 -0400 Subject: [PATCH] Adds Platform support for WorldEdit CUI --- .../sk89q/worldedit/bukkit/BukkitServerInterface.java | 1 + .../java/com/sk89q/worldedit/forge/ForgePlatform.java | 1 + .../worldedit/extension/platform/Capability.java | 5 +++++ .../worldedit/extension/platform/PlatformManager.java | 7 ++++++- .../worldedit/extension/platform/PlayerProxy.java | 11 ++++++++++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java index bf08bf45a..f67d2372d 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitServerInterface.java @@ -168,6 +168,7 @@ public class BukkitServerInterface extends ServerInterface { public Map getCapabilities() { Map capabilities = new EnumMap(Capability.class); capabilities.put(Capability.CONFIGURATION, Preference.NORMAL); + capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL); capabilities.put(Capability.GAME_HOOKS, Preference.PREFERRED); capabilities.put(Capability.PERMISSIONS, Preference.PREFERRED); capabilities.put(Capability.USER_COMMANDS, Preference.PREFERRED); diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgePlatform.java b/src/forge/java/com/sk89q/worldedit/forge/ForgePlatform.java index 818a14573..9451908ad 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgePlatform.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgePlatform.java @@ -205,6 +205,7 @@ class ForgePlatform extends ServerInterface { public Map getCapabilities() { Map capabilities = new EnumMap(Capability.class); capabilities.put(Capability.CONFIGURATION, Preference.PREFER_OTHERS); + capabilities.put(Capability.WORLDEDIT_CUI, Preference.NORMAL); capabilities.put(Capability.GAME_HOOKS, Preference.NORMAL); capabilities.put(Capability.PERMISSIONS, Preference.PREFER_OTHERS); capabilities.put(Capability.USER_COMMANDS, Preference.NORMAL); diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java b/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java index 61ee2bfb8..a753b0fd2 100644 --- a/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java +++ b/src/main/java/com/sk89q/worldedit/extension/platform/Capability.java @@ -65,6 +65,11 @@ public enum Capability { */ PERMISSIONS, + /** + * The capability of a platform to dispatch WorldEditCUI events. + */ + WORLDEDIT_CUI, + /** * The capability of a platform to perform modifications to a world. */ diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 3e70e2483..a62bc247a 100644 --- a/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -240,7 +240,12 @@ public class PlatformManager { permActor = player; } - return (T) new PlayerProxy(player, permActor, getWorldForEditing(player.getWorld())); + Player cuiActor = queryCapability(Capability.WORLDEDIT_CUI).matchPlayer(player); + if (cuiActor == null) { + cuiActor = player; + } + + return (T) new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld())); } else { return base; } diff --git a/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index ce14651be..b2569490f 100644 --- a/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -23,6 +23,7 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; @@ -32,14 +33,17 @@ class PlayerProxy extends AbstractPlayerActor { private final Player basePlayer; private final Actor permActor; + private final Actor cuiActor; private final World world; - PlayerProxy(Player basePlayer, Actor permActor, World world) { + PlayerProxy(Player basePlayer, Actor permActor, Actor cuiActor, World world) { checkNotNull(basePlayer); checkNotNull(permActor); + checkNotNull(cuiActor); checkNotNull(world); this.basePlayer = basePlayer; this.permActor = permActor; + this.cuiActor = cuiActor; this.world = world; } @@ -122,4 +126,9 @@ class PlayerProxy extends AbstractPlayerActor { public boolean hasPermission(String perm) { return permActor.hasPermission(perm); } + + @Override + public void dispatchCUIEvent(CUIEvent event) { + cuiActor.dispatchCUIEvent(event); + } }