Search in sources :

Example 56 with LivingEntity

use of org.bukkit.entity.LivingEntity in project acidisland by tastybento.

the class IslandGuard method onSplashPotionSplash.

/**
 * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them.
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("splash entity = " + e.getEntity());
        plugin.getLogger().info("splash entity type = " + e.getEntityType());
        plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities());
    // plugin.getLogger().info("splash hit entity = " + e.getHitEntity());
    }
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    // Try to get the shooter
    Projectile projectile = (Projectile) e.getEntity();
    if (DEBUG)
        plugin.getLogger().info("splash shooter = " + projectile.getShooter());
    if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
        Player attacker = (Player) projectile.getShooter();
        // Run through all the affected entities
        for (LivingEntity entity : e.getAffectedEntities()) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: affected splash entity = " + entity);
            // Self damage
            if (attacker.equals(entity)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Self damage from splash potion!");
                continue;
            }
            Island island = plugin.getGrid().getIslandAt(entity.getLocation());
            boolean inNether = false;
            if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) {
                inNether = true;
            }
            // Monsters being hurt
            if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
                // Normal island check
                if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
                    // Members always allowed
                    continue;
                }
                if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) {
                    continue;
                }
                // Not allowed
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }
            // Mobs being hurt
            if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) {
                if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
                    continue;
                }
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }
            // Establish whether PVP is allowed or not.
            boolean pvp = false;
            if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: PVP allowed");
                pvp = true;
            }
            // Players being hurt PvP
            if (entity instanceof Player) {
                if (pvp) {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: PVP allowed");
                    continue;
                } else {
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: PVP not allowed");
                    Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Squid(org.bukkit.entity.Squid) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Snowman(org.bukkit.entity.Snowman) IronGolem(org.bukkit.entity.IronGolem) Slime(org.bukkit.entity.Slime) Island(com.wasteofplastic.acidisland.Island) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 57 with LivingEntity

use of org.bukkit.entity.LivingEntity in project acidisland by tastybento.

the class Schematic method spawnCompanion.

/**
 * Spawns a random companion for the player with a random name at the location given
 * @param player
 * @param location
 */
protected void spawnCompanion(Player player, Location location) {
    // Bukkit.getLogger().info("DEBUG: spawning compantion at " + location);
    if (!islandCompanion.isEmpty() && location != null) {
        Random rand = new Random();
        int randomNum = rand.nextInt(islandCompanion.size());
        EntityType type = islandCompanion.get(randomNum);
        if (type != null) {
            LivingEntity companion = (LivingEntity) location.getWorld().spawnEntity(location, type);
            if (!companionNames.isEmpty()) {
                randomNum = rand.nextInt(companionNames.size());
                String name = companionNames.get(randomNum).replace("[player]", player.getName());
                // plugin.getLogger().info("DEBUG: name is " + name);
                companion.setCustomName(name);
                companion.setCustomNameVisible(true);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) Random(java.util.Random)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)57 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)23 EventHandler (org.bukkit.event.EventHandler)22 Location (org.bukkit.Location)12 ArrayList (java.util.ArrayList)11 Vector (org.bukkit.util.Vector)10 Projectile (org.bukkit.entity.Projectile)9 PotionEffect (org.bukkit.potion.PotionEffect)9 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)8 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)7 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)7 ItemStack (org.bukkit.inventory.ItemStack)7 List (java.util.List)5 Element (net.aufdemrand.denizencore.objects.Element)5 Island (com.wasteofplastic.acidisland.Island)4 HashMap (java.util.HashMap)4 World (org.bukkit.World)4 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)4 Helper (com.jacob_vejvoda.infernal_mobs.Helper)3