Search in sources :

Example 51 with Projectile

use of org.bukkit.entity.Projectile in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onEntityDamageByEntityEvent.

@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e) {
    Player p = null;
    RedProtect.get().logger.debug("RPLayerListener: Is EntityDamageByEntityEvent event");
    if (e.getDamager() instanceof Player) {
        p = (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile) {
        Projectile proj = (Projectile) e.getDamager();
        if (proj.getShooter() instanceof Player) {
            p = (Player) proj.getShooter();
        }
    }
    if (p != null) {
        RedProtect.get().logger.debug("Player: " + p.getName());
    } else {
        RedProtect.get().logger.debug("Player: is null");
        return;
    }
    RedProtect.get().logger.debug("Damager: " + e.getDamager().getType().name());
    // check killaura or freekill
    if (RPConfig.getBool("server-protection.check-killaura-freekill.enable")) {
        startCheckRate(p.getName());
    }
    Location l = e.getEntity().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (r == null) {
        return;
    }
    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }
    if (e.getEntity() instanceof Player && !p.equals(e.getEntity()) && r.flagExists("pvp") && !r.canPVP((Player) e.getEntity(), p)) {
        RPLang.sendMessage(p, "entitylistener.region.cantpvp");
        e.setCancelled(true);
    }
    if ((e.getEntity() instanceof Hanging || e.getEntity() instanceof EnderCrystal) && !r.canBuild(p) && !r.canBreak(e.getEntityType())) {
        RPLang.sendMessage(p, "playerlistener.region.cantremove");
        e.setCancelled(true);
    }
    if ((e.getEntity() instanceof Boat || e.getEntity() instanceof Minecart) && !r.canMinecart(p)) {
        RPLang.sendMessage(p, "blocklistener.region.cantbreak");
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) PvPlayer(me.NoChance.PvPManager.PvPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Hanging(org.bukkit.entity.Hanging) Minecart(org.bukkit.entity.Minecart) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EnderCrystal(org.bukkit.entity.EnderCrystal) Projectile(org.bukkit.entity.Projectile) Location(org.bukkit.Location) Boat(org.bukkit.entity.Boat) EventHandler(org.bukkit.event.EventHandler)

Example 52 with Projectile

use of org.bukkit.entity.Projectile 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 53 with Projectile

use of org.bukkit.entity.Projectile 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 54 with Projectile

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

the class CompatibilityUtils method spawnProjectile.

public static Projectile spawnProjectile(Class<?> projectileType, Location location, Vector direction, ProjectileSource source, float speed, float spread, float spreadLocations, Random random) {
    Constructor<? extends Object> constructor = null;
    Method shootMethod = null;
    Method setPositionRotationMethod = null;
    Field projectileSourceField = null;
    Field dirXField = null;
    Field dirYField = null;
    Field dirZField = null;
    Object nmsWorld = getHandle(location.getWorld());
    Projectile projectile = null;
    try {
        constructor = projectileType.getConstructor(class_World);
        if (class_EntityFireball.isAssignableFrom(projectileType)) {
            dirXField = projectileType.getField("dirX");
            dirYField = projectileType.getField("dirY");
            dirZField = projectileType.getField("dirZ");
        }
        if (class_EntityProjectile.isAssignableFrom(projectileType) || class_EntityArrow.isAssignableFrom(projectileType)) {
            shootMethod = projectileType.getMethod("shoot", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE);
        }
        setPositionRotationMethod = projectileType.getMethod("setPositionRotation", Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE);
        projectileSourceField = projectileType.getField("projectileSource");
        Object nmsProjectile = null;
        try {
            nmsProjectile = constructor.newInstance(nmsWorld);
        } catch (Exception ex) {
            nmsProjectile = null;
            Bukkit.getLogger().log(Level.WARNING, "Error spawning projectile of class " + projectileType.getName(), ex);
        }
        if (nmsProjectile == null) {
            throw new Exception("Failed to spawn projectile of class " + projectileType.getName());
        }
        // Velocity must be set manually- EntityFireball.setDirection applies a crazy-wide gaussian distribution!
        if (dirXField != null && dirYField != null && dirZField != null) {
            // Taken from EntityArrow
            double spreadWeight = Math.min(0.4f, spread * 0.007499999832361937D);
            double dx = speed * (direction.getX() + (random.nextGaussian() * spreadWeight));
            double dy = speed * (direction.getY() + (random.nextGaussian() * spreadWeight));
            double dz = speed * (direction.getZ() + (random.nextGaussian() * spreadWeight));
            dirXField.set(nmsProjectile, dx * 0.1D);
            dirYField.set(nmsProjectile, dy * 0.1D);
            dirZField.set(nmsProjectile, dz * 0.1D);
        }
        Vector modifiedLocation = location.toVector().clone();
        if (class_EntityFireball.isAssignableFrom(projectileType) && spreadLocations > 0) {
            modifiedLocation.setX(modifiedLocation.getX() + direction.getX() + (random.nextGaussian() * spread / 5));
            modifiedLocation.setY(modifiedLocation.getY() + direction.getY() + (random.nextGaussian() * spread / 5));
            modifiedLocation.setZ(modifiedLocation.getZ() + direction.getZ() + (random.nextGaussian() * spread / 5));
        }
        setPositionRotationMethod.invoke(nmsProjectile, modifiedLocation.getX(), modifiedLocation.getY(), modifiedLocation.getZ(), location.getYaw(), location.getPitch());
        if (shootMethod != null) {
            shootMethod.invoke(nmsProjectile, direction.getX(), direction.getY(), direction.getZ(), speed, spread);
        }
        Entity entity = NMSUtils.getBukkitEntity(nmsProjectile);
        if (entity == null || !(entity instanceof Projectile)) {
            throw new Exception("Got invalid bukkit entity from projectile of class " + projectileType.getName());
        }
        projectile = (Projectile) entity;
        if (source != null) {
            projectile.setShooter(source);
            projectileSourceField.set(nmsProjectile, source);
        }
        class_World_addEntityMethod.invoke(nmsWorld, nmsProjectile, CreatureSpawnEvent.SpawnReason.DEFAULT);
    } catch (Throwable ex) {
        ex.printStackTrace();
        return null;
    }
    return projectile;
}
Also used : Field(java.lang.reflect.Field) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) Method(java.lang.reflect.Method) Vector(org.bukkit.util.Vector) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) Projectile(org.bukkit.entity.Projectile)

Example 55 with Projectile

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

the class MagicController method getEntityUndo.

@Nullable
public UndoList getEntityUndo(Entity entity) {
    UndoList blockList = null;
    if (entity == null)
        return null;
    Mage mage = getRegisteredMage(entity);
    if (mage == null && entity instanceof Projectile) {
        Projectile projectile = (Projectile) entity;
        ProjectileSource source = projectile.getShooter();
        if (source instanceof LivingEntity) {
            entity = (LivingEntity) source;
            mage = getRegisteredMage(entity);
        }
    }
    if (mage != null) {
        UndoList undoList = mage.getLastUndoList();
        if (undoList != null) {
            long now = System.currentTimeMillis();
            if (undoList.getModifiedTime() > now - undoTimeWindow) {
                blockList = undoList;
            }
        }
    } else {
        blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
    }
    return blockList;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) Nullable(javax.annotation.Nullable)

Aggregations

Projectile (org.bukkit.entity.Projectile)86 EventHandler (org.bukkit.event.EventHandler)55 Player (org.bukkit.entity.Player)44 Entity (org.bukkit.entity.Entity)37 LivingEntity (org.bukkit.entity.LivingEntity)28 ProjectileSource (org.bukkit.projectiles.ProjectileSource)18 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)13 Location (org.bukkit.Location)9 Animals (org.bukkit.entity.Animals)9 Monster (org.bukkit.entity.Monster)9 Vector (org.bukkit.util.Vector)9 Villager (org.bukkit.entity.Villager)8 ItemStack (org.bukkit.inventory.ItemStack)8 Hanging (org.bukkit.entity.Hanging)7 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)7 PotionEffect (org.bukkit.potion.PotionEffect)7 Block (org.bukkit.block.Block)6 Arrow (org.bukkit.entity.Arrow)6 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)4 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)4