2014-04-03 03:03:52 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 03:03:52 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2014-04-03 03:03:52 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2014-04-03 03:03:52 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 03:03:52 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 03:03:52 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
|
2018-06-16 05:29:48 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.BlockVector2D;
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
2014-04-03 03:03:52 +00:00
|
|
|
import com.sk89q.worldedit.Vector;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.Vector2D;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
|
|
|
import com.sk89q.worldedit.blocks.LazyBlock;
|
2018-06-18 12:51:21 +00:00
|
|
|
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
|
|
|
import com.sk89q.worldedit.blocks.type.BlockType;
|
|
|
|
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
2014-07-14 19:10:38 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
2014-07-09 21:14:17 +00:00
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
2018-06-19 07:03:09 +00:00
|
|
|
import com.sk89q.worldedit.history.change.BlockChange;
|
2014-04-03 03:03:52 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
|
|
|
import com.sk89q.worldedit.util.TreeGenerator;
|
2018-06-16 05:29:48 +00:00
|
|
|
import com.sk89q.worldedit.world.AbstractWorld;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BaseBiome;
|
2018-06-18 12:51:21 +00:00
|
|
|
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
2014-07-09 21:14:17 +00:00
|
|
|
import org.bukkit.Effect;
|
|
|
|
import org.bukkit.TreeType;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Biome;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.block.Chest;
|
2014-04-28 06:34:39 +00:00
|
|
|
import org.bukkit.entity.Entity;
|
2014-04-03 03:03:52 +00:00
|
|
|
import org.bukkit.inventory.DoubleChestInventory;
|
|
|
|
import org.bukkit.inventory.Inventory;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2014-04-04 03:28:44 +00:00
|
|
|
import java.lang.ref.WeakReference;
|
2014-07-09 21:14:17 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2014-04-03 03:03:52 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2018-06-16 05:29:48 +00:00
|
|
|
import javax.annotation.Nullable;
|
2014-04-04 03:28:44 +00:00
|
|
|
|
2018-06-16 05:29:48 +00:00
|
|
|
public class BukkitWorld extends AbstractWorld {
|
2014-04-03 03:03:52 +00:00
|
|
|
|
|
|
|
private static final Logger logger = WorldEdit.logger;
|
|
|
|
|
2018-06-16 05:29:48 +00:00
|
|
|
private static final Map<Integer, Effect> effects = new HashMap<>();
|
2014-07-14 19:10:38 +00:00
|
|
|
static {
|
|
|
|
for (Effect effect : Effect.values()) {
|
|
|
|
effects.put(effect.getId(), effect);
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-14 19:10:38 +00:00
|
|
|
|
|
|
|
private final WeakReference<World> worldRef;
|
2014-04-03 03:03:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the object.
|
2014-07-14 19:10:38 +00:00
|
|
|
*
|
|
|
|
* @param world the world
|
2014-04-03 03:03:52 +00:00
|
|
|
*/
|
|
|
|
public BukkitWorld(World world) {
|
2018-06-16 05:29:48 +00:00
|
|
|
this.worldRef = new WeakReference<>(world);
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
2014-07-11 05:22:35 +00:00
|
|
|
@Override
|
|
|
|
public List<com.sk89q.worldedit.entity.Entity> getEntities(Region region) {
|
|
|
|
World world = getWorld();
|
|
|
|
|
2015-01-14 06:32:02 +00:00
|
|
|
List<Entity> ents = world.getEntities();
|
2018-06-16 05:29:48 +00:00
|
|
|
List<com.sk89q.worldedit.entity.Entity> entities = new ArrayList<>();
|
2015-01-14 06:32:02 +00:00
|
|
|
for (Entity ent : ents) {
|
|
|
|
if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
|
|
|
|
entities.add(BukkitAdapter.adapt(ent));
|
2014-07-11 05:22:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return entities;
|
|
|
|
}
|
|
|
|
|
2014-04-28 06:34:39 +00:00
|
|
|
@Override
|
|
|
|
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
|
2018-06-16 05:29:48 +00:00
|
|
|
List<com.sk89q.worldedit.entity.Entity> list = new ArrayList<>();
|
2014-04-28 06:34:39 +00:00
|
|
|
for (Entity entity : getWorld().getEntities()) {
|
|
|
|
list.add(BukkitAdapter.adapt(entity));
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2014-07-10 21:50:40 +00:00
|
|
|
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
2014-07-15 01:11:38 +00:00
|
|
|
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
|
|
|
if (adapter != null) {
|
|
|
|
Entity createdEntity = adapter.createEntity(BukkitAdapter.adapt(getWorld(), location), entity);
|
|
|
|
if (createdEntity != null) {
|
|
|
|
return new BukkitEntity(createdEntity);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2014-04-28 06:34:39 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 03:03:52 +00:00
|
|
|
/**
|
|
|
|
* Get the world handle.
|
|
|
|
*
|
2014-04-04 03:28:44 +00:00
|
|
|
* @return the world
|
2014-04-03 03:03:52 +00:00
|
|
|
*/
|
|
|
|
public World getWorld() {
|
2014-04-04 03:28:44 +00:00
|
|
|
return checkNotNull(worldRef.get(), "The world was unloaded and the reference is unavailable");
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-04 03:28:44 +00:00
|
|
|
* Get the world handle.
|
2014-04-03 03:03:52 +00:00
|
|
|
*
|
2014-04-04 03:28:44 +00:00
|
|
|
* @return the world
|
2014-04-03 03:03:52 +00:00
|
|
|
*/
|
2014-04-04 03:28:44 +00:00
|
|
|
protected World getWorldChecked() throws WorldEditException {
|
|
|
|
World world = worldRef.get();
|
|
|
|
if (world == null) {
|
|
|
|
throw new WorldUnloadedException();
|
|
|
|
}
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
2014-04-03 03:03:52 +00:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
2014-04-04 03:28:44 +00:00
|
|
|
return getWorld().getName();
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBlockLightLevel(Vector pt) {
|
2014-04-04 03:28:44 +00:00
|
|
|
return getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel();
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean regenerate(Region region, EditSession editSession) {
|
2018-06-19 07:03:09 +00:00
|
|
|
BlockStateHolder[] history = new BlockStateHolder[16 * 16 * (getMaxY() + 1)];
|
2014-04-03 03:03:52 +00:00
|
|
|
|
|
|
|
for (Vector2D chunk : region.getChunks()) {
|
|
|
|
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
|
|
|
|
|
|
|
|
// First save all the blocks inside
|
|
|
|
for (int x = 0; x < 16; ++x) {
|
|
|
|
for (int y = 0; y < (getMaxY() + 1); ++y) {
|
|
|
|
for (int z = 0; z < 16; ++z) {
|
|
|
|
Vector pt = min.add(x, y, z);
|
|
|
|
int index = y * 16 * 16 + z * 16 + x;
|
2018-06-18 12:51:21 +00:00
|
|
|
history[index] = editSession.getFullBlock(pt);
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2014-04-04 03:28:44 +00:00
|
|
|
getWorld().regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
|
2014-04-03 03:03:52 +00:00
|
|
|
} catch (Throwable t) {
|
2014-07-14 19:10:38 +00:00
|
|
|
logger.log(Level.WARNING, "Chunk generation via Bukkit raised an error", t);
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Then restore
|
|
|
|
for (int x = 0; x < 16; ++x) {
|
|
|
|
for (int y = 0; y < (getMaxY() + 1); ++y) {
|
|
|
|
for (int z = 0; z < 16; ++z) {
|
|
|
|
Vector pt = min.add(x, y, z);
|
|
|
|
int index = y * 16 * 16 + z * 16 + x;
|
|
|
|
|
|
|
|
// We have to restore the block if it was outside
|
|
|
|
if (!region.contains(pt)) {
|
|
|
|
editSession.smartSetBlock(pt, history[index]);
|
|
|
|
} else { // Otherwise fool with history
|
2018-06-19 07:03:09 +00:00
|
|
|
editSession.getChangeSet().add(new BlockChange(pt.toBlockVector(), history[index], editSession.getFullBlock(pt)));
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the single block inventory for a potentially double chest.
|
|
|
|
* Handles people who have an old version of Bukkit.
|
|
|
|
* This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
|
|
|
|
* in a few months (now = March 2012) // note from future dev - lol
|
|
|
|
*
|
|
|
|
* @param chest The chest to get a single block inventory for
|
|
|
|
* @return The chest's inventory
|
|
|
|
*/
|
|
|
|
private Inventory getBlockInventory(Chest chest) {
|
|
|
|
try {
|
|
|
|
return chest.getBlockInventory();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
if (chest.getInventory() instanceof DoubleChestInventory) {
|
|
|
|
DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
|
|
|
|
if (inven.getLeftSide().getHolder().equals(chest)) {
|
|
|
|
return inven.getLeftSide();
|
|
|
|
} else if (inven.getRightSide().getHolder().equals(chest)) {
|
|
|
|
return inven.getRightSide();
|
|
|
|
} else {
|
|
|
|
return inven;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return chest.getInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean clearContainerBlockContents(Vector pt) {
|
2014-04-04 03:28:44 +00:00
|
|
|
Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
2014-04-03 03:03:52 +00:00
|
|
|
if (block == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
BlockState state = block.getState();
|
|
|
|
if (!(state instanceof org.bukkit.inventory.InventoryHolder)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state;
|
|
|
|
Inventory inven = chest.getInventory();
|
|
|
|
if (chest instanceof Chest) {
|
|
|
|
inven = getBlockInventory((Chest) chest);
|
|
|
|
}
|
|
|
|
inven.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
|
|
|
|
*/
|
|
|
|
private static final EnumMap<TreeGenerator.TreeType, TreeType> treeTypeMapping =
|
2018-06-16 05:29:48 +00:00
|
|
|
new EnumMap<>(TreeGenerator.TreeType.class);
|
2014-04-03 03:03:52 +00:00
|
|
|
|
|
|
|
static {
|
|
|
|
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
|
|
|
|
try {
|
|
|
|
TreeType bukkitType = TreeType.valueOf(type.name());
|
|
|
|
treeTypeMapping.put(type, bukkitType);
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// Unhandled TreeType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Other mappings for WE-specific values
|
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.SHORT_JUNGLE, TreeType.SMALL_JUNGLE);
|
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM, TreeType.BROWN_MUSHROOM);
|
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_REDWOOD, TreeType.REDWOOD);
|
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.PINE, TreeType.REDWOOD);
|
2015-06-05 07:30:14 +00:00
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_BIRCH, TreeType.BIRCH);
|
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_JUNGLE, TreeType.JUNGLE);
|
|
|
|
treeTypeMapping.put(TreeGenerator.TreeType.RANDOM_MUSHROOM, TreeType.BROWN_MUSHROOM);
|
2014-04-03 03:03:52 +00:00
|
|
|
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
|
|
|
|
if (treeTypeMapping.get(type) == null) {
|
|
|
|
WorldEdit.logger.severe("No TreeType mapping for TreeGenerator.TreeType." + type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TreeType toBukkitTreeType(TreeGenerator.TreeType type) {
|
|
|
|
return treeTypeMapping.get(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) {
|
2014-04-04 03:28:44 +00:00
|
|
|
World world = getWorld();
|
2014-04-03 03:03:52 +00:00
|
|
|
TreeType bukkitType = toBukkitTreeType(type);
|
|
|
|
return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType,
|
|
|
|
new EditSessionBlockChangeDelegate(editSession));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dropItem(Vector pt, BaseItemStack item) {
|
2014-04-04 03:28:44 +00:00
|
|
|
World world = getWorld();
|
2018-06-18 07:53:33 +00:00
|
|
|
ItemStack bukkitItem = new ItemStack(item.getLegacyId(), item.getAmount()); // TODO Add data.
|
2014-04-03 03:03:52 +00:00
|
|
|
world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void checkLoadedChunk(Vector pt) {
|
2014-04-04 03:28:44 +00:00
|
|
|
World world = getWorld();
|
|
|
|
|
2014-04-03 03:03:52 +00:00
|
|
|
if (!world.isChunkLoaded(pt.getBlockX() >> 4, pt.getBlockZ() >> 4)) {
|
|
|
|
world.loadChunk(pt.getBlockX() >> 4, pt.getBlockZ() >> 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object other) {
|
2014-06-27 20:14:44 +00:00
|
|
|
if (other == null) {
|
|
|
|
return false;
|
|
|
|
} else if ((other instanceof BukkitWorld)) {
|
|
|
|
return ((BukkitWorld) other).getWorld().equals(getWorld());
|
|
|
|
} else if (other instanceof com.sk89q.worldedit.world.World) {
|
|
|
|
return ((com.sk89q.worldedit.world.World) other).getName().equals(getName());
|
|
|
|
} else {
|
2014-04-03 03:03:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2014-04-04 03:28:44 +00:00
|
|
|
return getWorld().hashCode();
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxY() {
|
2014-04-04 03:28:44 +00:00
|
|
|
return getWorld().getMaxHeight() - 1;
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fixAfterFastMode(Iterable<BlockVector2D> chunks) {
|
2014-04-04 03:28:44 +00:00
|
|
|
World world = getWorld();
|
2014-04-03 03:03:52 +00:00
|
|
|
for (BlockVector2D chunkPos : chunks) {
|
|
|
|
world.refreshChunk(chunkPos.getBlockX(), chunkPos.getBlockZ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean playEffect(Vector position, int type, int data) {
|
2014-04-04 03:28:44 +00:00
|
|
|
World world = getWorld();
|
|
|
|
|
2014-04-03 03:03:52 +00:00
|
|
|
final Effect effect = effects.get(type);
|
|
|
|
if (effect == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
world.playEffect(BukkitUtil.toLocation(world, position), effect, data);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void simulateBlockMine(Vector pt) {
|
2014-04-04 03:28:44 +00:00
|
|
|
getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-18 12:51:21 +00:00
|
|
|
public com.sk89q.worldedit.blocks.type.BlockState getBlock(Vector position) {
|
|
|
|
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
2018-06-19 00:53:15 +00:00
|
|
|
BlockType blockType = BlockTypes.getBlockType(
|
|
|
|
BundledBlockData.getInstance().fromLegacyId(bukkitBlock.getTypeId())
|
|
|
|
);
|
2018-06-18 12:51:21 +00:00
|
|
|
return blockType.getDefaultState(); // TODO Data
|
2014-07-14 19:10:38 +00:00
|
|
|
}
|
2014-04-03 03:03:52 +00:00
|
|
|
|
2014-07-14 19:10:38 +00:00
|
|
|
@Override
|
2018-06-18 12:51:21 +00:00
|
|
|
public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
|
2014-07-14 19:10:38 +00:00
|
|
|
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
|
|
|
if (adapter != null) {
|
|
|
|
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
|
|
|
|
} else {
|
|
|
|
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
2018-06-18 12:51:21 +00:00
|
|
|
return bukkitBlock.setTypeIdAndData(block.getBlockType().getLegacyId(), (byte) 0, notifyAndLight); // TODO Data
|
2014-07-14 19:10:38 +00:00
|
|
|
}
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-18 12:51:21 +00:00
|
|
|
public LazyBlock getLazyBlock(Vector position) {
|
2014-04-04 03:28:44 +00:00
|
|
|
World world = getWorld();
|
2014-04-03 03:03:52 +00:00
|
|
|
Block bukkitBlock = world.getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
|
|
|
return new LazyBlock(bukkitBlock.getTypeId(), bukkitBlock.getData(), this, position);
|
|
|
|
}
|
|
|
|
|
2018-06-18 12:51:21 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getFullBlock(Vector position) {
|
|
|
|
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
|
|
|
if (adapter != null) {
|
|
|
|
return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position));
|
|
|
|
} else {
|
|
|
|
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
|
|
|
return new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
@Override
|
|
|
|
public BaseBiome getBiome(Vector2D 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 boolean setBiome(Vector2D 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;
|
|
|
|
}
|
|
|
|
}
|
2014-04-03 03:03:52 +00:00
|
|
|
}
|