mirror of
https://github.com/5vl/ItemAdder.git
synced 2025-05-24 11:06:59 +00:00
Fixed most stuff that was broken!
This commit is contained in:
parent
59d7f1822e
commit
8102be41df
@ -27,6 +27,7 @@ class InteractListener : Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("deprecation")
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onInvClick(e: InventoryClickEvent) {
|
fun onInvClick(e: InventoryClickEvent) {
|
||||||
if (e.whoClicked !is Player) return
|
if (e.whoClicked !is Player) return
|
||||||
@ -34,7 +35,7 @@ class InteractListener : Listener {
|
|||||||
e.isCancelled = true
|
e.isCancelled = true
|
||||||
if (e.currentItem == null) return
|
if (e.currentItem == null) return
|
||||||
e.whoClicked.inventory.addItem(e.currentItem!!)
|
e.whoClicked.inventory.addItem(e.currentItem!!)
|
||||||
e.whoClicked.sendMessage(Utils.color("<green>Added <blue>${e.currentItem!!.itemMeta.displayName()} <green>to your inventory"))
|
e.whoClicked.sendMessage(Utils.color("<green>Added <blue>${e.currentItem!!.itemMeta.displayName} <green>to your inventory"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -8,21 +8,25 @@ import org.bukkit.Material
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent
|
import org.bukkit.event.player.PlayerInteractEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
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 finalItem: ItemStack
|
||||||
val abilities = HashMap<(PlayerInteractEvent) -> Unit, AbilityType>()
|
val abilities = HashMap<(PlayerInteractEvent) -> Unit, AbilityType>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val item = ItemStack(material)
|
val item = ItemStack(material)
|
||||||
val meta = item.itemMeta
|
val meta = item.itemMeta
|
||||||
meta.displayName(name)
|
meta.displayName(Utils.color("<!i>${rarity.color}$name"))
|
||||||
meta.lore(Utils.loreBuilder(lore, "", rarity.formatted + " " + type.type))
|
meta.lore(Utils.loreBuilder(lore, "", rarity.formatted + " " + type.type))
|
||||||
item.itemMeta = meta
|
item.itemMeta = meta
|
||||||
finalItem = item
|
finalItem = item
|
||||||
Items.items[uniqueName] = this
|
Items.items[uniqueName] = this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addAbility(type: AbilityType, runnable: (PlayerInteractEvent) -> Unit) {
|
fun addAbility(abilityType: AbilityType, name: String, addLore: String, runnable: (PlayerInteractEvent) -> Unit) {
|
||||||
abilities[runnable] = type
|
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, "", "<yellow><bold>$clickType: <gold>$name", addLore, rarity.formatted + " " + type.type))
|
||||||
|
finalItem.itemMeta = meta
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,8 +12,8 @@ class Main : JavaPlugin() {
|
|||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
Bukkit.getPluginManager().registerEvents(InteractListener(), this)
|
Bukkit.getPluginManager().registerEvents(InteractListener(), this)
|
||||||
getCommand("items")?.setExecutor(ItemsCommand())
|
getCommand("items")?.setExecutor(ItemsCommand())
|
||||||
Item("TEST_ITEM", Utils.color("<blue>Test Item"), Rarity.EPIC, Material.STONE_SWORD, ItemType.WEAPON, "<red>The most basic testing</red>\n<blue>sword, by 5vl</blue>")
|
Item("TEST_ITEM", "Test Item", Rarity.EPIC, Material.STONE_SWORD, ItemType.WEAPON, "<red>The most basic testing</red>\n<blue>sword, by 5vl</blue>")
|
||||||
Items.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK) { e: PlayerInteractEvent ->
|
Items.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK, "Send Message", "<light_purple>Sends you a nice message\n<light_purple>for using this item!") { e: PlayerInteractEvent ->
|
||||||
e.player.sendMessage(Utils.color("<red>You right clicked the TEST_ITEM!"))
|
e.player.sendMessage(Utils.color("<red>You right clicked the TEST_ITEM!"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@ object Utils {
|
|||||||
for (s in arr) {
|
for (s in arr) {
|
||||||
if (s.contains("\n")) {
|
if (s.contains("\n")) {
|
||||||
for (ss in s.split("\n")) {
|
for (ss in s.split("\n")) {
|
||||||
lore.add(color(ss))
|
lore.add(color("<!i>$ss"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lore.add(color(s))
|
lore.add(color("<!i>$s"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lore
|
return lore
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package me.fivevl.itemadder.types
|
package me.fivevl.itemadder.types
|
||||||
|
|
||||||
enum class Rarity(val formatted: String) {
|
enum class Rarity(val formatted: String, val color: String) {
|
||||||
COMMON("<white><bold>COMMON"),
|
COMMON("<white><bold>COMMON", "<white>"),
|
||||||
UNCOMMON("<lime><bold>UNCOMMON"),
|
UNCOMMON("<lime><bold>UNCOMMON", "<lime>"),
|
||||||
RARE("<blue><bold>RARE"),
|
RARE("<blue><bold>RARE", "<blue>"),
|
||||||
EPIC("<purple><bold>EPIC"),
|
EPIC("<dark_purple><bold>EPIC", "<dark_purple>"),
|
||||||
LEGENDARY("<gold><bold>LEGENDARY"),
|
LEGENDARY("<gold><bold>LEGENDARY", "<gold>"),
|
||||||
MYTHIC("<pink><bold>MYTHIC"),
|
MYTHIC("<pink><bold>MYTHIC", "<pink>"),
|
||||||
SPECIAL("<red><bold>SPECIAL")
|
SPECIAL("<red><bold>SPECIAL", "<red>"),
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user