use of com.sk89q.worldedit.extent.inventory.BlockBag 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.extent.inventory.BlockBag 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.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.
the class StackTool method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
if (face == null) {
return false;
}
BlockBag bag = session.getBlockBag(player);
try (EditSession editSession = session.createEditSession(player)) {
BlockStateHolder<?> block = editSession.getFullBlock(clicked.toVector().toBlockPoint());
try {
BlockVector3 position = clicked.toVector().toBlockPoint();
for (int i = 0; i < range; i++) {
position = position.add(face.toBlockVector());
if (!mask.test(position)) {
break;
}
editSession.setBlock(position, block);
}
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally {
if (bag != null) {
bag.flushChanges();
}
}
return true;
}
use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.
the class BlockReplacer method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
BlockBag bag = session.getBlockBag(player);
try (EditSession editSession = session.createEditSession(player)) {
try {
BlockVector3 position = clicked.toVector().toBlockPoint();
editSession.setBlock(position, pattern);
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
}
} finally {
if (bag != null) {
bag.flushChanges();
}
}
return true;
}
use of com.sk89q.worldedit.extent.inventory.BlockBag in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEditPlugin method createEditSession.
/**
* Gets the session for the player.
*
* @param player a player
* @return a session
*/
public EditSession createEditSession(Player player) {
com.sk89q.worldedit.entity.Player wePlayer = wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().locatableActor(wePlayer).maxBlocks(session.getBlockChangeLimit()).blockBag(blockBag).build();
editSession.enableStandardMode();
return editSession;
}
Aggregations