Search in sources :

Example 6 with MCEntity

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;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) MCEntity(com.laytonsmith.abstraction.MCEntity) Projectile(org.bukkit.entity.Projectile) MCProjectile(com.laytonsmith.abstraction.MCProjectile) MCProjectile(com.laytonsmith.abstraction.MCProjectile)

Example 7 with MCEntity

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;
}
Also used : MCBlockProjectileSource(com.laytonsmith.abstraction.blocks.MCBlockProjectileSource) MCEntityDamageByEntityEvent(com.laytonsmith.abstraction.events.MCEntityDamageByEntityEvent) MCEntity(com.laytonsmith.abstraction.MCEntity) MCPlayer(com.laytonsmith.abstraction.MCPlayer) CDouble(com.laytonsmith.core.constructs.CDouble) CString(com.laytonsmith.core.constructs.CString) MCProjectile(com.laytonsmith.abstraction.MCProjectile) MCProjectileSource(com.laytonsmith.abstraction.MCProjectileSource)

Example 8 with MCEntity

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;
    }
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) MCInventory(com.laytonsmith.abstraction.MCInventory) MCEntity(com.laytonsmith.abstraction.MCEntity) CArray(com.laytonsmith.core.constructs.CArray) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Example 9 with MCEntity

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;
}
Also used : BukkitMCHumanEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity) Entity(org.bukkit.entity.Entity) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCEntity(com.laytonsmith.abstraction.MCEntity) BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCEntity(com.laytonsmith.abstraction.MCEntity) ArrayList(java.util.ArrayList) Location(org.bukkit.Location) MCLocation(com.laytonsmith.abstraction.MCLocation)

Example 10 with MCEntity

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;
}
Also used : BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) Entity(org.bukkit.entity.Entity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCEntity(com.laytonsmith.abstraction.MCEntity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCEntity(com.laytonsmith.abstraction.MCEntity)

Aggregations

MCEntity (com.laytonsmith.abstraction.MCEntity)10 MCProjectile (com.laytonsmith.abstraction.MCProjectile)5 EntityType (org.bukkit.entity.EntityType)4 Projectile (org.bukkit.entity.Projectile)4 Entity (org.bukkit.entity.Entity)3 MCLocation (com.laytonsmith.abstraction.MCLocation)2 MCPlayer (com.laytonsmith.abstraction.MCPlayer)2 BukkitMCEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity)2 ArrayList (java.util.ArrayList)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Vector (org.bukkit.util.Vector)2 MCInventory (com.laytonsmith.abstraction.MCInventory)1 MCLivingEntity (com.laytonsmith.abstraction.MCLivingEntity)1 MCProjectileSource (com.laytonsmith.abstraction.MCProjectileSource)1 MCBlockProjectileSource (com.laytonsmith.abstraction.blocks.MCBlockProjectileSource)1 BukkitMCComplexLivingEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity)1 BukkitMCHumanEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity)1 BukkitMCLivingEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity)1 MCEntityDamageByEntityEvent (com.laytonsmith.abstraction.events.MCEntityDamageByEntityEvent)1 EventIdentifier (com.laytonsmith.annotations.EventIdentifier)1