From 20a5899d3841ad5ec91280f9d20268ca281b39d8 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sun, 2 Sep 2012 14:45:57 -0700 Subject: [PATCH] Update for the SpoutAPI changes of the past 30 seconds --- .../com/sk89q/worldedit/spout/SessionTimer.java | 3 ++- .../java/com/sk89q/worldedit/spout/SpoutUtil.java | 3 ++- .../com/sk89q/worldedit/spout/WorldEditPlugin.java | 13 +++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java b/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java index 13a027f44..6a4d7a41e 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java +++ b/src/main/java/com/sk89q/worldedit/spout/SessionTimer.java @@ -24,6 +24,7 @@ package com.sk89q.worldedit.spout; import com.sk89q.worldedit.SessionCheck; import com.sk89q.worldedit.WorldEdit; import org.spout.api.Engine; +import org.spout.api.Server; import org.spout.api.entity.Player; /** @@ -36,7 +37,7 @@ public class SessionTimer implements Runnable { private WorldEdit worldEdit; private SessionCheck checker; - public SessionTimer(WorldEdit worldEdit, final Engine game) { + public SessionTimer(WorldEdit worldEdit, final Server game) { this.worldEdit = worldEdit; this.checker = new SessionCheck() { public boolean isOnlinePlayer(String name) { diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java b/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java index 66881319c..55b960acc 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutUtil.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.Location; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldVector; import org.spout.api.Engine; +import org.spout.api.Server; import org.spout.api.entity.Entity; import org.spout.api.geo.World; import org.spout.api.geo.cuboid.Block; @@ -97,7 +98,7 @@ public class SpoutUtil { } public static Player matchSinglePlayer(Engine game, String name) { - return game.getPlayer(name, false); + return game instanceof Server ? ((Server) game).getPlayer(name, false) : null; } public static Block toBlock(BlockWorldVector pt) { diff --git a/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java b/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java index af111e778..1edc420b9 100644 --- a/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java +++ b/src/main/java/com/sk89q/worldedit/spout/WorldEditPlugin.java @@ -32,6 +32,7 @@ import com.sk89q.worldedit.spout.selections.CuboidSelection; import com.sk89q.worldedit.spout.selections.Polygonal2DSelection; import com.sk89q.worldedit.spout.selections.Selection; import com.sk89q.worldedit.util.YAMLConfiguration; +import org.spout.api.Server; import org.spout.api.command.CommandSource; import org.spout.api.geo.World; import org.spout.api.entity.Player; @@ -105,14 +106,22 @@ public class WorldEditPlugin extends CommonPlugin { } getEngine().getScheduler().scheduleAsyncRepeatingTask(this, - new SessionTimer(controller, getEngine()), 6 * 1000, 6 * 1000, TaskPriority.LOWEST); + new SessionTimer(controller, getServer()), 6 * 1000, 6 * 1000, TaskPriority.LOWEST); + } + + public Server getServer() { + if (!(getEngine() instanceof Server)) { + throw new IllegalStateException("WorldEdit must be running on a server for this operation!"); + } + + return (Server) getEngine(); } /** * Called on plugin disable. */ public void onDisable() { - for (Player player : getEngine().getOnlinePlayers()) { + for (Player player : getServer().getOnlinePlayers()) { LocalPlayer lPlayer = wrapPlayer(player); if (controller.getSession(lPlayer).hasCUISupport()) { lPlayer.dispatchCUIHandshake();