@Override protected Iterable<String> getChoices(CommandSource source) { Set<String> worldEntities = Sponge.getServer().getWorlds().stream().flatMap(x -> x.getEntities().stream()) .filter(this::checkEntity) .map(x -> x.getUniqueId().toString()) .collect(Collectors.toSet()); Collection<Player> players = Sponge.getServer().getOnlinePlayers(); if (!players.isEmpty() && checkEntity(players.iterator().next())) { final Set<String> setToReturn = new HashSet<>(worldEntities); // to ensure mutability players.forEach(x -> setToReturn.add(x.getName())); return setToReturn; } return worldEntities; }
@Override public List<? extends com.sk89q.worldedit.world.World> getWorlds() { Collection<org.spongepowered.api.world.World> worlds = Sponge.getServer().getWorlds(); List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(worlds.size()); for (org.spongepowered.api.world.World world : worlds) { ret.add(SpongeWorldEdit.inst().getAdapter().getWorld(world)); } return ret; }
@Override protected Object getValue(String choice) throws IllegalArgumentException { UUID uuid; try { uuid = UUID.fromString(choice); } catch (IllegalArgumentException ignored) { // Player could be a name return Sponge.getServer().getPlayer(choice) .orElseThrow(() -> new IllegalArgumentException("Input value " + choice + " does not represent a valid entity")); } boolean found = false; for (World world : Sponge.getServer().getWorlds()) { Optional<Entity> ret = world.getEntity(uuid); if (ret.isPresent()) { Entity entity = ret.get(); if (this.checkEntity(entity)) { return entity; } found = true; } } if (found) { throw new IllegalArgumentException("Input value " + choice + " was not an entity of the required type!"); } throw new IllegalArgumentException("Input value " + choice + " was not an entity"); }
@Nullable @Override public World matchWorld(World world) { if (world instanceof SpongeWorld) { return world; } else { for (org.spongepowered.api.world.World ws : Sponge.getServer().getWorlds()) { if (ws.getName().equals(world.getName())) { return SpongeWorldEdit.inst().getAdapter().getWorld(ws); } } return null; } }
@Override protected Object getValue(String choice) throws IllegalArgumentException { UUID uuid = UUID.fromString(choice); for (World world : Sponge.getServer().getWorlds()) { Optional<Entity> ret = world.getEntity(uuid); if (ret.isPresent()) { return ret.get(); } } throw new IllegalArgumentException("Input value " + choice + " was not an entity"); }
@Override public Optional<Entity> getLive() { for (World w : Sponge.getServer().getWorlds()) { Optional<Entity> e = w.getEntity(uuid); if (e.isPresent()) return Optional.of(e.get()); } return Optional.empty(); }
@Override protected Iterable<String> getChoices(CommandSource source) { Set<Iterable<Entity>> worldEntities = Sponge.getServer().getWorlds().stream().map(World::getEntities).collect(Collectors.toSet()); return Iterables.transform(Iterables.concat(worldEntities), input -> { if (input == null) { return null; } if (input instanceof Player) { return ((Player)input).getName(); } return input.getUniqueId().toString(); }); }
@Override public String getMainWorld() { return Sponge.getServer().getWorlds().iterator().next().getName(); }
/** * Gets the amount of entities on the server * * @return amount of entities */ private int getEntityCount() { return plugin.getGame().getServer().getWorlds().stream().mapToInt(world -> world.getEntities().size()).sum(); } }
@Override public String getDefaultWorld() { return ((SpongeLoader)loader).getGame().getServer().getWorlds().iterator().next().getName(); }
/** * Gets a specific entity by UUID. * @param uuid The UUID of the entity. * @return An optional containing the cached entity if found, or empty otherwise. */ public Optional<CachedEntity> getEntity(UUID uuid) { return WebAPI.runOnMain(() -> { Collection<World> worlds = Sponge.getServer().getWorlds(); for (World world : worlds) { Optional<Entity> optEnt = world.getEntity(uuid); if (optEnt.isPresent()) { return Optional.of(new CachedEntity(optEnt.get())); } } return Optional.empty(); }); }
/** * Gets the amount of loaded chunks * * @return amount of loaded chunks */ private int getLoadedChunks() { // DISABLED int loaded = 0; for (World world : plugin.getGame().getServer().getWorlds()) { loaded += world.getLoadedChunks().spliterator().estimateSize(); } return loaded; }
public static org.spongepowered.api.world.Location<World> getLocation(Location location) { Collection<World> worlds = Sponge.getServer().getWorlds(); World world = Sponge.getServer().getWorld(location.getWorld()).orElse(worlds.toArray(new World[worlds.size()])[0]); return new org.spongepowered.api.world.Location<>(world, location.getX(), location.getY(), location.getZ()); }
Stream<Extent> extents; if (world == null) extents = Sponge.getServer().getWorlds().stream().map(w -> (Extent)w); else { Optional<?> w = world.getLive();
Stream<Extent> extents; if (world == null) extents = Sponge.getServer().getWorlds().stream().map(w -> (Extent)w); else { Optional<?> w = world.getLive();
if (manager instanceof SinglePlotAreaManager) { SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea(); for (World world : Sponge.getServer().getWorlds()) { String name = world.getName(); PlotId id = PlotId.fromString(name);
private void sendUpdateSelf() { receiver.getTabList().removeEntry(receiver.getUniqueId()); receiver.getTabList().addEntry(TabListEntry.builder() .displayName(receiver.getDisplayNameData().displayName().get()) .latency(receiver.getConnection().getLatency()) .list(receiver.getTabList()) .gameMode(receiver.getGameModeData().type().get()) .profile(receiver.getProfile()) .build()); Location<World> oldLocation = receiver.getLocation(); Vector3d rotation = receiver.getRotation(); World receiverWorld = receiver.getWorld(); Sponge.getServer().getWorlds() .stream() .filter(world -> !world.equals(receiverWorld)) .findFirst() .ifPresent(world -> { receiver.setLocation(world.getSpawnLocation()); receiver.setLocationAndRotation(oldLocation, rotation); }); } }
@Override public void initialize() { Sponge.getGame().getScheduler().createTaskBuilder().intervalTicks(2L).execute(new SelfTriggerClock()).submit(CraftBookPlugin.inst()); Sponge.getGame().getEventManager().registerListeners(CraftBookPlugin.inst(), this); for(World world : Sponge.getGame().getServer().getWorlds()) { registerAll(world); } }