Search in sources :

Example 11 with Hanging

use of org.bukkit.entity.Hanging 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 12 with Hanging

use of org.bukkit.entity.Hanging 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 13 with Hanging

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

the class PushSpell method forceEntity.

protected void forceEntity(Entity target, double multiplier, Location sourceLocation, Location targetLocation, int magnitude, double damage, boolean pull) {
    // Check for protected Mages
    if (controller.isMage(target)) {
        Mage targetMage = controller.getMage(target);
        // Check for protected players (admins, generally...)
        if (isSuperProtected(targetMage)) {
            return;
        }
    }
    if (target instanceof Hanging) {
        return;
    }
    if (target instanceof LivingEntity) {
        LivingEntity li = (LivingEntity) target;
        registerModified(li);
        if (damage > 0) {
            CompatibilityUtils.magicDamage(li, damage, mage.getEntity());
        }
    }
    Location to = pull ? targetLocation : sourceLocation;
    Location from = pull ? sourceLocation : targetLocation;
    registerVelocity(target);
    magnitude = (int) (magnitude * multiplier);
    Vector toVector = new Vector(to.getBlockX(), to.getBlockY(), to.getBlockZ());
    Vector fromVector = new Vector(from.getBlockX(), from.getBlockY(), from.getBlockZ());
    Vector forceVector = fromVector;
    forceVector.subtract(toVector);
    if (forceVector.lengthSquared() < 1) {
        forceVector = sourceLocation.getDirection();
        if (pull) {
            forceVector.multiply(-1);
        }
    }
    forceVector.normalize();
    forceVector.multiply(magnitude);
    SafetyUtils.setVelocity(target, forceVector);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Hanging(org.bukkit.entity.Hanging) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 14 with Hanging

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

the class MaterialBrush method getTargetEntities.

@Nullable
@Override
public Collection<Entity> getTargetEntities() {
    if (cloneTarget == null || mage == null)
        return null;
    if (mode == BrushMode.CLONE || mode == BrushMode.REPLICATE || mode == BrushMode.SCHEMATIC) {
        List<Entity> targetData = new ArrayList<>();
        World targetWorld = cloneTarget.getWorld();
        List<Entity> targetEntities = targetWorld.getEntities();
        for (Entity entity : targetEntities) {
            // Schematics currently only deal with Hanging entities
            if (mode == BrushMode.SCHEMATIC && !(entity instanceof Hanging))
                continue;
            // Note that we ignore players and NPCs
            if (!(entity instanceof Player) && !mage.getController().isNPC(entity)) {
                targetData.add(entity);
            }
        }
        return targetData;
    }
    return null;
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) Hanging(org.bukkit.entity.Hanging) ArrayList(java.util.ArrayList) World(org.bukkit.World) Nullable(javax.annotation.Nullable)

Example 15 with Hanging

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

the class HangingController method onHangingBreakByEntity.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
    Entity breakingEntity = event.getRemover();
    if (breakingEntity == null)
        return;
    Hanging entity = event.getEntity();
    UndoList undoList = controller.getEntityUndo(breakingEntity);
    if (undoList != null && undoList.isScheduled()) {
        undoList.damage(entity);
        // Prevent item drops, but still remove it
        // Else it'll probably just break again.
        event.setCancelled(true);
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Hanging(org.bukkit.entity.Hanging) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Hanging (org.bukkit.entity.Hanging)19 EventHandler (org.bukkit.event.EventHandler)11 Entity (org.bukkit.entity.Entity)9 Location (org.bukkit.Location)8 Player (org.bukkit.entity.Player)8 LivingEntity (org.bukkit.entity.LivingEntity)7 Projectile (org.bukkit.entity.Projectile)7 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)5 Painting (org.bukkit.entity.Painting)4 BlockFace (org.bukkit.block.BlockFace)3 Animals (org.bukkit.entity.Animals)3 Minecart (org.bukkit.entity.Minecart)3 Monster (org.bukkit.entity.Monster)3 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)2 Block (org.bukkit.block.Block)2 ArmorStand (org.bukkit.entity.ArmorStand)2 Boat (org.bukkit.entity.Boat)2 EnderCrystal (org.bukkit.entity.EnderCrystal)2 Golem (org.bukkit.entity.Golem)2 ItemFrame (org.bukkit.entity.ItemFrame)2