Search in sources :

Example 1 with ComplexEntityPart

use of org.bukkit.entity.ComplexEntityPart in project MagicPlugin by elBukkit.

the class CompatibilityUtils method damage.

public static void damage(Damageable target, double amount, Entity source) {
    if (target == null || target.isDead())
        return;
    while (target instanceof ComplexEntityPart) {
        target = ((ComplexEntityPart) target).getParent();
    }
    if (USE_MAGIC_DAMAGE && target.getType() == EntityType.ENDER_DRAGON) {
        magicDamage(target, amount, source);
        return;
    }
    isDamaging = true;
    try {
        if (target instanceof ArmorStand) {
            double newHealth = Math.max(0, target.getHealth() - amount);
            if (newHealth <= 0) {
                EntityDeathEvent deathEvent = new EntityDeathEvent((ArmorStand) target, new ArrayList<ItemStack>());
                Bukkit.getPluginManager().callEvent(deathEvent);
                target.remove();
            } else {
                target.setHealth(newHealth);
            }
        } else {
            target.damage(amount, source);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    isDamaging = false;
}
Also used : ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) ArmorStand(org.bukkit.entity.ArmorStand) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) ItemStack(org.bukkit.inventory.ItemStack) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException)

Example 2 with ComplexEntityPart

use of org.bukkit.entity.ComplexEntityPart 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;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) ArrayList(java.util.ArrayList) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) List(java.util.List) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException)

Example 3 with ComplexEntityPart

use of org.bukkit.entity.ComplexEntityPart 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);
}
Also used : BukkitMCTameable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCTameable) BukkitMCHumanEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) BukkitMCComplexEntityPart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexEntityPart) BukkitMCTameable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCTameable) Tameable(org.bukkit.entity.Tameable) BukkitMCAgeable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCAgeable) BukkitMCEntityType(com.laytonsmith.abstraction.enums.bukkit.BukkitMCEntityType) BukkitMCCommandMinecart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCCommandMinecart) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart) Minecart(org.bukkit.entity.Minecart) BukkitMCMinecart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCMinecart) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) BukkitMCHanging(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHanging) Ageable(org.bukkit.entity.Ageable) BukkitMCAgeable(com.laytonsmith.abstraction.bukkit.entities.BukkitMCAgeable) BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) BukkitMCProjectile(com.laytonsmith.abstraction.bukkit.entities.BukkitMCProjectile) Projectile(org.bukkit.entity.Projectile) BukkitMCProjectile(com.laytonsmith.abstraction.bukkit.entities.BukkitMCProjectile) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Vehicle(org.bukkit.entity.Vehicle) BukkitMCVehicle(com.laytonsmith.abstraction.bukkit.entities.BukkitMCVehicle) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) BukkitMCMinecart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCMinecart) Hanging(org.bukkit.entity.Hanging) BukkitMCHanging(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHanging) BukkitMCHumanEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) BukkitMCComplexEntityPart(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexEntityPart) BukkitMCVehicle(com.laytonsmith.abstraction.bukkit.entities.BukkitMCVehicle)

Example 4 with ComplexEntityPart

use of org.bukkit.entity.ComplexEntityPart in project MagicPlugin by elBukkit.

the class MountAction method perform.

@Override
public SpellResult perform(CastContext context) {
    LivingEntity source = context.getLivingEntity();
    if (source == null) {
        return SpellResult.LIVING_ENTITY_REQUIRED;
    }
    // Make it so this spell can be used to get someone off of you
    if (eject) {
        source.eject();
        return SpellResult.CAST;
    }
    Entity current = source.getVehicle();
    if (current != null) {
        current.eject();
    }
    Entity targetEntity = context.getTargetEntity();
    if (targetEntity == null) {
        return SpellResult.NO_TARGET;
    }
    if (targetEntity == source.getPassenger() || source == targetEntity.getPassenger()) {
        return SpellResult.NO_TARGET;
    }
    while (targetEntity instanceof ComplexEntityPart) {
        targetEntity = ((ComplexEntityPart) targetEntity).getParent();
    }
    targetEntity.setPassenger(source);
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart)

Example 5 with ComplexEntityPart

use of org.bukkit.entity.ComplexEntityPart in project NoCheatPlus by NoCheatPlus.

the class InventoryListener method onPlayerInteractEntity.

@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public final void onPlayerInteractEntity(final PlayerInteractEntityEvent event) {
    final Player player = event.getPlayer();
    if (player.getGameMode() == GameMode.CREATIVE) {
        return;
    }
    if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
        // No zombies.
        event.setCancelled(true);
        counters.addPrimaryThread(idCancelDead, 1);
        return;
    } else if (MovingUtil.hasScheduledPlayerSetBack(player)) {
        event.setCancelled(true);
        return;
    }
    // TODO: Activate mob-egg check only for specific server versions.
    final ItemStack stack = Bridge1_9.getUsedItem(player, event);
    Entity entity = event.getRightClicked();
    if (stack != null && stack.getType() == Material.MONSTER_EGG && (entity == null || entity instanceof LivingEntity || entity instanceof ComplexEntityPart) && items.isEnabled(player, DataManager.getPlayerData(player))) {
        event.setCancelled(true);
        counters.addPrimaryThread(idEggOnEntity, 1);
        return;
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) Player(org.bukkit.entity.Player) ComplexEntityPart(org.bukkit.entity.ComplexEntityPart) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ComplexEntityPart (org.bukkit.entity.ComplexEntityPart)5 LivingEntity (org.bukkit.entity.LivingEntity)4 Entity (org.bukkit.entity.Entity)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)2 ComplexLivingEntity (org.bukkit.entity.ComplexLivingEntity)2 HumanEntity (org.bukkit.entity.HumanEntity)2 ItemStack (org.bukkit.inventory.ItemStack)2 BukkitMCAgeable (com.laytonsmith.abstraction.bukkit.entities.BukkitMCAgeable)1 BukkitMCCommandMinecart (com.laytonsmith.abstraction.bukkit.entities.BukkitMCCommandMinecart)1 BukkitMCComplexEntityPart (com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexEntityPart)1 BukkitMCComplexLivingEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity)1 BukkitMCEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity)1 BukkitMCHanging (com.laytonsmith.abstraction.bukkit.entities.BukkitMCHanging)1 BukkitMCHumanEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity)1 BukkitMCLivingEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity)1 BukkitMCMinecart (com.laytonsmith.abstraction.bukkit.entities.BukkitMCMinecart)1 BukkitMCProjectile (com.laytonsmith.abstraction.bukkit.entities.BukkitMCProjectile)1 BukkitMCTameable (com.laytonsmith.abstraction.bukkit.entities.BukkitMCTameable)1