/** * Copies the options from the specified world * * @param world World to copy options from * @return This object, for chaining */ public WorldCreator copy(World world) { if (world == null) { throw new IllegalArgumentException("World cannot be null"); } seed = world.getSeed(); environment = world.getEnvironment(); generator = world.getGenerator(); return this; }
/** * Attempt to resolve a world based on the contents of a compound tag. * * @param server The server to look up worlds in. * @param compound The tag to read the world from. * @return The world, or null if none could be found. */ public static World readWorld(GlowServer server, CompoundTag compound) { World world = compound .tryGetUuid("WorldUUIDMost", "WorldUUIDLeast") .map(server::getWorld) .orElseGet(() -> compound.tryGetString("World") .map(server::getWorld) .orElse(null)); if (world == null) { world = compound .tryGetInt("Dimension") .map(World.Environment::getEnvironment) .flatMap(env -> server.getWorlds().stream() .filter(serverWorld -> env == serverWorld.getEnvironment()) .findFirst()) .orElse(null); } return world; }
/** * Save world identifiers (UUID and dimension) to a compound tag for later lookup. * * @param world The world to identify. * @param compound The tag to write to. */ public static void writeWorld(World world, CompoundTag compound) { UUID worldUuid = world.getUID(); // world UUID used by Bukkit and code above compound.putLong("WorldUUIDMost", worldUuid.getMostSignificantBits()); compound.putLong("WorldUUIDLeast", worldUuid.getLeastSignificantBits()); // leave a Dimension value for possible Vanilla use compound.putInt("Dimension", world.getEnvironment().getId()); }
/** * Tests if the specified location is valid for a natural spawn position * * @param world The world we're testing on * @param x X-coordinate of the block to test * @param z Z-coordinate of the block to test * @return true if the location is valid, otherwise false */ public boolean canSpawn(World world, int x, int z) { Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z); switch (world.getEnvironment()) { case NETHER: return true; case THE_END: return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA; case NORMAL: default: return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL; } }
/** * Set world online * @param w - loaded world */ public void setWorldLoaded(World w) { world = w; env = world.getEnvironment(); skylight = (env == World.Environment.NORMAL); } /**
/** * Teleport this entity to the End. If no End world is loaded this does nothing. * * @return {@code true} if the teleport was successful. */ protected boolean teleportToEnd() { if (!server.getAllowEnd()) { return false; } Location target = null; for (World world : server.getWorlds()) { if (world.getEnvironment() == Environment.THE_END) { target = world.getSpawnLocation(); break; } } if (target == null) { return false; } EntityPortalEvent event = EventFactory.getInstance() .callEvent(new EntityPortalEvent(this, location.clone(), target, null)); if (event.isCancelled()) { return false; } target = event.getTo(); teleport(target); return true; }
@Override protected boolean teleportToEnd() { if (!server.getAllowEnd()) { return false; } Location target = null; for (World world : server.getWorlds()) { if (world.getEnvironment() == Environment.THE_END) { target = world.getSpawnLocation(); break; } } if (target == null) { return false; } PlayerPortalEvent event = EventFactory.getInstance() .callEvent(new PlayerPortalEvent(this, location.clone(), target, null)); if (event.isCancelled()) { return false; } target = event.getTo(); spawnAt(target); teleported = true; awardAchievement(Achievement.END_PORTAL, false); return true; }
/** * Get cache iterator */ public MapIterator getIterator(int x, int y, int z) { if(w.getEnvironment().toString().equals("THE_END")) return new OurEndMapIterator(x, y, z); return new OurMapIterator(x, y, z); } /**
public BukkitWorld(World w) { this(w.getName(), w.getMaxHeight(), w.getSeaLevel(), w.getEnvironment()); setWorldLoaded(w); new Permission("dynmap.world." + getName(), "Dynmap access for world " + getName(), PermissionDefault.OP); } public BukkitWorld(String name, int height, int sealevel, World.Environment env) {
private Flag getFlag(World w) { switch (w.getEnvironment()) { case NETHER: return Flags.PVP_NETHER; case THE_END: return Flags.PVP_END; default: return Flags.PVP_OVERWORLD; } }
public static boolean isDay(final World world) { final long time = world.getTime(); if (world.getEnvironment() == Environment.NETHER || world.getEnvironment() == Environment.THE_END) { return true; } if (time >= 23500 || time <= 12500) { return true; } return false; }
/** * @return List of over worlds */ public List<World> getOverWorlds() { return gameModes.keySet().stream().filter(w -> w.getEnvironment().equals(Environment.NORMAL)) .collect(Collectors.toList()); }
/** * Checks if a world is any of the island worlds * * @param world world * @return true if in a world or false if not */ public boolean inWorld(World world) { return ((world.getEnvironment().equals(Environment.NETHER) && isIslandNether(world)) || (world.getEnvironment().equals(Environment.THE_END) && isIslandEnd(world)) || (world.getEnvironment().equals(Environment.NORMAL)) && gameModes.containsKey(world)); }
/** * Checks if a world is a known end world * * @param world - world * @return true if world is a known and valid end world */ public boolean isEnd(World world) { return world.getEnvironment().equals(Environment.THE_END) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isEndGenerate(); }
public Set<Map.Entry<String, String>> getActiveContexts() { ImmutableSet.Builder<Map.Entry<String, String>> builder = ImmutableSet.builder(); builder.add(Maps.immutableEntry("world", player.getWorld().getName())); builder.add(Maps.immutableEntry("dimension", player.getWorld().getEnvironment().name().toLowerCase())); for (String serverTag : plugin.getManager().getConfig().getServerTags()) { builder.add(Maps.immutableEntry(PermissionsExPlugin.SERVER_TAG_CONTEXT, serverTag)); } return builder.build(); }
/** * Checks if a world is a known nether world * * @param world - world * @return true if world is a known and valid nether world */ public boolean isNether(World world) { return world.getEnvironment().equals(Environment.NETHER) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherGenerate(); }
private Material getRestore(World w) { if (w.getWorldType() == WorldType.FLAT || w.getName().equals("TARDIS_TimeVortex") || w.getGenerator() instanceof TARDISChunkGenerator) { return Material.AIR; } switch (w.getEnvironment()) { case NETHER: return Material.NETHERRACK; case THE_END: return Material.END_STONE; default: return Material.STONE; } }
/** * Checks if a world is a known island nether world * * @param world - world * @return true if world is a known and valid nether world */ public boolean isIslandNether(World world) { return world.getEnvironment().equals(Environment.NETHER) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isNetherGenerate() && gameModes.get(world).getWorldSettings().isNetherIslands(); }
/** * Checks if a world is a known island end world * * @param world * - world * @return true if world is a known and valid nether world */ public boolean isIslandEnd(World world) { return world.getEnvironment().equals(Environment.THE_END) && gameModes.containsKey(world) && gameModes.get(world).getWorldSettings().isEndGenerate() && gameModes.get(world).getWorldSettings().isEndIslands(); }
public void registerWorld(World world) { String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase() + " -g " + BentoBox.getInstance().getName(); String cmd2 = MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName(); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1); Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd2); }