Search in sources :

Example 81 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.P = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                if (e instanceof EntityPlayer && getOwner().equals(e)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.P = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    e.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 82 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (this.passenger == null || !(this.passenger instanceof EntityPlayer)) {
            hasRider = false;
            // climb height -> halfslab
            this.S = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (this.passenger != null) {
            if (this.passenger instanceof EntityPlayer) {
                if (getOwner().equals(this.passenger)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.S = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    this.passenger.mount(null);
                }
            } else {
                this.passenger.mount(null);
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 83 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.P = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                if (e instanceof EntityPlayer && getOwner().equals(e)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.P = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    e.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_9_R2.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 84 with PotionEffect

use of org.bukkit.potion.PotionEffect in project acidisland by tastybento.

the class AcidEffect method onPlayerMove.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
    // Fast return if acid isn't being used
    if (Settings.rainDamage == 0 && Settings.acidDamage == 0) {
        return;
    }
    final Player player = e.getPlayer();
    // Fast checks
    if (player.isDead() || player.getGameMode().toString().startsWith("SPECTATOR")) {
        return;
    }
    // Check if in teleport
    if (plugin.getPlayers().isInTeleport(player.getUniqueId())) {
        return;
    }
    // Check that they are in the ASkyBlock world
    if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
        return;
    }
    // Return if players are immune
    if (player.isOp()) {
        if (!Settings.damageOps) {
            return;
        }
    } else if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.noburn") || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "admin.noburn")) {
        return;
    }
    if (player.getGameMode().equals(GameMode.CREATIVE)) {
        return;
    }
    /*
        if (!e.getTo().toVector().equals(e.getFrom().toVector())) {
            // Head movements only
            return;
        }*/
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Acid Effect " + e.getEventName());
    // Slow checks
    final Location playerLoc = player.getLocation();
    final Block block = playerLoc.getBlock();
    final Block head = block.getRelative(BlockFace.UP);
    // Check for acid rain
    if (Settings.rainDamage > 0D && isRaining) {
        // Only check if they are in a non-dry biome
        Biome biome = playerLoc.getBlock().getBiome();
        if (biome != Biome.DESERT && biome != Biome.DESERT_HILLS && biome != Biome.SAVANNA && biome != Biome.MESA && biome != Biome.HELL) {
            if (isSafeFromRain(player)) {
                // plugin.getLogger().info("DEBUG: not hit by rain");
                wetPlayers.remove(player);
            } else {
                // plugin.getLogger().info("DEBUG: hit by rain");
                if (!wetPlayers.contains(player)) {
                    // plugin.getLogger().info("DEBUG: Start hurting player");
                    // Start hurting them
                    // Add to the list
                    wetPlayers.add(player);
                    // This runnable continuously hurts the player even if
                    // they are not
                    // moving but are in acid rain.
                    new BukkitRunnable() {

                        @Override
                        public void run() {
                            // Check if it is still raining or player is safe or dead or there is no damage
                            if (!isRaining || player.isDead() || isSafeFromRain(player) || Settings.rainDamage <= 0D) {
                                // plugin.getLogger().info("DEBUG: Player is dead or it has stopped raining");
                                wetPlayers.remove(player);
                                this.cancel();
                            // Check they are still in this world
                            } else {
                                player.damage((Settings.rainDamage - Settings.rainDamage * getDamageReduced(player)));
                                if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                                    player.getWorld().playSound(playerLoc, Sound.valueOf("FIZZ"), 3F, 3F);
                                } else {
                                    player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
                                }
                            }
                        }
                    }.runTaskTimer(plugin, 0L, 20L);
                }
            }
        }
    }
    // back up
    if (playerLoc.getBlockY() < 1 && Settings.GAMETYPE.equals(GameType.ACIDISLAND)) {
        final Vector v = new Vector(player.getVelocity().getX(), 1D, player.getVelocity().getZ());
        player.setVelocity(v);
    }
    // If they are already burning in acid then return
    if (burningPlayers.contains(player)) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: already burning in acid");
        return;
    }
    // plugin.getLogger().info("DEBUG: no acid water is false");
    if (isSafeFromAcid(player)) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: safe from acid");
        return;
    }
    // ACID!
    // plugin.getLogger().info("DEBUG: Acid!");
    // Put the player into the acid list
    burningPlayers.add(player);
    // This runnable continuously hurts the player even if they are not
    // moving but are in acid.
    new BukkitRunnable() {

        @Override
        public void run() {
            if (player.isDead() || isSafeFromAcid(player)) {
                burningPlayers.remove(player);
                this.cancel();
            } else {
                if (!Settings.acidDamageType.isEmpty()) {
                    for (PotionEffectType t : Settings.acidDamageType) {
                        if (t.equals(PotionEffectType.BLINDNESS) || t.equals(PotionEffectType.CONFUSION) || t.equals(PotionEffectType.HUNGER) || t.equals(PotionEffectType.SLOW) || t.equals(PotionEffectType.SLOW_DIGGING) || t.equals(PotionEffectType.WEAKNESS)) {
                            player.addPotionEffect(new PotionEffect(t, 600, 1));
                        } else {
                            // Poison
                            player.addPotionEffect(new PotionEffect(t, 200, 1));
                        }
                    }
                }
                // Apply damage if there is any
                if (Settings.acidDamage > 0D) {
                    player.damage((Settings.acidDamage - Settings.acidDamage * getDamageReduced(player)));
                    if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                        player.getWorld().playSound(playerLoc, Sound.valueOf("FIZZ"), 3F, 3F);
                    } else {
                        player.getWorld().playSound(playerLoc, Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
                    }
                }
            }
        }
    }.runTaskTimer(plugin, 0L, 20L);
}
Also used : Player(org.bukkit.entity.Player) Biome(org.bukkit.block.Biome) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 85 with PotionEffect

use of org.bukkit.potion.PotionEffect in project acidisland by tastybento.

the class AcidEffect method isSafeFromAcid.

/**
 * Check if player can be burned by acid
 * @param player
 * @return true if player is not safe
 */
private boolean isSafeFromAcid(Player player) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: safe from acid");
    if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: wrong world");
        return true;
    }
    // In liquid
    Material bodyMat = player.getLocation().getBlock().getType();
    Material headMat = player.getLocation().getBlock().getRelative(BlockFace.UP).getType();
    if (bodyMat.equals(Material.STATIONARY_WATER))
        bodyMat = Material.WATER;
    if (headMat.equals(Material.STATIONARY_WATER))
        headMat = Material.WATER;
    if (bodyMat != Material.WATER && headMat != Material.WATER) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: not in water " + player.getLocation().getBlock().isLiquid() + " " + player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid());
        return true;
    }
    // Check if player is in a boat
    Entity playersVehicle = player.getVehicle();
    if (playersVehicle != null) {
        // They are in a Vehicle
        if (playersVehicle.getType().equals(EntityType.BOAT)) {
            // I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT!
            if (DEBUG)
                plugin.getLogger().info("DEBUG: boat");
            return true;
        }
    }
    // Check if full armor protects
    if (Settings.fullArmorProtection) {
        boolean fullArmor = true;
        for (ItemStack item : player.getInventory().getArmorContents()) {
            if (item == null || (item != null && item.getType().equals(Material.AIR))) {
                fullArmor = false;
                break;
            }
        }
        if (fullArmor) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: full armor");
            return true;
        }
    }
    // Check if player has an active water potion or not
    Collection<PotionEffect> activePotions = player.getActivePotionEffects();
    for (PotionEffect s : activePotions) {
        // s.getType().toString());
        if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
            // Safe!
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Water breathing potion protection!");
            return true;
        }
    }
    // Check if water above sea-level is not acid
    Island island = plugin.getGrid().getIslandAt(player.getLocation());
    if (island != null && !island.getIgsFlag(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG:no acid damage above sea level 1");
        return true;
    }
    if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: no acid damage above sea level");
        return true;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: burn in acid");
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) PotionEffect(org.bukkit.potion.PotionEffect) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Island(com.wasteofplastic.acidisland.Island)

Aggregations

PotionEffect (org.bukkit.potion.PotionEffect)87 Player (org.bukkit.entity.Player)28 Location (org.bukkit.Location)16 LivingEntity (org.bukkit.entity.LivingEntity)13 ArrayList (java.util.ArrayList)12 PotionEffectType (org.bukkit.potion.PotionEffectType)12 EventHandler (org.bukkit.event.EventHandler)11 ItemStack (org.bukkit.inventory.ItemStack)10 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)9 Entity (org.bukkit.entity.Entity)9 Projectile (org.bukkit.entity.Projectile)6 Minigame (au.com.mineauz.minigames.minigame.Minigame)3 List (java.util.List)3 Vector (org.bukkit.util.Vector)3 LoadoutAddon (au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon)2 MinorPowerPowerStance (com.magmaguy.elitemobs.powerstances.MinorPowerPowerStance)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2