From 8102be41dfecf475631128a73c6a18076099f745 Mon Sep 17 00:00:00 2001 From: 5vl Date: Tue, 21 Jun 2022 17:22:53 +0200 Subject: [PATCH] Fixed most stuff that was broken! --- .../java/me/fivevl/itemadder/InteractListener.kt | 3 ++- src/main/java/me/fivevl/itemadder/Item.kt | 12 ++++++++---- src/main/java/me/fivevl/itemadder/Main.kt | 4 ++-- src/main/java/me/fivevl/itemadder/Utils.kt | 4 ++-- .../java/me/fivevl/itemadder/types/Rarity.kt | 16 ++++++++-------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/fivevl/itemadder/InteractListener.kt b/src/main/java/me/fivevl/itemadder/InteractListener.kt index d9acca7..f1a6184 100644 --- a/src/main/java/me/fivevl/itemadder/InteractListener.kt +++ b/src/main/java/me/fivevl/itemadder/InteractListener.kt @@ -27,6 +27,7 @@ class InteractListener : Listener { } } + @Suppress("deprecation") @EventHandler fun onInvClick(e: InventoryClickEvent) { if (e.whoClicked !is Player) return @@ -34,7 +35,7 @@ class InteractListener : Listener { e.isCancelled = true if (e.currentItem == null) return e.whoClicked.inventory.addItem(e.currentItem!!) - e.whoClicked.sendMessage(Utils.color("Added ${e.currentItem!!.itemMeta.displayName()} to your inventory")) + e.whoClicked.sendMessage(Utils.color("Added ${e.currentItem!!.itemMeta.displayName} to your inventory")) } @EventHandler diff --git a/src/main/java/me/fivevl/itemadder/Item.kt b/src/main/java/me/fivevl/itemadder/Item.kt index 70e882d..0787968 100644 --- a/src/main/java/me/fivevl/itemadder/Item.kt +++ b/src/main/java/me/fivevl/itemadder/Item.kt @@ -8,21 +8,25 @@ import org.bukkit.Material import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.inventory.ItemStack -class Item(uniqueName: String, name: Component, rarity: Rarity, material: Material, type: ItemType, lore: String) { +class Item(uniqueName: String, name: String, private val rarity: Rarity, material: Material, private val type: ItemType, private val lore: String) { val finalItem: ItemStack val abilities = HashMap<(PlayerInteractEvent) -> Unit, AbilityType>() init { val item = ItemStack(material) val meta = item.itemMeta - meta.displayName(name) + meta.displayName(Utils.color("${rarity.color}$name")) meta.lore(Utils.loreBuilder(lore, "", rarity.formatted + " " + type.type)) item.itemMeta = meta finalItem = item Items.items[uniqueName] = this } - fun addAbility(type: AbilityType, runnable: (PlayerInteractEvent) -> Unit) { - abilities[runnable] = type + fun addAbility(abilityType: AbilityType, name: String, addLore: String, runnable: (PlayerInteractEvent) -> Unit) { + abilities[runnable] = abilityType + val clickType = if (abilityType == AbilityType.LEFT_CLICK) "Left click" else if (abilityType == AbilityType.RIGHT_CLICK) "Right click" else "Other type" + val meta = finalItem.itemMeta + meta.lore(Utils.loreBuilder(lore, "", "$clickType: $name", addLore, rarity.formatted + " " + type.type)) + finalItem.itemMeta = meta } } \ No newline at end of file diff --git a/src/main/java/me/fivevl/itemadder/Main.kt b/src/main/java/me/fivevl/itemadder/Main.kt index e26d432..bc9f079 100644 --- a/src/main/java/me/fivevl/itemadder/Main.kt +++ b/src/main/java/me/fivevl/itemadder/Main.kt @@ -12,8 +12,8 @@ class Main : JavaPlugin() { override fun onEnable() { Bukkit.getPluginManager().registerEvents(InteractListener(), this) getCommand("items")?.setExecutor(ItemsCommand()) - Item("TEST_ITEM", Utils.color("Test Item"), Rarity.EPIC, Material.STONE_SWORD, ItemType.WEAPON, "The most basic testing\nsword, by 5vl") - Items.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK) { e: PlayerInteractEvent -> + Item("TEST_ITEM", "Test Item", Rarity.EPIC, Material.STONE_SWORD, ItemType.WEAPON, "The most basic testing\nsword, by 5vl") + Items.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK, "Send Message", "Sends you a nice message\nfor using this item!") { e: PlayerInteractEvent -> e.player.sendMessage(Utils.color("You right clicked the TEST_ITEM!")) } } diff --git a/src/main/java/me/fivevl/itemadder/Utils.kt b/src/main/java/me/fivevl/itemadder/Utils.kt index 7af9317..23f0ef3 100644 --- a/src/main/java/me/fivevl/itemadder/Utils.kt +++ b/src/main/java/me/fivevl/itemadder/Utils.kt @@ -14,10 +14,10 @@ object Utils { for (s in arr) { if (s.contains("\n")) { for (ss in s.split("\n")) { - lore.add(color(ss)) + lore.add(color("$ss")) } } else { - lore.add(color(s)) + lore.add(color("$s")) } } return lore diff --git a/src/main/java/me/fivevl/itemadder/types/Rarity.kt b/src/main/java/me/fivevl/itemadder/types/Rarity.kt index b43f100..6d7fc1b 100644 --- a/src/main/java/me/fivevl/itemadder/types/Rarity.kt +++ b/src/main/java/me/fivevl/itemadder/types/Rarity.kt @@ -1,11 +1,11 @@ package me.fivevl.itemadder.types -enum class Rarity(val formatted: String) { - COMMON("COMMON"), - UNCOMMON("UNCOMMON"), - RARE("RARE"), - EPIC("EPIC"), - LEGENDARY("LEGENDARY"), - MYTHIC("MYTHIC"), - SPECIAL("SPECIAL") +enum class Rarity(val formatted: String, val color: String) { + COMMON("COMMON", ""), + UNCOMMON("UNCOMMON", ""), + RARE("RARE", ""), + EPIC("EPIC", ""), + LEGENDARY("LEGENDARY", ""), + MYTHIC("MYTHIC", ""), + SPECIAL("SPECIAL", ""), } \ No newline at end of file