Search in sources :

Example 16 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project solinia3-core by mixxit.

the class ItemStackUtils method ConvertItemStackToJsonRegular.

public static String ConvertItemStackToJsonRegular(ItemStack itemStack) {
    // First we convert the item stack into an NMS itemstack
    net.minecraft.server.v1_15_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound compound = new NBTTagCompound();
    compound = nmsItemStack.save(compound);
    return compound.toString();
}
Also used : NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound)

Example 17 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project solinia3-core by mixxit.

the class ItemStackUtils method getWeaponDamageFromItemStack.

public static int getWeaponDamageFromItemStack(ItemStack itemStack, EnumItemSlot itemSlot) {
    double attackDamage = 1.0;
    UUID uuid = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
    net.minecraft.server.v1_15_R1.ItemStack craftItemStack = CraftItemStack.asNMSCopy(itemStack);
    net.minecraft.server.v1_15_R1.Item item = craftItemStack.getItem();
    if (item instanceof net.minecraft.server.v1_15_R1.ItemSword || item instanceof net.minecraft.server.v1_15_R1.ItemTool || item instanceof net.minecraft.server.v1_15_R1.ItemHoe) {
        Multimap<String, AttributeModifier> map = item.a(itemSlot);
        Collection<AttributeModifier> attributes = map.get(GenericAttributes.ATTACK_DAMAGE.getName());
        if (!attributes.isEmpty()) {
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.ADDITION)
                    attackDamage += am.getAmount();
            }
            double y = 1;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE)
                    y += am.getAmount();
            }
            attackDamage *= y;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL)
                    attackDamage *= (1 + am.getAmount());
            }
        }
    }
    Long rounded = Math.round(attackDamage);
    if (rounded > Integer.MAX_VALUE)
        rounded = (long) Integer.MAX_VALUE;
    int damage = Integer.valueOf(rounded.intValue());
    return damage;
}
Also used : AttributeModifier(net.minecraft.server.v1_15_R1.AttributeModifier) UUID(java.util.UUID)

Example 18 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project solinia3-core by mixxit.

the class PatchUtils method listToInventory.

public Inventory listToInventory(NBTTagList nbttaglist) {
    TileEntityChest tileentitychest = new TileEntityChest();
    for (int i = 0; i < nbttaglist.size(); i++) {
        NBTTagCompound nbttagcompound = (NBTTagCompound) nbttaglist.get(i);
        int j = nbttagcompound.getByte("Slot") & 0xFF;
        if (j >= 0 && j < 27) {
            tileentitychest.setItem(j, net.minecraft.server.v1_15_R1.ItemStack.a(nbttagcompound));
        }
    }
    return new CraftInventory(tileentitychest);
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory) TileEntityChest(net.minecraft.server.v1_15_R1.TileEntityChest) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound)

Example 19 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project solinia3-core by mixxit.

the class ItemStackAdapter method Adapt.

public static ItemStack Adapt(ISoliniaItem soliniaItem, long costmultiplier, boolean merchanttag) {
    ItemStack stack = new ItemStack(Material.valueOf(soliniaItem.getBasename().toUpperCase()), 1, soliniaItem.getColor());
    Timestamp lastItemTimestamp = soliniaItem.getLastUpdatedTime();
    // New Item ID storage system
    NamespacedKey soliniaIdKey = new NamespacedKey(StateManager.getInstance().getPlugin(), "soliniaid");
    NamespacedKey merchantKey = new NamespacedKey(StateManager.getInstance().getPlugin(), "merchant");
    NamespacedKey soliniaLastUpdatedKey = new NamespacedKey(StateManager.getInstance().getPlugin(), "sollastupdated");
    NamespacedKey soliniaAppearanceIdKey = new NamespacedKey(StateManager.getInstance().getPlugin(), "appearanceid");
    ItemMeta itemMeta = stack.getItemMeta();
    itemMeta.getCustomTagContainer().setCustomTag(merchantKey, ItemTagType.STRING, Boolean.toString(merchanttag));
    itemMeta.getCustomTagContainer().setCustomTag(soliniaIdKey, ItemTagType.INTEGER, soliniaItem.getId());
    if (lastItemTimestamp != null)
        itemMeta.getCustomTagContainer().setCustomTag(soliniaLastUpdatedKey, ItemTagType.LONG, lastItemTimestamp.getTime());
    if (soliniaItem.getAppearanceId() > 0)
        itemMeta.getCustomTagContainer().setCustomTag(soliniaAppearanceIdKey, ItemTagType.INTEGER, soliniaItem.getAppearanceId());
    stack.setItemMeta(itemMeta);
    net.minecraft.server.v1_15_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
    NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
    nmsStack.setTag(compound);
    stack = CraftItemStack.asBukkitCopy(nmsStack);
    if (soliniaItem.getItemWeaponDamage(false, stack) > 0) {
        if (soliniaItem.isMeleeWeapon()) {
            nmsStack = CraftItemStack.asNMSCopy(stack);
            compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
            NBTTagList modifiers = new NBTTagList();
            NBTTagCompound damagecompound = new NBTTagCompound();
            damagecompound.set("AttributeName", NBTTagString.a("generic.attackDamage"));
            damagecompound.set("Name", NBTTagString.a("generic.attackDamage"));
            damagecompound.set("Amount", NBTTagInt.a(soliniaItem.getItemWeaponDamage(false, null)));
            damagecompound.set("Operation", NBTTagInt.a(0));
            damagecompound.set("UUIDLeast", NBTTagInt.a(894654));
            damagecompound.set("UUIDMost", NBTTagInt.a(2872));
            damagecompound.set("Slot", NBTTagString.a("mainhand"));
            modifiers.add(damagecompound);
            compound.set("AttributeModifiers", modifiers);
            nmsStack.setTag(compound);
            stack = CraftItemStack.asBukkitCopy(nmsStack);
        }
    }
    ItemMeta i = stack.getItemMeta();
    if (soliniaItem.getBasename().equals("POTION") || soliniaItem.getBasename().equals("SPLASH_POTION") || soliniaItem.getBasename().equals("LINGERING_POTION")) {
        i = (PotionMeta) stack.getItemMeta();
        PotionData data = new PotionData(PotionType.INSTANT_HEAL);
        ((PotionMeta) i).setBasePotionData(data);
    }
    if (soliniaItem.getTexturebase64() != null && !soliniaItem.getTexturebase64().equals("") && soliniaItem.isSkullItem()) {
        UUID skinuuid = getUUIDFromString(soliniaItem.getTexturebase64());
        i = buildSkull((SkullMeta) i, skinuuid, soliniaItem.getTexturebase64(), null);
    }
    i.setUnbreakable(true);
    i.setDisplayName(soliniaItem.getDisplayname());
    if (soliniaItem.getBasename().equals("WRITTEN_BOOK")) {
        ((BookMeta) i).setAuthor("Unknown Author");
        ((BookMeta) i).setTitle(soliniaItem.getDisplayname());
        ((BookMeta) i).setPages(new ArrayList<String>());
        if (!soliniaItem.getBookAuthor().equals(""))
            ((BookMeta) i).setAuthor(soliniaItem.getBookAuthor());
        if (!soliniaItem.getDisplayname().equals(""))
            ((BookMeta) i).setTitle(soliniaItem.getDisplayname());
        if (soliniaItem.getBookPages().size() > 0)
            ((BookMeta) i).setPages(soliniaItem.getBookPages());
    }
    List<String> loretxt = new ArrayList<String>();
    if (soliniaItem.getLore() != null) {
        String[] lorestr = soliniaItem.getLore().split("(?<=\\G.{34})");
        loretxt.addAll(Arrays.asList(lorestr));
    }
    if (soliniaItem.getItemWeaponDamage(false, null) > 0) {
        loretxt.add("Damage: " + ChatColor.GREEN + soliniaItem.getItemWeaponDamage(false, null) + ChatColor.RESET);
        if (soliniaItem.getWeaponDelay() > 0) {
            loretxt.add("Atk Delay: " + ChatColor.GREEN + soliniaItem.getWeaponDelay() + ChatColor.RESET);
        }
    }
    loretxt.add("ItemType: " + ChatColor.GREEN + soliniaItem.getItemType().name().toUpperCase() + ChatColor.RESET);
    if (soliniaItem.isThrowing() == true && !soliniaItem.isSpellscroll()) {
        loretxt.add("This item can be thrown!");
    }
    if (soliniaItem.isArtifact() == true) {
        loretxt.add(ChatColor.GREEN + "This item is a unique artifact!" + ChatColor.RESET);
    }
    if (soliniaItem.getQuestId() > 0) {
        try {
            ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(soliniaItem.getQuestId());
            if (quest != null)
                loretxt.add(ChatColor.YELLOW + "Quest: " + quest.getName());
        } catch (CoreStateInitException e) {
        }
    }
    if (soliniaItem.isCrafting() == true) {
        loretxt.add(ChatColor.GOLD + "This looks like it could be crafted" + ChatColor.RESET);
        loretxt.add(ChatColor.GOLD + "into something useful" + ChatColor.RESET);
    }
    if (soliniaItem.isExperienceBonus() == true) {
        loretxt.add(ChatColor.GOLD + "Grant XP Experience!" + ChatColor.RESET);
    }
    if (soliniaItem.isBandage()) {
        loretxt.add(ChatColor.AQUA + "This item can be used with the bindwound ability" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Fingers)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : FINGERS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Waist)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : WAIST" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Neck)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : NECK" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Shoulders)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : SHOULDERS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Ears)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : EARS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Forearms)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : FOREARMS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Arms)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : ARMS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Hands)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : HANDS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Head)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : HEAD" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Chest)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : CHEST" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Legs)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : LEGS" + ChatColor.RESET);
    }
    if (soliniaItem.getEquipmentSlot().equals(EquipmentSlot.Feet)) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : FEET" + ChatColor.RESET);
    }
    if (soliniaItem.isAugmentation() == true) {
        loretxt.add(ChatColor.AQUA + "This looks like it could augment " + ChatColor.RESET);
        loretxt.add(ChatColor.AQUA + "weapon or armour" + ChatColor.RESET);
        loretxt.add(ChatColor.AQUA + "Augments Item Slots: " + soliniaItem.getAugmentationFitsSlotType().name() + ChatColor.RESET);
    }
    if (soliniaItem.getItemWeaponDamage(false, null) > 0) {
        if (soliniaItem.getBasename().equals("BOW") || soliniaItem.getBasename().equals("CROSSBOW")) {
            loretxt.add("Modifies Arrow Dmg: " + ChatColor.GREEN + soliniaItem.getItemWeaponDamage(false, null) + ChatColor.RESET);
        }
    }
    if (soliniaItem.getBaneUndead() > 0) {
        loretxt.add("Bane UNDEAD: " + ChatColor.GREEN + soliniaItem.getBaneUndead() + ChatColor.RESET);
    }
    if (soliniaItem.getAC() > 0) {
        loretxt.add("Armour Class: " + ChatColor.GREEN + soliniaItem.getAC() + ChatColor.RESET);
    }
    if (soliniaItem.getBasename().toUpperCase().equals("LEATHER_HELMET") || soliniaItem.getBasename().toUpperCase().equals("LEATHER_CHESTPLATE") || soliniaItem.getBasename().toUpperCase().equals("LEATHER_LEGGINGS") || soliniaItem.getBasename().toUpperCase().equals("LEATHER_BOOTS")) {
        try {
            if (soliniaItem.getLeatherRgbDecimal() > 0) {
                Color colorTmp = Color.fromRGB(soliniaItem.getLeatherRgbDecimal());
                loretxt.add("Leather Color (Closest): " + ColorUtil.fromRGB(colorTmp.getRed(), colorTmp.getGreen(), colorTmp.getBlue()) + "Dye Color" + ChatColor.RESET);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    String classtxt = "";
    if (soliniaItem.getAllowedClassNamesUpper().size() > 0) {
        classtxt = "Classes: ";
        for (String classname : soliniaItem.getAllowedClassNamesUpper()) {
            classtxt += ChatColor.YELLOW + classname + ChatColor.RESET + " ";
        }
    }
    if (!classtxt.equals("")) {
        loretxt.add(classtxt);
    }
    String racetxt = "";
    if (soliniaItem.getAllowedRaceNamesUpper().size() > 0) {
        racetxt = "Races: ";
        for (String racename : soliniaItem.getAllowedRaceNamesUpper()) {
            racetxt += ChatColor.YELLOW + racename + ChatColor.RESET + " ";
        }
    }
    if (!racetxt.equals("")) {
        loretxt.add(racetxt);
    }
    if (soliniaItem.getMinLevel() > 0) {
        loretxt.add("Minimum Level: " + ChatColor.YELLOW + soliniaItem.getMinLevel() + ChatColor.RESET);
    }
    String stattxt = "";
    if (soliniaItem.getStrength() > 0) {
        stattxt = "STR: " + ChatColor.GREEN + soliniaItem.getStrength() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getStamina() > 0) {
        stattxt += "STA: " + ChatColor.GREEN + soliniaItem.getStamina() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getAgility() > 0) {
        stattxt += "AGI: " + ChatColor.GREEN + soliniaItem.getAgility() + ChatColor.RESET + " ";
    }
    if (!stattxt.equals("")) {
        loretxt.add(stattxt);
    }
    stattxt = "";
    if (soliniaItem.getDexterity() > 0) {
        stattxt = "DEX: " + ChatColor.GREEN + soliniaItem.getDexterity() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getIntelligence() > 0) {
        stattxt += "INT: " + ChatColor.GREEN + soliniaItem.getIntelligence() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getWisdom() > 0) {
        stattxt += "WIS: " + ChatColor.GREEN + soliniaItem.getWisdom() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getCharisma() > 0) {
        stattxt += "CHA: " + ChatColor.GREEN + soliniaItem.getCharisma() + ChatColor.RESET + " ";
    }
    if (!stattxt.equals("")) {
        loretxt.add(stattxt);
    }
    String resisttxt = "";
    if (soliniaItem.getFireResist() > 0) {
        resisttxt += "FR: " + ChatColor.AQUA + soliniaItem.getFireResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getColdResist() > 0) {
        resisttxt += "CR: " + ChatColor.AQUA + soliniaItem.getColdResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getMagicResist() > 0) {
        resisttxt += "MR: " + ChatColor.AQUA + soliniaItem.getMagicResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getDiseaseResist() > 0) {
        resisttxt += "DR: " + ChatColor.AQUA + soliniaItem.getDiseaseResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getPoisonResist() > 0) {
        resisttxt += "PR: " + ChatColor.AQUA + soliniaItem.getPoisonResist() + ChatColor.RESET + " ";
    }
    if (!resisttxt.equals("")) {
        loretxt.add(resisttxt);
    }
    String regentxt = "";
    if (soliniaItem.getHpregen() > 0 || soliniaItem.getMpregen() > 0) {
        if (soliniaItem.getHpregen() > 0) {
            regentxt = ChatColor.WHITE + "HPRegen: " + ChatColor.YELLOW + soliniaItem.getHpregen() + ChatColor.RESET;
        }
        if (soliniaItem.getMpregen() > 0) {
            if (!regentxt.equals(""))
                regentxt += " ";
            regentxt += ChatColor.WHITE + "MPRegen: " + ChatColor.YELLOW + soliniaItem.getMpregen() + ChatColor.RESET;
        }
    }
    if (soliniaItem.getAttackspeed() > 0) {
        loretxt.add(ChatColor.WHITE + "Modifies Melee Attack Speed % by: " + ChatColor.YELLOW + soliniaItem.getAttackspeed() + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType().toString() + "  +(" + soliniaItem.getSkillModValue() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType2().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType2().toString() + "  +(" + soliniaItem.getSkillModValue2() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType3().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType3().toString() + "  +(" + soliniaItem.getSkillModValue3() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType4().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType4().toString() + "  +(" + soliniaItem.getSkillModValue4() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getAcceptsAugmentationSlotType().equals(AugmentationSlotType.NONE))) {
        loretxt.add(ChatColor.WHITE + "Augmentation Slot Types: " + ChatColor.YELLOW + soliniaItem.getAcceptsAugmentationSlotType().name() + ChatColor.RESET);
    }
    if (soliniaItem.getAttack() > 0) {
        resisttxt += "Attack: " + ChatColor.AQUA + soliniaItem.getAttack() + ChatColor.RESET + " ";
    }
    if (!regentxt.equals("")) {
        loretxt.add(regentxt);
    }
    String hpmanatxt = "";
    if (soliniaItem.getHp() > 0 || soliniaItem.getMana() > 0) {
        if (soliniaItem.getHp() > 0) {
            hpmanatxt = ChatColor.WHITE + "HP: " + ChatColor.YELLOW + soliniaItem.getHp() + ChatColor.RESET;
        }
        if (soliniaItem.getMana() > 0) {
            if (!hpmanatxt.equals(""))
                hpmanatxt += " ";
            hpmanatxt += ChatColor.WHITE + "Mana: " + ChatColor.YELLOW + soliniaItem.getMana() + ChatColor.RESET;
        }
    }
    if (!hpmanatxt.equals("")) {
        loretxt.add(hpmanatxt);
    }
    if (soliniaItem.isSpellscroll()) {
        loretxt.add("This item can be added to your /spellbook");
    }
    if (soliniaItem.getAbilityid() > 0 && soliniaItem.isSpellscroll()) {
        loretxt.addAll(generateSpellLoreText(soliniaItem));
    }
    if (soliniaItem.getFocusEffectId() > 0) {
        loretxt.addAll(generateFocusEffectLoreText(soliniaItem));
    }
    if (soliniaItem.getAbilityid() > 0 && !soliniaItem.isSpellscroll()) {
        loretxt.addAll(generateItemSpellLoreText(soliniaItem));
    }
    if (soliniaItem.getWeaponabilityid() > 0 && !soliniaItem.isSpellscroll()) {
        loretxt.addAll(generateWeaponAbilityLoreText(soliniaItem));
    }
    if (!soliniaItem.getLanguagePrimer().equals("")) {
        loretxt.add("Language Primer: " + soliniaItem.getLanguagePrimer());
    }
    if (soliniaItem.isMakesHotzone()) {
        loretxt.add("Makes hotzone on consume");
    }
    if (soliniaItem.isDistiller()) {
        loretxt.add("This is an Augmentation Distiller");
    }
    loretxt.add("Discovered By: " + soliniaItem.getDiscoverer());
    if ((soliniaItem.getWorth() * costmultiplier) > 0) {
        loretxt.add("Worth: " + (soliniaItem.getWorth() * costmultiplier));
    }
    if ((soliniaItem.getWorth() * costmultiplier) > 0) {
        loretxt.add("Inspiration Worth: " + (soliniaItem.getInspirationWorth()));
    }
    if (soliniaItem.getAwardsInspiration() > 0) {
        loretxt.add("Awards Inspiration Points: " + (soliniaItem.getAwardsInspiration()));
    }
    if (soliniaItem.isTemporary()) {
        loretxt.add("Temporary: " + StateManager.getInstance().getInstanceGuid());
    }
    if (soliniaItem.isConsumable()) {
        loretxt.add("This item is consumed on use");
    }
    i.setLore(loretxt);
    stack.setItemMeta(i);
    if (soliniaItem.getBasename().toUpperCase().equals("LEATHER_HELMET") || soliniaItem.getBasename().toUpperCase().equals("LEATHER_CHESTPLATE") || soliniaItem.getBasename().toUpperCase().equals("LEATHER_LEGGINGS") || soliniaItem.getBasename().toUpperCase().equals("LEATHER_BOOTS")) {
        try {
            LeatherArmorMeta lch = (LeatherArmorMeta) stack.getItemMeta();
            if (soliniaItem.getLeatherRgbDecimal() < 1)
                lch.setColor(null);
            else
                lch.setColor(Color.fromRGB(soliniaItem.getLeatherRgbDecimal()));
            stack.setItemMeta(lch);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (soliniaItem.getEnchantment1() != null) {
        if (soliniaItem.getEnchantment1val() > 0) {
            try {
                Enchantment enchantment = ItemStackUtils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment1());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment1val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getEnchantment2() != null) {
        if (soliniaItem.getEnchantment2val() > 0) {
            try {
                Enchantment enchantment = ItemStackUtils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment2());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment2val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getEnchantment3() != null) {
        if (soliniaItem.getEnchantment3val() > 0) {
            try {
                Enchantment enchantment = ItemStackUtils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment3());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment3val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getEnchantment4() != null) {
        if (soliniaItem.getEnchantment4val() > 0) {
            try {
                Enchantment enchantment = ItemStackUtils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment4());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment4val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getTexturebase64() != null && !soliniaItem.getTexturebase64().equals("") && soliniaItem.isSkullItem()) {
        stack.setDurability((short) 3);
    }
    return stack;
}
Also used : NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound) ArrayList(java.util.ArrayList) SkullMeta(org.bukkit.inventory.meta.SkullMeta) NBTTagString(net.minecraft.server.v1_15_R1.NBTTagString) Timestamp(java.sql.Timestamp) NBTTagList(net.minecraft.server.v1_15_R1.NBTTagList) PotionData(org.bukkit.potion.PotionData) NamespacedKey(org.bukkit.NamespacedKey) UUID(java.util.UUID) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Color(org.bukkit.Color) ChatColor(net.md_5.bungee.api.ChatColor) PotionMeta(org.bukkit.inventory.meta.PotionMeta) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 20 with net.minecraft.server.v1_15_R1

use of net.minecraft.server.v1_15_R1 in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
    net.minecraft.server.v1_15_R1.Entity raw = getHandle(entity);
    raw.onGround = true;
    // not sure of a better way around this - if onGround is false, then
    // navigation won't execute, and calling entity.move doesn't
    // entirely fix the problem.
    final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof EntityPlayer) {
            ((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
        } else {
            ((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
        }
    }
    return new MCNavigator() {

        float lastSpeed;

        CancelReason reason;

        @Override
        public CancelReason getCancelReason() {
            return reason;
        }

        @Override
        public Iterable<Vector> getPath() {
            return new NavigationIterable(navigation);
        }

        @Override
        public void stop() {
            if (params.debug() && navigation.k() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.k().e(); i++) {
                        PathPoint pp = navigation.k().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getBlockData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof EntityPlayer) {
                    ((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
                } else {
                    ((EntityInsentient) raw).a(PathType.WATER, oldWater);
                }
            }
            stopNavigation(navigation);
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change from", lastSpeed, "to", params.speed());
                }
                Entity handle = getHandle(entity);
                EntitySize size = null;
                try {
                    size = (EntitySize) SIZE_FIELD_GETTER.invoke(handle);
                    if (handle instanceof EntityHorse) {
                        SIZE_FIELD_SETTER.invoke(handle, new EntitySize(Math.min(0.99F, size.width), size.height, false));
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                try {
                    SIZE_FIELD_SETTER.invoke(handle, size);
                } catch (Throwable e) {
                    e.printStackTrace();
                // minecraft requires that an entity fit onto both blocks if width >= 1f, but we'd prefer to
                // make it just fit on 1 so hack around it a bit.
                }
                lastSpeed = params.speed();
            }
            if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
                BlockData data = Material.DANDELION.createBlockData();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.k().e(); i++) {
                        PathPoint pp = navigation.k().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), data);
                    }
                }
            }
            navigation.a((double) params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_15_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_15_R1.PathEntity) Player(org.bukkit.entity.Player) AdvancementDataPlayer(net.minecraft.server.v1_15_R1.AdvancementDataPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntitySize(net.minecraft.server.v1_15_R1.EntitySize) EntityInsentient(net.minecraft.server.v1_15_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_15_R1.NavigationAbstract) PathPoint(net.minecraft.server.v1_15_R1.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC) PathPoint(net.minecraft.server.v1_15_R1.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_15_R1.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) IBlockData(net.minecraft.server.v1_15_R1.IBlockData) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector) Entity(net.minecraft.server.v1_15_R1.Entity)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)10 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)9 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)7 ItemStack (org.bukkit.inventory.ItemStack)7 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)5 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)5 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)5 Container (net.minecraft.server.v1_15_R1.Container)3 CraftWorld (org.bukkit.craftbukkit.v1_15_R1.CraftWorld)3 Player (org.bukkit.entity.Player)3 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)2 ChunkSection (net.minecraft.server.v1_15_R1.ChunkSection)2 ContainerAnvil (net.minecraft.server.v1_15_R1.ContainerAnvil)2 EntityLiving (net.minecraft.server.v1_15_R1.EntityLiving)2 Chunk (org.bukkit.Chunk)2 Location (org.bukkit.Location)2 CraftEntity (org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity)2 CraftContainer (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftContainer)2