-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/ComponentsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.tr7zw.nbtapi.plugin.tests.items; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
|
||
import de.tr7zw.changeme.nbtapi.NBT; | ||
import de.tr7zw.changeme.nbtapi.NbtApiException; | ||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; | ||
import de.tr7zw.nbtapi.plugin.tests.Test; | ||
|
||
public class ComponentsTest implements Test { | ||
|
||
@Override | ||
public void test() throws Exception { | ||
if(!MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_20_R4)) { | ||
return; | ||
} | ||
ItemStack item = new ItemStack(Material.STICK); | ||
ItemMeta meta = item.getItemMeta(); | ||
meta.setDisplayName("test"); | ||
item.setItemMeta(meta); | ||
String comp = NBT.modifyComponents(item, n -> { | ||
return n.toString(); | ||
}); | ||
if(!comp.contains("test")) { | ||
throw new NbtApiException("ReadComponent didn't work!"); | ||
} | ||
NBT.modifyComponents(item, nbt -> { | ||
nbt.setString("minecraft:custom_name", "{\"extra\":[\"foobar\"],\"text\":\"\"}"); | ||
}); | ||
if(!item.getItemMeta().getDisplayName().equals("foobar")) { | ||
throw new NbtApiException("ModifyComponent didn't work!"); | ||
} | ||
} | ||
|
||
} |