use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class LongRangeBuildTool method actSecondary.
@Override
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
Location pos = getTargetFace(player);
if (pos == null) {
return false;
}
BlockBag bag = session.getBlockBag(player);
try (EditSession editSession = session.createEditSession(player, "LongRangeBuildTool")) {
try {
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BaseBlock applied = secondary.applyBlock(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
editSession.setBlock(blockPoint, secondary);
} else {
editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
}
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally {
if (bag != null) {
bag.flushChanges();
}
}
return true;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class LongRangeBuildTool method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
Location pos = getTargetFace(player);
if (pos == null) {
return false;
}
BlockBag bag = session.getBlockBag(player);
try (EditSession editSession = session.createEditSession(player, "LongRangeBuildTool")) {
try {
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
BaseBlock applied = primary.applyBlock(blockPoint);
if (applied.getBlockType().getMaterial().isAir()) {
editSession.setBlock(blockPoint, primary);
} else {
editSession.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
}
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally {
if (bag != null) {
bag.flushChanges();
}
}
return true;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class OffsetConverter method convert.
@Override
public ConversionResult<BlockVector3> convert(String input, InjectedValueAccess context) {
if (input.startsWith("^")) {
try {
// Looking at a relative vector.
Actor actor = context.injectedValue(Key.of(Actor.class)).orElseThrow(() -> new IllegalStateException("An actor is required to use relative offsets"));
if (!(actor instanceof Locatable)) {
throw new IllegalStateException("Only a locatable actor may use relative offsets");
}
Location location = ((Locatable) actor).getLocation();
return vectorConverter.convert(input.substring(1), context).map(blockVector3s -> blockVector3s.stream().map(vector -> rotateToRelative(location, vector)).collect(Collectors.toList()));
} catch (IllegalStateException e) {
return FailedConversion.from(e);
}
} else {
return directionVectorConverter.convert(input, context).orElse(vectorConverter.convert(input, context));
}
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class DistanceWand method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
Location target = getTarget(player);
if (target == null) {
return true;
}
RegionSelector selector = session.getRegionSelector(player.getWorld());
BlockVector3 blockPoint = target.toVector().toBlockPoint();
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainSecondarySelection(player, session, blockPoint);
}
return true;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class DistanceWand method getTarget.
private Location getTarget(Player player) {
Location target;
Mask mask = getTraceMask();
if (this.range > -1) {
target = player.getBlockTrace(getRange(), true, mask);
} else {
target = player.getBlockTrace(MAX_RANGE, false, mask);
}
if (target == null) {
player.print(Caption.of("worldedit.tool.no-block"));
return null;
}
return target;
}
Aggregations