use of com.sk89q.worldedit.WorldEditException in project BetonQuest by BetonQuest.
the class PasteSchematicEvent method execute.
@Override
protected Void execute(final String playerID) throws QuestRuntimeException {
try {
final ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format == null) {
throw new IOException("Unknown Schematic Format");
}
final Clipboard clipboard;
try (ClipboardReader reader = format.getReader(Files.newInputStream(file.toPath()))) {
clipboard = reader.read();
}
final Location location = loc.getLocation(playerID);
try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(location.getWorld()), -1)) {
final Operation operation = new ClipboardHolder(clipboard).createPaste(editSession).to(BukkitAdapter.asBlockVector(location)).ignoreAirBlocks(noAir).build();
Operations.complete(operation);
}
} catch (IOException | WorldEditException e) {
LOG.warn(instruction.getPackage(), "Error while pasting a schematic: " + e.getMessage(), e);
}
return null;
}
use of com.sk89q.worldedit.WorldEditException in project buildinggame by stefvanschie.
the class WorldEditBoundaryAssertion method onEditSession.
/**
* Cancels any edits being made for blocks outside the plot the actor is (possibly) on.
*
* @param event the event fired when a session is being edited
* @since 5.8.0
*/
@Subscribe
public void onEditSession(EditSessionEvent event) {
if (event.getActor() == null || !event.getActor().isPlayer())
return;
var player = Bukkit.getPlayer(event.getActor().getUniqueId());
var arena = ArenaManager.getInstance().getArena(player);
// don't do anything if the player isn't in an arena
if (arena == null)
return;
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
@Override
public boolean setBlock(BlockVector3 vector, BlockStateHolder block) throws WorldEditException {
var world = Bukkit.getWorld(event.getWorld().getName());
var loc = new Location(world, vector.getX(), vector.getY(), vector.getZ());
if (!arena.getPlot(player).getBoundary().isInside(loc)) {
return false;
}
return super.setBlock(vector, block);
}
});
}
use of com.sk89q.worldedit.WorldEditException in project WorldGuard by EngineHub.
the class SpongeUtil method clearSpongeWater.
/**
* Remove water around a sponge.
*
* @param world The world the sponge is in
* @param ox The x coordinate of the 'sponge' block
* @param oy The y coordinate of the 'sponge' block
* @param oz The z coordinate of the 'sponge' block
*/
public static void clearSpongeWater(World world, int ox, int oy, int oz) {
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
for (int cx = -wcfg.spongeRadius; cx <= wcfg.spongeRadius; cx++) {
for (int cy = -wcfg.spongeRadius; cy <= wcfg.spongeRadius; cy++) {
for (int cz = -wcfg.spongeRadius; cz <= wcfg.spongeRadius; cz++) {
BlockVector3 vector = BlockVector3.at(ox + cx, oy + cy, oz + cz);
BaseBlock block = world.getFullBlock(vector);
BlockType blockType = block.getBlockType();
if (isReplacable(blockType)) {
try {
world.setBlock(vector, BlockTypes.AIR.getDefaultState());
} catch (WorldEditException e) {
e.printStackTrace();
}
} else {
@SuppressWarnings("unchecked") Property<Object> waterloggedProp = waterloggable.computeIfAbsent(blockType, (bt -> (Property<Object>) bt.getPropertyMap().get("waterlogged")));
if (waterloggedProp != null) {
try {
world.setBlock(vector, block.with(waterloggedProp, false));
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
}
}
}
Aggregations