Easyadmin initial
All checks were successful
Maven Build / build (push) Successful in 10m35s

This commit is contained in:
rattatwinko
2025-05-10 19:16:33 +02:00
commit 7817301148
7 changed files with 847 additions and 0 deletions

View File

@@ -0,0 +1,286 @@
@file:Suppress("DEPRECATION")
package org.easyadmin.easyadmin
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta // Is very much needed but here is a error!
import org.bukkit.plugin.java.JavaPlugin
class Easyadmin : JavaPlugin(), Listener {
private val menuName = "${ChatColor.DARK_PURPLE}${ChatColor.BOLD}EasyAdmin"
override fun onEnable() {
// Register events and commands
server.pluginManager.registerEvents(this, this)
logger.info("${ChatColor.GREEN}EasyAdmin plugin enabled!")
}
override fun onDisable() {
logger.info("${ChatColor.RED}EasyAdmin plugin disabled!")
}
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender !is Player) {
sender.sendMessage("${ChatColor.RED}This command can only be used by players!")
return true
}
if (command.name.equals("easyadmin", ignoreCase = true)) {
if (!sender.hasPermission("easyadmin.use")) {
sender.sendMessage("${ChatColor.RED}You don't have permission to use this command!")
return true
}
openAdminMenu(sender)
return true
}
return false
}
private fun openAdminMenu(player: Player) {
val inventory = Bukkit.createInventory(null, 27, menuName)
// Time control
inventory.setItem(10, createGuiItem(Material.CLOCK, "${ChatColor.YELLOW}Time Control",
"${ChatColor.GRAY}Click to cycle time"))
// Weather control
inventory.setItem(11, createGuiItem(Material.WATER_BUCKET, "${ChatColor.BLUE}Weather Control",
"${ChatColor.GRAY}Click to cycle weather"))
// Kick all players
inventory.setItem(12, createGuiItem(Material.IRON_BOOTS, "${ChatColor.RED}Kick All",
"${ChatColor.GRAY}Kick all non-admin players"))
// Player management
inventory.setItem(13, createGuiItem(Material.PLAYER_HEAD, "${ChatColor.GREEN}Player Management",
"${ChatColor.GRAY}Manage online players"))
// World management
inventory.setItem(14, createGuiItem(Material.GRASS_BLOCK, "${ChatColor.GOLD}World Management",
"${ChatColor.GRAY}Manage worlds"))
// Server properties
inventory.setItem(15, createGuiItem(Material.COMMAND_BLOCK, "${ChatColor.LIGHT_PURPLE}Server Settings",
"${ChatColor.GRAY}View and modify server properties"))
// Plugin management
inventory.setItem(16, createGuiItem(Material.BOOK, "${ChatColor.AQUA}Plugin Management",
"${ChatColor.GRAY}Enable/disable plugins"))
player.openInventory(inventory)
}
private fun createGuiItem(material: Material, name: String, vararg lore: String): ItemStack {
val item = ItemStack(material, 1)
val meta = item.itemMeta!!
meta.setDisplayName(name)
if (lore.isNotEmpty()) {
meta.lore = lore.toList()
}
item.itemMeta = meta
return item
}
@EventHandler
fun onInventoryClick(event: InventoryClickEvent) {
if (event.view.title != menuName) return
event.isCancelled = true
val player = event.whoClicked as Player
if (!player.hasPermission("easyadmin.use")) return
when (event.slot) {
10 -> handleTimeControl(player)
11 -> handleWeatherControl(player)
12 -> handleKickAll(player)
13 -> openPlayerManagement(player)
14 -> openWorldManagement(player)
15 -> openServerSettings(player)
16 -> openPluginManagement(player)
}
}
private fun handleTimeControl(player: Player) {
val world = player.world
when (world.time) {
in 0..6000 -> world.time = 6000 // Set to noon
in 6001..12000 -> world.time = 12000 // Set to sunset
in 12001..18000 -> world.time = 18000 // Set to midnight
else -> world.time = 0 // Set to sunrise
}
player.sendMessage("${ChatColor.GREEN}Time changed in ${world.name}!")
}
private fun handleWeatherControl(player: Player) {
val world = player.world
when {
world.isThundering -> {
world.setStorm(false)
world.isThundering = false
player.sendMessage("${ChatColor.GREEN}Weather set to clear in ${world.name}!")
}
world.hasStorm() -> {
world.setStorm(true)
world.isThundering = true
player.sendMessage("${ChatColor.GREEN}Weather set to thunderstorm in ${world.name}!")
}
else -> {
world.setStorm(true)
player.sendMessage("${ChatColor.GREEN}Weather set to rain in ${world.name}!")
}
}
}
private fun handleKickAll(player: Player) {
val kickMessage = "${ChatColor.RED}Server is being maintained by an administrator."
var kickCount = 0
for (onlinePlayer in Bukkit.getOnlinePlayers()) {
if (!onlinePlayer.hasPermission("easyadmin.exempt") && onlinePlayer != player) {
onlinePlayer.kickPlayer(kickMessage)
kickCount++
}
}
player.sendMessage("${ChatColor.GREEN}Kicked $kickCount players from the server.")
}
private fun openPlayerManagement(player: Player) {
val inventory = Bukkit.createInventory(null, 54, "${ChatColor.GREEN}${ChatColor.BOLD}Player Management")
var slot = 0
for (onlinePlayer in Bukkit.getOnlinePlayers()) {
if (slot >= 54) break
val playerHead = ItemStack(Material.PLAYER_HEAD, 1)
val meta = playerHead.itemMeta!!
meta.setDisplayName("${ChatColor.YELLOW}${onlinePlayer.name}")
val lore = mutableListOf<String>()
lore.add("${ChatColor.GRAY}Health: ${ChatColor.RED}${onlinePlayer.health}")
lore.add("${ChatColor.GRAY}Gamemode: ${ChatColor.GOLD}${onlinePlayer.gameMode}")
lore.add("${ChatColor.GRAY}World: ${ChatColor.GREEN}${onlinePlayer.world.name}")
lore.add("")
lore.add("${ChatColor.GREEN}Left-click: ${ChatColor.WHITE}Teleport to player")
lore.add("${ChatColor.RED}Right-click: ${ChatColor.WHITE}More options")
meta.lore = lore
playerHead.itemMeta = meta
inventory.setItem(slot, playerHead)
slot++
}
player.openInventory(inventory)
}
private fun openWorldManagement(player: Player) {
val inventory = Bukkit.createInventory(null, 27, "${ChatColor.GOLD}${ChatColor.BOLD}World Management")
var slot = 0
for (world in Bukkit.getWorlds()) {
if (slot >= 27) break
val worldIcon = ItemStack(Material.GRASS_BLOCK, 1)
if (world.environment == org.bukkit.World.Environment.NETHER) {
worldIcon.type = Material.NETHERRACK
} else if (world.environment == org.bukkit.World.Environment.THE_END) {
worldIcon.type = Material.END_STONE
}
val meta = worldIcon.itemMeta!!
meta.setDisplayName("${ChatColor.YELLOW}${world.name}")
val lore = mutableListOf<String>()
lore.add("${ChatColor.GRAY}Players: ${ChatColor.WHITE}${world.players.size}")
lore.add("${ChatColor.GRAY}Time: ${ChatColor.WHITE}${world.time}")
lore.add("${ChatColor.GRAY}Weather: ${ChatColor.WHITE}${if (world.hasStorm()) "Raining" else "Clear"}")
lore.add("")
lore.add("${ChatColor.GREEN}Click: ${ChatColor.WHITE}Teleport to world spawn")
meta.lore = lore
worldIcon.itemMeta = meta
inventory.setItem(slot, worldIcon)
slot++
}
player.openInventory(inventory)
}
private fun openServerSettings(player: Player) {
val inventory = Bukkit.createInventory(null, 27, "${ChatColor.LIGHT_PURPLE}${ChatColor.BOLD}Server Settings")
// Difficulty setting
inventory.setItem(10, createGuiItem(Material.ZOMBIE_HEAD, "${ChatColor.RED}Difficulty",
"${ChatColor.GRAY}Current: ${ChatColor.WHITE}${player.world.difficulty}",
"${ChatColor.GRAY}Click to cycle"))
// Gamemode setting
inventory.setItem(11, createGuiItem(Material.DIAMOND_SWORD, "${ChatColor.BLUE}Default Gamemode",
"${ChatColor.GRAY}Current: ${ChatColor.WHITE}${Bukkit.getDefaultGameMode()}",
"${ChatColor.GRAY}Click to cycle"))
// Toggle mob spawning
inventory.setItem(12, createGuiItem(Material.SPAWNER, "${ChatColor.GREEN}Mob Spawning",
"${ChatColor.GRAY}Click to toggle mob spawning"))
// PVP toggle
inventory.setItem(13, createGuiItem(Material.GOLDEN_SWORD, "${ChatColor.GOLD}PVP",
"${ChatColor.GRAY}Click to toggle PVP"))
// Whitelist
inventory.setItem(14, createGuiItem(Material.PAPER, "${ChatColor.WHITE}Whitelist",
"${ChatColor.GRAY}Click to toggle whitelist"))
// Save all worlds
inventory.setItem(15, createGuiItem(Material.FLOWER_POT, "${ChatColor.AQUA}Save All",
"${ChatColor.GRAY}Click to save all worlds"))
// Restart server (placeholder)
inventory.setItem(16, createGuiItem(Material.REDSTONE_BLOCK, "${ChatColor.DARK_RED}Restart Server",
"${ChatColor.GRAY}Click to restart server",
"${ChatColor.RED}This requires additional setup"))
player.openInventory(inventory)
}
private fun openPluginManagement(player: Player) {
val inventory = Bukkit.createInventory(null, 54, "${ChatColor.AQUA}${ChatColor.BOLD}Plugin Management")
var slot = 0
for (plugin in Bukkit.getPluginManager().plugins) {
if (slot >= 54) break
val enabled = plugin.isEnabled
val material = if (enabled) Material.LIME_DYE else Material.GRAY_DYE
val pluginItem = createGuiItem(material,
"${if (enabled) ChatColor.GREEN else ChatColor.RED}${plugin.name}",
"${ChatColor.GRAY}Version: ${ChatColor.WHITE}${plugin.description.version}",
"${ChatColor.GRAY}Status: ${if (enabled) "${ChatColor.GREEN}Enabled" else "${ChatColor.RED}Disabled"}",
"",
"${ChatColor.YELLOW}Click to ${if (enabled) "disable" else "enable"}")
inventory.setItem(slot, pluginItem)
slot++
}
player.openInventory(inventory)
}
}

View File

@@ -0,0 +1,22 @@
name: EasyAdmin
version: 1.0-SNAPSHOT
main: org.easyadmin.easyadmin.Easyadmin
api-version: '1.21'
author: rattatwinko
description: A minimal yet powerful admin GUI for Minecraft servers
commands:
easyadmin:
description: Opens the EasyAdmin GUI
usage: /easyadmin
aliases: [ea, admin, adminpanel]
permission: easyadmin.use
permission-message: You don't have permission to use this command!
permissions:
easyadmin.use:
description: Allows access to the EasyAdmin GUI
default: op
easyadmin.exempt:
description: Exempts players from being kicked by the kick all function
default: op