Search in sources :

Example 16 with EntityType

use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.

the class MagicController method spawnMob.

@Nullable
@Override
public Entity spawnMob(String key, Location location) {
    EntityData mobType = mobs.get(key);
    if (mobType != null) {
        return mobType.spawn(this, location);
    }
    EntityType entityType = com.elmakers.mine.bukkit.entity.EntityData.parseEntityType(key);
    if (entityType == null) {
        return null;
    }
    return location.getWorld().spawnEntity(location, entityType);
}
Also used : EntityType(org.bukkit.entity.EntityType) EntityData(com.elmakers.mine.bukkit.api.entity.EntityData) Nullable(javax.annotation.Nullable)

Example 17 with EntityType

use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.

the class CycleEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    EntityType entityType = entity.getType();
    Mage mage = context.getMage();
    switch(entityType) {
        case PAINTING:
            context.registerModified(entity);
            Painting painting = (Painting) entity;
            Art[] artValues = Art.values();
            Art oldArt = painting.getArt();
            Art newArt = oldArt;
            int ordinal = (oldArt.ordinal() + 1);
            for (int i = 0; i < artValues.length; i++) {
                newArt = artValues[ordinal++ % artValues.length];
                painting.setArt(newArt);
                newArt = painting.getArt();
                if (oldArt != newArt) {
                    break;
                }
            }
            if (oldArt == newArt) {
                return SpellResult.FAIL;
            }
            mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
            break;
        case ITEM_FRAME:
            ItemFrame itemFrame = (ItemFrame) entity;
            ItemStack frameItem = itemFrame.getItem();
            if (frameItem == null || frameItem.getType() != Material.MAP) {
                return SpellResult.NO_TARGET;
            }
            short data = frameItem.getDurability();
            data++;
            MapView mapView = DeprecatedUtils.getMap(data);
            if (mapView == null) {
                data = 0;
                mapView = DeprecatedUtils.getMap(data);
                if (mapView == null) {
                    return SpellResult.NO_TARGET;
                }
            }
            context.registerModified(entity);
            frameItem.setDurability(data);
            itemFrame.setItem(frameItem);
            break;
        case HORSE:
            context.registerModified(entity);
            Horse horse = (Horse) entity;
            Horse.Color color = horse.getColor();
            Horse.Color[] colorValues = Horse.Color.values();
            color = colorValues[(color.ordinal() + 1) % colorValues.length];
            Horse.Style horseStyle = horse.getStyle();
            Horse.Style[] styleValues = Horse.Style.values();
            horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];
            horse.setStyle(horseStyle);
            horse.setColor(color);
            break;
        case OCELOT:
            context.registerModified(entity);
            Ocelot ocelot = (Ocelot) entity;
            Ocelot.Type catType = ocelot.getCatType();
            Ocelot.Type[] typeValues = Ocelot.Type.values();
            catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
            ocelot.setCatType(catType);
            break;
        case VILLAGER:
            context.registerModified(entity);
            Villager villager = (Villager) entity;
            Villager.Profession profession = villager.getProfession();
            Villager.Profession[] professionValues = Villager.Profession.values();
            int villagerOrdinal = (profession.ordinal() + 1) % professionValues.length;
            // Special-cases for zombie-reserved professions
            if (villagerOrdinal == 0 || villagerOrdinal == 7) {
                villagerOrdinal = 1;
            }
            profession = professionValues[villagerOrdinal];
            villager.setProfession(profession);
            break;
        case WOLF:
            context.registerModified(entity);
            Wolf wolf = (Wolf) entity;
            DyeColor wolfColor = wolf.getCollarColor();
            DyeColor[] wolfColorValues = DyeColor.values();
            wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
            wolf.setCollarColor(wolfColor);
            break;
        case SHEEP:
            context.registerModified(entity);
            Sheep sheep = (Sheep) entity;
            DyeColor dyeColor = sheep.getColor();
            DyeColor[] dyeColorValues = DyeColor.values();
            dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
            sheep.setColor(dyeColor);
            break;
        default:
            return SpellResult.NO_TARGET;
    }
    ;
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) Art(org.bukkit.Art) ItemFrame(org.bukkit.entity.ItemFrame) Horse(org.bukkit.entity.Horse) Villager(org.bukkit.entity.Villager) MapView(org.bukkit.map.MapView) Wolf(org.bukkit.entity.Wolf) DyeColor(org.bukkit.DyeColor) DyeColor(org.bukkit.DyeColor) Painting(org.bukkit.entity.Painting) EntityType(org.bukkit.entity.EntityType) Ocelot(org.bukkit.entity.Ocelot) EntityType(org.bukkit.entity.EntityType) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack)

Example 18 with EntityType

use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.

the class HitboxUtils method configureHeadSizes.

public static void configureHeadSizes(ConfigurationSection config) {
    headSizes.clear();
    Collection<String> keys = config.getKeys(false);
    for (String key : keys) {
        try {
            double size = config.getDouble(key);
            EntityType entityType = EntityType.valueOf(key.toUpperCase());
            if (size > 0) {
                headSizes.put(entityType, size);
            }
        } catch (Exception ex) {
            org.bukkit.Bukkit.getLogger().log(Level.WARNING, "Invalid entity type in head size definition: " + key, ex);
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType)

Example 19 with EntityType

use of org.bukkit.entity.EntityType in project MagicPlugin by elBukkit.

the class HitboxUtils method configureHitboxes.

public static void configureHitboxes(ConfigurationSection config) {
    hitboxes.clear();
    Collection<String> keys = config.getKeys(false);
    for (String key : keys) {
        try {
            Vector bounds = ConfigurationUtils.getVector(config, key);
            String upperKey = key.toUpperCase();
            double halfX = bounds.getX() / 2;
            double halfZ = bounds.getZ() / 2;
            BoundingBox bb = new BoundingBox(-halfX, halfX, 0, bounds.getY(), -halfZ, halfZ).scaleFromBase(hitboxScale, hitboxScaleY);
            if (upperKey.equals("DEFAULT")) {
                defaultHitbox = bb;
                continue;
            }
            EntityType entityType = EntityType.valueOf(upperKey);
            hitboxes.put(entityType, bb);
        } catch (Exception ex) {
            org.bukkit.Bukkit.getLogger().log(Level.WARNING, "Invalid entity type in hitbox definition: " + key, ex);
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Vector(org.bukkit.util.Vector)

Example 20 with EntityType

use of org.bukkit.entity.EntityType in project TokenManager by RealizedMC.

the class ItemUtil method loadFromString.

public static ItemStack loadFromString(final String line) {
    if (line == null || line.isEmpty()) {
        throw new IllegalArgumentException("Line is empty or null!");
    }
    final String[] args = line.split(" +");
    final String[] materialData = args[0].split(":");
    final Material material = Material.matchMaterial(materialData[0]);
    if (material == null) {
        throw new IllegalArgumentException("'" + args[0] + "' is not a valid material.");
    }
    ItemStack result = new ItemStack(material, 1);
    if (materialData.length > 1) {
        // Handle potions and spawn eggs switching to NBT in 1.9+
        if (!ItemUtil.isPre1_9()) {
            if (material.name().contains("POTION")) {
                final String[] values = materialData[1].split("-");
                final PotionType type;
                if ((type = EnumUtil.getByName(values[0], PotionType.class)) == null) {
                    throw new IllegalArgumentException("'" + values[0] + "' is not a valid PotionType. Available: " + EnumUtil.getNames(PotionType.class));
                }
                result = new Potions(type, Arrays.asList(values)).toItemStack();
            } else if (material == Material.MONSTER_EGG) {
                final EntityType type;
                if ((type = EnumUtil.getByName(materialData[1], EntityType.class)) == null) {
                    throw new IllegalArgumentException("'" + materialData[0] + "' is not a valid EntityType. Available: " + EnumUtil.getNames(EntityType.class));
                }
                result = new SpawnEggs(type).toItemStack();
            }
        }
        final OptionalLong value;
        if ((value = NumberUtil.parseLong(materialData[1])).isPresent()) {
            result.setDurability((short) value.getAsLong());
        }
    }
    if (args.length < 2) {
        return result;
    }
    result.setAmount(Integer.parseInt(args[1]));
    if (args.length > 2) {
        for (int i = 2; i < args.length; i++) {
            final String argument = args[i];
            final String[] pair = argument.split(":", 2);
            if (pair.length < 2) {
                continue;
            }
            applyMeta(result, pair[0], pair[1]);
        }
    }
    return result;
}
Also used : Potions(me.realized.tokenmanager.util.compat.Potions) EntityType(org.bukkit.entity.EntityType) SpawnEggs(me.realized.tokenmanager.util.compat.SpawnEggs) OptionalLong(java.util.OptionalLong) Material(org.bukkit.Material) PotionType(org.bukkit.potion.PotionType) ItemStack(org.bukkit.inventory.ItemStack)

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