use of com.sk89q.worldedit.util.Location 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;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class DistanceWand method actSecondary.
@Override
public boolean actSecondary(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.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
selector.explainPrimarySelection(player, session, blockPoint);
}
return true;
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class LocationConverter method convert.
@Override
public ConversionResult<Location> convert(String s, InjectedValueAccess injectedValueAccess) {
String[] split4 = s.split(",", 4);
if (split4.length != 4) {
return FailedConversion.from(new IllegalArgumentException("Must have exactly 1 world and 3 vector components"));
}
String[] split2 = s.split(",", 2);
ConversionResult<World> world = worldConverter.convert(split2[0], injectedValueAccess);
if (!world.isSuccessful()) {
return (FailedConversion) world;
}
ConversionResult<BlockVector3> vector = vectorConverter.convert(split2[1], injectedValueAccess);
if (!vector.isSuccessful()) {
return (FailedConversion) vector;
}
Location location = new Location(world.get().iterator().next(), vector.get().iterator().next().toVector3());
return SuccessfulConversion.fromSingle(location);
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class SmoothBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
Vector3 posDouble = position.toVector3();
Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max);
HeightMap heightMap = new HeightMap(editSession, region, mask);
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
heightMap.applyFilter(filter, iterations);
}
use of com.sk89q.worldedit.util.Location in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEditListener method onPlayerInteract.
/**
* Called when a player interacts.
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!plugin.getInternalPlatform().isHookingEvents()) {
return;
}
if (event.useItemInHand() == Result.DENY) {
return;
}
if (event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
final Player player = plugin.wrapPlayer(event.getPlayer());
final World world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
final Direction direction = BukkitAdapter.adapt(event.getBlockFace());
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos, direction)) {
event.setCancelled(true);
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.LEFT_CLICK_AIR) {
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final Location pos = new Location(world, clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos, direction)) {
event.setCancelled(true);
}
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR) {
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
}
}
Aggregations