/** * Create a WorldEdit world from a Bukkit world. * * @param world the Bukkit world * @return a WorldEdit world */ public static World adapt(org.bukkit.World world) { checkNotNull(world); return new BukkitWorld(world); }
@Nullable @Override public BukkitWorld matchWorld(com.sk89q.worldedit.world.World world) { if (world instanceof BukkitWorld) { return (BukkitWorld) world; } else { World bukkitWorld = server.getWorld(world.getName()); return bukkitWorld != null ? new BukkitWorld(bukkitWorld) : null; } }
private EditSession getEditSession(CityWorldGenerator generator) { return new EditSession(new BukkitWorld(generator.getWorld()), blockCount); }
/** * Gets a List of all TARDIS regions in a world. * * @param w the world to get the regions for * @return a list of TARDIS region names for this world */ public List<String> getTARDISRegions(World w) { List<String> regions = new ArrayList<>(); RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); rm.getRegions().forEach((key, value) -> { if (key.contains("tardis")) { regions.add(key); } }); return regions; }
/** * Gets a List of all TARDIS regions in a world where the build flag is set. * * @param w the world to get the regions for * @return a list of TARDIS region names for this world */ public List<String> getRegions(World w) { List<String> regions = new ArrayList<>(); RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); rm.getRegions().forEach((key, value) -> { if (key.contains("tardis") && value.getFlags().containsKey(Flags.BUILD)) { regions.add(key); } }); return regions; }
@Override public void copyArena(final World arenaWorld, final SkyArena arena, final SkyBlockLocation target) { Validate.isTrue(target.world.equals(arenaWorld.getName()), "Destination world not arena world."); if (editWorld == null) { editWorld = new BukkitWorld(arenaWorld); } MemoryBlockArea area = cache.get(arena.getArenaName()); Validate.notNull(area, "Arena " + arena.getArenaName() + " not loaded."); area.applyWorldEdit(arenaWorld, editWorld, target.x, target.y, target.z, new RandomChestProvider(plugin.getChestRandomizer(), arena)); }
@Override public OperationHandle startCopyOperation(final World arenaWorld, final SkyArena arena, final SkyBlockLocation target, final long ticksTillCompletion) { Validate.isTrue(target.world.equals(arenaWorld.getName()), "Destination world is not arena world."); if (editWorld == null) { editWorld = new BukkitWorld(arenaWorld); } MemoryBlockArea area = cache.get(arena.getArenaName()); Validate.notNull(area, "Arena " + arena.getArenaName() + " not loaded."); MultiPartOperation storageOperation = area.applyMultiPartWorldEdit(arenaWorld, editWorld, target.x, target.y, target.z, new RandomChestProvider(plugin.getChestRandomizer(), arena), plugin.getConfiguration().getArenaCopyingBlockSize()); OperationTimer timer = new OperationTimer(storageOperation, ticksTillCompletion, target); timer.start(); return timer; }
/** * Sets a block with the properties of a sponge * * @param b the sponge block * @param clear whether to set the sponge area or remove it */ public void sponge(Block b, boolean clear) { if (clear) { // remove water SpongeUtil.clearSpongeWater(new BukkitWorld(b.getWorld()), b.getX(), b.getY(), b.getZ()); } else { // put water back SpongeUtil.addSpongeWater(new BukkitWorld(b.getWorld()), b.getX(), b.getY(), b.getZ()); } }
/** * Gets a TARDIS WorldGuard region. * * @param world the world the region is in * @param p the Time Lord whose region it is * @return the protected region */ public ProtectedRegion getRegion(String world, String p) { World w = plugin.getServer().getWorld(world); if (w == null) { return null; } RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); return rm.getRegion("tardis_" + p); }
@Override public void run(String playerID) throws QuestRuntimeException { try { Location location = loc.getLocation(playerID); SchematicFormat schematic = SchematicFormat.getFormat(file); CuboidClipboard clipboard = schematic.load(file); BukkitWorld world = new BukkitWorld(location.getWorld()); EditSession editSession = we.getWorldEdit().getEditSessionFactory().getEditSession(world, 64*64*64); Vector newOrigin = BukkitUtil.toVector(location); clipboard.paste(editSession, newOrigin, noAir); } catch (DataException | IOException | MaxChangedBlocksException e) { Debug.error("Error while pasting a schematic: " + e.getMessage()); } }
/** * Adds a player to a region's membership. * * @param w the world the region is located in * @param owner the player whose region it is * @param a the player to add */ public void addMemberToRegion(World w, String owner, String a) { RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); if (rm.hasRegion("tardis_" + owner)) { plugin.getServer().dispatchCommand(plugin.getConsole(), "rg addmember tardis_" + owner + " " + a + " -w " + w.getName()); } }
/** * Removes a player from a region's membership. * * @param w the world the region is located in * @param owner the player whose region it is * @param a the player to add */ public void removeMemberFromRegion(World w, String owner, String a) { RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); if (rm.hasRegion("tardis_" + owner)) { plugin.getServer().dispatchCommand(plugin.getConsole(), "rg removemember tardis_" + owner + " " + a + " -w " + w.getName()); } }
@Override public void destroyArena(final World arenaWorld, final SkyArena arena, final SkyBlockLocation target) { Validate.isTrue(target.world.equals(arenaWorld.getName()), "Destination world not arena world."); if (editWorld == null) { editWorld = new BukkitWorld(arenaWorld); } SkyBlockLocationRange clearingArea = arena.getBoundaries().getClearing(); SkyBlockLocation clearingMin = new SkyBlockLocation(target.x + clearingArea.min.x, target.y + clearingArea.min.y, target.z + clearingArea.min.z, null); SkyBlockLocation clearingMax = new SkyBlockLocation(target.x + clearingArea.max.x, target.y + clearingArea.max.y, target.z + clearingArea.max.z, null); for (int x = clearingMin.x; x <= clearingMax.x; x++) { for (int y = clearingMin.y; y <= clearingMax.y; y++) { for (int z = clearingMin.z; z <= clearingMax.z; z++) { editWorld.setBlockType(new Vector(x, y, z), 0); // 0 = hardcoded Material.AIR } } } // TODO: do this part with WorldEdit too clearEntities(arenaWorld, clearingMin, clearingMax); }
/** * Removes the WorldGuard region when the TARDIS is deleted. * * @param w the world the region is located in * @param p the player's name */ public void removeRegion(World w, String p) { RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); rm.removeRegion("tardis_" + p); try { rm.save(); } catch (StorageException e) { plugin.getConsole().sendMessage(plugin.getPluginName() + "Could not remove WorldGuard Protection for TARDIS! " + e.getMessage()); } }
/** * Checks whether there is a protected region at a location and if so whether mobs can spawn. * * @param l the location to check * @return true if mobs can spawn, otherwise false */ public boolean mobsCanSpawnAtLocation(Location l) { RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(l.getWorld())); BlockVector3 vector = BlockVector3.at(l.getX(), l.getY(), l.getZ()); ApplicableRegionSet ars = rm.getApplicableRegions(vector); return ars.testState(null, Flags.MOB_SPAWNING); } }
/** * Checks whether a block can be broken * * @param p the player trying to break the block * @param b the block * @return whether the block can be broken */ public boolean canBreakBlock(Player p, Block b) { BlockVector3 vector = BlockVector3.at(b.getX(), b.getY(), b.getZ()); RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(b.getWorld())); ApplicableRegionSet rs = rm.getApplicableRegions(vector); return rs.testState(wgp.wrapPlayer(p), Flags.BUILD); }
/** * Checks if a player can build (a Police Box) at this location. * * @param p the player to check * @param l the location to check * @return true of false depending on whether the player has permission to build at this location */ public boolean canBuild(Player p, Location l) { BlockVector3 vector = BlockVector3.at(l.getX(), l.getY(), l.getZ()); RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(l.getWorld())); ApplicableRegionSet rs = rm.getApplicableRegions(vector); return rs.testState(wgp.wrapPlayer(p), Flags.BUILD); }
/** * Removes the exterior rendering room region when the room is jettisoned or the TARDIS is deleted. * * @param w the world the region is located in * @param p the player's name * @param r the room region to remove */ public void removeRoomRegion(World w, String p, String r) { RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); if (rm.hasRegion(r + "_" + p)) { rm.removeRegion(r + "_" + p); try { rm.save(); } catch (StorageException e) { plugin.getConsole().sendMessage(plugin.getPluginName() + "Could not remove WorldGuard Protection for " + r + " room! " + e.getMessage()); } } }
/** * Removes the WorldGuard region when the recharger is removed. * * @param name the name of the recharger to remove */ public void removeRechargerRegion(String name) { World w = plugin.getServer().getWorld(plugin.getConfig().getString("rechargers." + name + ".world")); RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(w)); rm.removeRegion("tardis_recharger_" + name); try { rm.save(); } catch (StorageException e) { plugin.getConsole().sendMessage(plugin.getPluginName() + "Could not remove recharger WorldGuard Protection for recharger! " + e.getMessage()); } }
public static boolean pasteSchematic(File schematicFile, Location location, boolean withAir) { try { Vector pasteLocation = new Vector(location.getX(), location.getY(), location.getZ()); World pasteWorld = new BukkitWorld(location.getWorld()); WorldData pasteWorldData = pasteWorld.getWorldData(); Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(schematicFile)).read(pasteWorldData); ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, pasteWorldData); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1); Operation operation = clipboardHolder .createPaste(editSession, pasteWorldData) .to(pasteLocation) .ignoreAirBlocks(!withAir) .build(); Operations.completeLegacy(operation); return true; } catch (IOException | MaxChangedBlocksException e) { FunnyGuildsLogger.exception(e); return false; } }