/** * Gets whether a {@link Server} instance is available without throwing an * exception from calling {@link #getServer()}. * * @see Game#isServerAvailable() * @return True if the server instance is available */ public static boolean isServerAvailable() { return getGame().isServerAvailable(); }
/** * Gets the {@link GameDictionary} instance from the * {@link Game} instance. * * @see Game#getGameDictionary() * @return The game dictionary instance, or empty if unsupported */ public static Optional<GameDictionary> getDictionary() { return getGame().getGameDictionary(); }
/** * Gets the {@link Server} instance from the * {@link Game} instance. * * <p>Note: During various {@link GameState}s, a {@link Server} instance * may <strong>NOT</strong> be available. During these specific states, * calling {@link Game#getServer()} will throw an exception. To double * check, call {@link #isServerAvailable()}</p> * * @see Game#getServer() * @see Game#isServerAvailable() * @return The server instance */ public static Server getServer() { return getGame().getServer(); }
@Override protected Object getValue(String choice) throws IllegalArgumentException { Optional<Player> ret = Sponge.getGame().getServer().getPlayer(choice); if (!ret.isPresent()) { throw new IllegalArgumentException("Input value " + choice + " was not a player"); } return ret.get(); }
@Override protected Object getValue(String choice) throws IllegalArgumentException { Optional<WorldProperties> ret = Sponge.getGame().getServer().getWorldProperties(choice); if (!ret.isPresent()) { throw new IllegalArgumentException("Provided argument " + choice + " did not match a WorldProperties"); } return ret.get(); } }
@Override protected Object getValue(String choice) throws IllegalArgumentException { final Optional<T> ret = Sponge.getGame().getRegistry().getType(this.catalogType, choice); if (!ret.isPresent()) { throw new IllegalArgumentException("Invalid input " + choice + " was found"); } return ret.get(); } }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServer().getOnlinePlayers().stream() .map(input -> input == null ? null : input.getName()) .collect(Collectors.toList()); }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServer().getAllWorldProperties().stream() .map(input -> input.getWorldName()) .collect(Collectors.toList()); }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getRegistry().getAllOf(this.catalogType).stream() .<String>map(input -> { return input == null ? null : input.getId(); // TODO: ids or names? }) .collect(Collectors.toList()); }
@Override public Collection<MessageReceiver> getMembers() { PermissionService service = Sponge.getGame().getServiceManager().provideUnchecked(PermissionService.class); return service.getLoadedCollections().values().stream() .flatMap(input -> input.getLoadedWithPermission(this.permission).entrySet().stream() .filter(Map.Entry::getValue) .map(entry -> entry.getKey().getCommandSource().orElse(null)) .filter(source -> source != null)) .collect(ImmutableSet.toImmutableSet()); }
/** * Sets the location of this entity using a safe one from * {@link TeleportHelper#getSafeLocation(Location)}. This is equivalent to a * teleport and also moves this entity's passengers. * * @param location The location to set * @return True if location was set successfully, false if location couldn't * be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled. */ default boolean setLocationSafely(Location<World> location) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(this::setLocation) .orElse(false); }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServiceManager().provideUnchecked(UserStorageService.class).getAll().stream() .map(GameProfile::getName) .filter(Optional::isPresent) .map(Optional::get) .collect(ImmutableList.toImmutableList()); }
/** * Gets a new Builder instance for {@link WorldArchetype}. * * @return A new builder instance */ static WorldArchetype.Builder builder() { return Sponge.getGame().getRegistry().createBuilder(Builder.class); }
@Override protected Object getValue(String choice) throws IllegalArgumentException { return Sponge.getGame().getServiceManager().provideUnchecked(UserStorageService.class).get(choice) .orElseThrow(() -> new IllegalArgumentException("Input value '" + choice + "' was not a user!")); }
protected Iterable<String> getCompletionChoices(CommandSource source) { return Iterables.concat(getChoices(source), ImmutableSet.of("#first", "#me"), Iterables.transform(Sponge.getGame().getRegistry() .getAllOf(DimensionType.class), input2 -> "#" + input2.getId())); }
/** * Sets the location using a safe one from * {@link TeleportHelper#getSafeLocation(Location)} and the rotation of this * entity. * * <p>The format of the rotation is represented by:</p> * * <p>{@code x -> pitch}, {@code y -> yaw}, {@code z -> roll}</p> * * @param location The location to set * @param rotation The rotation to set * @return True if location was set successfully, false if either location * couldn't be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled */ default boolean setLocationAndRotationSafely(Location<World> location, Vector3d rotation) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(safe -> this.setLocationAndRotation(safe, rotation)) .orElse(false); }
/** * Sets the location using a safe one from * {@link TeleportHelper#getSafeLocation(Location)} and the rotation of this * entity. {@link RelativePositions} listed inside the EnumSet are * considered relative. * * <p>The format of the rotation is represented by:</p> * * <p>{@code x -> pitch}, {@code y -> yaw}, {@code z -> roll}</p> * * @param location The location to set * @param rotation The rotation to set * @param relativePositions The coordinates to set relatively * @return True if location was set successfully, false if either location * couldn't be set as no safe location was found or * {@link org.spongepowered.api.event.entity.MoveEntityEvent.Teleport} * was cancelled */ default boolean setLocationAndRotationSafely(Location<World> location, Vector3d rotation, EnumSet<RelativePositions> relativePositions) { return Sponge.getGame().getTeleportHelper() .getSafeLocation(location) .map(safe -> this.setLocationAndRotation(safe, rotation, relativePositions)) .orElse(false); }
@Override public List<BaseBiome> getBiomes() { List<BaseBiome> list = new ArrayList<>(); for (BiomeType biome : Sponge.getGame().getRegistry().getAllOf(BiomeType.class)) { list.add(new BaseBiome(SpongeWorldEdit.inst().getAdapter().resolve(biome))); } return list; }
public void registerPermission(CommandCallable command, String permission) { Sponge.getGame().getServiceManager().getRegistration(PermissionService.class).ifPresent((permissionService -> { PermissionDescription.Builder permissionBuilder = permissionService.getProvider().newDescriptionBuilder(SpongeWorldEdit.inst()); permissionBuilder.id(permission).register(); })); }
@Override public void giveItem(BaseItemStack itemStack) { this.player.getInventory().offer( ItemStack.of(Sponge.getGame().getRegistry().getType(ItemType.class, itemStack.getType().getId()).get(), itemStack.getAmount()) ); }