diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/block/BrushBoundBaseBlock.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/block/BrushBoundBaseBlock.java index 3e2f0421..182f8b7a 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/block/BrushBoundBaseBlock.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/block/BrushBoundBaseBlock.java @@ -49,21 +49,29 @@ public class BrushBoundBaseBlock extends BaseBlock implements BrushHolder { this.session = session; } + private static final ThreadLocal RECURSION = new ThreadLocal<>(); + @Override public BrushTool getTool() { if (tool == null && hasNbtData()) { StringTag json = (StringTag) getNbtData().getValue().get("weBrushJson"); if (json != null) { try { + if (RECURSION.get() != null) return null; + RECURSION.set(true); + this.tool = BrushTool.fromString(player, session, json.getValue()); this.tool.setHolder(this); brushCache.put(getKey(item), tool); } catch (Throwable ignore) { - Fawe.debug("Invalid brush for " + player + " holding " + item + ": " + json.getValue()); + ignore.printStackTrace(); + Fawe.debug("Invalid brush for " + player + " holding " + item.getType() + ": " + json.getValue()); if (item != null) { item = Fawe.imp().getItemUtil().setNBT(item, null); brushCache.remove(getKey(item)); } + } finally { + RECURSION.remove(); } } } diff --git a/core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java b/core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java index bcdbd909..6cfc03f4 100644 --- a/core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java +++ b/core/src/main/java/com/boydti/fawe/object/brush/BrushSettings.java @@ -121,7 +121,14 @@ public class BrushSettings { } public BrushSettings setBrush(Brush brush) { - this.brush = brush; + Brush tmp = this.brush; + if (tmp != brush) { + if (brush == null || (tmp != null && tmp.getClass() != brush.getClass())) { + // clear + clear(); + } + this.brush = brush; + } return this; }