Search in sources :

Example 1 with AcidRainEvent

use of com.wasteofplastic.askyblock.events.AcidRainEvent in project askyblock 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 {
                                double reduction = Settings.rainDamage * getDamageReduced(player);
                                double totalDamage = (Settings.rainDamage - reduction);
                                AcidRainEvent e = new AcidRainEvent(player, totalDamage, reduction);
                                plugin.getServer().getPluginManager().callEvent(e);
                                if (!e.isCancelled()) {
                                    player.damage(e.getRainDamage());
                                    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 {
                AcidEvent acidEvent = new AcidEvent(player, (Settings.acidDamage - Settings.acidDamage * getDamageReduced(player)), Settings.acidDamage * getDamageReduced(player), Settings.acidDamageType);
                plugin.getServer().getPluginManager().callEvent(acidEvent);
                if (!acidEvent.isCancelled()) {
                    for (PotionEffectType t : acidEvent.getPotionEffects()) {
                        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 (acidEvent.getTotalDamage() > 0D) {
                        player.damage(acidEvent.getTotalDamage());
                        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 : AcidRainEvent(com.wasteofplastic.askyblock.events.AcidRainEvent) Player(org.bukkit.entity.Player) Biome(org.bukkit.block.Biome) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) AcidEvent(com.wasteofplastic.askyblock.events.AcidEvent) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.askyblock.ASkyBlock) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ASkyBlock (com.wasteofplastic.askyblock.ASkyBlock)1 AcidEvent (com.wasteofplastic.askyblock.events.AcidEvent)1 AcidRainEvent (com.wasteofplastic.askyblock.events.AcidRainEvent)1 Location (org.bukkit.Location)1 Biome (org.bukkit.block.Biome)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 PotionEffect (org.bukkit.potion.PotionEffect)1 PotionEffectType (org.bukkit.potion.PotionEffectType)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1 Vector (org.bukkit.util.Vector)1