Search in sources :

Example 56 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Minigames by AddstarMC.

the class PlayerLoadout method equiptLoadout.

public void equiptLoadout(MinigamePlayer player) {
    player.getPlayer().getInventory().clear();
    player.getPlayer().getInventory().setHelmet(null);
    player.getPlayer().getInventory().setChestplate(null);
    player.getPlayer().getInventory().setLeggings(null);
    player.getPlayer().getInventory().setBoots(null);
    for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
        player.getPlayer().removePotionEffect(potion.getType());
    }
    if (!itemSlot.isEmpty()) {
        for (Integer slot : itemSlot.keySet()) {
            if (slot < 100)
                player.getPlayer().getInventory().setItem(slot, getItem(slot));
            else if (slot == 100)
                player.getPlayer().getInventory().setBoots(getItem(slot));
            else if (slot == 101)
                player.getPlayer().getInventory().setLeggings(getItem(slot));
            else if (slot == 102)
                player.getPlayer().getInventory().setChestplate(getItem(slot));
            else if (slot == 103)
                player.getPlayer().getInventory().setHelmet(getItem(slot));
        }
        player.updateInventory();
    }
    final MinigamePlayer fplayer = player;
    Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.plugin, new Runnable() {

        @Override
        public void run() {
            fplayer.getPlayer().addPotionEffects(potions);
        }
    });
    for (Entry<Class<? extends LoadoutAddon>, Object> addonValue : addonValues.entrySet()) {
        LoadoutAddon<Object> addon = LoadoutModule.getAddon(addonValue.getKey());
        if (addon != null) {
            addon.applyLoadout(player, addonValue.getValue());
        }
    }
    if (level != -1)
        player.getPlayer().setLevel(level);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) LoadoutAddon(au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon)

Example 57 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Minigames by AddstarMC.

the class PlayerLoadout method save.

public void save(ConfigurationSection section) {
    for (Integer slot : getItems()) section.set("items." + slot, getItem(slot));
    for (PotionEffect eff : getAllPotionEffects()) {
        section.set("potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
        section.set("potions." + eff.getType().getName() + ".dur", eff.getDuration());
    }
    if (getUsePermissions())
        section.set("usepermissions", true);
    if (!hasFallDamage())
        section.set("falldamage", hasFallDamage());
    if (hasHunger())
        section.set("hunger", hasHunger());
    if (getDisplayName() != null)
        section.set("displayName", getDisplayName());
    if (isArmourLocked())
        section.set("armourLocked", isArmourLocked());
    if (isInventoryLocked())
        section.set("inventoryLocked", isInventoryLocked());
    if (getTeamColor() != null)
        section.set("team", getTeamColor().toString());
    if (!isDisplayedInMenu())
        section.set("displayInMenu", isDisplayedInMenu());
    if (!allowOffHand())
        section.set("allowOffhand", allowOffHand());
    for (Entry<Class<? extends LoadoutAddon>, Object> addonValue : addonValues.entrySet()) {
        ConfigurationSection subSection = section.createSection("addons." + addonValue.getKey().getName().replace('.', '-'));
        LoadoutAddon<Object> addon = LoadoutModule.getAddon(addonValue.getKey());
        addon.save(subSection, addonValue.getValue());
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) LoadoutAddon(au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 58 with PotionEffect

use of org.bukkit.potion.PotionEffect in project Minigames by AddstarMC.

the class GameOverModule method startEndGameTimer.

public void startEndGameTimer() {
    Minigames.plugin.mdata.sendMinigameMessage(getMinigame(), MinigameUtils.formStr("minigame.gameOverQuit", timer.getFlag()), null, null);
    getMinigame().setState(MinigameState.ENDED);
    List<MinigamePlayer> allPlys = new ArrayList<MinigamePlayer>(winners.size() + losers.size());
    allPlys.addAll(losers);
    allPlys.addAll(winners);
    for (MinigamePlayer p : allPlys) {
        if (!isInteractAllowed()) {
            p.setCanInteract(false);
        }
        if (isHumiliationMode() && losers.contains(p)) {
            p.getPlayer().getInventory().clear();
            p.getPlayer().getInventory().setHelmet(null);
            p.getPlayer().getInventory().setChestplate(null);
            p.getPlayer().getInventory().setLeggings(null);
            p.getPlayer().getInventory().setBoots(null);
            for (PotionEffect potion : p.getPlayer().getActivePotionEffects()) {
                p.getPlayer().removePotionEffect(potion.getType());
            }
        }
        if (isInvincible()) {
            p.setInvincible(true);
        }
    }
    if (timer.getFlag() > 0) {
        if (task != -1)
            stopEndGameTimer();
        task = Bukkit.getScheduler().scheduleSyncDelayedTask(Minigames.plugin, new Runnable() {

            @Override
            public void run() {
                for (MinigamePlayer loser : new ArrayList<MinigamePlayer>(losers)) {
                    if (loser.isInMinigame())
                        Minigames.plugin.pdata.quitMinigame(loser, true);
                }
                for (MinigamePlayer winner : new ArrayList<MinigamePlayer>(winners)) {
                    if (winner.isInMinigame())
                        Minigames.plugin.pdata.quitMinigame(winner, true);
                }
                clearLosers();
                clearWinners();
            }
        }, timer.getFlag() * 20);
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList)

Example 59 with PotionEffect

use of org.bukkit.potion.PotionEffect in project EliteMobs by MagmaGuy.

the class SpawnMobCommandHandler method spawnMob.

public void spawnMob(CommandSender commandSender, String[] args) {
    World world = null;
    Location location = null;
    String entityInput = null;
    int mobLevel = 0;
    List<String> mobPower = new ArrayList<>();
    if (commandSender instanceof Player) {
        Player player = (Player) commandSender;
        if (args.length == 1) {
            player.sendMessage("Valid command syntax:");
            player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these mobPowers as many as you'd like)]");
        }
        world = player.getWorld();
        location = player.getTargetBlock((HashSet<Byte>) null, 30).getLocation().add(0, 1, 0);
        entityInput = args[1].toLowerCase();
        if (args.length > 2) {
            try {
                mobLevel = Integer.valueOf(args[2]);
            } catch (NumberFormatException ex) {
                player.sendMessage("Not a valid level.");
                player.sendMessage("Valid command syntax:");
                player.sendMessage("/elitemobs SpawnMob [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these mobPowers as many as you'd like)]");
            }
        }
        if (args.length > 3) {
            int index = 0;
            for (String arg : args) {
                //mob powers start after arg 2
                if (index > 2) {
                    mobPower.add(arg);
                }
                index++;
            }
        }
    } else if (commandSender instanceof ConsoleCommandSender || commandSender instanceof BlockCommandSender) {
        for (World worldIterator : worldList) {
            //find world
            if (worldIterator.getName().equals(args[1])) {
                world = worldIterator;
                //find x coord
                try {
                    double xCoord = Double.parseDouble(args[2]);
                    double yCoord = Double.parseDouble(args[3]);
                    double zCoord = Double.parseDouble(args[4]);
                    location = new Location(worldIterator, xCoord, yCoord, zCoord);
                    entityInput = args[5].toLowerCase();
                    break;
                } catch (NumberFormatException ex) {
                    getConsoleSender().sendMessage("At least one of the coordinates (x:" + args[2] + ", y:" + args[3] + ", z:" + args[4] + ") is not valid");
                    getConsoleSender().sendMessage("Valid command syntax: /elitemobs SpawnMob worldName xCoord yCoord " + "zCoord mobType mobLevel mobPower mobPower(you can keep adding these mobPowers as many as you'd like)");
                }
                if (args.length > 6) {
                    int index = 0;
                    for (String arg : args) {
                        //mob powers start after arg 2
                        if (index > 2) {
                            mobPower.add(arg);
                        }
                        index++;
                    }
                }
            }
        }
        if (world == null) {
            getConsoleSender().sendMessage("World " + args[1] + "not found. Valid command syntax: /elitemobs SpawnMob" + " [worldName] [xCoord] [yCoord] [zCoord] [mobType] [mobLevel] [mobPower] [mobPower(you can keep adding these " + "mobPowers as many as you'd like)]");
        }
    }
    EntityType entityType = null;
    switch(entityInput) {
        case "blaze":
            entityType = EntityType.BLAZE;
            break;
        case "cavespider":
            entityType = EntityType.CAVE_SPIDER;
            break;
        case "creeper":
            entityType = EntityType.CREEPER;
            break;
        case "enderman":
            entityType = EntityType.ENDERMAN;
            break;
        case "endermite":
            entityType = EntityType.ENDERMITE;
            break;
        case "husk":
            entityType = EntityType.HUSK;
            break;
        case "irongolem":
            entityType = EntityType.IRON_GOLEM;
            break;
        case "pigzombie":
            entityType = EntityType.PIG_ZOMBIE;
            break;
        case "polarbear":
            entityType = EntityType.POLAR_BEAR;
            break;
        case "silverfish":
            entityType = EntityType.SILVERFISH;
            break;
        case "skeleton":
            entityType = EntityType.SKELETON;
            break;
        case "spider":
            entityType = EntityType.SPIDER;
            break;
        case "stray":
            entityType = EntityType.STRAY;
            break;
        case "witch":
            entityType = EntityType.WITCH;
            break;
        case "witherskeleton":
            entityType = EntityType.WITHER_SKELETON;
            break;
        case "zombie":
            entityType = EntityType.ZOMBIE;
            break;
        case "chicken":
            entityType = EntityType.CHICKEN;
            break;
        case "cow":
            entityType = EntityType.COW;
            break;
        case "mushroomcow":
            entityType = EntityType.MUSHROOM_COW;
            break;
        case "pig":
            entityType = EntityType.PIG;
            break;
        case "sheep":
            entityType = EntityType.SHEEP;
            break;
        default:
            if (commandSender instanceof Player) {
                ((Player) commandSender).getPlayer().sendTitle("Could not spawn mob type " + entityInput, "If this is incorrect, please contact the dev.");
            } else if (commandSender instanceof ConsoleCommandSender) {
                getConsoleSender().sendMessage("Could not spawn mob type " + entityInput + ". If this is incorrect, " + "please contact the dev.");
            }
            break;
    }
    Entity entity = null;
    if (entityType != null) {
        entity = world.spawnEntity(location, entityType);
    }
    if (entityType == EntityType.CHICKEN || entityType == EntityType.COW || entityType == EntityType.MUSHROOM_COW || entityType == EntityType.PIG || entityType == EntityType.SHEEP) {
        HealthHandler.passiveHealthHandler(entity, ConfigValues.defaultConfig.getInt("Passive EliteMob stack amount"));
        NameHandler.customPassiveName(entity, plugin);
        return;
    }
    if (mobLevel > 0) {
        entity.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, mobLevel));
    }
    if (mobPower.size() > 0) {
        boolean inputError = false;
        int powerCount = 0;
        MetadataHandler metadataHandler = new MetadataHandler();
        for (String string : mobPower) {
            switch(string) {
                //major powers
                case MetadataHandler.ZOMBIE_FRIENDS_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_FRIENDS_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                case MetadataHandler.ZOMBIE_NECRONOMICON_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_NECRONOMICON_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                case MetadataHandler.ZOMBIE_TEAM_ROCKET_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_TEAM_ROCKET_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                case MetadataHandler.ZOMBIE_PARENTS_H:
                    if (entity instanceof Zombie) {
                        entity.setMetadata(MetadataHandler.ZOMBIE_PARENTS_MD, new FixedMetadataValue(plugin, true));
                        powerCount++;
                    }
                    break;
                //minor powers
                case MetadataHandler.ATTACK_ARROW_H:
                    entity.setMetadata(MetadataHandler.ATTACK_ARROW_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_BLINDING_H:
                    entity.setMetadata(MetadataHandler.ATTACK_BLINDING_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_CONFUSING_H:
                    entity.setMetadata(MetadataHandler.ATTACK_CONFUSING_MD, new FixedMetadataValue(plugin, true));
                    //                        minorPowerPowerStance.attackConfusing(entity);
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_FIRE_H:
                    entity.setMetadata(MetadataHandler.ATTACK_FIRE_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_FIREBALL_H:
                    entity.setMetadata(MetadataHandler.ATTACK_FIREBALL_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_FREEZE_H:
                    entity.setMetadata(MetadataHandler.ATTACK_FREEZE_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_GRAVITY_H:
                    entity.setMetadata(MetadataHandler.ATTACK_GRAVITY_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_POISON_H:
                    entity.setMetadata(MetadataHandler.ATTACK_POISON_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_PUSH_H:
                    entity.setMetadata(MetadataHandler.ATTACK_PUSH_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_WEAKNESS_H:
                    entity.setMetadata(MetadataHandler.ATTACK_WEAKNESS_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_WEB_H:
                    entity.setMetadata(MetadataHandler.ATTACK_WEB_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.ATTACK_WITHER_H:
                    entity.setMetadata(MetadataHandler.ATTACK_WITHER_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.BONUS_LOOT_H:
                    entity.setMetadata(MetadataHandler.BONUS_LOOT_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.DOUBLE_DAMAGE_H:
                    if (!(entity instanceof IronGolem)) {
                        entity.setMetadata(MetadataHandler.DOUBLE_DAMAGE_MD, new FixedMetadataValue(plugin, true));
                    }
                    powerCount++;
                    break;
                case MetadataHandler.DOUBLE_HEALTH_H:
                    if (!(entity instanceof IronGolem)) {
                        entity.setMetadata(MetadataHandler.DOUBLE_HEALTH_MD, new FixedMetadataValue(plugin, true));
                    }
                    powerCount++;
                    break;
                case MetadataHandler.INVISIBILITY_H:
                    entity.setMetadata(MetadataHandler.INVISIBILITY_MD, new FixedMetadataValue(plugin, true));
                    ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1));
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_ARROW_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_ARROW_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_FALL_DAMAGE_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_FALL_DAMAGE_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_FIRE_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_FIRE_MD, new FixedMetadataValue(plugin, true));
                    //                        minorPowerPowerStance.invulnerabilityFireEffect(entity);
                    powerCount++;
                    break;
                case MetadataHandler.INVULNERABILITY_KNOCKBACK_H:
                    entity.setMetadata(MetadataHandler.INVULNERABILITY_KNOCKBACK_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case MetadataHandler.MOVEMENT_SPEED_H:
                    entity.setMetadata(MetadataHandler.MOVEMENT_SPEED_MD, new FixedMetadataValue(plugin, true));
                    ((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2));
                    powerCount++;
                    break;
                case MetadataHandler.TAUNT_H:
                    entity.setMetadata(MetadataHandler.TAUNT_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                case "custom":
                    entity.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
                    powerCount++;
                    break;
                default:
                    if (commandSender instanceof Player) {
                        Player player = (Player) commandSender;
                        player.sendMessage(string + " is not a valid power.");
                    } else if (commandSender instanceof ConsoleCommandSender) {
                        getConsoleSender().sendMessage(string + " is not a valid power.");
                    }
                    inputError = true;
            }
        }
        entity.setMetadata(MetadataHandler.MINOR_POWER_AMOUNT_MD, new FixedMetadataValue(plugin, powerCount));
        minorPowerPowerStance.itemEffect(entity);
        majorPowerPowerStance.itemEffect(entity);
        if (inputError) {
            if (commandSender instanceof Player) {
                Player player = (Player) commandSender;
                player.sendMessage("Valid powers: " + MetadataHandler.powerListHumanFormat() + " custom");
            } else if (commandSender instanceof ConsoleCommandSender) {
                getConsoleSender().sendMessage("Valid powers: " + MetadataHandler.powerListHumanFormat() + MetadataHandler.majorPowerList() + " custom");
            }
        }
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MetadataHandler(com.magmaguy.elitemobs.MetadataHandler) World(org.bukkit.World) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) Location(org.bukkit.Location) HashSet(java.util.HashSet) BlockCommandSender(org.bukkit.command.BlockCommandSender)

Example 60 with PotionEffect

use of org.bukkit.potion.PotionEffect in project EliteMobs by MagmaGuy.

the class EliteDropsHandler method superDropParser.

public void superDropParser() {
    List<String> lootCount = lootCounter();
    for (String lootEntry : lootCount) {
        int itemPower = 0;
        StringBuilder path = new StringBuilder();
        path.append(lootEntry);
        String previousPath = path.toString();
        String itemType = itemTypeHandler(previousPath);
        itemPower += itemTypePower(Material.getMaterial(itemType));
        Bukkit.getLogger().info("Adding: " + previousPath);
        String itemName = itemNameHandler(previousPath);
        List itemLore = itemLoreHandler(previousPath);
        List itemEnchantments = itemEnchantmentHandler(previousPath);
        List potionEffects = itemPotionEffectHandler(previousPath);
        ItemStack itemStack = new ItemStack(Material.getMaterial(itemType), 1);
        ItemMeta itemMeta = itemStack.getItemMeta();
        itemMeta.setDisplayName(itemName);
        itemMeta.setLore(itemLore);
        if (itemEnchantments != null) {
            for (Object object : itemEnchantments) {
                String string = object.toString();
                String[] parsedString = string.split(",");
                String enchantmentName = parsedString[0];
                Enchantment enchantmentType = Enchantment.getByName(enchantmentName);
                int enchantmentLevel = Integer.parseInt(parsedString[1]);
                itemPower += enchantmentLevel;
                itemMeta.addEnchant(enchantmentType, enchantmentLevel, true);
            }
        }
        itemStack.setItemMeta(itemMeta);
        lootList.add(itemStack);
        List<PotionEffect> parsedPotionEffect = new ArrayList();
        //Add potion effects to a separate list to reduce i/o operations
        if (potionEffects != null) {
            for (Object object : potionEffects) {
                String string = object.toString();
                String[] parsedString = string.split(",");
                String potionEffectTypeString = parsedString[0];
                PotionEffectType potionEffectType = PotionEffectType.getByName(potionEffectTypeString);
                //this is a really bad way of doing things, two wrongs make a right
                if (parsedString.length % 2 != 0) {
                    getLogger().info("Your item " + itemName + " has a problematic potions effect entry.");
                }
                int potionEffectAmplifier = Integer.parseInt(parsedString[1]);
                itemPower += potionEffectAmplifier;
                PotionEffect potionEffect = new PotionEffect(potionEffectType, 40, potionEffectAmplifier);
                parsedPotionEffect.add(potionEffect);
            }
            potionEffectItemList.put(itemStack, parsedPotionEffect);
        }
        rankedItemMapCreator(itemPower, itemStack);
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

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