Search in sources :

Example 41 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class EntityData method load.

protected void load(@Nonnull MageController controller, ConfigurationSection parameters) {
    name = parameters.getString("name");
    if (name != null) {
        name = ChatColor.translateAlternateColorCodes('&', name);
    }
    if (parameters.contains("health")) {
        health = parameters.getDouble("health", 1);
        maxHealth = health;
    }
    if (parameters.contains("max_health")) {
        maxHealth = parameters.getDouble("max_health", 1);
    }
    isSilent = parameters.getBoolean("silent", false);
    String entityName = parameters.getString("type");
    if (entityName != null) {
        type = parseEntityType(entityName);
        if (type == null) {
            controller.getLogger().log(Level.WARNING, " Invalid entity type: " + entityName);
        }
    }
    disguise = ConfigurationUtils.getConfigurationSection(parameters, "disguise");
    isTamed = parameters.getBoolean("tamed", false);
    isBaby = parameters.getBoolean("baby", false);
    hasAI = parameters.getBoolean("ai", true);
    potionEffects = ConfigurationUtils.getPotionEffectObjects(parameters, "potion_effects", controller.getLogger());
    hasPotionEffects = potionEffects != null && !potionEffects.isEmpty();
    defaultDrops = parameters.getBoolean("default_drops", true);
    if (parameters.contains("xp")) {
        xp = parameters.getInt("xp");
    }
    if (parameters.contains("drop_xp")) {
        dropXp = parameters.getInt("drop_xp");
    }
    interactSpell = parameters.getString("interact_spell");
    drops = ConfigurationUtils.getStringList(parameters, "drops");
    List<String> tagList = ConfigurationUtils.getStringList(parameters, "tags");
    if (tagList != null) {
        tags = new HashSet<>(tagList);
    }
    try {
        if (type == EntityType.HORSE) {
            extraData = new EntityHorseData(parameters, controller);
        } else if (type == EntityType.VILLAGER) {
            extraData = new EntityVillagerData(parameters, controller);
        } else if (type == EntityType.AREA_EFFECT_CLOUD) {
            extraData = new EntityAreaEffectCloudData(parameters, controller);
        } else if (type == EntityType.OCELOT && parameters.contains("ocelot_type")) {
            ocelotType = Ocelot.Type.valueOf(parameters.getString("ocelot_type").toUpperCase());
        } else if (type == EntityType.RABBIT && parameters.contains("rabbit_type")) {
            rabbitType = Rabbit.Type.valueOf(parameters.getString("rabbit_type").toUpperCase());
        } else if (type == EntityType.ZOMBIE || type == EntityType.PIG_ZOMBIE) {
            EntityZombieData zombieData = new EntityZombieData();
            zombieData.isBaby = isBaby;
            extraData = zombieData;
        } else if (type == EntityType.ARMOR_STAND) {
            extraData = new EntityArmorStandData(parameters);
        } else if (type == EntityType.SLIME || type == EntityType.MAGMA_CUBE) {
            EntitySlimeData slimeData = new EntitySlimeData();
            slimeData.size = parameters.getInt("size", 16);
            extraData = slimeData;
        }
    } catch (Exception ex) {
        controller.getLogger().log(Level.WARNING, "Invalid entity type or sub-type", ex);
    }
    ConfigurationSection attributeConfiguration = ConfigurationUtils.getConfigurationSection(parameters, "entity_attributes");
    // Migrate old attributes
    ConfigurationSection migrateAttributes = ConfigurationUtils.getConfigurationSection(parameters, "attributes");
    if (migrateAttributes != null) {
        boolean nagged = false;
        Set<String> keys = migrateAttributes.getKeys(false);
        for (String attributeKey : keys) {
            try {
                Attribute.valueOf(attributeKey.toUpperCase());
            } catch (IllegalArgumentException ignored) {
                continue;
            }
            if (attributeConfiguration == null) {
                attributeConfiguration = parameters.createSection("entity_attributes");
            }
            attributeConfiguration.set(attributeKey, migrateAttributes.get(attributeKey));
            parameters.set("attributes", null);
            if (key != null && !nagged) {
                controller.getLogger().warning("You have vanilla entity attributes in the 'attributes' property of mob template '" + key + "', please rename that to entity_attributes.");
                nagged = true;
            }
        }
    }
    if (attributeConfiguration != null) {
        Set<String> keys = attributeConfiguration.getKeys(false);
        if (keys.size() > 0) {
            attributes = new HashMap<>();
        }
        for (String attributeKey : keys) {
            try {
                Attribute attribute = Attribute.valueOf(attributeKey.toUpperCase());
                attributes.put(attribute, attributeConfiguration.getDouble(attributeKey));
            } catch (Exception ex) {
                controller.getLogger().log(Level.WARNING, "Invalid attribute type: " + attributeKey, ex);
            }
        }
    }
    MaterialAndData itemData = ConfigurationUtils.getMaterialAndData(parameters, "item");
    item = itemData == null ? null : itemData.getItemStack(parameters.getInt("amount", 1));
    itemInHand = controller.getOrCreateItem(parameters.getString("item"));
    helmet = controller.getOrCreateItem(parameters.getString("helmet"));
    chestplate = controller.getOrCreateItem(parameters.getString("chestplate"));
    leggings = controller.getOrCreateItem(parameters.getString("leggings"));
    boots = controller.getOrCreateItem(parameters.getString("boots"));
    canPickupItems = parameters.getBoolean("can_pickup_items", false);
    EntityMageData mageData = new EntityMageData(controller, parameters);
    if (!mageData.isEmpty()) {
        this.mageData = mageData;
    }
}
Also used : Attribute(org.bukkit.attribute.Attribute) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 42 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class PlayerController method loadProperties.

public void loadProperties(ConfigurationSection properties) {
    clickCooldown = properties.getInt("click_cooldown", 0);
    enableCreativeModeEjecting = properties.getBoolean("enable_creative_mode_ejecting", false);
    enchantBlockMaterial = new MaterialAndData(properties.getString("enchant_block", "enchantment_table"));
    enchantClickSpell = properties.getString("enchant_click");
    enchantSneakClickSpell = properties.getString("enchant_sneak_click");
    cancelInteractOnLeftClick = properties.getBoolean("cancel_interact_on_left_click", true);
    cancelInteractOnRightClick = properties.getBoolean("cancel_interact_on_right_click", false);
    allowOffhandCasting = properties.getBoolean("allow_offhand_casting", true);
}
Also used : MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData)

Example 43 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class WandCommandExecutor method onWandDescribe.

public boolean onWandDescribe(CommandSender sender, Player player, String[] parameters) {
    // Force-save wand data so it is up to date
    Mage mage = controller.getMage(player);
    Wand activeWand = mage.getActiveWand();
    if (activeWand != null) {
        activeWand.saveState();
    }
    ItemStack itemInHand = player.getInventory().getItemInMainHand();
    if (itemInHand == null) {
        if (sender != player) {
            sender.sendMessage(api.getMessages().getParameterized("wand.player_no_item", "$name", player.getName()));
        } else {
            player.sendMessage(api.getMessages().get("wand.no_item"));
        }
        return true;
    }
    if (api.isSpell(itemInHand)) {
        String spellKey = api.getSpell(itemInHand);
        sender.sendMessage(ChatColor.GOLD + "Spell: " + spellKey);
        SpellTemplate spell = api.getSpellTemplate(spellKey);
        if (spell != null) {
            sender.sendMessage(" " + ChatColor.GOLD + spell.getName());
        } else {
            sender.sendMessage(ChatColor.RED + " (Unknown Spell)");
        }
    } else if (api.isBrush(itemInHand)) {
        String brushKey = api.getBrush(itemInHand);
        sender.sendMessage(ChatColor.GRAY + "Brush: " + brushKey);
        MaterialAndData brush = new MaterialAndData(brushKey);
        sender.sendMessage(" " + ChatColor.GRAY + brush.getName());
    } else if (api.isWand(itemInHand) || api.isUpgrade(itemInHand)) {
        Wand wand = api.getWand(itemInHand);
        if (parameters.length == 0) {
            sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/wand describe <property>" + ChatColor.BLUE + " for specific properties");
            wand.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
        } else {
            Object property = wand.getProperty(parameters[0]);
            if (property == null) {
                sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)");
            } else {
                sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.WHITE + InventoryUtils.describeProperty(property));
            }
        }
    } else {
        sender.sendMessage(ChatColor.RED + "That is not a magic item");
    }
    return true;
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ItemStack(org.bukkit.inventory.ItemStack) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 44 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class TargetingSpell method getMessage.

@Override
public String getMessage(String messageKey, String def) {
    String message = super.getMessage(messageKey, def);
    // Escape targeting parameters
    String useTargetName = null;
    if (currentCast != null) {
        useTargetName = currentCast.getTargetName();
    }
    if (useTargetName == null) {
        Target target = targeting.getTarget();
        if (target != null) {
            if (target.hasEntity() && getTargetType() != TargetType.BLOCK) {
                useTargetName = controller.getEntityDisplayName(target.getEntity());
            } else if (target.isValid() && getTargetType() != TargetType.OTHER_ENTITY && getTargetType() != TargetType.ANY_ENTITY) {
                MaterialAndData material = target.getTargetedMaterial();
                if (material != null) {
                    useTargetName = material.getName();
                }
            }
        }
    }
    if (useTargetName == null) {
        message = message.replace("$target", "Nothing");
    } else {
        message = message.replace("$target", useTargetName);
    }
    return message;
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData)

Example 45 with MaterialAndData

use of com.elmakers.mine.bukkit.block.MaterialAndData in project MagicPlugin by elBukkit.

the class TargetingSpell method getEffectMaterial.

@Nullable
@Override
public com.elmakers.mine.bukkit.api.block.MaterialAndData getEffectMaterial() {
    Target target = targeting.getTarget();
    if (target != null && target.isValid()) {
        Block block = target.getBlock();
        MaterialAndData targetMaterial = new MaterialAndData(block);
        if (targetMaterial.getMaterial() == Material.AIR) {
            targetMaterial.setMaterial(DEFAULT_EFFECT_MATERIAL);
        }
        return targetMaterial;
    }
    return super.getEffectMaterial();
}
Also used : Target(com.elmakers.mine.bukkit.utility.Target) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block) Nullable(javax.annotation.Nullable)

Aggregations

MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)47 Block (org.bukkit.block.Block)20 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)10 Material (org.bukkit.Material)8 Nullable (javax.annotation.Nullable)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 Target (com.elmakers.mine.bukkit.utility.Target)5 Player (org.bukkit.entity.Player)5 MageController (com.elmakers.mine.bukkit.api.magic.MageController)4 Wand (com.elmakers.mine.bukkit.api.wand.Wand)4 List (java.util.List)4 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)3 MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)3 IOException (java.io.IOException)3 Location (org.bukkit.Location)3 CurrencyItem (com.elmakers.mine.bukkit.api.block.CurrencyItem)2 ParseException (java.text.ParseException)2