This commit is contained in:
Jesse Boyd 2018-04-17 06:08:10 +10:00
parent 7997c60db4
commit a7aef5bfd2
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 17 additions and 2 deletions

View File

@ -49,21 +49,29 @@ public class BrushBoundBaseBlock extends BaseBlock implements BrushHolder {
this.session = session; this.session = session;
} }
private static final ThreadLocal<Boolean> RECURSION = new ThreadLocal<>();
@Override @Override
public BrushTool getTool() { public BrushTool getTool() {
if (tool == null && hasNbtData()) { if (tool == null && hasNbtData()) {
StringTag json = (StringTag) getNbtData().getValue().get("weBrushJson"); StringTag json = (StringTag) getNbtData().getValue().get("weBrushJson");
if (json != null) { if (json != null) {
try { try {
if (RECURSION.get() != null) return null;
RECURSION.set(true);
this.tool = BrushTool.fromString(player, session, json.getValue()); this.tool = BrushTool.fromString(player, session, json.getValue());
this.tool.setHolder(this); this.tool.setHolder(this);
brushCache.put(getKey(item), tool); brushCache.put(getKey(item), tool);
} catch (Throwable ignore) { } 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) { if (item != null) {
item = Fawe.<FaweBukkit>imp().getItemUtil().setNBT(item, null); item = Fawe.<FaweBukkit>imp().getItemUtil().setNBT(item, null);
brushCache.remove(getKey(item)); brushCache.remove(getKey(item));
} }
} finally {
RECURSION.remove();
} }
} }
} }

View File

@ -121,7 +121,14 @@ public class BrushSettings {
} }
public BrushSettings setBrush(Brush brush) { 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; return this;
} }