Search in sources :

Example 36 with PotionEffectType

use of org.bukkit.potion.PotionEffectType 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 {
                                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.acidisland.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.acidisland.events.AcidEvent) 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 37 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project BKCommonLib by bergerhealer.

the class WrapperConversion method toPotionEffectType.

@ConverterMethod(input = "net.minecraft.world.effect.MobEffectList")
public static PotionEffectType toPotionEffectType(Object nmsMobEffectListHandle) {
    int id = MobEffectListHandle.T.getId.invoke(nmsMobEffectListHandle);
    @SuppressWarnings("deprecation") PotionEffectType type = PotionEffectType.getById(id);
    if (type != null) {
        return type;
    } else {
        return null;
    }
}
Also used : PotionEffectType(org.bukkit.potion.PotionEffectType) ConverterMethod(com.bergerkiller.mountiplex.conversion.annotations.ConverterMethod)

Example 38 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project CitizensAPI by CitizensDev.

the class ItemStorage method deserialiseMeta.

private static void deserialiseMeta(DataKey root, ItemStack res) {
    if (root.keyExists("encoded-meta")) {
        byte[] raw = BaseEncoding.base64().decode(root.getString("encoded-meta"));
        try {
            BukkitObjectInputStream inp = new BukkitObjectInputStream(new ByteArrayInputStream(raw));
            ItemMeta meta = (ItemMeta) inp.readObject();
            res.setItemMeta(meta);
            Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
            return;
        } catch (IOException e1) {
            e1.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    if (SUPPORTS_CUSTOM_MODEL_DATA) {
        try {
            if (root.keyExists("custommodel")) {
                ItemMeta meta = ensureMeta(res);
                meta.setCustomModelData(root.getInt("custommodel"));
                res.setItemMeta(meta);
            }
        } catch (Throwable t) {
            SUPPORTS_CUSTOM_MODEL_DATA = false;
        }
    }
    if (root.keyExists("flags")) {
        ItemMeta meta = ensureMeta(res);
        for (DataKey key : root.getRelative("flags").getIntegerSubKeys()) {
            meta.addItemFlags(ItemFlag.valueOf(key.getString("")));
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("lore")) {
        ItemMeta meta = ensureMeta(res);
        List<String> lore = Lists.newArrayList();
        for (DataKey key : root.getRelative("lore").getIntegerSubKeys()) lore.add(key.getString(""));
        meta.setLore(lore);
        res.setItemMeta(meta);
    }
    if (root.keyExists("displayname")) {
        ItemMeta meta = ensureMeta(res);
        meta.setDisplayName(root.getString("displayname"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("firework")) {
        FireworkMeta meta = ensureMeta(res);
        for (DataKey sub : root.getRelative("firework.effects").getIntegerSubKeys()) {
            meta.addEffect(deserialiseFireworkEffect(sub));
        }
        meta.setPower(root.getInt("firework.power"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("book")) {
        BookMeta meta = ensureMeta(res);
        for (DataKey sub : root.getRelative("book.pages").getIntegerSubKeys()) {
            meta.addPage(sub.getString(""));
        }
        meta.setTitle(root.getString("book.title"));
        meta.setAuthor(root.getString("book.author"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("armor")) {
        LeatherArmorMeta meta = ensureMeta(res);
        meta.setColor(Color.fromRGB(root.getInt("armor.color")));
        res.setItemMeta(meta);
    }
    if (root.keyExists("map")) {
        MapMeta meta = ensureMeta(res);
        meta.setScaling(root.getBoolean("map.scaling"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("blockstate")) {
        BlockStateMeta meta = ensureMeta(res);
        if (root.keyExists("blockstate.banner")) {
            Banner banner = (Banner) meta.getBlockState();
            deserialiseBanner(root.getRelative("blockstate"), banner);
            banner.update(true);
            meta.setBlockState(banner);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("enchantmentstorage")) {
        EnchantmentStorageMeta meta = ensureMeta(res);
        for (DataKey key : root.getRelative("enchantmentstorage").getSubKeys()) {
            meta.addStoredEnchant(deserialiseEnchantment(key.name()), key.getInt(""), true);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("skull")) {
        SkullMeta meta = ensureMeta(res);
        if (root.keyExists("skull.owner") && !root.getString("skull.owner").isEmpty()) {
            meta.setOwner(root.getString("skull.owner", ""));
        }
        if (root.keyExists("skull.texture") && !root.getString("skull.texture").isEmpty()) {
            CitizensAPI.getSkullMetaProvider().setTexture(root.getString("skull.texture", ""), meta);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("banner")) {
        BannerMeta meta = ensureMeta(res);
        if (root.keyExists("banner.basecolor")) {
            meta.setBaseColor(DyeColor.valueOf(root.getString("banner.basecolor")));
        }
        if (root.keyExists("banner.patterns")) {
            for (DataKey sub : root.getRelative("banner.patterns").getIntegerSubKeys()) {
                Pattern pattern = new Pattern(DyeColor.valueOf(sub.getString("color")), PatternType.getByIdentifier(sub.getString("type")));
                meta.addPattern(pattern);
            }
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("potion")) {
        PotionMeta meta = ensureMeta(res);
        try {
            PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")), root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
            meta.setBasePotionData(data);
        } catch (Throwable t) {
        }
        for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
            int duration = sub.getInt("duration");
            int amplifier = sub.getInt("amplifier");
            PotionEffectType type = PotionEffectType.getByName(sub.getString("type"));
            boolean ambient = sub.getBoolean("ambient");
            meta.addCustomEffect(new PotionEffect(type, duration, amplifier, ambient), true);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("crossbow") && SUPPORTS_1_14_API) {
        CrossbowMeta meta = null;
        try {
            meta = ensureMeta(res);
        } catch (Throwable t) {
            SUPPORTS_1_14_API = false;
        // old MC version
        }
        if (meta != null) {
            for (DataKey key : root.getRelative("crossbow.projectiles").getSubKeys()) {
                meta.addChargedProjectile(ItemStorage.loadItemStack(key));
            }
            res.setItemMeta(meta);
        }
    }
    if (root.keyExists("repaircost") && res.getItemMeta() instanceof Repairable) {
        ItemMeta meta = ensureMeta(res);
        ((Repairable) meta).setRepairCost(root.getInt("repaircost"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("attributes") && SUPPORTS_ATTRIBUTES) {
        ItemMeta meta = ensureMeta(res);
        try {
            for (DataKey attr : root.getRelative("attributes").getSubKeys()) {
                Attribute attribute = Attribute.valueOf(attr.name());
                for (DataKey modifier : attr.getIntegerSubKeys()) {
                    UUID uuid = UUID.fromString(modifier.getString("uuid"));
                    String name = modifier.getString("name");
                    double amount = modifier.getDouble("amount");
                    Operation operation = Operation.valueOf(modifier.getString("operation"));
                    EquipmentSlot slot = modifier.keyExists("slot") ? EquipmentSlot.valueOf(modifier.getString("slot")) : null;
                    meta.addAttributeModifier(attribute, new AttributeModifier(uuid, name, amount, operation, slot));
                }
            }
        } catch (Throwable e) {
            SUPPORTS_ATTRIBUTES = false;
        }
        res.setItemMeta(meta);
    }
    ItemMeta meta = res.getItemMeta();
    if (meta != null) {
        try {
            meta.setUnbreakable(root.getBoolean("unbreakable", false));
        } catch (Throwable t) {
        // probably backwards-compat issue, don't log
        }
        res.setItemMeta(meta);
    }
    Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
}
Also used : CitizensDeserialiseMetaEvent(net.citizensnpcs.api.event.CitizensDeserialiseMetaEvent) PotionEffect(org.bukkit.potion.PotionEffect) Attribute(org.bukkit.attribute.Attribute) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Operation(org.bukkit.attribute.AttributeModifier.Operation) PotionData(org.bukkit.potion.PotionData) UUID(java.util.UUID) ItemMeta(org.bukkit.inventory.meta.ItemMeta) CrossbowMeta(org.bukkit.inventory.meta.CrossbowMeta) Repairable(org.bukkit.inventory.meta.Repairable) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Pattern(org.bukkit.block.banner.Pattern) BukkitObjectInputStream(org.bukkit.util.io.BukkitObjectInputStream) Banner(org.bukkit.block.Banner) PotionEffectType(org.bukkit.potion.PotionEffectType) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) PotionMeta(org.bukkit.inventory.meta.PotionMeta) IOException(java.io.IOException) AttributeModifier(org.bukkit.attribute.AttributeModifier) BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) ByteArrayInputStream(java.io.ByteArrayInputStream) MapMeta(org.bukkit.inventory.meta.MapMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 39 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project Bukkit by Bukkit.

the class EffectCommand method execute.

@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender)) {
        return true;
    }
    if (args.length < 2) {
        sender.sendMessage(getUsage());
        return true;
    }
    final Player player = sender.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(ChatColor.RED + String.format("Player, %s, not found", args[0]));
        return true;
    }
    if ("clear".equalsIgnoreCase(args[1])) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        sender.sendMessage(String.format("Took all effects from %s", args[0]));
        return true;
    }
    PotionEffectType effect = PotionEffectType.getByName(args[1]);
    if (effect == null) {
        effect = PotionEffectType.getById(getInteger(sender, args[1], 0));
    }
    if (effect == null) {
        sender.sendMessage(ChatColor.RED + String.format("Effect, %s, not found", args[1]));
        return true;
    }
    int duration = 600;
    int duration_temp = 30;
    int amplification = 0;
    if (args.length >= 3) {
        duration_temp = getInteger(sender, args[2], 0, 1000000);
        if (effect.isInstant()) {
            duration = duration_temp;
        } else {
            duration = duration_temp * 20;
        }
    } else if (effect.isInstant()) {
        duration = 1;
    }
    if (args.length >= 4) {
        amplification = getInteger(sender, args[3], 0, 255);
    }
    if (duration_temp == 0) {
        if (!player.hasPotionEffect(effect)) {
            sender.sendMessage(String.format("Couldn't take %s from %s as they do not have the effect", effect.getName(), args[0]));
            return true;
        }
        player.removePotionEffect(effect);
        broadcastCommandMessage(sender, String.format("Took %s from %s", effect.getName(), args[0]));
    } else {
        final PotionEffect applyEffect = new PotionEffect(effect, duration, amplification);
        player.addPotionEffect(applyEffect, true);
        broadcastCommandMessage(sender, String.format("Given %s (ID %d) * %d to %s for %d seconds", effect.getName(), effect.getId(), amplification, args[0], duration_temp));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType)

Example 40 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project WildernessTp by AcmeProject.

the class WorldConfig method hurryPeter.

private HashMap<Trigger, PotionEffect[]> hurryPeter(ConfigurationSection v, ConfigurationSection d, int w) {
    HashMap<Trigger, PotionEffect[]> map = new HashMap<Trigger, PotionEffect[]>();
    for (Trigger when : Trigger.values()) {
        HashSet<PotionEffect> effects = new HashSet<PotionEffect>();
        String emmaString = "Effects." + when.toString();
        List<String> emmaGivDis = (v != null && v.contains(emmaString)) ? v.getStringList(emmaString) : d.getStringList(emmaString);
        emmaGivDis.forEach(patronus -> {
            String[] spell = patronus.split(":");
            PotionEffectType agrud = PotionEffectType.getByName(spell[0]);
            if (agrud == null)
                return;
            int voldo = 0;
            if (spell.length == 2)
                try {
                    voldo = Integer.parseInt(spell[1]);
                } catch (NumberFormatException e) {
                }
            effects.add(new PotionEffect(agrud, w + 1200, voldo, false, false, false));
        });
        map.put(when, (PotionEffect[]) effects.toArray(new PotionEffect[] {}));
    }
    return map;
}
Also used : Trigger(net.poweredbyhate.wildtp.TeleportGoneWild.Trigger) HashMap(java.util.HashMap) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) HashSet(java.util.HashSet)

Aggregations

PotionEffectType (org.bukkit.potion.PotionEffectType)54 PotionEffect (org.bukkit.potion.PotionEffect)41 ArrayList (java.util.ArrayList)12 Player (org.bukkit.entity.Player)8 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)6 HashMap (java.util.HashMap)6 ItemStack (org.bukkit.inventory.ItemStack)6 Map (java.util.Map)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 PotionType (org.bukkit.potion.PotionType)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)4 Material (org.bukkit.Material)4 LivingEntity (org.bukkit.entity.LivingEntity)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 EntityTag (com.denizenscript.denizen.objects.EntityTag)3 File (java.io.File)3 IOException (java.io.IOException)3 List (java.util.List)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 Entity (org.bukkit.entity.Entity)3