use of org.bukkit.NamespacedKey in project Prism-Bukkit by prism.
the class EnchantmentUtils method getEnchantmentFromCommonName.
/**
* Return the enchantment based on a common name.
*
* @param name String
* @return Enchantment
*/
@SuppressWarnings("unused")
public static Enchantment getEnchantmentFromCommonName(String name) {
switch(name.toLowerCase()) {
case "aquaaffinity":
return Enchantment.WATER_WORKER;
case "bane":
return Enchantment.DAMAGE_ARTHROPODS;
case "efficiency":
return Enchantment.DIG_SPEED;
case "explosion":
return Enchantment.PROTECTION_EXPLOSIONS;
case "fall":
return Enchantment.PROTECTION_FALL;
case "fire":
return Enchantment.PROTECTION_FIRE;
case "fireaspect":
return Enchantment.FIRE_ASPECT;
case "flame":
return Enchantment.ARROW_FIRE;
case "fortune":
return Enchantment.LOOT_BONUS_BLOCKS;
case "infinity":
return Enchantment.ARROW_INFINITE;
case "knockback":
return Enchantment.KNOCKBACK;
case "power":
return Enchantment.ARROW_DAMAGE;
case "looting":
return Enchantment.LOOT_BONUS_MOBS;
case "projectile":
return Enchantment.PROTECTION_PROJECTILE;
case "protection":
return Enchantment.PROTECTION_ENVIRONMENTAL;
case "punch":
return Enchantment.ARROW_KNOCKBACK;
case "respiration":
return Enchantment.OXYGEN;
case "sharpness":
return Enchantment.DAMAGE_ALL;
case "silktouch":
return Enchantment.SILK_TOUCH;
case "smite":
return Enchantment.DAMAGE_UNDEAD;
case "unbreaking":
return Enchantment.DURABILITY;
default:
String formattedName = name.replace(' ', '_');
NamespacedKey key = NamespacedKey.minecraft(formattedName);
return Enchantment.getByKey(key);
}
}
use of org.bukkit.NamespacedKey in project WildernessTp by AcmeProject.
the class TeleportGoneWild method auscultate.
private static KeyedBossBar auscultate(Player sickPlayer, BarColor color, BarStyle style) {
NamespacedKey key = cerealKiller(sickPlayer);
KeyedBossBar bossbar = Bukkit.getBossBar(key);
if (bossbar == null) {
bossbar = Bukkit.createBossBar(key, "", color, style);
bossbar.addPlayer(sickPlayer);
bossbar.setVisible(true);
} else {
bossbar.setColor(color);
bossbar.setStyle(style);
}
return bossbar;
}
use of org.bukkit.NamespacedKey in project WildernessTp by AcmeProject.
the class TeleportGoneWild method cure.
static void cure(Player guiltyPlayer) {
NamespacedKey key = cerealKiller(guiltyPlayer);
KeyedBossBar bossbar = Bukkit.getBossBar(key);
if (bossbar == null)
return;
bossbar.removeAll();
Bukkit.removeBossBar(cerealKiller(guiltyPlayer));
}
use of org.bukkit.NamespacedKey in project Karus-Commons by Pante.
the class KnowledgeBookBuilderTest method build.
@Test
void build() {
NamespacedKey recipe = mock(NamespacedKey.class);
builder.recipe(recipe);
verify(meta).addRecipe(recipe);
}
use of org.bukkit.NamespacedKey in project Denizen-For-Bukkit by DenizenScript.
the class ItemTag method registerTags.
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
PropertyParser.registerPropertyTagHandlers(ItemTag.class, tagProcessor);
// <--[tag]
// @attribute <ItemTag.repairable>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the item can be repaired.
// If this returns true, it will enable access to:
// <@link mechanism ItemTag.durability>,
// <@link tag ItemTag.max_durability>, and <@link tag ItemTag.durability>.
// Note that due to odd design choices in Spigot, this is effectively true for all items, even though the durability value of most items is locked at zero.
// -->
tagProcessor.registerTag(ElementTag.class, "repairable", (attribute, object) -> {
return new ElementTag(ItemDurability.describes(object));
});
// <--[tag]
// @attribute <ItemTag.is_book>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the item is considered an editable book.
// If this returns true, it will enable access to:
// <@link mechanism ItemTag.book>,
// <@link tag ItemTag.book_author>, <@link tag ItemTag.book_title>, and <@link tag ItemTag.book_pages>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_book", (attribute, object) -> {
return new ElementTag(ItemBook.describes(object));
});
// <--[tag]
// @attribute <ItemTag.is_colorable>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the item can have a custom color.
// If this returns true, it will enable access to:
// <@link mechanism ItemTag.color>, and <@link tag ItemTag.color>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_colorable", (attribute, object) -> {
return new ElementTag(ItemColor.describes(object));
});
tagProcessor.registerTag(ElementTag.class, "is_dyeable", (attribute, object) -> {
return new ElementTag(ItemColor.describes(object));
});
// <--[tag]
// @attribute <ItemTag.is_firework>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the item is a firework.
// If this returns true, it will enable access to:
// <@link mechanism ItemTag.firework>, and <@link tag ItemTag.firework>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_firework", (attribute, object) -> {
return new ElementTag(ItemFirework.describes(object));
});
// <--[tag]
// @attribute <ItemTag.has_inventory>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the item has an inventory.
// If this returns true, it will enable access to:
// <@link mechanism ItemTag.inventory_contents>, and <@link tag ItemTag.inventory_contents>.
// -->
tagProcessor.registerTag(ElementTag.class, "has_inventory", (attribute, object) -> {
return new ElementTag(ItemInventory.describes(object));
});
// <--[tag]
// @attribute <ItemTag.is_lockable>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the item is lockable.
// If this returns true, it will enable access to:
// <@link mechanism ItemTag.lock>, and <@link tag ItemTag.lock>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_lockable", (attribute, object) -> {
return new ElementTag(ItemLock.describes(object));
});
// <--[tag]
// @attribute <ItemTag.material>
// @returns MaterialTag
// @mechanism ItemTag.material
// @group conversion
// @description
// Returns the MaterialTag that is the basis of the item.
// EG, a stone with lore and a display name, etc. will return only "m@stone".
// -->
tagProcessor.registerTag(ObjectTag.class, "material", (attribute, object) -> {
if (attribute.getAttribute(2).equals("formatted")) {
return object;
}
if (object.getItemMeta() instanceof BlockStateMeta) {
if (object.getBukkitMaterial() == Material.SHIELD) {
MaterialTag material = new MaterialTag(Material.SHIELD);
material.setModernData(((BlockStateMeta) object.getItemMeta()).getBlockState().getBlockData());
return material;
}
return new MaterialTag(((BlockStateMeta) object.getItemMeta()).getBlockState());
}
return object.getMaterial();
});
// <--[tag]
// @attribute <ItemTag.json>
// @returns ElementTag
// @group conversion
// @description
// Returns the item converted to a raw JSON object with one layer of escaping for network transmission.
// EG, via /tellraw.
// Generally, prefer tags like <@link tag ElementTag.on_hover.type> with type 'show_item'.
// -->
tagProcessor.registerTag(ElementTag.class, "json", (attribute, object) -> {
return new ElementTag(NMSHandler.getItemHelper().getJsonString(object.item));
});
// <--[tag]
// @attribute <ItemTag.meta_type>
// @returns ElementTag
// @group conversion
// @description
// Returns the name of the Bukkit item meta type that applies to this item.
// This is for debugging purposes.
// -->
tagProcessor.registerTag(ElementTag.class, "meta_type", (attribute, object) -> {
return new ElementTag(object.getItemMeta().getClass().getName());
});
// <--[tag]
// @attribute <ItemTag.bukkit_serial>
// @returns ElementTag
// @group conversion
// @description
// Returns a YAML text section representing the Bukkit serialization of the item, under subkey "item".
// -->
tagProcessor.registerTag(ElementTag.class, "bukkit_serial", (attribute, object) -> {
YamlConfiguration config = new YamlConfiguration();
config.set("item", object.getItemStack());
return new ElementTag(config.saveToString());
});
// <--[tag]
// @attribute <ItemTag.simple>
// @returns ElementTag
// @group conversion
// @description
// Returns a simple reusable item identification for this item, with minimal extra data.
// -->
tagProcessor.registerTag(ElementTag.class, "simple", (attribute, object) -> {
return new ElementTag(object.identifySimple());
});
// <--[tag]
// @attribute <ItemTag.recipe_ids[(<type>)]>
// @returns ListTag
// @description
// If the item is a scripted item, returns a list of all recipe IDs created by the item script.
// Others, returns a list of all recipe IDs that the server lists as capable of crafting the item.
// Returns a list in the Namespace:Key format, for example "minecraft:gold_nugget".
// Optionally, specify a recipe type (CRAFTING, FURNACE, COOKING, BLASTING, SHAPED, SHAPELESS, SMOKING, STONECUTTING)
// to limit to just recipes of that type.
// -->
tagProcessor.registerTag(ListTag.class, "recipe_ids", (attribute, object) -> {
String type = attribute.hasParam() ? CoreUtilities.toLowerCase(attribute.getParam()) : null;
ItemScriptContainer container = object.isItemscript() ? ItemScriptHelper.getItemScriptContainer(object.getItemStack()) : null;
ListTag list = new ListTag();
for (Recipe recipe : Bukkit.getRecipesFor(object.getItemStack())) {
if (!Utilities.isRecipeOfType(recipe, type)) {
continue;
}
if (recipe instanceof Keyed) {
NamespacedKey key = ((Keyed) recipe).getKey();
if (key.getNamespace().equalsIgnoreCase("denizen")) {
if (container != ItemScriptHelper.recipeIdToItemScript.get(key.toString())) {
continue;
}
} else if (container != null) {
continue;
}
list.add(key.toString());
}
}
return list;
});
// <--[tag]
// @attribute <ItemTag.formatted>
// @returns ElementTag
// @group formatting
// @description
// Returns the formatted material name of the item to be used in a sentence.
// Correctly uses singular and plural forms of item names, among other things.
// -->
tagProcessor.registerTag(ElementTag.class, "formatted", (attribute, object) -> {
return new ElementTag(object.formattedName());
});
// <--[tag]
// @attribute <ItemTag.advanced_matches[<matcher>]>
// @returns ElementTag(Boolean)
// @group element checking
// @description
// Returns whether the item matches some matcher text, using the system behind <@link language Advanced Script Event Matching>.
// -->
tagProcessor.registerTag(ElementTag.class, "advanced_matches", (attribute, object) -> {
if (!attribute.hasParam()) {
return null;
}
return new ElementTag(BukkitScriptEvent.tryItem(object, attribute.getParam()));
});
}
Aggregations