use of com.laytonsmith.abstraction.MCEntity in project CommandHelper by EngineHub.
the class BukkitMCBlockProjectileSource method launchProjectile.
@Override
public MCProjectile launchProjectile(MCProjectileType projectile) {
EntityType et = EntityType.valueOf(projectile.name());
Class<? extends Entity> c = et.getEntityClass();
Projectile proj = bps.launchProjectile(c.asSubclass(Projectile.class));
MCEntity e = BukkitConvertor.BukkitGetCorrectEntity(proj);
if (e instanceof MCProjectile) {
return (MCProjectile) e;
} else {
return null;
}
}
use of com.laytonsmith.abstraction.MCEntity in project CommandHelper by EngineHub.
the class EntityEvents method parseEntityDamageEvent.
public static Map<String, Construct> parseEntityDamageEvent(MCEntityDamageEvent event, Map<String, Construct> map) {
if (event != null) {
MCEntity victim = event.getEntity();
map.put("type", new CString(victim.getType().name(), Target.UNKNOWN));
map.put("id", new CString(victim.getUniqueId().toString(), Target.UNKNOWN));
map.put("cause", new CString(event.getCause().name(), Target.UNKNOWN));
map.put("amount", new CDouble(event.getDamage(), Target.UNKNOWN));
map.put("finalamount", new CDouble(event.getFinalDamage(), Target.UNKNOWN));
map.put("world", new CString(event.getEntity().getWorld().getName(), Target.UNKNOWN));
map.put("location", ObjectGenerator.GetGenerator().location(event.getEntity().getLocation()));
if (event instanceof MCEntityDamageByEntityEvent) {
MCEntity damager = ((MCEntityDamageByEntityEvent) event).getDamager();
if (damager instanceof MCPlayer) {
map.put("damager", new CString(((MCPlayer) damager).getName(), Target.UNKNOWN));
} else {
map.put("damager", new CString(damager.getUniqueId().toString(), Target.UNKNOWN));
}
if (damager instanceof MCProjectile) {
MCProjectileSource shooter = ((MCProjectile) damager).getShooter();
if (shooter instanceof MCPlayer) {
map.put("shooter", new CString(((MCPlayer) shooter).getName(), Target.UNKNOWN));
} else if (shooter instanceof MCEntity) {
map.put("shooter", new CString(((MCEntity) shooter).getUniqueId().toString(), Target.UNKNOWN));
} else if (shooter instanceof MCBlockProjectileSource) {
map.put("shooter", ObjectGenerator.GetGenerator().location(((MCBlockProjectileSource) shooter).getBlock().getLocation()));
}
}
}
}
return map;
}
use of com.laytonsmith.abstraction.MCEntity in project CommandHelper by EngineHub.
the class InventoryManagement method GetInventory.
// @api
// public static class pinv_consolidate extends AbstractFunction {
//
// public String getName() {
// return "pinv_consolidate";
// }
//
// public Integer[] numArgs() {
// return new Integer[]{0, 1};
// }
//
// public String docs() {
// return "void {[player]} Consolidates a player's inventory as much as possible."
// + " There is no guarantee anything will happen after this function"
// + " is called, and there is no way to specify details about how"
// + " consolidation occurs, however, the following heuristics are followed:"
// + " The hotbar items will not be moved from the hotbar, unless there are"
// + " two+ slots that have the same item. Items in the main inventory area"
// + " will be moved closer to the bottom of the main inventory. No empty slots"
// + " will be filled in the hotbar.";
// }
//
// public Class<? extends CREThrowable>[] thrown() {
// return new Class[]{};
// }
//
// public boolean isRestricted() {
// return true;
// }
//
// public boolean preResolveVariables() {
// return true;
// }
//
// public Boolean runAsync() {
// return false;
// }
//
// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
// MCPlayer p = environment.GetPlayer();
// if(args.length == 1){
// p = Static.GetPlayer(args[0], t);
// }
// //First, we need to address the hotbar
// for(int i = 0; i < 10; i++){
// //If the stack size is maxed out, we're done.
// }
//
// return CVoid.VOID;
// }
//
// public CHVersion since() {
// return CHVersion.V3_3_1;
// }
// }
private static MCInventory GetInventory(Construct specifier, MCWorld w, Target t) {
MCInventory inv;
if (specifier instanceof CArray) {
MCLocation l = ObjectGenerator.GetGenerator().location(specifier, w, t);
inv = StaticLayer.GetConvertor().GetLocationInventory(l);
} else {
MCEntity entity = Static.getEntity(specifier, t);
inv = StaticLayer.GetConvertor().GetEntityInventory(entity);
}
if (inv == null) {
throw new CREFormatException("The entity or location specified is not capable of having an inventory.", t);
} else {
return inv;
}
}
use of com.laytonsmith.abstraction.MCEntity in project CommandHelper by EngineHub.
the class BukkitConvertor method GetEntitiesAt.
@Override
public List<MCEntity> GetEntitiesAt(MCLocation location, double radius) {
if (location == null) {
return Collections.EMPTY_LIST;
}
if (radius <= 0) {
radius = 1;
}
Location l = (Location) location.getHandle();
Collection<Entity> near;
try {
near = l.getWorld().getNearbyEntities(l, radius, radius, radius);
} catch (NoSuchMethodError ex) {
// Probably before 1.8.3
Entity tempEntity = l.getWorld().spawnEntity(l, EntityType.ARROW);
near = tempEntity.getNearbyEntities(radius, radius, radius);
tempEntity.remove();
}
List<MCEntity> entities = new ArrayList<>();
for (Entity e : near) {
entities.add(BukkitGetCorrectEntity(e));
}
return entities;
}
use of com.laytonsmith.abstraction.MCEntity in project CommandHelper by EngineHub.
the class BukkitMCChunk method getEntities.
@Override
public MCEntity[] getEntities() {
Entity[] entities = c.getEntities();
MCEntity[] r = new MCEntity[entities.length];
for (int i = 0; i < r.length; i++) {
r[i] = new BukkitMCEntity(entities[i]);
}
return r;
}
Aggregations