use of com.sk89q.worldedit.WorldEditException in project FastAsyncWorldEdit by IntellectualSites.
the class MultiStageReorder method commitBefore.
@Override
public Operation commitBefore() {
if (!commitRequired()) {
return null;
}
List<Operation> operations = new ArrayList<>();
for (PlacementPriority priority : PlacementPriority.values()) {
BlockMap<BaseBlock> blocks = stages.get(priority);
operations.add(new SetBlockMap(getExtent(), blocks) {
@Override
public Operation resume(RunContext run) throws WorldEditException {
Operation operation = super.resume(run);
if (operation == null) {
blocks.clear();
}
return operation;
}
});
}
return new OperationQueue(operations);
}
use of com.sk89q.worldedit.WorldEditException in project FastAsyncWorldEdit by IntellectualSites.
the class SelectionCommands method select.
@Command(name = "/sel", aliases = { ";", "/desel", "/deselect" }, desc = "Choose a region selector")
// FAWE start
@CommandPermissions("worldedit.analysis.sel")
public // FAWE end
void select(Actor actor, World world, LocalSession session, @Arg(desc = "Selector to switch to", def = "") SelectorChoice selector, @Switch(name = 'd', desc = "Set default selector") boolean setDefaultSelector) throws WorldEditException {
if (selector == null) {
session.getRegionSelector(world).clear();
session.dispatchCUISelection(actor);
actor.print(Caption.of("worldedit.select.cleared"));
return;
}
final RegionSelector oldSelector = session.getRegionSelector(world);
final RegionSelector newSelector;
switch(selector) {
case CUBOID:
newSelector = new CuboidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.cuboid.message"));
break;
case EXTEND:
newSelector = new ExtendingCuboidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.extend.message"));
break;
case POLY:
{
newSelector = new Polygonal2DRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.poly.message"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.poly.limit-message", TextComponent.of(integer))));
break;
}
case ELLIPSOID:
newSelector = new EllipsoidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.ellipsoid.message"));
break;
case SPHERE:
newSelector = new SphereRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.sphere.message"));
break;
case CYL:
newSelector = new CylinderRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.cyl.message"));
break;
case CONVEX:
case HULL:
case POLYHEDRON:
{
newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.convex.message"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.convex.limit-message", TextComponent.of(integer))));
break;
}
// FAWE start
case POLYHEDRAL:
newSelector = new PolyhedralRegionSelector(world);
actor.print(Caption.of("fawe.selection.sel.convex.polyhedral"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", integer)));
actor.print(Caption.of("fawe.selection.sel.list"));
break;
case FUZZY:
case MAGIC:
Mask maskOpt = new IdMask(world);
newSelector = new FuzzyRegionSelector(actor, world, maskOpt);
actor.print(Caption.of("fawe.selection.sel.fuzzy"));
actor.print(Caption.of("fawe.selection.sel.list"));
break;
// FAWE end
case LIST:
default:
CommandListBox box = new CommandListBox("Selection modes", null, null);
box.setHidingHelp(true);
TextComponentProducer contents = box.getContents();
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
box.appendCommand("cuboid", Caption.of("worldedit.select.cuboid.description"), "//sel cuboid");
box.appendCommand("extend", Caption.of("worldedit.select.extend.description"), "//sel extend");
box.appendCommand("poly", Caption.of("worldedit.select.poly.description"), "//sel poly");
box.appendCommand("ellipsoid", Caption.of("worldedit.select.ellipsoid.description"), "//sel ellipsoid");
box.appendCommand("sphere", Caption.of("worldedit.select.sphere.description"), "//sel sphere");
box.appendCommand("cyl", Caption.of("worldedit.select.cyl.description"), "//sel cyl");
box.appendCommand("convex", Caption.of("worldedit.select.convex.description"), "//sel convex");
// FAWE start
box.appendCommand("polyhedral", Caption.of("fawe.selection.sel.polyhedral"), "//sel polyhedral");
box.appendCommand("fuzzy[=<mask>]", Caption.of("fawe.selection.sel.fuzzy-instruction"), "//sel fuzzy[=<mask>]");
box.setComponentsPerPage(box.getComponentsSize());
// FAWE end
actor.print(box.create(1));
return;
}
if (setDefaultSelector) {
RegionSelectorType found = null;
for (RegionSelectorType type : RegionSelectorType.values()) {
if (type.getSelectorClass() == newSelector.getClass()) {
found = type;
break;
}
}
if (found != null) {
session.setDefaultRegionSelector(found);
actor.print(Caption.of("worldedit.select.default-set", TextComponent.of(found.name())));
} else {
throw new RuntimeException("Something unexpected happened. Please report this.");
}
}
session.setRegionSelector(world, newSelector);
session.dispatchCUISelection(actor);
}
use of com.sk89q.worldedit.WorldEditException in project WorldGuard by EngineHub.
the class SpongeUtil method addSpongeWater.
/**
* Add water around a sponge.
*
* @param world The world the sponge is located 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 addSpongeWater(World world, int ox, int oy, int oz) {
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
// The negative x edge
int cx = ox - wcfg.spongeRadius - 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx + 1, cy, cz);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
// The positive x edge
cx = ox + wcfg.spongeRadius + 1;
for (int cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx - 1, cy, cz);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
// The negative y edge
int cy = oy - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy + 1, cz);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
// The positive y edge
cy = oy + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (int cz = oz - wcfg.spongeRadius - 1; cz <= oz + wcfg.spongeRadius + 1; cz++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy - 1, cz);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
// The negative z edge
int cz = oz - wcfg.spongeRadius - 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy, cz + 1);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
// The positive z edge
cz = oz + wcfg.spongeRadius + 1;
for (cx = ox - wcfg.spongeRadius - 1; cx <= ox + wcfg.spongeRadius + 1; cx++) {
for (cy = oy - wcfg.spongeRadius - 1; cy <= oy + wcfg.spongeRadius + 1; cy++) {
BlockVector3 vector = BlockVector3.at(cx, cy, cz);
if (isReplacable(world.getBlock(vector).getBlockType())) {
try {
setBlockToWater(world, cx, cy, cz - 1);
} catch (WorldEditException e) {
e.printStackTrace();
}
}
}
}
}
use of com.sk89q.worldedit.WorldEditException in project ChuoCity by jaoafa.
the class Event_WGNonProtection method onWEEdit.
@Subscribe
public void onWEEdit(EditSessionEvent event) {
if (Main.getWorldGuard() == null) {
return;
}
if (event.getStage() == EditSession.Stage.BEFORE_REORDER) {
return;
}
Actor actor = event.getActor();
if (actor == null || !actor.isPlayer()) {
return;
}
Player player = Bukkit.getPlayer(actor.getUniqueId());
if (player == null) {
return;
}
if (player.hasPermission("worldguard.region.bypass")) {
return;
}
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
private boolean canBuild(int x, int y, int z) {
LocalPlayer localPlayer = Main.getWorldGuard().wrapPlayer(player);
if (Main.isChuoCity(new Location(player.getWorld(), x, y, z))) {
return true;
}
if (!player.getWorld().getName().equalsIgnoreCase("Jao_Afa")) {
// Jao_Afa以外では適用しない
return true;
}
ProtectedRegion region = Main.getTopRegion(new Location(player.getWorld(), x, y, z));
if (region == null) {
// 誰も保護していない
return false;
}
if (region.isOwner(localPlayer)) {
// オーナー
return true;
}
// メンバー
return region.isMember(localPlayer);
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block) throws WorldEditException {
return canBuild(location.getBlockX(), location.getBlockY(), location.getBlockZ()) && super.setBlock(location, block);
}
});
}
use of com.sk89q.worldedit.WorldEditException in project FunnyGuilds by FunnyGuilds.
the class WorldEdit7Hook method pasteSchematic.
@Override
public boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
try {
BlockVector3 pasteLocation = BlockVector3.at(location.getX(), location.getY(), location.getZ());
World pasteWorld = BukkitAdapter.adapt(location.getWorld());
Clipboard clipboard = ClipboardFormats.findByFile(schematicFile).getReader(new FileInputStream(schematicFile)).read();
ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard);
EditSession editSession = WorldEdit.getInstance().newEditSession(pasteWorld);
Operation operation = clipboardHolder.createPaste(editSession).to(pasteLocation).ignoreAirBlocks(!withAir).build();
Operations.complete(operation);
editSession.close();
return true;
} catch (IOException | WorldEditException e) {
FunnyGuilds.getPluginLogger().error("Could not paste schematic: " + schematicFile.getAbsolutePath(), e);
return false;
}
}
Aggregations