use of org.bukkit.entity.ComplexLivingEntity in project MagicPlugin by elBukkit.
the class CompatibilityUtils method getNearbyEntities.
public static List<Entity> getNearbyEntities(Location location, double x, double y, double z) {
if (location == null)
return null;
Object worldHandle = getHandle(location.getWorld());
try {
x = Math.min(x, CompatibilityUtils.MAX_ENTITY_RANGE);
z = Math.min(z, CompatibilityUtils.MAX_ENTITY_RANGE);
Object bb = class_AxisAlignedBB_Constructor.newInstance(location.getX() - x, location.getY() - y, location.getZ() - z, location.getX() + x, location.getY() + y, location.getZ() + z);
// The input entity is only used for equivalency testing, so this "null" should be ok.
@SuppressWarnings("unchecked") List<? extends Object> entityList = (List<? extends Object>) class_World_getEntitiesMethod.invoke(worldHandle, null, bb);
List<Entity> bukkitEntityList = new java.util.ArrayList<>(entityList.size());
for (Object entity : entityList) {
Entity bukkitEntity = (Entity) class_Entity_getBukkitEntityMethod.invoke(entity);
if (bukkitEntity instanceof ComplexLivingEntity) {
ComplexLivingEntity complex = (ComplexLivingEntity) bukkitEntity;
Set<ComplexEntityPart> parts = complex.getParts();
for (ComplexEntityPart part : parts) {
bukkitEntityList.add(part);
}
} else {
bukkitEntityList.add(bukkitEntity);
}
}
return bukkitEntityList;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
use of org.bukkit.entity.ComplexLivingEntity in project CommandHelper by EngineHub.
the class BukkitConvertor method BukkitGetCorrectEntity.
// /**
// * We don't want to allow scripts to clear other plugin's tasks
// * on accident, so only ids registered through our interface
// * can also be cancelled.
// */
// private static final Set<Integer> validIDs = new TreeSet<Integer>();
//
// @Override
// public synchronized int SetFutureRunnable(DaemonManager dm, long ms, Runnable r) {
// int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CommandHelperPlugin.self, r, Static.msToTicks(ms));
// validIDs.add(id);
// return id;
// }
//
// @Override
// public synchronized int SetFutureRepeater(DaemonManager dm, long ms, long initialDelay, Runnable r){
// int id = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CommandHelperPlugin.self, r, Static.msToTicks(initialDelay), Static.msToTicks(ms));
// validIDs.add(id);
// return id;
// }
//
// @Override
// public synchronized void ClearAllRunnables() {
// //Doing cancelTasks apparently does not work, so let's just manually cancel each task, which does appear to work.
// //Anyways, it's better that way anyhow, because we actually remove IDs from validIDs that way.
// //((BukkitMCServer)Static.getServer()).__Server().getScheduler().cancelTasks(CommandHelperPlugin.self);
// Set<Integer> ids = new TreeSet<Integer>(validIDs);
// for(int id : ids){
// try{
// //If this doesn't work, it shouldn't kill everything.
// ClearFutureRunnable(id);
// } catch(Exception e){
// Logger.getLogger(BukkitConvertor.class.getName()).log(null, Level.SEVERE, e);
// }
// }
// }
//
// @Override
// public void ClearFutureRunnable(int id) {
// if(validIDs.contains(id)){
// Bukkit.getServer().getScheduler().cancelTask(id);
// validIDs.remove(id);
// }
// }
public static MCEntity BukkitGetCorrectEntity(Entity be) {
if (be == null) {
return null;
}
BukkitMCEntityType type = BukkitMCEntityType.valueOfConcrete(be.getType());
if (type.getWrapperClass() != null) {
return ReflectionUtils.newInstance(type.getWrapperClass(), new Class[] { Entity.class }, new Object[] { be });
}
if (be instanceof Hanging) {
type.setWrapperClass(BukkitMCHanging.class);
return new BukkitMCHanging(be);
}
if (be instanceof Minecart) {
// Must come before Vehicle
type.setWrapperClass(BukkitMCMinecart.class);
return new BukkitMCMinecart(be);
}
if (be instanceof Projectile) {
type.setWrapperClass(BukkitMCProjectile.class);
return new BukkitMCProjectile(be);
}
if (be instanceof Tameable) {
// Must come before Ageable
type.setWrapperClass(BukkitMCTameable.class);
return new BukkitMCTameable(be);
}
if (be instanceof Ageable) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCAgeable.class);
return new BukkitMCAgeable(be);
}
if (be instanceof HumanEntity) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCHumanEntity.class);
return new BukkitMCHumanEntity(be);
}
if (be instanceof ComplexEntityPart) {
type.setWrapperClass(BukkitMCComplexEntityPart.class);
return new BukkitMCComplexEntityPart(be);
}
if (be instanceof ComplexLivingEntity) {
// Must come before LivingEntity
type.setWrapperClass(BukkitMCComplexLivingEntity.class);
return new BukkitMCComplexLivingEntity(be);
}
if (be instanceof LivingEntity) {
type.setWrapperClass(BukkitMCLivingEntity.class);
return new BukkitMCLivingEntity(be);
}
if (be instanceof Vehicle) {
type.setWrapperClass(BukkitMCVehicle.class);
return new BukkitMCVehicle(be);
}
// Handle generically if we can't find a more specific type
type.setWrapperClass(BukkitMCEntity.class);
return new BukkitMCEntity(be);
}
Aggregations