Search in sources :

Example 1 with HeadDatabaseAPI

use of me.arcaniax.hdb.api.HeadDatabaseAPI in project ItemJoin by RockinChaos.

the class Menu method headerStack.

/**
 * Gets the Header ItemStack.
 *
 * @param player - The player getting the Header Stack.
 * @param itemMap - The ItemMap to be formatted.
 * @return The formatted Header ItemStack.
 */
private static ItemStack headerStack(final Player player, final ItemMap itemMap) {
    String slotList = "";
    String slotString = "";
    ItemStack item = new ItemStack(Material.STONE);
    if (StringUtils.nullCheck(itemMap.getMultipleSlots().toString()) != "NONE") {
        for (String slot : itemMap.getMultipleSlots()) {
            slotString += slot + ", ";
        }
        if (slotString.length() >= 2) {
            for (String split : StringUtils.softSplit(StringUtils.nullCheck(slotString.substring(0, slotString.length() - 2)))) {
                slotList += "&a" + split + " /n ";
            }
        }
    }
    String itemflagsList = "";
    if (StringUtils.nullCheck(itemMap.getItemFlags()) != "NONE") {
        for (String split : StringUtils.softSplit(itemMap.getItemFlags())) {
            itemflagsList += "&a" + split + " /n ";
        }
    }
    String triggersList = "";
    if (StringUtils.nullCheck(itemMap.getTriggers()) != "NONE") {
        for (String split : StringUtils.softSplit(itemMap.getTriggers())) {
            triggersList += "&a" + split + " /n ";
        }
    }
    String disabledList = "";
    if (StringUtils.nullCheck(itemMap.getDisabledWorlds().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getDisabledWorlds().toString()))) {
            disabledList += "&a" + split + " /n ";
        }
    }
    String enabledList = "";
    if (StringUtils.nullCheck(itemMap.getEnabledWorlds().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getEnabledWorlds().toString()))) {
            enabledList += "&a" + split + " /n ";
        }
    }
    String regionList = "";
    if (StringUtils.nullCheck(itemMap.getEnabledRegions().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getEnabledRegions().toString()))) {
            regionList += "&a" + split + " /n ";
        }
    }
    String enchantList = "";
    if (StringUtils.nullCheck(itemMap.getEnchantments().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getEnchantments().toString()))) {
            enchantList += "&a" + split + " /n ";
        }
    }
    String potionList = "";
    String potionString = "";
    if (StringUtils.nullCheck(itemMap.getPotionEffect().toString()) != "NONE") {
        for (PotionEffect potions : itemMap.getPotionEffect()) {
            potionString += potions.getType().getName().toUpperCase() + ":" + potions.getAmplifier() + ":" + potions.getDuration() + ", ";
        }
        if (potionString.length() >= 2) {
            for (String split : StringUtils.softSplit(StringUtils.nullCheck(potionString.substring(0, potionString.length() - 2)))) {
                potionList += "&a" + split + " /n ";
            }
        }
    }
    String attributeList = "";
    String attributeString = "";
    if (StringUtils.nullCheck(itemMap.getAttributes().toString()) != "NONE") {
        for (String attribute : itemMap.getAttributes().keySet()) {
            attributeString += attribute + ":" + itemMap.getAttributes().get(attribute) + ", ";
        }
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(attributeString.substring(0, attributeString.length())))) {
            attributeList += "&a" + split + " /n ";
        }
    }
    String patternList = "";
    String patternString = "";
    if (ServerUtils.hasSpecificUpdate("1_8") && StringUtils.nullCheck(itemMap.getBannerPatterns().toString()) != "NONE") {
        for (Pattern patterns : itemMap.getBannerPatterns()) {
            patternString += patterns.getColor() + ":" + patterns.getPattern().name().toUpperCase() + ", ";
        }
        if (patternString.length() >= 2) {
            for (String split : StringUtils.softSplit(StringUtils.nullCheck(patternString.substring(0, patternString.length() - 2)))) {
                patternList += "&a" + split + " /n ";
            }
        }
    }
    String colorList = "";
    if (StringUtils.nullCheck(itemMap.getFireworkColor().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getFireworkColor().toString()))) {
            colorList += "&a" + split + " /n ";
        }
    }
    boolean useCommands = true;
    if (itemMap.getCommands().length == 1) {
        for (ItemCommand command : itemMap.getCommands()) {
            if (command.getRawCommand().equalsIgnoreCase("default: ")) {
                useCommands = false;
            }
        }
    } else if (itemMap.getCommands().length == 0) {
        useCommands = false;
    }
    boolean useToggle = itemMap.getToggleCommands() != null && !itemMap.getToggleCommands().isEmpty();
    String mobs = "";
    for (EntityType entity : itemMap.getMobsDrop().keySet()) {
        mobs += entity.name() + ", ";
    }
    String blocks = "";
    for (Material material : itemMap.getBlocksDrop().keySet()) {
        blocks += material.name() + ", ";
    }
    try {
        item = ItemHandler.getItem(itemMap.getMaterial().toString() + ((itemMap.getDataValue() != null && itemMap.getDataValue() != 0) ? ":" + itemMap.getDataValue() : ""), 1, false, "&7*&6&l&nItem Information", "&7", "&9&lNode: &a" + itemMap.getConfigName(), "&9&lMaterial: &a" + itemMap.getMaterial().toString() + ((itemMap.getDataValue() != null && itemMap.getDataValue() != 0) ? ":" + itemMap.getDataValue() : ""), (itemMap.getMultipleSlots() != null && !itemMap.getMultipleSlots().isEmpty() ? "&9&lSlot(s): &a" + slotList : "&9&lSlot: &a" + itemMap.getSlot().toUpperCase()), (itemMap.getCount(player) != 1 && itemMap.getCount(player) != 0) ? "&9&lCount: &a" + itemMap.getCount(player) : "", ((StringUtils.nullCheck(itemMap.getCustomName()) != "NONE" && !ItemHandler.getMaterialName(itemMap.getTempItem()).equalsIgnoreCase(itemMap.getCustomName())) ? "&9&lName: &a" + itemMap.getCustomName() : ""), (StringUtils.nullCheck(itemMap.getCustomLore().toString()) != "NONE" ? "&9&lLore: &a" + (StringUtils.nullCheck(itemMap.getCustomLore().toString()).replace(",,", ",").replace(", ,", ",").length() > 40 ? StringUtils.nullCheck(itemMap.getCustomLore().toString()).replace(",,", ",").replace(", ,", ",").substring(0, 40) : StringUtils.nullCheck(itemMap.getCustomLore().toString()).replace(",,", ",").replace(", ,", ",")) : ""), (StringUtils.nullCheck(itemMap.getDurability() + "&7") != "NONE" ? "&9&lDurability: &a" + itemMap.getDurability() : ""), (StringUtils.nullCheck(itemMap.getData() + "&7") != "NONE" ? "&9&lTexture Data: &a" + itemMap.getData() : ""), (useCommands ? "&9&lCommands: &aYES" : ""), (useToggle ? "&9&lTogglable: &aYES" : ""), (StringUtils.nullCheck(itemMap.getItemCost() + "") != "NONE" ? "&9&lCommands-Item: &a" + itemMap.getItemCost() : ""), (StringUtils.nullCheck(itemMap.getCommandCost() + "&7") != "NONE" ? "&9&lCommands-Cost: &a" + itemMap.getCommandCost() : ""), (StringUtils.nullCheck(itemMap.getCommandReceive() + "&7") != "NONE" ? "&9&lCommands-Receive: &a" + itemMap.getCommandReceive() : ""), (StringUtils.nullCheck(itemMap.getCommandSequence() + "") != "NONE" ? "&9&lCommands-Sequence: &a" + itemMap.getCommandSequence() : ""), (StringUtils.nullCheck(itemMap.getCommandCooldown() + "&7") != "NONE" ? "&9&lCommands-Cooldown: &a" + itemMap.getCommandCooldown() + " second(s)" : ""), (StringUtils.nullCheck(itemMap.getCooldownMessage()) != "NONE" ? "&9&lCooldown-Message: &a" + itemMap.getCooldownMessage() : ""), (StringUtils.nullCheck(itemMap.getCommandSound() + "") != "NONE" ? "&9&lCommands-Sound: &a" + itemMap.getCommandSound() : ""), (StringUtils.nullCheck(itemMap.getCommandParticle() + "") != "NONE" ? "&9&lCommands-Particle: &a" + itemMap.getCommandParticle() : ""), (StringUtils.nullCheck(itemMap.getEnchantments().toString()) != "NONE" ? "&9&lEnchantments: &a" + enchantList : ""), (StringUtils.nullCheck(itemMap.getItemFlags()) != "NONE" ? "&9&lItemflags: &a" + itemflagsList : ""), (StringUtils.nullCheck(itemMap.getTriggers()) != "NONE" ? "&9&lTriggers: &a" + triggersList : ""), (StringUtils.nullCheck(itemMap.getPermissionNode()) != "NONE" ? "&9&lPermission Node: &a" + itemMap.getPermissionNode() : ""), (StringUtils.nullCheck(itemMap.getDisabledWorlds().toString()) != "NONE" ? "&9&lDisabled Worlds: &a" + disabledList : ""), (StringUtils.nullCheck(itemMap.getEnabledWorlds().toString()) != "NONE" ? "&9&lEnabled Worlds: &a" + enabledList : ""), (StringUtils.nullCheck(itemMap.getEnabledRegions().toString()) != "NONE" ? "&9&lEnabled Regions: &a" + regionList : ""), (!itemMap.getDynamicMaterials().isEmpty() ? "&9&lMaterial Animations: &aYES" : ""), (!itemMap.getDynamicNames().isEmpty() ? "&9&lName Animations: &aYES" : ""), (!itemMap.getDynamicLores().isEmpty() ? "&9&lLore Animations: &aYES" : ""), (!itemMap.getDynamicOwners().isEmpty() || !itemMap.getDynamicTextures().isEmpty() ? "&9&lSkull Animations: &aYES" : ""), (StringUtils.nullCheck(itemMap.getLimitModes()) != "NONE" ? "&9&lLimit-Modes: &a" + itemMap.getLimitModes() : ""), (StringUtils.nullCheck(itemMap.getProbability() + "&a%") != "NONE" ? "&9&lProbability: &a" + itemMap.getProbability() + "%" : ""), (StringUtils.nullCheck(itemMap.getInteractCooldown() + "&7") != "NONE" ? "&9&lUse-Cooldown: &a" + itemMap.getInteractCooldown() : ""), (StringUtils.nullCheck(itemMap.getLeatherColor()) != "NONE" ? "&9&lLeather Color: &a" + itemMap.getLeatherColor() : ""), (StringUtils.nullCheck(itemMap.getLeatherHex()) != "NONE" ? "&9&lLeather Color: &a" + itemMap.getLeatherHex() : ""), (StringUtils.nullCheck(itemMap.getMapImage()) != "NONE" ? "&9&lMap-Image: &a" + itemMap.getMapImage() : ""), (StringUtils.nullCheck(itemMap.getChargeColor() + "") != "NONE" ? "&9&lCharge Color: &a" + itemMap.getChargeColor() : ""), (StringUtils.nullCheck(patternList) != "NONE" ? "&9&lBanner Meta: &a" + patternList : ""), (StringUtils.nullCheck(potionList) != "NONE" ? "&9&lPotion-Effects: &a" + potionList : ""), (itemMap.getIngredients() != null && !itemMap.getIngredients().isEmpty() ? "&9&lRecipe: &aYES" : ""), (!mobs.isEmpty() ? "&9&lMobs Drop: &a" + mobs.substring(0, mobs.length() - 2) : ""), (!blocks.isEmpty() ? "&9&lBlocks Drop: &a" + blocks.substring(0, blocks.length() - 2) : ""), (StringUtils.nullCheck(itemMap.getCommandConditions() + "") != "NONE" ? "&9&lCommand Conditions: &aYES" : ""), (StringUtils.nullCheck(itemMap.getDisposableConditions() + "") != "NONE" ? "&9&lDisposable Conditions: &aYES" : ""), (StringUtils.nullCheck(itemMap.getTriggerConditions() + "") != "NONE" ? "&9&lTrigger Conditions: &aYES" : ""), (StringUtils.nullCheck(itemMap.getNBTValues() + "") != "NONE" ? "&9&lNBT Properties: &aYES" : ""), (StringUtils.nullCheck(itemMap.getContents() + "") != "NONE" ? "&9&lContents: &aYES" : ""), (StringUtils.nullCheck(attributeList) != "NONE" ? "&9&lAttributes: &a" + attributeList : ""), (StringUtils.nullCheck(itemMap.getPages() + "") != "NONE" ? "&9&lBook Pages: &aYES" : ""), (StringUtils.nullCheck(itemMap.getAuthor()) != "NONE" ? "&9&lBook Author: &a" + itemMap.getAuthor() : ""), (StringUtils.nullCheck(itemMap.getSkull()) != "NONE" ? "&9&lSkull-Owner: &a" + itemMap.getSkull() : ""), (StringUtils.nullCheck(itemMap.getSkullTexture()) != "NONE" ? "&9&lSkull-Texture: &a" + (itemMap.getSkullTexture().length() > 40 ? itemMap.getSkullTexture().substring(0, 40) : itemMap.getSkullTexture()) : ""), (StringUtils.nullCheck(itemMap.getFireworkType() + "") != "NONE" ? "&9&lFirework Type: &a" + itemMap.getFireworkType().name() : ""), (StringUtils.nullCheck(itemMap.getFireworkPower() + "&7") != "NONE" ? "&9&lFirework Power: &a" + itemMap.getFireworkPower() : ""), (StringUtils.nullCheck(colorList) != "NONE" ? "&9&lFirework Color(s): &a" + colorList : ""), (itemMap.getFireworkTrail() ? "&9&lFirework Trail: &aENABLED" : ""), (itemMap.getFireworkFlicker() ? "&9&lFirework Flicker: &aENABLED" : ""));
    } catch (Exception e) {
        ServerUtils.sendDebugTrace(e);
    }
    if (ItemHandler.isSkull(itemMap.getMaterial())) {
        ItemMeta itemMeta = item.getItemMeta();
        if (itemMap.getSkull() != null) {
            itemMeta = ItemHandler.setSkullOwner(itemMeta, StringUtils.translateLayout(itemMap.getSkull(), player));
        } else if (itemMap.getSkullTexture() != null && !itemMap.isHeadDatabase()) {
            try {
                if (ServerUtils.hasSpecificUpdate("1_8")) {
                    GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
                    gameProfile.getProperties().put("textures", new Property("textures", new String(itemMap.getSkullTexture())));
                    Field declaredField = itemMeta.getClass().getDeclaredField("profile");
                    declaredField.setAccessible(true);
                    declaredField.set(itemMeta, gameProfile);
                }
            } catch (Exception e) {
                ServerUtils.sendDebugTrace(e);
            }
        } else if (itemMap.isHeadDatabase() && itemMap.getSkullTexture() != null) {
            HeadDatabaseAPI api = new HeadDatabaseAPI();
            ItemStack sk = api.getItemHead(itemMap.getSkullTexture());
            item = (sk != null ? sk : item.clone());
        }
        item.setItemMeta(itemMeta);
    }
    return item;
}
Also used : Pattern(org.bukkit.block.banner.Pattern) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) PotionEffect(org.bukkit.potion.PotionEffect) Material(org.bukkit.Material) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) EntityType(org.bukkit.entity.EntityType) Field(java.lang.reflect.Field) GameProfile(com.mojang.authlib.GameProfile) ItemStack(org.bukkit.inventory.ItemStack) Property(com.mojang.authlib.properties.Property) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 2 with HeadDatabaseAPI

use of me.arcaniax.hdb.api.HeadDatabaseAPI in project ItemJoin by RockinChaos.

the class ItemMap method setSkullDatabase.

/**
 * Sets the Skull Database Textures.
 */
private void setSkullDatabase() {
    if (this.headDatabase && this.skullTexture != null) {
        HeadDatabaseAPI api = new HeadDatabaseAPI();
        ItemStack sk = api.getItemHead(this.skullTexture);
        this.tempItem = (sk != null ? sk : this.tempItem.clone());
    }
}
Also used : HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

HeadDatabaseAPI (me.arcaniax.hdb.api.HeadDatabaseAPI)2 ItemStack (org.bukkit.inventory.ItemStack)2 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 Field (java.lang.reflect.Field)1 ItemCommand (me.RockinChaos.itemjoin.item.ItemCommand)1 Material (org.bukkit.Material)1 Pattern (org.bukkit.block.banner.Pattern)1 EntityType (org.bukkit.entity.EntityType)1 ItemMeta (org.bukkit.inventory.meta.ItemMeta)1 PotionEffect (org.bukkit.potion.PotionEffect)1