GUI && new system idk
This commit is contained in:
@@ -2,10 +2,14 @@ package org.server_info.MOTD
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
|
||||
class MOTD : JavaPlugin() {
|
||||
private var quotesTask: Int = -1
|
||||
private val quotesList = ArrayList<String>()
|
||||
private val quotesList = ArrayList<QuoteItem>()
|
||||
|
||||
// Quote data class to store text and color
|
||||
data class QuoteItem(val text: String, val color: String)
|
||||
|
||||
override fun onEnable() {
|
||||
// Save default config if it doesn't exist
|
||||
@@ -14,9 +18,12 @@ class MOTD : JavaPlugin() {
|
||||
// Load quotes from config
|
||||
loadQuotes()
|
||||
|
||||
// Register command
|
||||
// Register commands
|
||||
getCommand("motd")?.setExecutor(MOTDCommand(this))
|
||||
|
||||
// Register GUI handler
|
||||
server.pluginManager.registerEvents(MOTDGuiHandler(this), this)
|
||||
|
||||
// Schedule the MOTD update task
|
||||
startQuoteTask()
|
||||
|
||||
@@ -35,19 +42,70 @@ class MOTD : JavaPlugin() {
|
||||
// Clear existing quotes
|
||||
quotesList.clear()
|
||||
|
||||
// Load quotes from config
|
||||
val configQuotes = config.getStringList("quotes")
|
||||
if (configQuotes.isNotEmpty()) {
|
||||
quotesList.addAll(configQuotes)
|
||||
// Check if we have the new quote format
|
||||
if (config.contains("quotes") && config.isList("quotes")) {
|
||||
// Check if it's the old format (simple string list) or new format (list of maps)
|
||||
val quotesSection = config.getList("quotes")
|
||||
if (quotesSection != null && quotesSection.isNotEmpty()) {
|
||||
if (quotesSection[0] is String) {
|
||||
// Old format - migrate
|
||||
migrateOldQuotesFormat()
|
||||
} else {
|
||||
// New format - load quotes with colors
|
||||
for (i in 0 until config.getList("quotes")!!.size) {
|
||||
val quoteSection = config.getConfigurationSection("quotes.$i")
|
||||
if (quoteSection != null) {
|
||||
val text = quoteSection.getString("text") ?: continue
|
||||
val color = quoteSection.getString("color") ?: "§f" // Default to white
|
||||
quotesList.add(QuoteItem(text, color))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add default quotes if none found in config
|
||||
quotesList.add("Add Quote in Config file (config.yml)")
|
||||
|
||||
// Save default quotes to config
|
||||
config.set("quotes", quotesList)
|
||||
saveConfig()
|
||||
logger.info("No quotes found in config, created default quotes list.")
|
||||
// Create default quotes
|
||||
createDefaultQuotes()
|
||||
}
|
||||
|
||||
// If still empty after loading, create defaults
|
||||
if (quotesList.isEmpty()) {
|
||||
createDefaultQuotes()
|
||||
}
|
||||
}
|
||||
|
||||
private fun migrateOldQuotesFormat() {
|
||||
val oldQuotes = config.getStringList("quotes")
|
||||
val newQuotesList = ArrayList<Map<String, String>>()
|
||||
|
||||
for (quote in oldQuotes) {
|
||||
newQuotesList.add(mapOf("text" to quote, "color" to "§f"))
|
||||
}
|
||||
|
||||
// Save in new format
|
||||
config.set("quotes", newQuotesList)
|
||||
saveConfig()
|
||||
|
||||
// Load the quotes
|
||||
for (quoteMap in newQuotesList) {
|
||||
quotesList.add(QuoteItem(quoteMap["text"] ?: "", quoteMap["color"] ?: "§f"))
|
||||
}
|
||||
|
||||
logger.info("Migrated ${oldQuotes.size} quotes to the new format with colors.")
|
||||
}
|
||||
|
||||
private fun createDefaultQuotes() {
|
||||
val defaultQuotes = listOf(
|
||||
QuoteItem("Welcome to our Minecraft server!", "§e"),
|
||||
QuoteItem("Have fun and be respectful to others!", "§a"),
|
||||
QuoteItem("Check out our website for server rules.", "§b")
|
||||
)
|
||||
|
||||
quotesList.addAll(defaultQuotes)
|
||||
|
||||
// Save default quotes to config
|
||||
saveQuotesToConfig()
|
||||
|
||||
logger.info("No quotes found in config, created default quotes list.")
|
||||
}
|
||||
|
||||
fun startQuoteTask() {
|
||||
@@ -77,10 +135,10 @@ class MOTD : JavaPlugin() {
|
||||
}
|
||||
|
||||
// Get a random quote
|
||||
val quote = getRandomQuote()
|
||||
val quoteItem = getRandomQuote()
|
||||
|
||||
// Format the quote
|
||||
val formattedQuote = formatMOTD(quote)
|
||||
// Format the quote with its specific color
|
||||
val formattedQuote = formatMOTD(quoteItem)
|
||||
|
||||
// Set the server MOTD
|
||||
val server = Bukkit.getServer()
|
||||
@@ -89,22 +147,25 @@ class MOTD : JavaPlugin() {
|
||||
logger.info("MOTD updated: $formattedQuote")
|
||||
}
|
||||
|
||||
fun getRandomQuote(): String {
|
||||
fun getRandomQuote(): QuoteItem {
|
||||
return if (quotesList.isNotEmpty()) {
|
||||
quotesList.random()
|
||||
} else {
|
||||
"No quotes available"
|
||||
QuoteItem("No quotes available", "§c")
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatMOTD(quote: String): String {
|
||||
private fun formatMOTD(quoteItem: QuoteItem): String {
|
||||
// Get prefix and suffix from config
|
||||
val prefix = config.getString("motd-prefix", "§e§l") ?: "§e§l"
|
||||
val prefix = config.getString("motd-prefix", "") ?: ""
|
||||
val suffix = config.getString("motd-suffix", "") ?: ""
|
||||
|
||||
// Trim and limit the quote length if it's too long (Minecraft has MOTD length limitations)
|
||||
// Apply the quote's specific color
|
||||
val coloredQuote = quoteItem.color + quoteItem.text
|
||||
|
||||
// Trim and limit the quote length if it's too long
|
||||
val maxLength = config.getInt("max-motd-length", 50)
|
||||
var trimmedQuote = quote
|
||||
var trimmedQuote = coloredQuote
|
||||
if (trimmedQuote.length > maxLength) {
|
||||
trimmedQuote = trimmedQuote.substring(0, maxLength - 3) + "..."
|
||||
}
|
||||
@@ -116,4 +177,68 @@ class MOTD : JavaPlugin() {
|
||||
reloadConfig()
|
||||
loadQuotes()
|
||||
}
|
||||
|
||||
fun getCurrentQuotes(): List<QuoteItem> {
|
||||
return quotesList.toList()
|
||||
}
|
||||
|
||||
fun addQuote(text: String, color: String): Boolean {
|
||||
if (text.isBlank()) return false
|
||||
|
||||
// Validate color code
|
||||
val validColor = if (color.startsWith("§") && color.length == 2) {
|
||||
color
|
||||
} else {
|
||||
"§f" // Default to white if invalid
|
||||
}
|
||||
|
||||
// Add to internal list
|
||||
quotesList.add(QuoteItem(text, validColor))
|
||||
|
||||
// Save to config
|
||||
saveQuotesToConfig()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun removeQuote(index: Int): Boolean {
|
||||
if (index < 0 || index >= quotesList.size) return false
|
||||
|
||||
quotesList.removeAt(index)
|
||||
saveQuotesToConfig()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun editQuote(index: Int, text: String, color: String): Boolean {
|
||||
if (index < 0 || index >= quotesList.size || text.isBlank()) return false
|
||||
|
||||
// Validate color code
|
||||
val validColor = if (color.startsWith("§") && color.length == 2) {
|
||||
color
|
||||
} else {
|
||||
"§f" // Default to white if invalid
|
||||
}
|
||||
|
||||
quotesList[index] = QuoteItem(text, validColor)
|
||||
saveQuotesToConfig()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun saveQuotesToConfig() {
|
||||
// Convert quotes to format that can be saved in config
|
||||
val quotesToSave = ArrayList<Map<String, String>>()
|
||||
|
||||
for (quote in quotesList) {
|
||||
quotesToSave.add(mapOf(
|
||||
"text" to quote.text,
|
||||
"color" to quote.color
|
||||
))
|
||||
}
|
||||
|
||||
// Save to config
|
||||
config.set("quotes", quotesToSave)
|
||||
saveConfig()
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,14 @@ import org.bukkit.ChatColor
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
class MOTDCommand(private val plugin: MOTD) : CommandExecutor {
|
||||
|
||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||
if (args.isEmpty()) {
|
||||
// Display help
|
||||
sender.sendMessage("${ChatColor.GOLD}==== MOTD Quote Plugin ====")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd refresh ${ChatColor.WHITE}- Set a new random quote")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd reload ${ChatColor.WHITE}- Reload quotes from config")
|
||||
displayHelp(sender)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -28,6 +27,7 @@ class MOTDCommand(private val plugin: MOTD) : CommandExecutor {
|
||||
sender.sendMessage("${ChatColor.GREEN}MOTD has been updated!")
|
||||
return true
|
||||
}
|
||||
|
||||
"reload" -> {
|
||||
if (!sender.hasPermission("motd.reload")) {
|
||||
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.")
|
||||
@@ -39,10 +39,158 @@ class MOTDCommand(private val plugin: MOTD) : CommandExecutor {
|
||||
sender.sendMessage("${ChatColor.GREEN}MOTD quotes reloaded from config!")
|
||||
return true
|
||||
}
|
||||
|
||||
"list" -> {
|
||||
if (!sender.hasPermission("motd.list")) {
|
||||
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.")
|
||||
return true
|
||||
}
|
||||
|
||||
listQuotes(sender)
|
||||
return true
|
||||
}
|
||||
|
||||
"add" -> {
|
||||
if (!sender.hasPermission("motd.edit")) {
|
||||
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.")
|
||||
return true
|
||||
}
|
||||
|
||||
if (args.size < 2) {
|
||||
sender.sendMessage("${ChatColor.RED}Usage: /motd add <text> [color]")
|
||||
return true
|
||||
}
|
||||
|
||||
// Extract text from arguments (can contain spaces)
|
||||
val text = args.slice(1 until if (args.size > 2 && args.last().matches(Regex("&[0-9a-fA-Fk-oK-OrR]"))) args.size - 1 else args.size).joinToString(" ")
|
||||
|
||||
// Extract color if provided
|
||||
val colorCode = if (args.size > 2 && args.last().matches(Regex("&[0-9a-fA-Fk-oK-OrR]"))) {
|
||||
args.last().replace('&', '§')
|
||||
} else {
|
||||
"§f" // Default to white
|
||||
}
|
||||
|
||||
if (plugin.addQuote(text, colorCode)) {
|
||||
sender.sendMessage("${ChatColor.GREEN}Added new quote: ${colorCode}$text")
|
||||
} else {
|
||||
sender.sendMessage("${ChatColor.RED}Failed to add quote. Make sure the text is not empty.")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
"remove" -> {
|
||||
if (!sender.hasPermission("motd.edit")) {
|
||||
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.")
|
||||
return true
|
||||
}
|
||||
|
||||
if (args.size < 2 || args[1].toIntOrNull() == null) {
|
||||
sender.sendMessage("${ChatColor.RED}Usage: /motd remove <index>")
|
||||
sender.sendMessage("${ChatColor.YELLOW}Use /motd list to view quote indices.")
|
||||
return true
|
||||
}
|
||||
|
||||
val index = args[1].toInt() - 1 // Convert to 0-based index
|
||||
|
||||
if (plugin.removeQuote(index)) {
|
||||
sender.sendMessage("${ChatColor.GREEN}Successfully removed quote #${index + 1}.")
|
||||
} else {
|
||||
sender.sendMessage("${ChatColor.RED}Invalid quote index. Use /motd list to view valid indices.")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
"edit" -> {
|
||||
if (!sender.hasPermission("motd.edit")) {
|
||||
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.")
|
||||
return true
|
||||
}
|
||||
|
||||
if (args.size < 3 || args[1].toIntOrNull() == null) {
|
||||
sender.sendMessage("${ChatColor.RED}Usage: /motd edit <index> <text> [color]")
|
||||
sender.sendMessage("${ChatColor.YELLOW}Use /motd list to view quote indices.")
|
||||
return true
|
||||
}
|
||||
|
||||
val index = args[1].toInt() - 1 // Convert to 0-based index
|
||||
|
||||
// Extract text from arguments (can contain spaces)
|
||||
val text = args.slice(2 until if (args.size > 3 && args.last().matches(Regex("&[0-9a-fA-Fk-oK-OrR]"))) args.size - 1 else args.size).joinToString(" ")
|
||||
|
||||
// Extract color if provided
|
||||
val colorCode = if (args.size > 3 && args.last().matches(Regex("&[0-9a-fA-Fk-oK-OrR]"))) {
|
||||
args.last().replace('&', '§')
|
||||
} else {
|
||||
// Keep existing color if not specified
|
||||
val quotes = plugin.getCurrentQuotes()
|
||||
if (index >= 0 && index < quotes.size) {
|
||||
quotes[index].color
|
||||
} else {
|
||||
"§f" // Default to white
|
||||
}
|
||||
}
|
||||
|
||||
if (plugin.editQuote(index, text, colorCode)) {
|
||||
sender.sendMessage("${ChatColor.GREEN}Successfully edited quote #${index + 1}.")
|
||||
} else {
|
||||
sender.sendMessage("${ChatColor.RED}Failed to edit quote. Check the index and make sure the text is not empty.")
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
"gui" -> {
|
||||
if (!sender.hasPermission("motd.gui")) {
|
||||
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.")
|
||||
return true
|
||||
}
|
||||
|
||||
if (sender !is Player) {
|
||||
sender.sendMessage("${ChatColor.RED}This command can only be used by players.")
|
||||
return true
|
||||
}
|
||||
|
||||
// Open the GUI for the player
|
||||
MOTDGuiHandler(plugin).openQuotesGui(sender)
|
||||
return true
|
||||
}
|
||||
|
||||
else -> {
|
||||
sender.sendMessage("${ChatColor.RED}Unknown command. Use /motd for help.")
|
||||
displayHelp(sender)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayHelp(sender: CommandSender) {
|
||||
sender.sendMessage("${ChatColor.GOLD}==== MOTD Quote Plugin ====")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd refresh ${ChatColor.WHITE}- Set a new random quote")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd reload ${ChatColor.WHITE}- Reload quotes from config")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd list ${ChatColor.WHITE}- List all available quotes")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd add <text> [color] ${ChatColor.WHITE}- Add a new quote")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd remove <index> ${ChatColor.WHITE}- Remove a quote")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd edit <index> <text> [color] ${ChatColor.WHITE}- Edit a quote")
|
||||
sender.sendMessage("${ChatColor.YELLOW}/motd gui ${ChatColor.WHITE}- Open quote management GUI")
|
||||
sender.sendMessage("${ChatColor.AQUA}Colors: &0-&9, &a-&f, &k-&o, &r (Example: &e for yellow)")
|
||||
}
|
||||
|
||||
private fun listQuotes(sender: CommandSender) {
|
||||
val quotes = plugin.getCurrentQuotes()
|
||||
|
||||
if (quotes.isEmpty()) {
|
||||
sender.sendMessage("${ChatColor.YELLOW}No quotes are currently configured.")
|
||||
return
|
||||
}
|
||||
|
||||
sender.sendMessage("${ChatColor.GOLD}==== MOTD Quotes (${quotes.size}) ====")
|
||||
|
||||
// List all quotes with their indices
|
||||
quotes.forEachIndexed { index, quoteItem ->
|
||||
// Show the quote with its actual color
|
||||
sender.sendMessage("${ChatColor.GREEN}${index + 1}. ${quoteItem.color}${quoteItem.text}${ChatColor.GRAY} [${quoteItem.color.replace('§', '&')}]")
|
||||
}
|
||||
}
|
||||
}
|
||||
294
src/main/kotlin/org/server_info/mOTD/MOTDGuiHandler.kt
Normal file
294
src/main/kotlin/org/server_info/mOTD/MOTDGuiHandler.kt
Normal file
@@ -0,0 +1,294 @@
|
||||
package org.server_info.MOTD
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.EventHandler
|
||||
import org.bukkit.event.Listener
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.inventory.Inventory
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import java.util.*
|
||||
import org.bukkit.conversations.*
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class MOTDGuiHandler(private val plugin: MOTD) : Listener {
|
||||
|
||||
private val editingSessions = HashMap<UUID, EditSession>()
|
||||
|
||||
data class EditSession(
|
||||
val index: Int,
|
||||
val action: String // "edit" or "add"
|
||||
)
|
||||
|
||||
// Main quotes management GUI
|
||||
fun openQuotesGui(player: Player) {
|
||||
val quotes = plugin.getCurrentQuotes()
|
||||
val inventorySize = ((quotes.size / 9) + 2) * 9 // Round up to nearest multiple of 9, plus action buttons row
|
||||
|
||||
val inventory = Bukkit.createInventory(null, inventorySize, "MOTD Quotes Manager")
|
||||
|
||||
// Add quotes
|
||||
quotes.forEachIndexed { index, quoteItem ->
|
||||
val item = ItemStack(Material.PAPER)
|
||||
val meta = item.itemMeta
|
||||
|
||||
if (meta != null) {
|
||||
meta.setDisplayName("${quoteItem.color}Quote #${index + 1}")
|
||||
|
||||
val lore = ArrayList<String>()
|
||||
lore.add("${ChatColor.WHITE}${quoteItem.text}")
|
||||
lore.add("${ChatColor.GRAY}Color: ${quoteItem.color.replace('§', '&')}")
|
||||
lore.add("")
|
||||
lore.add("${ChatColor.YELLOW}Click to edit")
|
||||
lore.add("${ChatColor.RED}Shift-click to delete")
|
||||
|
||||
meta.lore = lore
|
||||
item.itemMeta = meta
|
||||
}
|
||||
|
||||
inventory.setItem(index, item)
|
||||
}
|
||||
|
||||
// Add action buttons at the bottom
|
||||
val addButton = ItemStack(Material.EMERALD_BLOCK)
|
||||
val addMeta = addButton.itemMeta
|
||||
if (addMeta != null) {
|
||||
addMeta.setDisplayName("${ChatColor.GREEN}Add New Quote")
|
||||
addButton.itemMeta = addMeta
|
||||
}
|
||||
|
||||
val refreshButton = ItemStack(Material.GOLD_BLOCK)
|
||||
val refreshMeta = refreshButton.itemMeta
|
||||
if (refreshMeta != null) {
|
||||
refreshMeta.setDisplayName("${ChatColor.YELLOW}Refresh MOTD Now")
|
||||
refreshButton.itemMeta = refreshMeta
|
||||
}
|
||||
|
||||
val exitButton = ItemStack(Material.REDSTONE_BLOCK)
|
||||
val exitMeta = exitButton.itemMeta
|
||||
if (exitMeta != null) {
|
||||
exitMeta.setDisplayName("${ChatColor.RED}Close")
|
||||
exitButton.itemMeta = exitMeta
|
||||
}
|
||||
|
||||
// Set buttons in the last row
|
||||
val lastRowStart = inventorySize - 9
|
||||
inventory.setItem(lastRowStart + 2, addButton)
|
||||
inventory.setItem(lastRowStart + 4, refreshButton)
|
||||
inventory.setItem(lastRowStart + 6, exitButton)
|
||||
|
||||
player.openInventory(inventory)
|
||||
}
|
||||
|
||||
// GUI for selecting a color
|
||||
fun openColorSelectorGui(player: Player, index: Int, action: String) {
|
||||
val inventory = Bukkit.createInventory(null, 27, "Select Quote Color")
|
||||
|
||||
// Store the user's editing session
|
||||
editingSessions[player.uniqueId] = EditSession(index, action)
|
||||
|
||||
// Add color options
|
||||
addColorOption(inventory, 0, Material.WHITE_WOOL, "White", "§f")
|
||||
addColorOption(inventory, 1, Material.ORANGE_WOOL, "Gold", "§6")
|
||||
addColorOption(inventory, 2, Material.MAGENTA_WOOL, "Light Purple", "§d")
|
||||
addColorOption(inventory, 3, Material.LIGHT_BLUE_WOOL, "Aqua", "§b")
|
||||
addColorOption(inventory, 4, Material.YELLOW_WOOL, "Yellow", "§e")
|
||||
addColorOption(inventory, 5, Material.LIME_WOOL, "Green", "§a")
|
||||
addColorOption(inventory, 6, Material.PINK_WOOL, "Light Red", "§c")
|
||||
addColorOption(inventory, 7, Material.GRAY_WOOL, "Dark Gray", "§8")
|
||||
addColorOption(inventory, 8, Material.LIGHT_GRAY_WOOL, "Gray", "§7")
|
||||
addColorOption(inventory, 9, Material.CYAN_WOOL, "Dark Aqua", "§3")
|
||||
addColorOption(inventory, 10, Material.PURPLE_WOOL, "Dark Purple", "§5")
|
||||
addColorOption(inventory, 11, Material.BLUE_WOOL, "Blue", "§9")
|
||||
addColorOption(inventory, 12, Material.BROWN_WOOL, "Brown", "§6") // Using gold as closest to brown
|
||||
addColorOption(inventory, 13, Material.GREEN_WOOL, "Dark Green", "§2")
|
||||
addColorOption(inventory, 14, Material.RED_WOOL, "Dark Red", "§4")
|
||||
addColorOption(inventory, 15, Material.BLACK_WOOL, "Black", "§0")
|
||||
|
||||
// Add formatting options
|
||||
addColorOption(inventory, 18, Material.IRON_INGOT, "Bold", "§l")
|
||||
addColorOption(inventory, 19, Material.GOLD_INGOT, "Italic", "§o")
|
||||
addColorOption(inventory, 20, Material.DIAMOND, "Underline", "§n")
|
||||
addColorOption(inventory, 21, Material.EMERALD, "Strikethrough", "§m")
|
||||
addColorOption(inventory, 22, Material.REDSTONE, "Obfuscated", "§k")
|
||||
addColorOption(inventory, 23, Material.QUARTZ, "Reset", "§r")
|
||||
|
||||
// Cancel button
|
||||
val cancelButton = ItemStack(Material.BARRIER)
|
||||
val cancelMeta = cancelButton.itemMeta
|
||||
if (cancelMeta != null) {
|
||||
cancelMeta.setDisplayName("${ChatColor.RED}Cancel")
|
||||
cancelButton.itemMeta = cancelMeta
|
||||
}
|
||||
inventory.setItem(26, cancelButton)
|
||||
|
||||
player.openInventory(inventory)
|
||||
}
|
||||
|
||||
private fun addColorOption(inventory: Inventory, slot: Int, material: Material, name: String, colorCode: String) {
|
||||
val item = ItemStack(material)
|
||||
val meta = item.itemMeta
|
||||
|
||||
if (meta != null) {
|
||||
meta.setDisplayName("${colorCode}$name")
|
||||
|
||||
val lore = ArrayList<String>()
|
||||
lore.add("${ChatColor.GRAY}Color code: ${colorCode.replace('§', '&')}")
|
||||
lore.add("${ChatColor.YELLOW}Click to select")
|
||||
|
||||
meta.lore = lore
|
||||
item.itemMeta = meta
|
||||
}
|
||||
|
||||
inventory.setItem(slot, item)
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onInventoryClick(event: InventoryClickEvent) {
|
||||
val player = event.whoClicked as? Player ?: return
|
||||
val clickedInventory = event.clickedInventory ?: return
|
||||
val title = event.view.title
|
||||
|
||||
// Prevent moving items
|
||||
if (title == "MOTD Quotes Manager" || title == "Select Quote Color") {
|
||||
event.isCancelled = true
|
||||
}
|
||||
|
||||
when (title) {
|
||||
"MOTD Quotes Manager" -> {
|
||||
handleMainGuiClick(event, player)
|
||||
}
|
||||
"Select Quote Color" -> {
|
||||
handleColorSelectorClick(event, player)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleMainGuiClick(event: InventoryClickEvent, player: Player) {
|
||||
val item = event.currentItem ?: return
|
||||
|
||||
if (item.type == Material.PAPER) {
|
||||
// Clicked on a quote
|
||||
val slotIndex = event.slot
|
||||
|
||||
if (event.isShiftClick) {
|
||||
// Delete the quote
|
||||
if (plugin.removeQuote(slotIndex)) {
|
||||
player.sendMessage("${ChatColor.GREEN}Quote #${slotIndex + 1} has been deleted.")
|
||||
openQuotesGui(player) // Refresh the GUI
|
||||
}
|
||||
} else {
|
||||
// Edit the quote
|
||||
openColorSelectorGui(player, slotIndex, "edit")
|
||||
}
|
||||
} else if (item.type == Material.EMERALD_BLOCK) {
|
||||
// Add new quote
|
||||
openColorSelectorGui(player, -1, "add")
|
||||
} else if (item.type == Material.GOLD_BLOCK) {
|
||||
// Refresh MOTD
|
||||
plugin.updateServerMOTD()
|
||||
player.sendMessage("${ChatColor.GREEN}MOTD has been refreshed!")
|
||||
} else if (item.type == Material.REDSTONE_BLOCK) {
|
||||
// Close GUI
|
||||
player.closeInventory()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleColorSelectorClick(event: InventoryClickEvent, player: Player) {
|
||||
val item = event.currentItem ?: return
|
||||
|
||||
if (item.type == Material.BARRIER) {
|
||||
// Cancel and go back
|
||||
openQuotesGui(player)
|
||||
editingSessions.remove(player.uniqueId)
|
||||
return
|
||||
}
|
||||
|
||||
// Get the color code from the clicked item
|
||||
val meta = item.itemMeta ?: return
|
||||
val displayName = meta.displayName
|
||||
|
||||
if (displayName.isNotEmpty()) {
|
||||
val colorCode = "§" + displayName[0].toString().replace("§", "")
|
||||
val session = editingSessions[player.uniqueId] ?: return
|
||||
|
||||
player.closeInventory()
|
||||
|
||||
// Start conversation for text input
|
||||
startTextInputConversation(player, session.index, session.action, colorCode)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startTextInputConversation(player: Player, index: Int, action: String, colorCode: String) {
|
||||
val factory = ConversationFactory(plugin)
|
||||
.withModality(true)
|
||||
.withPrefix { "${ChatColor.GOLD}[MOTD] ${ChatColor.RESET}" }
|
||||
.withFirstPrompt(object : StringPrompt() {
|
||||
override fun getPromptText(context: ConversationContext): String {
|
||||
return if (action == "add") {
|
||||
"${ChatColor.YELLOW}Enter the text for your new quote:"
|
||||
} else {
|
||||
"${ChatColor.YELLOW}Enter the new text for quote #${index + 1}:"
|
||||
}
|
||||
}
|
||||
|
||||
override fun acceptInput(context: ConversationContext, input: String?): Prompt? {
|
||||
if (input == null || input.isBlank()) {
|
||||
player.sendMessage("${ChatColor.RED}Quote text cannot be empty. Operation cancelled.")
|
||||
return Prompt.END_OF_CONVERSATION
|
||||
}
|
||||
|
||||
if (action == "add") {
|
||||
if (plugin.addQuote(input, colorCode)) {
|
||||
player.sendMessage("${ChatColor.GREEN}New quote added: ${colorCode}$input")
|
||||
} else {
|
||||
player.sendMessage("${ChatColor.RED}Failed to add quote.")
|
||||
}
|
||||
} else {
|
||||
if (plugin.editQuote(index, input, colorCode)) {
|
||||
player.sendMessage("${ChatColor.GREEN}Quote #${index + 1} has been updated: ${colorCode}$input")
|
||||
} else {
|
||||
player.sendMessage("${ChatColor.RED}Failed to update quote.")
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule opening the GUI on the next tick
|
||||
Bukkit.getScheduler().runTask(plugin, Runnable {
|
||||
openQuotesGui(player)
|
||||
})
|
||||
|
||||
return Prompt.END_OF_CONVERSATION
|
||||
}
|
||||
})
|
||||
.withEscapeSequence("cancel")
|
||||
.withLocalEcho(false)
|
||||
.thatExcludesNonPlayersWithMessage("This command can only be run by a player")
|
||||
|
||||
val conversation = factory.buildConversation(player)
|
||||
conversation.begin()
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun onInventoryClose(event: InventoryCloseEvent) {
|
||||
val player = event.player as? Player ?: return
|
||||
|
||||
// If the inventory being closed is the color selector but not via clicking a color option,
|
||||
// remove the editing session
|
||||
if (event.view.title == "Select Quote Color") {
|
||||
// This check is a bit simplistic; in a production plugin you'd want to be more careful
|
||||
// to differentiate between programmatic closes (which should keep the session) and
|
||||
// user-initiated closes (which should clear it)
|
||||
if (!editingSessions.containsKey(player.uniqueId)) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, Runnable {
|
||||
if (player.openInventory.title != "MOTD Quotes Manager")
|
||||
if (player.openInventory.title != "MOTD Quotes Manager") {
|
||||
editingSessions.remove(player.uniqueId)
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,12 @@
|
||||
# MOTD Quote Plugin Configuration
|
||||
|
||||
# How often to update the MOTD (in minutes)
|
||||
// config.yml
|
||||
update-interval-minutes: 60
|
||||
|
||||
# Maximum length for MOTD quotes
|
||||
max-motd-length: 50
|
||||
|
||||
# Style settings
|
||||
motd-prefix: "§e§l" # Gold color and bold
|
||||
motd-prefix: ""
|
||||
motd-suffix: ""
|
||||
|
||||
# Debug mode (shows more console output)
|
||||
debug: false
|
||||
|
||||
# List of quotes to use for MOTD
|
||||
quotes:
|
||||
- "Wie heißt der Workshop? Rassismus ohne Schule"
|
||||
- "What da fäck is hier passiert bitte sehr?"
|
||||
- "Digga meine Yeezys!"
|
||||
- "Da Sessel kommt auffi, nd owi."
|
||||
- text: "Welcome to our Minecraft server!"
|
||||
color: "§e"
|
||||
- text: "Have fun and be respectful to others!"
|
||||
color: "§a"
|
||||
- text: "Check out our website for server rules."
|
||||
color: "§b"
|
||||
@@ -2,12 +2,12 @@ name: MOTD
|
||||
version: 1.0-SNAPSHOT
|
||||
main: org.server_info.MOTD.MOTD
|
||||
api-version: 1.19
|
||||
description: Sets the server MOTD to random quotes from config
|
||||
description: Sets the server MOTD to random quotes from config with GUI management
|
||||
author: YourName
|
||||
commands:
|
||||
motd:
|
||||
description: Control the MOTD quote plugin
|
||||
usage: /motd [refresh|reload]
|
||||
usage: /motd [refresh|reload|list|add|remove|edit|gui]
|
||||
permission: motd.use
|
||||
aliases: [quotemotd]
|
||||
permissions:
|
||||
@@ -19,4 +19,13 @@ permissions:
|
||||
default: op
|
||||
motd.reload:
|
||||
description: Allows reloading the plugin configuration
|
||||
default: op
|
||||
motd.list:
|
||||
description: Allows listing all available quotes
|
||||
default: op
|
||||
motd.edit:
|
||||
description: Allows adding, removing, and editing quotes
|
||||
default: op
|
||||
motd.gui:
|
||||
description: Allows using the quote management GUI
|
||||
default: op
|
||||
Binary file not shown.
@@ -1,21 +1,12 @@
|
||||
# MOTD Quote Plugin Configuration
|
||||
|
||||
# How often to update the MOTD (in minutes)
|
||||
// config.yml
|
||||
update-interval-minutes: 60
|
||||
|
||||
# Maximum length for MOTD quotes
|
||||
max-motd-length: 50
|
||||
|
||||
# Style settings
|
||||
motd-prefix: "§e§l" # Gold color and bold
|
||||
motd-prefix: ""
|
||||
motd-suffix: ""
|
||||
|
||||
# Debug mode (shows more console output)
|
||||
debug: false
|
||||
|
||||
# List of quotes to use for MOTD
|
||||
quotes:
|
||||
- "Wie heißt der Workshop? Rassismus ohne Schule"
|
||||
- "What da fäck is hier passiert bitte sehr?"
|
||||
- "Digga meine Yeezys!"
|
||||
- "Da Sessel kommt auffi, nd owi."
|
||||
- text: "Welcome to our Minecraft server!"
|
||||
color: "§e"
|
||||
- text: "Have fun and be respectful to others!"
|
||||
color: "§a"
|
||||
- text: "Check out our website for server rules."
|
||||
color: "§b"
|
||||
Binary file not shown.
Binary file not shown.
@@ -2,12 +2,12 @@ name: MOTD
|
||||
version: 1.0-SNAPSHOT
|
||||
main: org.server_info.MOTD.MOTD
|
||||
api-version: 1.19
|
||||
description: Sets the server MOTD to random quotes from config
|
||||
description: Sets the server MOTD to random quotes from config with GUI management
|
||||
author: YourName
|
||||
commands:
|
||||
motd:
|
||||
description: Control the MOTD quote plugin
|
||||
usage: /motd [refresh|reload]
|
||||
usage: /motd [refresh|reload|list|add|remove|edit|gui]
|
||||
permission: motd.use
|
||||
aliases: [quotemotd]
|
||||
permissions:
|
||||
@@ -19,4 +19,13 @@ permissions:
|
||||
default: op
|
||||
motd.reload:
|
||||
description: Allows reloading the plugin configuration
|
||||
default: op
|
||||
motd.list:
|
||||
description: Allows listing all available quotes
|
||||
default: op
|
||||
motd.edit:
|
||||
description: Allows adding, removing, and editing quotes
|
||||
default: op
|
||||
motd.gui:
|
||||
description: Allows using the quote management GUI
|
||||
default: op
|
||||
Binary file not shown.
Reference in New Issue
Block a user