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;
}
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);
}
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);
}
}
}
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);
}
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;
}
Aggregations