/** * Given a world, possibly return the same world but using a different * platform preferred for world editing operations. * * @param base the world to match * @return the preferred world, if one was found, otherwise the given world */ public World getWorldForEditing(World base) { checkNotNull(base); World match = queryCapability(Capability.WORLD_EDITING).matchWorld(base); return match != null ? match : base; }
/** * Get the current configuration. * * <p>If no platform has been registered yet, then a default configuration * will be returned.</p> * * @return the configuration */ public LocalConfiguration getConfiguration() { return queryCapability(Capability.CONFIGURATION).getConfiguration(); }
@Override public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException { Platform platform = platformManager.queryCapability(Capability.USER_COMMANDS); if (platform instanceof MultiUserPlatform) { List<String> suggestions = new ArrayList<>(); Collection<Actor> users = ((MultiUserPlatform) platform).getConnectedUsers(); for (Actor user : users) { if (user.getName().toLowerCase().startsWith(arguments.toLowerCase().trim())) { suggestions.add(user.getName()); } } return suggestions; } else { return Collections.emptyList(); } }
/** * Given an actor, return a new one that may use a different platform * for permissions and world editing. * * @param base the base actor to match * @return a new delegate actor */ @SuppressWarnings("unchecked") public <T extends Actor> T createProxyActor(T base) { checkNotNull(base); if (base instanceof Player) { Player player = (Player) base; Player permActor = queryCapability(Capability.PERMISSIONS).matchPlayer(player); if (permActor == null) { permActor = player; } Player cuiActor = queryCapability(Capability.WORLDEDIT_CUI).matchPlayer(player); if (cuiActor == null) { cuiActor = player; } return (T) new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld())); } else { return base; } }
private void loadAdapter() { WorldEdit worldEdit = WorldEdit.getInstance(); // Attempt to load a Sponge adapter SpongeImplLoader adapterLoader = new SpongeImplLoader(); try { adapterLoader.addFromPath(getClass().getClassLoader()); } catch (IOException e) { logger.warn("Failed to search path for Sponge adapters"); } try { adapterLoader.addFromJar(container.getSource().get().toFile()); } catch (IOException e) { logger.warn("Failed to search " + container.getSource().get().toFile() + " for Sponge adapters", e); } try { spongeAdapter = adapterLoader.loadAdapter(); logger.info("Using " + spongeAdapter.getClass().getCanonicalName() + " as the Sponge adapter"); } catch (AdapterLoadException e) { Platform platform = worldEdit.getPlatformManager().queryCapability(Capability.WORLD_EDITING); if (platform instanceof SpongePlatform) { logger.warn(e.getMessage()); } else { logger.info("WorldEdit could not find a Sponge adapter for this MC version, " + "but it seems that you have another implementation of WorldEdit installed (" + platform.getPlatformName() + ") " + "that handles the world editing."); } } }
@Override public Mask parseFromInput(String input, ParserContext context) throws InputParseException { if (!input.startsWith("$")) { return null; } Set<BaseBiome> biomes = new HashSet<>(); BiomeRegistry biomeRegistry = worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List<BaseBiome> knownBiomes = biomeRegistry.getBiomes(); for (String biomeName : Splitter.on(",").split(input.substring(1))) { BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry); if (biome == null) { throw new InputParseException("Unknown biome '" + biomeName + '\''); } biomes.add(biome); } return Masks.asMask(new BiomeMask2D(context.requireExtent(), biomes)); } }
/** * Choose preferred platforms and perform necessary initialization. */ private synchronized void choosePreferred() { for (Capability capability : Capability.values()) { Platform preferred = findMostPreferred(capability); if (preferred != null) { preferences.put(capability, preferred); capability.initialize(this, preferred); } } // Fire configuration event if (preferences.containsKey(Capability.CONFIGURATION) && configured.compareAndSet(false, true)) { worldEdit.getEventBus().post(new ConfigurationLoadEvent(queryCapability(Capability.CONFIGURATION).getConfiguration())); } }
private void loadAdapter() { WorldEdit worldEdit = WorldEdit.getInstance(); // Attempt to load a Bukkit adapter BukkitImplLoader adapterLoader = new BukkitImplLoader(); try { adapterLoader.addFromPath(getClass().getClassLoader()); } catch (IOException e) { log.log(Level.WARNING, "Failed to search path for Bukkit adapters"); } try { adapterLoader.addFromJar(getFile()); } catch (IOException e) { log.log(Level.WARNING, "Failed to search " + getFile() + " for Bukkit adapters", e); } try { bukkitAdapter = adapterLoader.loadAdapter(); log.log(Level.INFO, "Using " + bukkitAdapter.getClass().getCanonicalName() + " as the Bukkit adapter"); } catch (AdapterLoadException e) { Platform platform = worldEdit.getPlatformManager().queryCapability(Capability.WORLD_EDITING); if (platform instanceof BukkitServerInterface) { log.log(Level.WARNING, e.getMessage()); } else { log.log(Level.INFO, "WorldEdit could not find a Bukkit adapter for this MC version, " + "but it seems that you have another implementation of WorldEdit installed (" + platform.getPlatformName() + ") " + "that handles the world editing."); } } }
/** * Gets the properties of this BlockType in a {@code key->property} mapping. * * @return The properties map */ public Map<String, ? extends Property<?>> getPropertyMap() { return updateField(properties, () -> ImmutableMap.copyOf(WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getProperties(this))); }
@Override protected Set<BlockType> load() { return WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries() .getBlockCategoryRegistry().getAll(this); }
@Override protected Set<ItemType> load() { return WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries() .getItemCategoryRegistry().getAll(this); }
@Command( aliases = { "reload" }, usage = "", desc = "Reload configuration", min = 0, max = 0 ) @CommandPermissions("worldedit.reload") public void reload(Actor actor) throws WorldEditException { we.getPlatformManager().queryCapability(Capability.CONFIGURATION).reload(); we.getEventBus().post(new ConfigurationLoadEvent(we.getPlatformManager().queryCapability(Capability.CONFIGURATION).getConfiguration())); actor.print("Configuration reloaded!"); }
/** * Get the material for this BlockType. * * @return The material */ public BlockMaterial getMaterial() { return updateField(blockMaterial, () -> WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this)); }
/** * Gets the name of this block, or the ID if the name cannot be found. * * @return The name, or ID */ public String getName() { String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this); if (name == null) { return getId(); } else { return name; } }
/** * Gets the name of this item, or the ID if the name cannot be found. * * @return The name, or ID */ public String getName() { String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getName(this); if (name == null) { return getId(); } else { return name; } }
@Command( aliases = { "version", "ver" }, usage = "", desc = "Get WorldEdit version", min = 0, max = 0 ) public void version(Actor actor) throws WorldEditException { actor.print("WorldEdit version " + WorldEdit.getVersion()); actor.print("https://github.com/sk89q/worldedit/"); PlatformManager pm = we.getPlatformManager(); actor.printDebug("----------- Platforms -----------"); for (Platform platform : pm.getPlatforms()) { actor.printDebug(String.format("* %s (%s)", platform.getPlatformName(), platform.getPlatformVersion())); } actor.printDebug("----------- Capabilities -----------"); for (Capability capability : Capability.values()) { Platform platform = pm.queryCapability(capability); actor.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE")); } }
/** * Gets an {@link BaseBiome} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = BaseBiome.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public BaseBiome getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException { String input = context.next(); if (input != null) { BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List<BaseBiome> knownBiomes = biomeRegistry.getBiomes(); BaseBiome biome = Biomes.findBiomeByName(knownBiomes, input, biomeRegistry); if (biome != null) { return biome; } else { throw new ParameterException( String.format("Can't recognize biome type '%s' -- use /biomelist to list available types", input)); } } else { throw new ParameterException( "This command takes a 'default' biome if one is not set, except there is no particular " + "biome that should be 'default', so the command should not be taking a default biome"); } }
Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING); for (World world : platform.getWorlds()) { List<? extends Entity> entities = world.getEntities();
public void biomeInfo(Player player, LocalSession session, CommandContext args) throws WorldEditException { BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); Set<BaseBiome> biomes = new HashSet<>(); String qualifier;
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List<BaseBiome> biomes = biomeRegistry.getBiomes(); int totalPages = biomes.size() / 19 + 1;