/** * 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); }
@Override public int hashCode() { return getWorld().hashCode(); }
@Override public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt) { World world = getWorld(); TreeType bukkitType = toBukkitTreeType(type); return type != null && world.generateTree(BukkitAdapter.adapt(world, pt), bukkitType, new EditSessionBlockChangeDelegate(editSession)); }
@Override public boolean equals(Object other) { if (other == null) { return false; } else if ((other instanceof BukkitWorld)) { return ((BukkitWorld) other).getWorld().equals(getWorld()); } else if (other instanceof com.sk89q.worldedit.world.World) { return ((com.sk89q.worldedit.world.World) other).getName().equals(getName()); } else { return false; } }
@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); }
@Override public boolean clearContainerBlockContents(BlockVector3 pt) { Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (block == null) { return false; } BlockState state = block.getState(); if (!(state instanceof org.bukkit.inventory.InventoryHolder)) { return false; } org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state; Inventory inven = chest.getInventory(); if (chest instanceof Chest) { inven = getBlockInventory((Chest) chest); } inven.clear(); return true; }
@Override public boolean regenerate(Region region, EditSession editSession) { BaseBlock[] history = new BaseBlock[16 * 16 * (getMaxY() + 1)]; for (int y = 0; y < (getMaxY() + 1); ++y) { for (int z = 0; z < 16; ++z) { BlockVector3 pt = min.add(x, y, z); getWorld().regenerateChunk(chunk.getBlockX(), chunk.getBlockZ()); } catch (Throwable t) { logger.log(Level.WARNING, "Chunk generation via Bukkit raised an error", t); for (int y = 0; y < (getMaxY() + 1); ++y) { for (int z = 0; z < 16; ++z) { BlockVector3 pt = min.add(x, y, z);
@Test public void testTreeTypeMapping() { for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) { Assert.assertNotNull("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type)); } }
@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; }
@Override public long getRemainingWeatherDuration() { return getWorld().getWeatherDuration(); }
/** * 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 String getName() { return getWorld().getName(); }
@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 int getMaxY() { return getWorld().getMaxHeight() - 1; }
/** * Adds a WorldGuard protected region to exterior renderer room. * * @param name the name of the recharger * @param one a start location of a cuboid region * @param two an end location of a cuboid region */ public void addRendererProtection(String name, Location one, Location two) { RegionManager rm = wg.getRegionContainer().get(new BukkitWorld(one.getWorld())); BlockVector3 b1; BlockVector3 b2; b1 = makeBlockVector(one); b2 = makeBlockVector(two); ProtectedCuboidRegion region = new ProtectedCuboidRegion("renderer_" + name, b1, b2); HashMap<Flag<?>, Object> flags = new HashMap<>(); flags.put(Flags.TNT, State.DENY); flags.put(Flags.CREEPER_EXPLOSION, State.DENY); flags.put(Flags.FIRE_SPREAD, State.DENY); flags.put(Flags.LAVA_FIRE, State.DENY); flags.put(Flags.LAVA_FLOW, State.DENY); flags.put(Flags.LIGHTER, State.DENY); flags.put(Flags.LEAF_DECAY, State.DENY); region.setFlags(flags); rm.addRegion(region); try { rm.save(); } catch (StorageException e) { plugin.getConsole().sendMessage(plugin.getPluginName() + "Could not create WorldGuard Protection for exterior renderering room! " + e.getMessage()); } }