Made gui and added first item.

This commit is contained in:
5vl 2022-05-30 00:58:47 +02:00
parent a4adf307d4
commit ea485a0526
No known key found for this signature in database
GPG Key ID: DA8938F22548E4D5
5 changed files with 80 additions and 1 deletions

View File

@ -1,9 +1,12 @@
package me.fivevl.troll package me.fivevl.troll
import me.fivevl.troll.commands.TrollCommand
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
class Main : JavaPlugin() { class Main : JavaPlugin() {
override fun onEnable() { override fun onEnable() {
Utils.instance = this
getCommand("troll")!!.setExecutor(TrollCommand())
logger.info("Troll plugin enabled successfully!")
} }
} }

View File

@ -0,0 +1,18 @@
package me.fivevl.troll
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.minimessage.MiniMessage
object Utils {
lateinit var instance: Main
fun color(s: String): Component {
return MiniMessage.miniMessage().deserialize(s)
}
fun loreBuilder(vararg arr: String): ArrayList<Component> {
val lore = ArrayList<Component>()
for (s in arr) {
lore.add(color("<color:#40fff9>$s</color>"))
}
return lore
}
}

View File

@ -0,0 +1,30 @@
package me.fivevl.troll.commands
import me.fivevl.troll.Utils
import me.fivevl.troll.gui.TrollGui
import org.bukkit.Bukkit
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
class TrollCommand : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>?): Boolean {
if (sender !is Player) {
sender.sendMessage(Utils.color("<red>You must be a player to use this command!</red>"))
return true
}
val p = sender.player!!
if (args == null || args.size != 1) {
p.sendMessage(Utils.color("<red>Usage: /troll <player></red>"))
return true
}
val target = Bukkit.getPlayer(args[0])
if (target == null) {
p.sendMessage(Utils.color("<red>Player not found!</red>"))
return true
}
p.openInventory(TrollGui.getGui(target))
return true
}
}

View File

@ -0,0 +1,25 @@
package me.fivevl.troll.gui
import me.fivevl.troll.Utils
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
object TrollGui {
fun getGui(target: Player): Inventory {
val gui = Bukkit.createInventory(null, 54, Utils.color("<color:#ff9e36>Troll Menu - ${target.name}</color>"))
gui.setItem(0, getYeetItem())
return gui
}
private fun getYeetItem(): ItemStack {
val item = ItemStack(Material.ELYTRA)
val meta = item.itemMeta
meta.displayName(Utils.color("<color:#ffd6cf>Yeet</color>"))
meta.lore(Utils.loreBuilder("This will yeet the player", "in a random direction."))
item.itemMeta = meta
return item
}
}

View File

@ -4,3 +4,6 @@ main: me.fivevl.troll.Main
api-version: 1.18 api-version: 1.18
authors: [ 5vl ] authors: [ 5vl ]
description: This is a cool troll plugin! description: This is a cool troll plugin!
commands:
troll:
description: Troll a player!