From 3b5972b7f2e60a8e84016f2eeb4b575401674a4c Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Tue, 30 Oct 2018 18:06:00 -0700 Subject: [PATCH] Flush / unbuffer more tools --- .../command/tool/BlockDataCyler.java | 18 +++++----- .../command/tool/FloatingTreeRemover.java | 34 +++++++++---------- .../worldedit/command/tool/FloodFillTool.java | 18 +++++----- .../command/tool/LongRangeBuildTool.java | 8 ++--- .../worldedit/command/tool/TreePlanter.java | 32 ++++++++--------- 5 files changed, 56 insertions(+), 54 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 faee49faf..474c689b3 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 @@ -79,15 +79,17 @@ public class BlockDataCyler implements DoubleActionBlockTool { index = (index + 1) % currentProperty.getValues().size(); BlockState newBlock = block.with(currentProperty, currentProperty.getValues().get(index)); - EditSession editSession = session.createEditSession(player); + try (EditSession editSession = session.createEditSession(player)) { + editSession.disableBuffering(); - try { - editSession.setBlock(clicked.toVector(), newBlock); - player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString()); - } catch (MaxChangedBlocksException e) { - player.printError("Max blocks change limit reached."); - } finally { - session.remember(editSession); + try { + editSession.setBlock(clicked.toVector(), newBlock); + player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString()); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + session.remember(editSession); + } } } else { List> properties = Lists.newArrayList(block.getStates().keySet()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index b0a47626d..5c457f13b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -76,25 +76,25 @@ public class FloatingTreeRemover implements BlockTool { return true; } - final EditSession editSession = session.createEditSession(player); - - try { - final Set blockSet = bfs(world, clicked.toVector()); - if (blockSet == null) { - player.printError("That's not a floating tree."); - return true; - } - - for (Vector blockVector : blockSet) { - final BlockState otherState = editSession.getBlock(blockVector); - if (isTreeBlock(otherState.getBlockType())) { - editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState()); + try (EditSession editSession = session.createEditSession(player)) { + try { + final Set blockSet = bfs(world, clicked.toVector()); + if (blockSet == null) { + player.printError("That's not a floating tree."); + return true; } + + for (Vector blockVector : blockSet) { + final BlockState otherState = editSession.getBlock(blockVector); + if (isTreeBlock(otherState.getBlockType())) { + editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState()); + } + } + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + session.remember(editSession); } - } catch (MaxChangedBlocksException e) { - player.printError("Max blocks change limit reached."); - } finally { - session.remember(editSession); } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java index 3d5220c8a..16030d299 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java @@ -69,15 +69,15 @@ public class FloodFillTool implements BlockTool { return true; } - EditSession editSession = session.createEditSession(player); - - try { - recurse(editSession, clicked.toVector().toBlockVector(), - clicked.toVector(), range, initialType, new HashSet<>()); - } catch (MaxChangedBlocksException e) { - player.printError("Max blocks change limit reached."); - } finally { - session.remember(editSession); + try (EditSession editSession = session.createEditSession(player)) { + try { + recurse(editSession, clicked.toVector().toBlockVector(), + clicked.toVector(), range, initialType, new HashSet<>()); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + session.remember(editSession); + } } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java index 445c5e158..3d056de68 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java @@ -53,8 +53,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) { Location pos = getTargetFace(player); if (pos == null) return false; - EditSession eS = session.createEditSession(player); - try { + try (EditSession eS = session.createEditSession(player)) { + eS.disableBuffering(); BlockStateHolder applied = secondary.apply(pos.toVector()); if (applied.getBlockType().getMaterial().isAir()) { eS.setBlock(pos.toVector(), secondary); @@ -73,8 +73,8 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { Location pos = getTargetFace(player); if (pos == null) return false; - EditSession eS = session.createEditSession(player); - try { + try (EditSession eS = session.createEditSession(player)) { + eS.disableBuffering(); BlockStateHolder applied = primary.apply(pos.toVector()); if (applied.getBlockType().getMaterial().isAir()) { eS.setBlock(pos.toVector(), primary); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java index 436d42104..27c1df2e9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java @@ -48,25 +48,25 @@ public class TreePlanter implements BlockTool { @Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { - EditSession editSession = session.createEditSession(player); + try (EditSession editSession = session.createEditSession(player)) { + try { + boolean successful = false; - try { - boolean successful = false; - - for (int i = 0; i < 10; i++) { - if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0))) { - successful = true; - break; + for (int i = 0; i < 10; i++) { + if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0))) { + successful = true; + break; + } } + + if (!successful) { + player.printError("A tree can't go there."); + } + } catch (MaxChangedBlocksException e) { + player.printError("Max. blocks changed reached."); + } finally { + session.remember(editSession); } - - if (!successful) { - player.printError("A tree can't go there."); - } - } catch (MaxChangedBlocksException e) { - player.printError("Max. blocks changed reached."); - } finally { - session.remember(editSession); } return true;