/** * Create a WorldEdit Player from a Bukkit Player. * * @param player The Bukkit player * @return The WorldEdit player */ public static BukkitPlayer adapt(Player player) { return WorldEditPlugin.getInstance().wrapPlayer(player); }
@Nullable @Override public Map<String, ? extends Property<?>> getProperties(BlockType blockType) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getProperties(blockType); } return super.getProperties(blockType); }
@Override public BaseEntity getState() { org.bukkit.entity.Entity entity = entityRef.get(); if (entity != null) { if (entity instanceof Player) { return null; } BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { return adapter.getEntity(entity); } else { return null; } } else { return null; } }
@Nullable @Override public BiomeData getData(BaseBiome biome) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { final Biome bukkitBiome = adapter.getBiome(biome.getId()); return bukkitBiome::name; } else { return null; } }
@Override public List<BaseBiome> getBiomes() { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { List<BaseBiome> biomes = new ArrayList<>(); for (Biome biome : Biome.values()) { int biomeId = adapter.getBiomeId(biome); biomes.add(new BaseBiome(biomeId)); } return biomes; } else { return Collections.emptyList(); } }
/** * Convert any WorldEdit world into an equivalent wrapped Bukkit world. * * <p>If a matching world cannot be found, a {@link RuntimeException} * will be thrown.</p> * * @param world the world * @return a wrapped Bukkit world */ public static BukkitWorld asBukkitWorld(World world) { if (world instanceof BukkitWorld) { return (BukkitWorld) world; } else { BukkitWorld bukkitWorld = WorldEditPlugin.getInstance().getInternalPlatform().matchWorld(world); if (bukkitWorld == null) { throw new RuntimeException("World '" + world.getName() + "' has no matching version in Bukkit"); } return bukkitWorld; } }
@Override public boolean notifyAndLightBlock(BlockVector3 position, com.sk89q.worldedit.world.block.BlockState previousType) throws WorldEditException { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { adapter.notifyAndLightBlock(BukkitAdapter.adapt(getWorld(), position), previousType); return true; } return false; }
@Nullable @Override public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { try { Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity); if (createdEntity != null) { return new BukkitEntity(createdEntity); } else { return null; } } catch (Exception e) { logger.warning("Corrupt entity found when creating: " + entity.getType().getId()); if (entity.getNbtData() != null) { logger.warning(entity.getNbtData().toString()); } e.printStackTrace(); return null; } } else { return null; } }
@Override public BaseBlock getFullBlock(BlockVector3 position) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)); } else { return getBlock(position).toBaseBlock(); } }
@Override public boolean setBiome(BlockVector2 position, BaseBiome biome) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { Biome bukkitBiome = adapter.getBiome(biome.getId()); getWorld().setBiome(position.getBlockX(), position.getBlockZ(), bukkitBiome); return true; } else { return false; } } }
@Override public BaseBiome getBiome(BlockVector2 position) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { int id = adapter.getBiomeId(getWorld().getBiome(position.getBlockX(), position.getBlockZ())); return new BaseBiome(id); } else { return new BaseBiome(0); } }
@Override public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { try { return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight); } catch (Exception e) { if (block instanceof BaseBlock && ((BaseBlock) block).getNbtData() != null) { logger.warning("Tried to set a corrupt tile entity at " + position.toString()); logger.warning(((BaseBlock) block).getNbtData().toString()); } e.printStackTrace(); Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight); return true; } } else { Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); bukkitBlock.setBlockData(BukkitAdapter.adapt(block), notifyAndLight); return true; } }
@Override public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) { Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()); if (block == null) { player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); } else { player.sendBlockChange(loc, BukkitAdapter.adapt(block)); if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData()); if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) { adapter.sendFakeOP(player); } } } } } }