Search in sources :

Example 1 with NamespacedKey

use of org.bukkit.NamespacedKey in project EliteMobs by MagmaGuy.

the class PlayerItem method fullUpdate.

private boolean fullUpdate(ItemStack itemStack) {
    // case when both are null
    if (itemStack == null && this.itemStack == null)
        return false;
    // case when it became null
    if (itemStack == null)
        return fillNullItem();
    // case when it's the same item as before - best performance
    if (itemStack.isSimilar(this.itemStack))
        return false;
    if (EnchantmentsConfig.getEnchantment(SoulbindEnchantment.key + ".yml").isEnabled())
        if (!SoulbindEnchantment.isValidSoulbindUser(itemStack.getItemMeta(), player)) {
            player.getWorld().dropItem(player.getLocation(), itemStack);
            itemStack.setAmount(0);
            itemStack = new ItemStack(Material.AIR);
        }
    // case when the item changed during runtime to another valid ItemStack
    this.itemStack = itemStack;
    if (equipmentSlot.equals(EquipmentSlot.MAINHAND))
        this.itemTier = ItemTierFinder.mainHandCombatParser(itemStack);
    else
        this.itemTier = ItemTierFinder.findBattleTier(itemStack);
    this.continuousPotionEffects = ItemTagger.getPotionEffects(itemStack.getItemMeta(), ItemTagger.continuousPotionEffectKey);
    this.onHitPotionEffects = ItemTagger.getPotionEffects(itemStack.getItemMeta(), ItemTagger.onHitPotionEffectKey);
    if (equipmentSlot.equals(EquipmentSlot.MAINHAND)) {
        this.damageArthropodsLevel = ItemTagger.getEnchantment(itemStack.getItemMeta(), Enchantment.DAMAGE_ARTHROPODS.getKey());
        this.damageUndeadLevel = ItemTagger.getEnchantment(itemStack.getItemMeta(), Enchantment.DAMAGE_UNDEAD.getKey());
        this.critChance = ItemTagger.getEnchantment(itemStack.getItemMeta(), new NamespacedKey(MetadataHandler.PLUGIN, CriticalStrikesEnchantment.key)) / 10D;
        this.lightningChance = Math.pow(ItemTagger.getEnchantment(itemStack.getItemMeta(), new NamespacedKey(MetadataHandler.PLUGIN, LightningEnchantment.key)), 2) / 1000D;
    }
    if (equipmentSlot.equals(EquipmentSlot.BOOTS)) {
        this.plasmaBootsLevel = ItemTagger.getEnchantment(itemStack.getItemMeta(), new NamespacedKey(MetadataHandler.PLUGIN, PlasmaBootsEnchantment.key));
    }
    this.hunterChance = ItemTagger.getEnchantment(itemStack.getItemMeta(), new NamespacedKey(MetadataHandler.PLUGIN, HunterEnchantment.key)) * EnchantmentsConfig.getEnchantment("hunter.yml").getFileConfiguration().getDouble("hunterSpawnBonus");
    this.earthquakeLevel = ItemTagger.getEnchantment(itemStack.getItemMeta(), new NamespacedKey(MetadataHandler.PLUGIN, EarthquakeEnchantment.key));
    checkArmorSpecificFeatures();
    return true;
}
Also used : NamespacedKey(org.bukkit.NamespacedKey) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with NamespacedKey

use of org.bukkit.NamespacedKey in project Glowstone by GlowstoneMC.

the class NbtSerialization method readBlockData.

public static BlockData readBlockData(CompoundTag tag) {
    NamespacedKey key = namespacedKeyFromString(tag.getString("Name"));
    Material type = Material.getMaterial(key.toString());
    Optional<CompoundTag> properties = tag.tryGetCompound("Properties");
    return Bukkit.getServer().createBlockData(type);
}
Also used : NamespacedKey(org.bukkit.NamespacedKey) Material(org.bukkit.Material) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 3 with NamespacedKey

use of org.bukkit.NamespacedKey in project EliteMobs by MagmaGuy.

the class CustomSummonPower method onCombatEnterSummonReinforcement.

private void onCombatEnterSummonReinforcement(EliteEntity spawningEntity) {
    for (CustomBossReinforcement customBossReinforcement : customBossReinforcements) {
        if (!customBossReinforcement.summonType.equals(SummonType.ON_COMBAT_ENTER))
            continue;
        if (customBossReinforcement.bossFileName != null) {
            summonReinforcement(spawningEntity, customBossReinforcement);
        } else {
            Location spawnLocation = getFinalSpawnLocation(spawningEntity, customBossReinforcement.spawnLocationOffset);
            Entity entity = spawnLocation.getWorld().spawnEntity(spawnLocation, customBossReinforcement.entityType);
            entity.getPersistentDataContainer().set(new NamespacedKey(MetadataHandler.PLUGIN, "eliteCrystal"), PersistentDataType.STRING, "eliteCrystal");
            entity.setPersistent(false);
            CrashFix.persistentTracker(entity);
            if (entity instanceof Mob && !spawningEntity.getDamagers().isEmpty()) {
                Player target = null;
                double damageDealt = 0;
                for (Player player : spawningEntity.getDamagers().keySet()) {
                    if (spawningEntity.getDamagers().get(player) < damageDealt)
                        continue;
                    target = player;
                    damageDealt = spawningEntity.getDamagers().get(player);
                }
                if (target != null)
                    ((Mob) entity).setTarget(target);
            }
            if (customBossReinforcement.isLightningRod)
                new EnderCrystalLightningRod(spawningEntity, (EnderCrystal) entity);
            customBossReinforcement.isSummoned = true;
            spawningEntity.addReinforcement(entity);
        }
    }
}
Also used : EliteEntity(com.magmaguy.elitemobs.mobconstructor.EliteEntity) CustomBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.CustomBossEntity) RegionalBossEntity(com.magmaguy.elitemobs.mobconstructor.custombosses.RegionalBossEntity) NamespacedKey(org.bukkit.NamespacedKey) EnderCrystalLightningRod(com.magmaguy.elitemobs.powers.specialpowers.EnderCrystalLightningRod) Location(org.bukkit.Location)

Example 4 with NamespacedKey

use of org.bukkit.NamespacedKey in project EliteMobs by MagmaGuy.

the class EnhancementMenu method calculateOutput.

private static void calculateOutput(Inventory EnhancementInventory) {
    if (EnhancementInventory.getItem(EnhancementMenuConfig.eliteUpgradeOrbInputSlot) == null || EnhancementInventory.getItem(EnhancementMenuConfig.eliteItemInputSlot) == null) {
        EnhancementInventory.setItem(EnhancementMenuConfig.outputSlot, null);
        return;
    }
    int enhancementScore = ItemTagger.getEnchantment(EnhancementInventory.getItem(EnhancementMenuConfig.eliteUpgradeOrbInputSlot).getItemMeta(), "EliteUpgradeItem");
    int itemScore = ItemTierFinder.findBattleTier(EnhancementInventory.getItem(EnhancementMenuConfig.eliteItemInputSlot));
    if (enhancementScore <= itemScore) {
        EnhancementInventory.setItem(EnhancementMenuConfig.outputSlot, null);
        return;
    }
    ItemStack outputItem = EnhancementInventory.getItem(EnhancementMenuConfig.eliteItemInputSlot).clone();
    Enchantment mainCombatEnchantment = ItemTierFinder.getMainCombatEnchantment(outputItem.getType());
    NamespacedKey enchantmentKey = mainCombatEnchantment.getKey();
    ItemMeta itemMeta = outputItem.getItemMeta();
    int enchantmentLevel = ItemTagger.getEnchantment(outputItem.getItemMeta(), enchantmentKey) + 1;
    if (outputItem.getEnchantmentLevel(mainCombatEnchantment) < mainCombatEnchantment.getMaxLevel())
        outputItem.addEnchantment(mainCombatEnchantment, enchantmentLevel);
    ItemTagger.registerEnchantment(itemMeta, enchantmentKey, enchantmentLevel);
    outputItem.setItemMeta(itemMeta);
    new EliteItemLore(outputItem, false);
    EnhancementInventory.setItem(outputSlot, outputItem);
}
Also used : EliteItemLore(com.magmaguy.elitemobs.items.EliteItemLore) NamespacedKey(org.bukkit.NamespacedKey) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 5 with NamespacedKey

use of org.bukkit.NamespacedKey in project EliteMobs by MagmaGuy.

the class CustomItem method generateDefaultsItemStack.

public ItemStack generateDefaultsItemStack(Player player, boolean showItemWorth, EliteEntity eliteEntity) {
    if (player != null && !permission.isEmpty() && !player.hasPermission(permission))
        return null;
    ItemStack itemStack = ItemConstructor.constructItem(getName(), getMaterial(), getEnchantments(), getCustomEnchantments(), getPotionEffects(), getLore(), eliteEntity, player, showItemWorth, customItemsConfigFields.getCustomModelID());
    ItemMeta itemMeta = itemStack.getItemMeta();
    // Adds the filename to the persistent data container, useful for several things but mostly used for tracking quest keys
    Objects.requireNonNull(itemMeta).getPersistentDataContainer().set(new NamespacedKey(MetadataHandler.PLUGIN, fileName), PersistentDataType.STRING, fileName);
    itemStack.setItemMeta(itemMeta);
    return itemStack;
}
Also used : NamespacedKey(org.bukkit.NamespacedKey) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

NamespacedKey (org.bukkit.NamespacedKey)24 Enchantment (org.bukkit.enchantments.Enchantment)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)3 ListTag (com.denizenscript.denizencore.objects.core.ListTag)3 ItemStack (org.bukkit.inventory.ItemStack)3 Test (org.junit.jupiter.api.Test)3 AdvancementHelper (com.denizenscript.denizen.nms.interfaces.AdvancementHelper)2 Advancement (com.denizenscript.denizen.nms.util.Advancement)2 ItemTag (com.denizenscript.denizen.objects.ItemTag)2 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 List (java.util.List)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2 Entity (net.minecraft.world.entity.Entity)2 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)2 LivingEntity (net.minecraft.world.entity.LivingEntity)2 MobType (net.minecraft.world.entity.MobType)2 Location (org.bukkit.Location)2 KeyedBossBar (org.bukkit.boss.KeyedBossBar)2 Player (org.bukkit.entity.Player)2