mirror of
				https://github.com/5vl/ItemAdder.git
				synced 2025-11-04 13:43:36 +00:00 
			
		
		
		
	Fixed most stuff that was broken!
This commit is contained in:
		@@ -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("<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
 | 
			
		||||
 
 | 
			
		||||
@@ -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("<!i>${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, "", "<yellow><bold>$clickType: <gold>$name", addLore, rarity.formatted + " " + type.type))
 | 
			
		||||
        finalItem.itemMeta = meta
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -12,8 +12,8 @@ class Main : JavaPlugin() {
 | 
			
		||||
    override fun onEnable() {
 | 
			
		||||
        Bukkit.getPluginManager().registerEvents(InteractListener(), this)
 | 
			
		||||
        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>")
 | 
			
		||||
        Items.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK) { e: PlayerInteractEvent ->
 | 
			
		||||
        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, "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!"))
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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("<!i>$ss"))
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                lore.add(color(s))
 | 
			
		||||
                lore.add(color("<!i>$s"))
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return lore
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
package me.fivevl.itemadder.types
 | 
			
		||||
 | 
			
		||||
enum class Rarity(val formatted: String) {
 | 
			
		||||
    COMMON("<white><bold>COMMON"),
 | 
			
		||||
    UNCOMMON("<lime><bold>UNCOMMON"),
 | 
			
		||||
    RARE("<blue><bold>RARE"),
 | 
			
		||||
    EPIC("<purple><bold>EPIC"),
 | 
			
		||||
    LEGENDARY("<gold><bold>LEGENDARY"),
 | 
			
		||||
    MYTHIC("<pink><bold>MYTHIC"),
 | 
			
		||||
    SPECIAL("<red><bold>SPECIAL")
 | 
			
		||||
enum class Rarity(val formatted: String, val color: String) {
 | 
			
		||||
    COMMON("<white><bold>COMMON", "<white>"),
 | 
			
		||||
    UNCOMMON("<lime><bold>UNCOMMON", "<lime>"),
 | 
			
		||||
    RARE("<blue><bold>RARE", "<blue>"),
 | 
			
		||||
    EPIC("<dark_purple><bold>EPIC", "<dark_purple>"),
 | 
			
		||||
    LEGENDARY("<gold><bold>LEGENDARY", "<gold>"),
 | 
			
		||||
    MYTHIC("<pink><bold>MYTHIC", "<pink>"),
 | 
			
		||||
    SPECIAL("<red><bold>SPECIAL", "<red>"),
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user