2014-04-27 04:57:45 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.bukkit;
|
|
|
|
|
2014-07-15 01:11:38 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
2014-04-28 06:34:39 +00:00
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
2014-04-27 04:57:45 +00:00
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2014-07-15 01:11:38 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2014-07-16 02:47:47 +00:00
|
|
|
import com.sk89q.worldedit.entity.metadata.EntityType;
|
2014-04-27 04:57:45 +00:00
|
|
|
import com.sk89q.worldedit.entity.metadata.Tameable;
|
2014-06-29 22:36:41 +00:00
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
2014-04-27 04:57:45 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2014-04-28 06:34:39 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2014-04-27 04:57:45 +00:00
|
|
|
/**
|
|
|
|
* An adapter to adapt a Bukkit entity into a WorldEdit one.
|
|
|
|
*/
|
2014-04-28 06:34:39 +00:00
|
|
|
class BukkitEntity implements Entity {
|
|
|
|
|
|
|
|
private final org.bukkit.entity.Entity entity;
|
2014-04-27 04:57:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param entity the entity
|
|
|
|
*/
|
|
|
|
BukkitEntity(org.bukkit.entity.Entity entity) {
|
2014-04-28 06:34:39 +00:00
|
|
|
checkNotNull(entity);
|
|
|
|
this.entity = entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the underlying Bukkit entity.
|
|
|
|
*
|
|
|
|
* @return the Bukkit entity
|
|
|
|
*/
|
|
|
|
protected org.bukkit.entity.Entity getEntity() {
|
|
|
|
return entity;
|
2014-04-27 04:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
<T> T getMetaData(Class<T> metaDataClass) {
|
2014-06-29 05:43:41 +00:00
|
|
|
if (metaDataClass == Tameable.class && getEntity() instanceof org.bukkit.entity.Tameable) {
|
2014-04-28 06:34:39 +00:00
|
|
|
return (T) new TameableAdapter((org.bukkit.entity.Tameable) getEntity());
|
2014-04-27 04:57:45 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-29 22:36:41 +00:00
|
|
|
public Extent getExtent() {
|
2014-04-28 06:34:39 +00:00
|
|
|
return BukkitAdapter.adapt(getEntity().getWorld());
|
2014-04-27 04:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
2014-04-28 06:34:39 +00:00
|
|
|
return BukkitAdapter.adapt(getEntity().getLocation());
|
2014-04-27 04:57:45 +00:00
|
|
|
}
|
2014-04-28 06:34:39 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BaseEntity getState() {
|
2014-07-15 01:11:38 +00:00
|
|
|
if (entity instanceof Player) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
|
|
|
if (adapter != null) {
|
|
|
|
return adapter.getEntity(entity);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2014-06-29 22:36:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean remove() {
|
2014-07-15 01:11:38 +00:00
|
|
|
entity.remove();
|
|
|
|
return entity.isDead();
|
2014-04-28 06:34:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public <T> T getFacet(Class<? extends T> cls) {
|
|
|
|
if (EntityType.class.isAssignableFrom(cls)) {
|
|
|
|
return (T) new BukkitEntityType(entity);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2014-04-27 04:57:45 +00:00
|
|
|
}
|