@Override public boolean isValidMobType(String type) { return Sponge.getRegistry().getType(EntityType.class, type).isPresent(); }
@Override public <T extends CatalogType> Optional<List<T>> getCatalogTypeList(DataQuery path, Class<T> catalogType) { checkNotNull(path, "path"); checkNotNull(catalogType, "catalogType"); return getStringList(path).map(list -> list.stream() .map(string -> Sponge.getRegistry().getType(catalogType, string)) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()) ); }
@Override public <T extends CatalogType> Optional<T> getCatalogType(DataQuery path, Class<T> catalogType) { checkNotNull(path, "path"); checkNotNull(catalogType, "dummy type"); return getString(path).flatMap(string -> Sponge.getRegistry().getType(catalogType, string)); }
@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(); } }
@SuppressWarnings("WeakerAccess") protected BlockState getBlockState(BlockStateHolder<?> block) { if (block instanceof com.sk89q.worldedit.world.block.BlockState) { BlockState state = Sponge.getRegistry().getType(BlockType.class, block.getBlockType().getId()).orElse(BlockTypes.AIR).getDefaultState(); for (Map.Entry<Property<?>, Object> entry : block.getStates().entrySet()) { // TODO Convert across states } return state; } else { throw new UnsupportedOperationException("Missing Sponge adapter for WorldEdit!"); } }
@Override public void setWeather(WeatherType weatherType, long duration) { getWorld().setWeather(Sponge.getRegistry().getType(Weather.class, weatherType.getId()).get(), duration); }
@Override public void setWeather(WeatherType weatherType) { getWorld().setWeather(Sponge.getRegistry().getType(Weather.class, weatherType.getId()).get()); }
@Override public void setGameMode(GameMode gameMode) { player.getGameModeData().type().set(Sponge.getRegistry().getType(org.spongepowered.api.entity.living.player.gamemode.GameMode.class, gameMode.getId()).get()); }
@Override public void giveItem(BaseItemStack itemStack) { this.player.getInventory().offer( ItemStack.of(Sponge.getGame().getRegistry().getType(ItemType.class, itemStack.getType().getId()).get(), itemStack.getAmount()) ); }
@Override public TextFormat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { TextColor color = TextColors.NONE; GameRegistry registry = Sponge.getRegistry(); String colorId = value.getNode(NODE_COLOR).getString(); if (colorId != null) { color = registry.getType(TextColor.class, colorId).orElseThrow(() -> new ObjectMappingException("Color not found: " + colorId)); } TextStyle style = TextStyles.NONE; ConfigurationNode styleNode = value.getNode(NODE_STYLE); for (TextStyle.Base component : registry.getAllOf(TextStyle.Base.class)) { if (styleNode.getNode(component.getId().toLowerCase()).getBoolean()) { style = style.and(component); } } return TextFormat.NONE.color(color).style(style); }
@Nullable @Override public Entity createEntity(Location location, BaseEntity entity) { World world = getWorld(); EntityType entityType = Sponge.getRegistry().getType(EntityType.class, entity.getType().getId()).get(); Vector3d pos = new Vector3d(location.getX(), location.getY(), location.getZ()); org.spongepowered.api.entity.Entity newEnt = world.createEntity(entityType, pos); if (entity.hasNbtData()) { applyEntityData(newEnt, entity); } // Overwrite any data set by the NBT application Vector3 dir = location.getDirection(); newEnt.setLocationAndRotation( new org.spongepowered.api.world.Location<>(getWorld(), pos), new Vector3d(dir.getX(), dir.getY(), dir.getZ()) ); if (world.spawnEntity(newEnt)) { return new SpongeEntity(newEnt); } return null; }
public boolean setReplaceId(String replaceId) { Optional<BlockState> state = Sponge.getRegistry().getType(BlockState.class, replaceId); if (state.isPresent()) { this.replaceId = state.get(); return true; } return false; }
/** * Gets the live version of this CachedCatalogType. * @param clazz The class of the CatalogType. * @return The live CatalogType. */ @JsonIgnore @ApiModelProperty(hidden = true) public Optional<T> getLive(Class<T> clazz) { return Sponge.getRegistry().getType(clazz, this.id); }
public boolean setVoxelId(String voxelId) { Optional<BlockState> state = Sponge.getRegistry().getType(BlockState.class, voxelId); if (state.isPresent()) { this.voxelId = state.get(); return true; } return false; }
@Override public <T extends CatalogType> Optional<List<T>> getCatalogTypeList(DataQuery path, Class<T> catalogType) { checkNotNull(path, "path"); checkNotNull(catalogType, "catalogType"); return getStringList(path).map(list -> list.stream() .map(string -> Sponge.getRegistry().getType(catalogType, string)) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()) ); }
@Override public <T extends CatalogType> Optional<T> getCatalogType(DataQuery path, Class<T> catalogType) { checkNotNull(path, "path"); checkNotNull(catalogType, "dummy type"); return getString(path).flatMap(string -> Sponge.getRegistry().getType(catalogType, string)); }
@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(); } }
/** * Reset to default values. */ public void reset() { this.voxelId = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_VOXEL_ID).orElse(BlockTypes.AIR.getDefaultState()); this.replaceId = Sponge.getRegistry().getType(BlockState.class, VoxelSniperConfiguration.DEFAULT_REPLACE_ID).orElse(BlockTypes.AIR.getDefaultState()); this.brushSize = VoxelSniperConfiguration.DEFAULT_BRUSH_SIZE; this.voxelHeight = VoxelSniperConfiguration.DEFAULT_VOXEL_HEIGHT; this.cCen = VoxelSniperConfiguration.DEFAULT_CYLINDER_CENTER; this.voxelList = new VoxelList(); this.voxelInkKey = null; this.voxelInkValue = null; this.replaceInkKey = null; this.replaceInkValue = null; }
public CachedItemData(ItemData value) { super(value); this.item = new CachedCatalogType<>(Sponge.getRegistry().getType(ItemType.class, value.getItemid()).orElse(null)); this.banReason = value.getBanreason(); this.ownershipBanned = value.getOwnershipbanned(); this.usageBanned = value.getUsagebanned(); this.breakingBanned = value.getBreakingbanned(); this.placingBanned = value.getPlacingbanned(); this.dropBanned = value.getDropbanned(); this.craftBanned = value.getCraftbanned(); this.worldBanned = value.getWorldbanned(); }
@Override public TextFormat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { TextColor color = TextColors.NONE; GameRegistry registry = Sponge.getRegistry(); String colorId = value.getNode(NODE_COLOR).getString(); if (colorId != null) { color = registry.getType(TextColor.class, colorId).orElseThrow(() -> new ObjectMappingException("Color not found: " + colorId)); } TextStyle style = TextStyles.NONE; ConfigurationNode styleNode = value.getNode(NODE_STYLE); for (TextStyle.Base component : registry.getAllOf(TextStyle.Base.class)) { if (styleNode.getNode(component.getId().toLowerCase()).getBoolean()) { style = style.and(component); } } return TextFormat.NONE.color(color).style(style); }