Skip to content

Commit

Permalink
Add nbt tag to custom item stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Reldeam committed Feb 2, 2022
1 parent 5e301de commit a5bdf83
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,21 @@ lore: [<string>] # (optional) The item lore (appears under the item name)

attributeModifiers: [<attribute modifier>] # (optional) A list of attribute
# modifiers

nbt: <string> # (optional) USE AT OWN RISK - This will apply a NBT tag to the
# item before anything else. This means that all of the other properties in
# <item stack> will overwrite any values that may be set here. Using this
# property may lead to unexpected behaviour. Issues involving the use of the
# nbt property will be closed without investigation.
#
# Example:
#
# nbt: >
# {display:{Name:'[{"text":"Cool Thingy"}]'}}
```

_&lt;money&gt;_



```yaml
money: <number>

Expand Down Expand Up @@ -200,10 +209,10 @@ ADD | MULTIPLY | MULTIPLY_ALL_MODIFIERS
"ingotForEmerald":
result:
material: IRON_INGOT
amount: 24
amount: 10
ingredients:
- material: EMERALD
amount: 10
amount: 24
maxUses: 6
experience: 10
chance: 0.5
Expand Down Expand Up @@ -336,6 +345,25 @@ ADD | MULTIPLY | MULTIPLY_ALL_MODIFIERS
maxUses: 20
experience: 10
chance: 0.1

# This trade uses a the nbt tag to add a custom NTB (in this case a
# display name) to the item.
#
# USE THIS AT YOUR OWN RISK - If the tag is invalid you won't know about it and
# it could cause unexpected behaviour!

"coolThingy":
result:
material: GOLD_SWORD
amount: 1
nbt: >
{display:{Name:'[{"text":"Cool Thingy"}]'}}
ingredients:
- material: EMERALD
amount: 5
maxUses: 4
experience: 20
chance: 0.3
```
## Commands
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>online.meinkraft</groupId>
<artifactId>customvillagertrades</artifactId>
<packaging>jar</packaging>
<version>1.3-SNAPSHOT</version>
<version>1.4-SNAPSHOT</version>
<name>CustomVillagerTrades</name>
<url>http://maven.apache.org</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.UUID;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
Expand Down Expand Up @@ -216,6 +217,7 @@ static public List<ItemStack> toItemStackList(CustomVillagerTrades plugin, List<
return ingredients;
}

@SuppressWarnings("deprecation")
static public ItemStack toItemStack(CustomVillagerTrades plugin, Map<?, ?> map) throws EconomyNotEnabledException {

// if it's a money item
Expand Down Expand Up @@ -260,7 +262,15 @@ static public ItemStack toItemStack(CustomVillagerTrades plugin, Map<?, ?> map)
Integer amount = (Integer) map.get("amount");
if(amount == null) amount = 1;

String nbt = (String) map.get("nbt");

ItemStack itemStack = new ItemStack(Material.valueOf(material), amount);

// this is unsupported - use at your own risk
if(nbt != null) {
org.bukkit.UnsafeValues unsafe = Bukkit.getUnsafe();
unsafe.modifyItemStack(itemStack, nbt);
}

ItemMeta itemMeta = itemStack.getItemMeta();

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
main: online.meinkraft.customvillagertrades.CustomVillagerTrades
name: CustomVillagerTrades
version: 1.2-SNAPSHOT
version: 1.4-SNAPSHOT
description: Adds custom villager trades
api-version: 1.18
load: STARTUP
Expand Down

0 comments on commit a5bdf83

Please sign in to comment.