Search in sources :

Example 56 with EntityType

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

the class Challenges method createItem.

/**
 * Creates an inventory item for the challenge
 * @param challengeName
 * @param player
 * @return Control Panel item
 */
private CPItem createItem(String challengeName, Player player) {
    CPItem item = null;
    // Get the icon
    ItemStack icon = null;
    String iconName = getChallengeConfig().getString("challenges.challengeList." + challengeName + ".icon", "");
    if (!iconName.isEmpty()) {
        try {
            // Split if required
            String[] split = iconName.split(":");
            if (split.length == 1) {
                // Some material does not show in the inventory
                if (iconName.equalsIgnoreCase("potato")) {
                    iconName = "POTATO_ITEM";
                } else if (iconName.equalsIgnoreCase("brewing_stand")) {
                    iconName = "BREWING_STAND_ITEM";
                } else if (iconName.equalsIgnoreCase("carrot")) {
                    iconName = "CARROT_ITEM";
                } else if (iconName.equalsIgnoreCase("cauldron")) {
                    iconName = "CAULDRON_ITEM";
                } else if (iconName.equalsIgnoreCase("lava") || iconName.equalsIgnoreCase("stationary_lava")) {
                    iconName = "LAVA_BUCKET";
                } else if (iconName.equalsIgnoreCase("water") || iconName.equalsIgnoreCase("stationary_water")) {
                    iconName = "WATER_BUCKET";
                } else if (iconName.equalsIgnoreCase("portal")) {
                    iconName = "OBSIDIAN";
                } else if (iconName.equalsIgnoreCase("PUMPKIN_STEM")) {
                    iconName = "PUMPKIN";
                } else if (iconName.equalsIgnoreCase("skull")) {
                    iconName = "SKULL_ITEM";
                } else if (iconName.equalsIgnoreCase("COCOA")) {
                    iconName = "INK_SACK:3";
                } else if (iconName.equalsIgnoreCase("NETHER_WARTS")) {
                    iconName = "NETHER_STALK";
                }
                if (StringUtils.isNumeric(iconName)) {
                    icon = new ItemStack(Integer.parseInt(iconName));
                } else {
                    icon = new ItemStack(Material.valueOf(iconName));
                }
                // Check POTION for V1.9 - for some reason, it must be declared as WATER otherwise comparison later causes an NPE
                if (icon.getType().name().contains("POTION")) {
                    if (!plugin.getServer().getVersion().contains("(MC: 1.8") && !plugin.getServer().getVersion().contains("(MC: 1.7")) {
                        PotionMeta potionMeta = (PotionMeta) icon.getItemMeta();
                        potionMeta.setBasePotionData(new PotionData(PotionType.WATER));
                        icon.setItemMeta(potionMeta);
                    }
                }
            } else if (split.length == 2) {
                if (StringUtils.isNumeric(split[0])) {
                    icon = new ItemStack(Integer.parseInt(split[0]));
                } else {
                    icon = new ItemStack(Material.valueOf(split[0]));
                }
                // Check POTION for V1.9 - for some reason, it must be declared as WATER otherwise comparison later causes an NPE
                if (icon.getType().name().contains("POTION")) {
                    if (!plugin.getServer().getVersion().contains("(MC: 1.8") && !plugin.getServer().getVersion().contains("(MC: 1.7")) {
                        PotionMeta potionMeta = (PotionMeta) icon.getItemMeta();
                        try {
                            potionMeta.setBasePotionData(new PotionData(PotionType.valueOf(split[1].toUpperCase())));
                        } catch (Exception e) {
                            plugin.getLogger().severe("Challenges icon: Potion type of " + split[1] + " is unknown, setting to WATER. Valid types are:");
                            for (PotionType type : PotionType.values()) {
                                plugin.getLogger().severe(type.name());
                            }
                            potionMeta.setBasePotionData(new PotionData(PotionType.WATER));
                        }
                        icon.setItemMeta(potionMeta);
                    }
                } else if (icon.getType().equals(Material.MONSTER_EGG)) {
                    // Handle monster egg icons
                    try {
                        EntityType type = EntityType.valueOf(split[1].toUpperCase());
                        if (Bukkit.getServer().getVersion().contains("(MC: 1.8") || Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
                            icon = new SpawnEgg(type).toItemStack();
                        } else {
                            try {
                                icon = new SpawnEgg1_9(type).toItemStack();
                            } catch (Exception ex) {
                                plugin.getLogger().severe("Monster eggs not supported with this server version.");
                            }
                        }
                    } catch (Exception e) {
                        Bukkit.getLogger().severe("Spawn eggs must be described by name. Try one of these (not all are possible):");
                        for (EntityType type : EntityType.values()) {
                            if (type.isSpawnable() && type.isAlive()) {
                                plugin.getLogger().severe(type.toString());
                            }
                        }
                    }
                } else {
                    icon.setDurability(Integer.valueOf(split[1]).shortValue());
                }
            }
        } catch (Exception e) {
            // Icon was not well formatted
            plugin.getLogger().warning("Error in challenges.yml - icon format is incorrect for " + challengeName + ":" + iconName);
            plugin.getLogger().warning("Format should be 'icon: MaterialType:Damage' where Damage is optional");
        }
    }
    if (icon == null) {
        icon = new ItemStack(Material.PAPER);
    }
    // Handle spaces (AIR icon)
    if (icon.getType() == Material.AIR) {
        return new CPItem(icon, "");
    }
    String description = ChatColor.GREEN + ChatColor.translateAlternateColorCodes('&', getChallengeConfig().getString("challenges.challengeList." + challengeName + ".friendlyname", challengeName.substring(0, 1).toUpperCase() + challengeName.substring(1)));
    // Remove extraneous info
    ItemMeta im = icon.getItemMeta();
    if (!plugin.getServer().getVersion().contains("1.7")) {
        im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        im.addItemFlags(ItemFlag.HIDE_DESTROYS);
        im.addItemFlags(ItemFlag.HIDE_PLACED_ON);
    }
    // Check if completed or not
    boolean complete = false;
    if (Settings.addCompletedGlow && plugin.getPlayers().checkChallenge(player.getUniqueId(), challengeName)) {
        // Complete! Make the icon glow
        im.addEnchant(Enchantment.ARROW_DAMAGE, 0, true);
        if (!plugin.getServer().getVersion().contains("1.7")) {
            im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        }
        complete = true;
    }
    icon.setItemMeta(im);
    boolean repeatable = false;
    if (getChallengeConfig().getBoolean("challenges.challengeList." + challengeName + ".repeatable", false)) {
        // Repeatable
        repeatable = true;
    }
    // setting Settings.removeCompleteOntimeChallenges
    if (!complete || ((complete && repeatable) || !Settings.removeCompleteOntimeChallenges)) {
        // Store the challenge panel item and the command that will be
        // called if it is activated.
        item = new CPItem(icon, description, Settings.CHALLENGECOMMAND + " c " + challengeName, null);
        // Get the challenge description, that changes depending on
        // whether the challenge is complete or not.
        List<String> lore = challengeDescription(challengeName, player);
        item.setLore(lore);
    }
    return item;
}
Also used : SpawnEgg1_9(com.wasteofplastic.acidisland.util.SpawnEgg1_9) PotionMeta(org.bukkit.inventory.meta.PotionMeta) SpawnEgg(org.bukkit.material.SpawnEgg) IOException(java.io.IOException) EntityType(org.bukkit.entity.EntityType) PotionData(org.bukkit.potion.PotionData) PotionType(org.bukkit.potion.PotionType) ItemStack(org.bukkit.inventory.ItemStack) CPItem(com.wasteofplastic.acidisland.panels.CPItem) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 57 with EntityType

use of org.bukkit.entity.EntityType in project Minigames by AddstarMC.

the class ContainsEntityCondition method displayMenu.

@Override
public boolean displayMenu(MinigamePlayer player, Menu prev) {
    Menu menu = new Menu(3, "Contians Entity", player);
    menu.addItem(new MenuItemEnum<EntityType>("Entity Type", Material.MONSTER_EGGS, entityType.getCallback(), EntityType.class));
    menu.addItem(new MenuItemNewLine());
    menu.addItem(matchName.getMenuItem("Match Display Name", Material.NAME_TAG));
    MenuItemString menuItem = (MenuItemString) customName.getMenuItem("Display Name", Material.NAME_TAG, MinigameUtils.stringToList("The name to match.;Use % to do a wildcard match"));
    menuItem.setAllowNull(true);
    menu.addItem(menuItem);
    menu.addItem(new MenuItemPage("Back", Material.REDSTONE_TORCH_ON, prev), menu.getSize() - 9);
    menu.displayMenu(player);
    return true;
}
Also used : EntityType(org.bukkit.entity.EntityType) MenuItemPage(au.com.mineauz.minigames.menu.MenuItemPage) MenuItemNewLine(au.com.mineauz.minigames.menu.MenuItemNewLine) Menu(au.com.mineauz.minigames.menu.Menu) MenuItemString(au.com.mineauz.minigames.menu.MenuItemString)

Example 58 with EntityType

use of org.bukkit.entity.EntityType in project Glowstone by GlowstoneMC.

the class SummonCommand method tabComplete.

@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");
    if (args.length == 1) {
        String arg = args[0];
        ArrayList<String> completion = new ArrayList<>();
        for (EntityType type : EntityType.values()) {
            if (checkSummon(null, type.getName()) && StringUtils.startsWithIgnoreCase(type.getName(), arg)) {
                completion.add(type.getName());
            }
        }
        EntityRegistry.getRegisteredCustomEntities().forEach((d) -> {
            if (StringUtils.startsWithIgnoreCase(d.getId(), arg))
                completion.add(d.getId().toLowerCase());
        });
        return completion;
    } else {
        return ImmutableList.of();
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) ArrayList(java.util.ArrayList)

Example 59 with EntityType

use of org.bukkit.entity.EntityType in project TotalFreedomMod by TotalFreedom.

the class Command_tossmob method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (!ConfigEntry.TOSSMOB_ENABLED.getBoolean()) {
        msg("Tossmob is currently disabled.");
        return true;
    }
    FPlayer playerData = plugin.pl.getPlayer(playerSender);
    EntityType type = null;
    if (args.length >= 1) {
        if ("off".equals(args[0])) {
            playerData.disableMobThrower();
            msg("MobThrower is disabled.", ChatColor.GREEN);
            return true;
        }
        if (args[0].equalsIgnoreCase("list")) {
            StringBuilder sb = new StringBuilder();
            for (EntityType loop : EntityType.values()) {
                if (loop.isAlive()) {
                    sb.append(" ").append(DepreciationAggregator.getName_EntityType(loop));
                }
            }
            msg("Supported mobs: " + sb.toString().trim(), ChatColor.GREEN);
            return true;
        }
        for (EntityType loopType : EntityType.values()) {
            if (DepreciationAggregator.getName_EntityType(loopType).toLowerCase().equalsIgnoreCase(args[0])) {
                type = loopType;
                break;
            }
        }
        if (type == null) {
            msg(args[0] + " is not a supported mob type. Using a pig instead.", ChatColor.RED);
            msg("By the way, you can type /tossmob list to see all possible mobs.", ChatColor.RED);
            type = EntityType.PIG;
        }
    }
    double speed = 1.0;
    if (args.length >= 2) {
        try {
            speed = Double.parseDouble(args[1]);
        } catch (NumberFormatException nfex) {
        }
    }
    if (speed < 1.0) {
        speed = 1.0;
    } else if (speed > 5.0) {
        speed = 5.0;
    }
    playerData.enableMobThrower(type, speed);
    msg("MobThrower is enabled. Creature: " + type + " - Speed: " + speed + ".", ChatColor.GREEN);
    msg("Left click while holding a " + Material.BONE.toString() + " to throw mobs!", ChatColor.GREEN);
    msg("Type '/tossmob off' to disable.  -By Madgeek1450", ChatColor.GREEN);
    playerSender.getEquipment().setItemInMainHand(new ItemStack(Material.BONE, 1));
    return true;
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) EntityType(org.bukkit.entity.EntityType) ItemStack(org.bukkit.inventory.ItemStack)

Example 60 with EntityType

use of org.bukkit.entity.EntityType in project TotalFreedomMod by TotalFreedom.

the class Command_spawnmob method run.

@Override
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length < 1) {
        return false;
    }
    EntityType type = null;
    for (EntityType loop : EntityType.values()) {
        if (loop.getName().equalsIgnoreCase(args[0])) {
            type = loop;
            break;
        }
    }
    if (type == null) {
        msg("Unknown entity type: " + args[0], ChatColor.RED);
        return true;
    }
    if (!type.isSpawnable() || !type.isAlive()) {
        msg("Can not spawn entity type: " + type.getName());
        return true;
    }
    int amount = 1;
    if (args.length > 1) {
        try {
            amount = Integer.parseInt(args[1]);
        } catch (NumberFormatException nfex) {
            msg("Invalid amount: " + args[1], ChatColor.RED);
            return true;
        }
    }
    if (amount > 10 || amount < 1) {
        msg("Invalid amount: " + args[1] + ". Must be 1-10.", ChatColor.RED);
        return true;
    }
    Location l = playerSender.getLocation();
    World w = playerSender.getWorld();
    msg("Spawning " + amount + " of " + type.getName());
    for (int i = 0; i < amount; amount++) {
        w.spawnEntity(l, type);
    }
    return true;
}
Also used : EntityType(org.bukkit.entity.EntityType) World(org.bukkit.World) Location(org.bukkit.Location)

Aggregations

EntityType (org.bukkit.entity.EntityType)109 ArrayList (java.util.ArrayList)29 ItemStack (org.bukkit.inventory.ItemStack)28 Material (org.bukkit.Material)23 Player (org.bukkit.entity.Player)23 Entity (org.bukkit.entity.Entity)19 Location (org.bukkit.Location)17 IOException (java.io.IOException)16 File (java.io.File)13 LivingEntity (org.bukkit.entity.LivingEntity)13 EventHandler (org.bukkit.event.EventHandler)12 PotionType (org.bukkit.potion.PotionType)12 HashMap (java.util.HashMap)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 Block (org.bukkit.block.Block)8 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)8 World (org.bukkit.World)7 SpawnEgg (org.bukkit.material.SpawnEgg)7 UUID (java.util.UUID)5 Biome (org.bukkit.block.Biome)5