From 38607f387ad57c336e58df215a63f668f6905805 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sat, 1 Jun 2019 15:53:03 +1000 Subject: [PATCH] Added a permission node to set NBT data, allowing servers to disallow NBT interactions. --- .../java/com/sk89q/worldedit/LocalSession.java | 9 +++++++++ .../extent/world/SurvivalModeExtent.java | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index 5dd9aabee..c71e7d1aa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -232,6 +232,9 @@ public class LocalSession { newEditSession.enableStandardMode(); newEditSession.setReorderMode(reorderMode); newEditSession.setFastMode(fastMode); + if (newEditSession.getSurvivalExtent() != null) { + newEditSession.getSurvivalExtent().setStripNbt(!player.hasPermission("worldedit.setnbt")); + } editSession.undo(newEditSession); } return editSession; @@ -257,6 +260,9 @@ public class LocalSession { newEditSession.enableStandardMode(); newEditSession.setReorderMode(reorderMode); newEditSession.setFastMode(fastMode); + if (newEditSession.getSurvivalExtent() != null) { + newEditSession.getSurvivalExtent().setStripNbt(!player.hasPermission("worldedit.setnbt")); + } editSession.redo(newEditSession); } ++historyPointer; @@ -887,6 +893,9 @@ public class LocalSession { editSession.setFastMode(fastMode); editSession.setReorderMode(reorderMode); editSession.setMask(mask); + if (editSession.getSurvivalExtent() != null) { + editSession.getSurvivalExtent().setStripNbt(!player.hasPermission("worldedit.setnbt")); + } return editSession; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java index 56f136c39..9f2c3a4f6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java @@ -40,6 +40,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { private final World world; private boolean toolUse = false; + private boolean stripNbt = false; /** * Create a new instance. @@ -78,13 +79,26 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { this.toolUse = toolUse; } + public boolean hasStripNbt() { + return stripNbt; + } + + public void setStripNbt(boolean stripNbt) { + this.stripNbt = stripNbt; + } + @Override public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { if (toolUse && block.getBlockType().getMaterial().isAir()) { world.simulateBlockMine(location); return true; } else { - return super.setBlock(location, block); + // Can't be an inlined check due to inconsistent generic return type + if (stripNbt) { + return super.setBlock(location, block.toBaseBlock(null)); + } else { + return super.setBlock(location, block); + } } }