use of com.fastasyncworldedit.core.extent.ResettableExtent in project FastAsyncWorldEdit by IntellectualSites.
the class BrushTool method act.
public boolean act(BrushAction action, Player player, LocalSession session) {
switch(action) {
case PRIMARY:
setContext(primary);
break;
case SECONDARY:
setContext(secondary);
break;
default:
throw new IllegalStateException("Unexpected value: " + action);
}
BrushSettings current = getContext();
Brush brush = current.getBrush();
if (brush == null) {
return false;
}
if (!current.canUse(player)) {
player.print(Caption.of("fawe.error.no-perm", StringMan.join(current.getPermissions(), ",")));
return false;
}
try (EditSession editSession = session.createEditSession(player, current.toString())) {
Location target = player.getBlockTrace(getRange(), true, traceMask);
if (target == null) {
editSession.cancel();
player.print(Caption.of("worldedit.tool.no-block"));
return true;
}
BlockBag bag = session.getBlockBag(player);
Request.request().setEditSession(editSession);
Mask mask = current.getMask();
if (mask != null) {
Mask existingMask = editSession.getMask();
if (existingMask == null) {
editSession.setMask(mask);
} else if (existingMask instanceof MaskIntersection) {
((MaskIntersection) existingMask).add(mask);
} else {
MaskIntersection newMask = new MaskIntersection(existingMask);
newMask.add(mask);
editSession.setMask(newMask);
}
}
Mask sourceMask = current.getSourceMask();
if (sourceMask != null) {
editSession.addSourceMask(sourceMask);
}
ResettableExtent transform = current.getTransform();
if (transform != null) {
editSession.addTransform(transform);
}
try {
new PatternTraverser(current).reset(editSession);
double size = current.getSize();
WorldEdit.getInstance().checkMaxBrushRadius(size);
brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size);
} catch (MaxChangedBlocksException e) {
player.print(Caption.of("worldedit.tool.max-block-changes"));
} finally {
session.remember(editSession);
if (bag != null) {
bag.flushChanges();
}
}
} finally {
Request.reset();
}
return true;
}
Aggregations