From 60560528060c18a49db1a810195e19b3f8cf025e Mon Sep 17 00:00:00 2001 From: Heath Date: Fri, 22 Oct 2021 01:46:36 +1300 Subject: [PATCH] custom item api example --- readme.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7a951a2..db8f419 100644 --- a/readme.md +++ b/readme.md @@ -128,4 +128,29 @@ Database.executeQuery("SELECT * FROM table WHERE id = ?", Database.execute("DELETE FROM table", { statement -> }) ``` -## CustomItems \ No newline at end of file +## CustomItems + +```groovy +import dev.cobblesword.cobblegroovy.tools.CC +import me.lucko.helper.Events +import org.bukkit.Material +import org.bukkit.event.block.BlockBreakEvent + +def lemonItem = CustomItem.create(Material.GOLD_BLOCK, "LEMON") + .displayName("Lemon") + .LoreSupplier { player, item -> + return [CC.red + "Sour", "Owner: " + item.getNBTString("owner")] + } + .onConsume { player, item -> + player.sendMessage("Too sour!") + } + .build() + +Events.subscribe(BlockBreakEvent.class).handler{ e -> + Block block = e.getBlock() + if(block.getType() == Material.JUNGLE_LEAVES) + { + DropItem(lemonItem, block) + } +} +``` \ No newline at end of file