use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method set.
public BrushSettings set(InjectedValueAccess context, Brush brush, String permission) throws InvalidToolBindException {
Player player = context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"));
LocalSession session = player.getSession();
BrushSettings bs = new BrushSettings();
BrushTool tool = session.getBrushTool(player, false);
if (tool != null) {
BrushSettings currentContext = tool.getContext();
if (currentContext != null) {
Brush currentBrush = currentContext.getBrush();
if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
bs = currentContext;
}
}
}
Arguments arguments = context.injectedValue(Key.of(Arguments.class)).orElse(null);
if (arguments != null) {
String args = arguments.get();
bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
}
bs.addPermission(permission);
bs.setBrush(brush);
return process(player, arguments, bs);
}
use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.
the class ToolUtilCommands method transform.
@Command(name = "transform", aliases = { "/transform" }, desc = "Set the brush transform")
@CommandPermissions({ "worldedit.brush.options.transform", "worldedit.transform.brush" })
public void transform(Player player, LocalSession session, EditSession editSession, @Arg(desc = "The transform", def = "") ResettableExtent transform, @Switch(name = 'h', desc = "Whether the offhand should be considered or not") boolean offHand, Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(Caption.of("fawe.worldedit.brush.brush.none"));
return;
}
if (transform == null) {
player.print(Caption.of("fawe.worldedit.brush.brush.transform.disabled"));
tool.setTransform(null);
return;
}
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.TRANSFORM, lastArg);
settings.setTransform(transform);
tool.update();
player.print(Caption.of("fawe.worldedit.brush.brush.transform"));
}
use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.
the class ToolUtilCommands method mask.
// FAWE start - destination mask > mask
@Command(name = "mask", aliases = "/mask", desc = "Set the brush destination mask")
@CommandPermissions({ "worldedit.brush.options.mask", "worldedit.mask.brush" })
public void mask(Player player, LocalSession session, @Switch(name = 'h', desc = "Whether the offhand should be considered or not") boolean offHand, @Arg(desc = "The destination mask", def = "") Mask maskOpt, Arguments arguments) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
player.print(Caption.of("fawe.worldedit.brush.brush.none"));
return;
}
if (maskOpt == null) {
player.print(Caption.of("worldedit.tool.mask.disabled"));
tool.setMask(null);
} else {
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.MASK, lastArg);
settings.setMask(maskOpt);
tool.update();
player.print(Caption.of("worldedit.tool.mask.set"));
}
}
use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings in project FastAsyncWorldEdit by IntellectualSites.
the class BrushTool method setBrush.
// FAWE end
/**
* Set the brush.
*
* @param brush the brush
* @param permission the permission
*/
public void setBrush(Brush brush, String permission) {
// FAWE start - We use our own logic
BrushSettings current = getContext();
current.clearPerms();
current.setBrush(brush);
current.addPermission(permission);
update();
// FAWE end
}
use of com.fastasyncworldedit.core.command.tool.brush.BrushSettings 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