mirror of
				https://github.com/5vl/ItemAdder.git
				synced 2025-11-04 14:03:41 +00:00 
			
		
		
		
	put stuff in lambda function thing
This commit is contained in:
		@@ -1,8 +0,0 @@
 | 
				
			|||||||
package me.fivevl.itemadder
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import org.bukkit.event.player.PlayerInteractEvent
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
enum class AbilityType(val event: PlayerInteractEvent) {
 | 
					 | 
				
			||||||
    LEFT_CLICK(Utils.interactEvent),
 | 
					 | 
				
			||||||
    RIGHT_CLICK(Utils.interactEvent)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package me.fivevl.itemadder
 | 
					package me.fivevl.itemadder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.AbilityType
 | 
				
			||||||
import org.bukkit.entity.Player
 | 
					import org.bukkit.entity.Player
 | 
				
			||||||
import org.bukkit.event.EventHandler
 | 
					import org.bukkit.event.EventHandler
 | 
				
			||||||
import org.bukkit.event.Listener
 | 
					import org.bukkit.event.Listener
 | 
				
			||||||
@@ -12,14 +13,14 @@ class InteractListener : Listener {
 | 
				
			|||||||
    @EventHandler
 | 
					    @EventHandler
 | 
				
			||||||
    fun onInteract(e: PlayerInteractEvent) {
 | 
					    fun onInteract(e: PlayerInteractEvent) {
 | 
				
			||||||
        if (e.item == null) return
 | 
					        if (e.item == null) return
 | 
				
			||||||
        for (check in Utils.items.values) {
 | 
					        for (check in Items.items.values) {
 | 
				
			||||||
            if (check.finalItem == e.item) {
 | 
					            if (check.finalItem == e.item) {
 | 
				
			||||||
                for (ability in check.abilities.keys) {
 | 
					                for (ability in check.abilities.keys) {
 | 
				
			||||||
                    if (check.abilities[ability]!! == AbilityType.RIGHT_CLICK && (e.action == Action.RIGHT_CLICK_AIR || e.action == Action.RIGHT_CLICK_BLOCK)) {
 | 
					                    if (check.abilities[ability]!! == AbilityType.RIGHT_CLICK && (e.action == Action.RIGHT_CLICK_AIR || e.action == Action.RIGHT_CLICK_BLOCK)) {
 | 
				
			||||||
                        ability.run()
 | 
					                        ability.invoke(e)
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    if (check.abilities[ability]!! == AbilityType.LEFT_CLICK && (e.action == Action.LEFT_CLICK_AIR || e.action == Action.LEFT_CLICK_BLOCK)) {
 | 
					                    if (check.abilities[ability]!! == AbilityType.LEFT_CLICK && (e.action == Action.LEFT_CLICK_AIR || e.action == Action.LEFT_CLICK_BLOCK)) {
 | 
				
			||||||
                        ability.run()
 | 
					                        ability.invoke(e)
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,16 @@
 | 
				
			|||||||
package me.fivevl.itemadder
 | 
					package me.fivevl.itemadder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.AbilityType
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.ItemType
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.Rarity
 | 
				
			||||||
import net.kyori.adventure.text.Component
 | 
					import net.kyori.adventure.text.Component
 | 
				
			||||||
import org.bukkit.Material
 | 
					import org.bukkit.Material
 | 
				
			||||||
 | 
					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: Type, lore: String) {
 | 
					class Item(uniqueName: String, name: Component, rarity: Rarity, material: Material, type: ItemType, lore: String) {
 | 
				
			||||||
    val finalItem: ItemStack
 | 
					    val finalItem: ItemStack
 | 
				
			||||||
    val abilities = HashMap<Runnable, AbilityType>()
 | 
					    val abilities = HashMap<(PlayerInteractEvent) -> Unit, AbilityType>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    init {
 | 
					    init {
 | 
				
			||||||
        val item = ItemStack(material)
 | 
					        val item = ItemStack(material)
 | 
				
			||||||
@@ -15,10 +19,10 @@ class Item(uniqueName: String, name: Component, rarity: Rarity, material: Materi
 | 
				
			|||||||
        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
 | 
				
			||||||
        Utils.items[uniqueName] = this
 | 
					        Items.items[uniqueName] = this
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun addAbility(type: AbilityType, runnable: Runnable) {
 | 
					    fun addAbility(type: AbilityType, runnable: (PlayerInteractEvent) -> Unit) {
 | 
				
			||||||
        abilities[runnable] = type
 | 
					        abilities[runnable] = type
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										5
									
								
								src/main/java/me/fivevl/itemadder/Items.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/main/java/me/fivevl/itemadder/Items.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					package me.fivevl.itemadder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					object Items {
 | 
				
			||||||
 | 
					    val items = HashMap<String, Item>()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -14,6 +14,7 @@ class ItemsCommand : CommandExecutor {
 | 
				
			|||||||
        val p = sender.player!!
 | 
					        val p = sender.player!!
 | 
				
			||||||
        if (p.hasPermission("itemadder.items")) {
 | 
					        if (p.hasPermission("itemadder.items")) {
 | 
				
			||||||
            p.openInventory(ItemsGui.getGui())
 | 
					            p.openInventory(ItemsGui.getGui())
 | 
				
			||||||
 | 
					            Utils.inItemsGui.add(p)
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            p.sendMessage(Utils.color("<red>You don't have permission to use this command"))
 | 
					            p.sendMessage(Utils.color("<red>You don't have permission to use this command"))
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,7 @@ import org.bukkit.inventory.Inventory
 | 
				
			|||||||
object ItemsGui {
 | 
					object ItemsGui {
 | 
				
			||||||
    fun getGui(): Inventory {
 | 
					    fun getGui(): Inventory {
 | 
				
			||||||
        val gui = Bukkit.createInventory(null, 54, Utils.color("Items"))
 | 
					        val gui = Bukkit.createInventory(null, 54, Utils.color("Items"))
 | 
				
			||||||
        for (item in Utils.items.values) {
 | 
					        for (item in Items.items.values) {
 | 
				
			||||||
            gui.addItem(item.finalItem)
 | 
					            gui.addItem(item.finalItem)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return gui
 | 
					        return gui
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,16 +1,19 @@
 | 
				
			|||||||
package me.fivevl.itemadder
 | 
					package me.fivevl.itemadder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.AbilityType
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.ItemType
 | 
				
			||||||
 | 
					import me.fivevl.itemadder.types.Rarity
 | 
				
			||||||
import org.bukkit.Bukkit
 | 
					import org.bukkit.Bukkit
 | 
				
			||||||
import org.bukkit.Material
 | 
					import org.bukkit.Material
 | 
				
			||||||
 | 
					import org.bukkit.event.player.PlayerInteractEvent
 | 
				
			||||||
import org.bukkit.plugin.java.JavaPlugin
 | 
					import org.bukkit.plugin.java.JavaPlugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Main : JavaPlugin() {
 | 
					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, Type.WEAPON, "<red>The most basic testing</red>\n<blue>sword, by 5vl</blue>")
 | 
					        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>")
 | 
				
			||||||
        Utils.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK) {
 | 
					        Items.items["TEST_ITEM"]!!.addAbility(AbilityType.RIGHT_CLICK) { e: PlayerInteractEvent ->
 | 
				
			||||||
            val e = AbilityType.RIGHT_CLICK.event
 | 
					 | 
				
			||||||
            e.player.sendMessage(Utils.color("<red>You right clicked the TEST_ITEM!"))
 | 
					            e.player.sendMessage(Utils.color("<red>You right clicked the TEST_ITEM!"))
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,11 +3,8 @@ package me.fivevl.itemadder
 | 
				
			|||||||
import net.kyori.adventure.text.Component
 | 
					import net.kyori.adventure.text.Component
 | 
				
			||||||
import net.kyori.adventure.text.minimessage.MiniMessage
 | 
					import net.kyori.adventure.text.minimessage.MiniMessage
 | 
				
			||||||
import org.bukkit.entity.Player
 | 
					import org.bukkit.entity.Player
 | 
				
			||||||
import org.bukkit.event.player.PlayerInteractEvent
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
object Utils {
 | 
					object Utils {
 | 
				
			||||||
    lateinit var interactEvent: PlayerInteractEvent
 | 
					 | 
				
			||||||
    val items = HashMap<String, Item>()
 | 
					 | 
				
			||||||
    val inItemsGui = ArrayList<Player>()
 | 
					    val inItemsGui = ArrayList<Player>()
 | 
				
			||||||
    fun color(s: String): Component {
 | 
					    fun color(s: String): Component {
 | 
				
			||||||
        return MiniMessage.miniMessage().deserialize(s)
 | 
					        return MiniMessage.miniMessage().deserialize(s)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								src/main/java/me/fivevl/itemadder/types/AbilityType.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/java/me/fivevl/itemadder/types/AbilityType.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					package me.fivevl.itemadder.types
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum class AbilityType {
 | 
				
			||||||
 | 
					    LEFT_CLICK,
 | 
				
			||||||
 | 
					    RIGHT_CLICK
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
package me.fivevl.itemadder
 | 
					package me.fivevl.itemadder.types
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum class Type(val type: String) {
 | 
					enum class ItemType(val type: String) {
 | 
				
			||||||
    WEAPON("WEAPON"),
 | 
					    WEAPON("WEAPON"),
 | 
				
			||||||
    PICKAXE("PICKAXE"),
 | 
					    PICKAXE("PICKAXE"),
 | 
				
			||||||
    ITEM("ITEM"),
 | 
					    ITEM("ITEM"),
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
package me.fivevl.itemadder
 | 
					package me.fivevl.itemadder.types
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum class Rarity(val formatted: String) {
 | 
					enum class Rarity(val formatted: String) {
 | 
				
			||||||
    COMMON("<white><bold>COMMON"),
 | 
					    COMMON("<white><bold>COMMON"),
 | 
				
			||||||
		Reference in New Issue
	
	Block a user