[Bukkit] Implement the new entity API.

This commit is contained in:
sk89q 2014-07-14 18:11:38 -07:00
parent 505d45237d
commit e2082ee8a4
7 changed files with 65 additions and 3 deletions

View File

@ -113,6 +113,23 @@ final class BukkitAdapter {
position.getX(), position.getY(), position.getZ());
}
/**
* Create a Bukkit location from a WorldEdit location with a Bukkit world.
*
* @param world the Bukkit world
* @param location the WorldEdit location
* @return a Bukkit location
*/
public static org.bukkit.Location adapt(org.bukkit.World world, Location location) {
checkNotNull(world);
checkNotNull(location);
return new org.bukkit.Location(
world,
location.getX(), location.getY(), location.getZ(),
(float) Math.toDegrees(location.getYaw()),
(float) Math.toDegrees(location.getPitch()));
}
/**
* Create a WorldEdit entity from a Bukkit entity.
*

View File

@ -19,8 +19,10 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.entity.metadata.Tameable;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
@ -74,12 +76,22 @@ class BukkitEntity implements Entity {
@Override
public BaseEntity getState() {
return null;
if (entity instanceof Player) {
return null;
}
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
return adapter.getEntity(entity);
} else {
return null;
}
}
@Override
public boolean remove() {
return false;
entity.remove();
return entity.isDead();
}
}

View File

@ -142,7 +142,17 @@ public class BukkitWorld extends LocalWorld {
@Nullable
@Override
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
throw new UnsupportedOperationException("Not implemented yet");
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;
}
}
/**

View File

@ -20,7 +20,11 @@
package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import javax.annotation.Nullable;
/**
* An interface for adapters of various Bukkit implementations.
@ -45,5 +49,24 @@ public interface BukkitImplAdapter {
*/
boolean setBlock(Location location, BaseBlock state, boolean notifyAndLight);
/**
* Get the state for the given entity.
*
* @param entity the entity
* @return the state, or null
*/
@Nullable
BaseEntity getEntity(Entity entity);
/**
* Create the given entity.
*
* @param location the location
* @param state the state
* @return the created entity or null
*/
@Nullable
Entity createEntity(Location location, BaseEntity state);
}