From 0d347a3837b20b47f46cf8c1051a0a63cc33708c Mon Sep 17 00:00:00 2001 From: flamin_scotsman Date: Tue, 10 Mar 2015 21:51:35 +0000 Subject: [PATCH 1/2] Fix incorrect instantiation of BlockBag and EditSession in two of the tools. Used EditSessionFactory rather than getting the EditSession from the local session. --- .../com/sk89q/worldedit/command/tool/BlockReplacer.java | 7 +++---- .../java/com/sk89q/worldedit/command/tool/QueryTool.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java index d1af045bb..8d4f718c4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java @@ -46,10 +46,9 @@ public class BlockReplacer implements DoubleActionBlockTool { @Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { -BlockBag bag = session.getBlockBag(player); + BlockBag bag = session.getBlockBag(player); - World world = (World) clicked.getExtent(); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag, player); + EditSession editSession = session.createEditSession(player); try { editSession.setBlock(clicked.toVector(), targetBlock); @@ -68,7 +67,7 @@ BlockBag bag = session.getBlockBag(player); @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, player); + EditSession editSession = session.createEditSession(player); targetBlock = (editSession).getBlock(clicked.toVector()); BlockType type = BlockType.fromID(targetBlock.getType()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index 6aa5262a0..aa039de9c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -43,7 +43,7 @@ public class QueryTool implements BlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 0, player); + EditSession editSession = session.createEditSession(player); BaseBlock block = (editSession).rawGetBlock(clicked.toVector()); BlockType type = BlockType.fromID(block.getType()); From f71d037a35476d11ff56745cbcea67ceeb940478 Mon Sep 17 00:00:00 2001 From: flamin_scotsman Date: Tue, 10 Mar 2015 21:55:51 +0000 Subject: [PATCH 2/2] Change cycler tool to use EditSession rather than changing the world directly --- .../worldedit/command/tool/BlockDataCyler.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java index 41bff5f2a..60045d3da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java @@ -19,9 +19,12 @@ package com.sk89q.worldedit.command.tool; +import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.BlockData; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; @@ -54,12 +57,19 @@ public class BlockDataCyler implements DoubleActionBlockTool { } int increment = forward ? 1 : -1; - data = (new BaseBlock(type, data)).cycleData(increment); + BaseBlock block = new BaseBlock(type, BlockData.cycle(type, data, increment)); + EditSession editSession = session.createEditSession(player); if (data < 0) { player.printError("That block's data cannot be cycled!"); } else { - world.setBlockData(clicked.toVector(), data); + try { + editSession.setBlock(clicked.toVector(), block); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + session.remember(editSession); + } } return true;