From 672e6fc584161d28b67e818d6faf14033df5b73c Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sun, 25 Nov 2012 17:16:35 -0800 Subject: [PATCH] Update for Spout changes --- .../java/com/sk89q/worldedit/spout/SpoutPlayer.java | 8 ++++---- .../sk89q/worldedit/spout/SpoutPlayerBlockBag.java | 7 +++---- .../java/com/sk89q/worldedit/spout/SpoutUtil.java | 2 +- .../java/com/sk89q/worldedit/spout/SpoutWorld.java | 7 ++++--- .../sk89q/worldedit/spout/WorldEditCUIMessage.java | 7 ++++++- .../com/sk89q/worldedit/spout/WorldEditPlugin.java | 11 ++++++++++- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayer.java b/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayer.java index fab38985a..a87e50dd4 100644 --- a/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayer.java +++ b/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayer.java @@ -36,8 +36,8 @@ import org.spout.api.geo.discrete.Point; import org.spout.api.inventory.Inventory; import org.spout.api.inventory.ItemStack; import org.spout.api.entity.Player; -import org.spout.vanilla.component.inventory.window.Window; -import org.spout.vanilla.component.living.Human; +import org.spout.vanilla.component.inventory.PlayerInventory; +import org.spout.vanilla.component.living.neutral.Human; import org.spout.vanilla.material.VanillaMaterial; import org.spout.vanilla.material.VanillaMaterials; @@ -55,7 +55,7 @@ public class SpoutPlayer extends LocalPlayer { @Override public int getItemInHand() { if (player.has(Human.class)) { - return ((VanillaMaterial) player.get(Human.class).getInventory().getQuickbar() + return ((VanillaMaterial) player.get(PlayerInventory.class).getQuickbar() .getCurrentItem().getMaterial()).getMinecraftId(); } else { return 0; @@ -87,7 +87,7 @@ public class SpoutPlayer extends LocalPlayer { @Override public void giveItem(int type, int amt) { if (player.has(Human.class)) { - player.get(Human.class).getInventory().add(new ItemStack(VanillaMaterials.getMaterial((short) type), amt)); + player.get(PlayerInventory.class).add(new ItemStack(VanillaMaterials.getMaterial((short) type), amt)); } } diff --git a/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java b/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java index 88ef284dc..d81c4547a 100644 --- a/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java +++ b/src/spout/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java @@ -34,9 +34,8 @@ import org.spout.api.inventory.ItemStack; import org.spout.api.material.Material; import org.spout.api.entity.Player; import org.spout.vanilla.component.inventory.PlayerInventory; -import org.spout.vanilla.component.living.Human; +import org.spout.vanilla.component.living.neutral.Human; import org.spout.vanilla.material.VanillaMaterials; -import org.spout.vanilla.util.VanillaPlayerUtil; public class SpoutPlayerBlockBag extends BlockBag { /** @@ -80,7 +79,7 @@ public class SpoutPlayerBlockBag extends BlockBag { boolean includesFullInventory = true; ItemStack[] items; Human human = player.get(Human.class); - PlayerInventory inv = human.getInventory(); + PlayerInventory inv = player.get(PlayerInventory.class); if (human.isCreative()) { includesFullInventory = false; items = new ItemStack[inv.getQuickbar().size()]; @@ -237,7 +236,7 @@ public class SpoutPlayerBlockBag extends BlockBag { @Override public void flushChanges() { if (items != null) { - PlayerInventory inv = player.get(Human.class).getInventory(); + PlayerInventory inv = player.get(PlayerInventory.class); for (int i = 0; i < inv.getQuickbar().size(); i++) { inv.getQuickbar().set(i, items.inventory[i]); } diff --git a/src/spout/java/com/sk89q/worldedit/spout/SpoutUtil.java b/src/spout/java/com/sk89q/worldedit/spout/SpoutUtil.java index 834757ba3..68da1e10b 100644 --- a/src/spout/java/com/sk89q/worldedit/spout/SpoutUtil.java +++ b/src/spout/java/com/sk89q/worldedit/spout/SpoutUtil.java @@ -102,7 +102,7 @@ public class SpoutUtil { } public static Block toBlock(BlockWorldVector pt) { - return toWorld(pt).getBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), WorldEditPlugin.getInstance()); + return toWorld(pt).getBlock(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); } public static World toWorld(WorldVector pt) { diff --git a/src/spout/java/com/sk89q/worldedit/spout/SpoutWorld.java b/src/spout/java/com/sk89q/worldedit/spout/SpoutWorld.java index 6183f56a5..28b870c01 100644 --- a/src/spout/java/com/sk89q/worldedit/spout/SpoutWorld.java +++ b/src/spout/java/com/sk89q/worldedit/spout/SpoutWorld.java @@ -41,6 +41,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; import org.spout.api.component.Component; import org.spout.api.entity.Entity; +import org.spout.api.event.cause.PluginCause; import org.spout.api.generator.biome.BiomeGenerator; import org.spout.api.geo.LoadOption; import org.spout.api.geo.World; @@ -110,7 +111,7 @@ public class SpoutWorld extends LocalWorld { final int x = pt.getBlockX(); final int y = pt.getBlockY(); final int z = pt.getBlockZ(); - return world.getChunkFromBlock(x, y, z, LoadOption.LOAD_GEN).setBlockMaterial(x, y, z, (BlockMaterial) mat, (short) 0, WorldEditPlugin.getInstance()); + return world.getChunkFromBlock(x, y, z, LoadOption.LOAD_GEN).setBlockMaterial(x, y, z, (BlockMaterial) mat, (short) 0, WorldEditPlugin.asCause()); } return false; } @@ -141,7 +142,7 @@ public class SpoutWorld extends LocalWorld { final int x = pt.getBlockX(); final int y = pt.getBlockY(); final int z = pt.getBlockZ(); - return world.getChunkFromBlock(x, y, z, LoadOption.LOAD_GEN).setBlockMaterial(x, y, z, (BlockMaterial) mat, (short) data, WorldEditPlugin.getInstance()); + return world.getChunkFromBlock(x, y, z, LoadOption.LOAD_GEN).setBlockMaterial(x, y, z, (BlockMaterial) mat, (short) data, WorldEditPlugin.asCause()); } return false; } @@ -185,7 +186,7 @@ public class SpoutWorld extends LocalWorld { final int x = pt.getBlockX(); final int y = pt.getBlockY(); final int z = pt.getBlockZ(); - world.getChunkFromBlock(x, y, z, LoadOption.LOAD_GEN).setBlockData(x, y, z, (short) data, WorldEditPlugin.getInstance()); + world.getChunkFromBlock(x, y, z, LoadOption.LOAD_GEN).setBlockData(x, y, z, (short) data, WorldEditPlugin.asCause()); } /** diff --git a/src/spout/java/com/sk89q/worldedit/spout/WorldEditCUIMessage.java b/src/spout/java/com/sk89q/worldedit/spout/WorldEditCUIMessage.java index 477815378..2a77547de 100644 --- a/src/spout/java/com/sk89q/worldedit/spout/WorldEditCUIMessage.java +++ b/src/spout/java/com/sk89q/worldedit/spout/WorldEditCUIMessage.java @@ -24,7 +24,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.spout.api.protocol.Message; import org.spout.api.util.SpoutToStringStyle; -public class WorldEditCUIMessage implements Message { +public class WorldEditCUIMessage implements Message { private final String message; public WorldEditCUIMessage(String mesage) { @@ -50,4 +50,9 @@ public class WorldEditCUIMessage implements Message { .append("message", message) .toString(); } + + @Override + public int getChannelId() { + return DEFAULT_CHANNEL; + } } diff --git a/src/spout/java/com/sk89q/worldedit/spout/WorldEditPlugin.java b/src/spout/java/com/sk89q/worldedit/spout/WorldEditPlugin.java index c3582e54a..949393f5d 100644 --- a/src/spout/java/com/sk89q/worldedit/spout/WorldEditPlugin.java +++ b/src/spout/java/com/sk89q/worldedit/spout/WorldEditPlugin.java @@ -34,9 +34,12 @@ 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.event.Cause; +import org.spout.api.event.cause.PluginCause; import org.spout.api.geo.World; import org.spout.api.entity.Player; import org.spout.api.plugin.CommonPlugin; +import org.spout.api.plugin.Plugin; import org.spout.api.protocol.Protocol; import org.spout.api.scheduler.TaskPriority; @@ -65,8 +68,10 @@ public class WorldEditPlugin extends CommonPlugin { private YAMLConfiguration config; private static WorldEditPlugin instance; + private static PluginCause instanceCause; { instance = this; + instanceCause = new PluginCause(this); } /** @@ -105,7 +110,7 @@ public class WorldEditPlugin extends CommonPlugin { proto.registerPacket(WorldEditCUICodec.class, new WorldEditCUIMessageHandler(this)); } - getEngine().getScheduler().scheduleAsyncRepeatingTask(this, + getEngine().getScheduler().scheduleSyncRepeatingTask(this, new SessionTimer(controller, getServer()), 6 * 1000, 6 * 1000, TaskPriority.LOWEST); } @@ -356,4 +361,8 @@ public class WorldEditPlugin extends CommonPlugin { static WorldEditPlugin getInstance() { return instance; } + + static Cause asCause() { + return instanceCause; + } }