fixed left clicking i think
All checks were successful
Maven Build / build (push) Successful in 10m39s
All checks were successful
Maven Build / build (push) Successful in 10m39s
This commit is contained in:
@@ -12,9 +12,10 @@ import org.bukkit.event.EventHandler
|
|||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent
|
import org.bukkit.event.inventory.InventoryClickEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.ItemMeta // Is very much needed but here is a error!
|
import org.bukkit.inventory.meta.ItemMeta // Don't remove!
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin // Don't remove!
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
class Easyadmin : JavaPlugin(), Listener {
|
class Easyadmin : JavaPlugin(), Listener {
|
||||||
private val menuName = "${ChatColor.DARK_PURPLE}${ChatColor.BOLD}EasyAdmin"
|
private val menuName = "${ChatColor.DARK_PURPLE}${ChatColor.BOLD}EasyAdmin"
|
||||||
|
|
||||||
@@ -97,21 +98,151 @@ class Easyadmin : JavaPlugin(), Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onInventoryClick(event: InventoryClickEvent) {
|
fun onInventoryClick(event: InventoryClickEvent) {
|
||||||
if (event.view.title != menuName) return
|
val title = event.view.title
|
||||||
|
|
||||||
event.isCancelled = true
|
|
||||||
|
|
||||||
val player = event.whoClicked as Player
|
val player = event.whoClicked as Player
|
||||||
|
|
||||||
if (!player.hasPermission("easyadmin.use")) return
|
if (!player.hasPermission("easyadmin.use")) return
|
||||||
|
|
||||||
when (event.slot) {
|
// Handle clicks in the main menu
|
||||||
10 -> handleTimeControl(player)
|
if (title == menuName) {
|
||||||
11 -> handleWeatherControl(player)
|
event.isCancelled = true
|
||||||
12 -> handleKickAll(player)
|
|
||||||
13 -> openPlayerManagement(player)
|
when (event.slot) {
|
||||||
14 -> openWorldManagement(player)
|
10 -> handleTimeControl(player)
|
||||||
15 -> openServerSettings(player)
|
11 -> handleWeatherControl(player)
|
||||||
16 -> openPluginManagement(player)
|
12 -> handleKickAll(player)
|
||||||
|
13 -> openPlayerManagement(player)
|
||||||
|
14 -> openWorldManagement(player)
|
||||||
|
15 -> openServerSettings(player)
|
||||||
|
16 -> openPluginManagement(player)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle player management menu
|
||||||
|
if (title == "${ChatColor.GREEN}${ChatColor.BOLD}Player Management") {
|
||||||
|
event.isCancelled = true
|
||||||
|
|
||||||
|
val clickedItem = event.currentItem ?: return
|
||||||
|
if (clickedItem.type != Material.PLAYER_HEAD) return
|
||||||
|
|
||||||
|
val itemMeta = clickedItem.itemMeta ?: return
|
||||||
|
val displayName = itemMeta.displayName
|
||||||
|
val targetPlayerName = ChatColor.stripColor(displayName) ?: return
|
||||||
|
|
||||||
|
val targetPlayer = Bukkit.getPlayerExact(targetPlayerName) ?: return
|
||||||
|
|
||||||
|
// Left click: teleport to player
|
||||||
|
if (event.isLeftClick) {
|
||||||
|
player.teleport(targetPlayer.location)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Teleported to ${targetPlayer.name}!")
|
||||||
|
player.closeInventory()
|
||||||
|
}
|
||||||
|
// Right click: open player options menu
|
||||||
|
else if (event.isRightClick) {
|
||||||
|
openPlayerOptionsMenu(player, targetPlayer)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle world management menu
|
||||||
|
if (title == "${ChatColor.GOLD}${ChatColor.BOLD}World Management") {
|
||||||
|
event.isCancelled = true
|
||||||
|
|
||||||
|
val clickedItem = event.currentItem ?: return
|
||||||
|
if (clickedItem.type !in listOf(Material.GRASS_BLOCK, Material.NETHERRACK, Material.END_STONE)) return
|
||||||
|
|
||||||
|
val itemMeta = clickedItem.itemMeta ?: return
|
||||||
|
val displayName = itemMeta.displayName
|
||||||
|
val worldName = ChatColor.stripColor(displayName) ?: return
|
||||||
|
|
||||||
|
val world = Bukkit.getWorld(worldName) ?: return
|
||||||
|
|
||||||
|
player.teleport(world.spawnLocation)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Teleported to ${world.name}'s spawn point!")
|
||||||
|
player.closeInventory()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle server settings menu
|
||||||
|
if (title == "${ChatColor.LIGHT_PURPLE}${ChatColor.BOLD}Server Settings") {
|
||||||
|
event.isCancelled = true
|
||||||
|
|
||||||
|
when (event.slot) {
|
||||||
|
10 -> cycleDifficulty(player)
|
||||||
|
11 -> cycleDefaultGamemode(player)
|
||||||
|
12 -> toggleMobSpawning(player)
|
||||||
|
13 -> togglePvP(player)
|
||||||
|
14 -> toggleWhitelist(player)
|
||||||
|
15 -> saveAllWorlds(player)
|
||||||
|
16 -> player.sendMessage("${ChatColor.YELLOW}Server restart requires additional configuration.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh the menu to show updated settings
|
||||||
|
openServerSettings(player)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle plugin management menu
|
||||||
|
if (title == "${ChatColor.AQUA}${ChatColor.BOLD}Plugin Management") {
|
||||||
|
event.isCancelled = true
|
||||||
|
|
||||||
|
val clickedItem = event.currentItem ?: return
|
||||||
|
if (clickedItem.type !in listOf(Material.LIME_DYE, Material.GRAY_DYE)) return
|
||||||
|
|
||||||
|
val itemMeta = clickedItem.itemMeta ?: return
|
||||||
|
val displayName = itemMeta.displayName
|
||||||
|
val pluginName = ChatColor.stripColor(displayName) ?: return
|
||||||
|
|
||||||
|
val plugin = Bukkit.getPluginManager().getPlugin(pluginName) ?: return
|
||||||
|
|
||||||
|
if (plugin.name == "EasyAdmin") {
|
||||||
|
player.sendMessage("${ChatColor.RED}You cannot disable the EasyAdmin plugin from within itself!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.isEnabled) {
|
||||||
|
Bukkit.getPluginManager().disablePlugin(plugin)
|
||||||
|
player.sendMessage("${ChatColor.RED}Disabled plugin: ${plugin.name}")
|
||||||
|
} else {
|
||||||
|
Bukkit.getPluginManager().enablePlugin(plugin)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Enabled plugin: ${plugin.name}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Refresh the plugin management menu
|
||||||
|
openPluginManagement(player)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle player options menu
|
||||||
|
if (title.startsWith("${ChatColor.YELLOW}Player: ")) {
|
||||||
|
event.isCancelled = true
|
||||||
|
|
||||||
|
val targetPlayerName = title.substring("${ChatColor.YELLOW}Player: ".length)
|
||||||
|
val targetPlayer = Bukkit.getPlayerExact(targetPlayerName) ?: return
|
||||||
|
|
||||||
|
when (event.slot) {
|
||||||
|
10 -> {
|
||||||
|
player.teleport(targetPlayer.location)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Teleported to ${targetPlayer.name}!")
|
||||||
|
player.closeInventory()
|
||||||
|
}
|
||||||
|
11 -> {
|
||||||
|
targetPlayer.teleport(player.location)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Teleported ${targetPlayer.name} to you!")
|
||||||
|
player.closeInventory()
|
||||||
|
}
|
||||||
|
12 -> cycleGamemode(player, targetPlayer)
|
||||||
|
13 -> healPlayer(player, targetPlayer)
|
||||||
|
14 -> kickPlayer(player, targetPlayer)
|
||||||
|
15 -> {
|
||||||
|
// Open ban interface (simplified for this example)
|
||||||
|
player.sendMessage("${ChatColor.YELLOW}Use /ban ${targetPlayer.name} <reason> to ban this player.")
|
||||||
|
player.closeInventory()
|
||||||
|
}
|
||||||
|
26 -> openPlayerManagement(player) // Back button
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +320,84 @@ class Easyadmin : JavaPlugin(), Listener {
|
|||||||
player.openInventory(inventory)
|
player.openInventory(inventory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun openPlayerOptionsMenu(player: Player, targetPlayer: Player) {
|
||||||
|
val inventory = Bukkit.createInventory(null, 27, "${ChatColor.YELLOW}Player: ${targetPlayer.name}")
|
||||||
|
|
||||||
|
// Teleport to player
|
||||||
|
inventory.setItem(10, createGuiItem(Material.ENDER_PEARL, "${ChatColor.GREEN}Teleport to Player",
|
||||||
|
"${ChatColor.GRAY}Teleport to ${targetPlayer.name}"))
|
||||||
|
|
||||||
|
// Teleport player to you
|
||||||
|
inventory.setItem(11, createGuiItem(Material.ENDER_EYE, "${ChatColor.BLUE}Teleport Player to You",
|
||||||
|
"${ChatColor.GRAY}Teleport ${targetPlayer.name} to your location"))
|
||||||
|
|
||||||
|
// Change player gamemode
|
||||||
|
inventory.setItem(12, createGuiItem(Material.DIAMOND_SWORD, "${ChatColor.GOLD}Change Gamemode",
|
||||||
|
"${ChatColor.GRAY}Current: ${ChatColor.WHITE}${targetPlayer.gameMode}",
|
||||||
|
"${ChatColor.GRAY}Click to cycle"))
|
||||||
|
|
||||||
|
// Heal player
|
||||||
|
inventory.setItem(13, createGuiItem(Material.GOLDEN_APPLE, "${ChatColor.LIGHT_PURPLE}Heal Player",
|
||||||
|
"${ChatColor.GRAY}Health: ${ChatColor.RED}${targetPlayer.health}/${targetPlayer.maxHealth}",
|
||||||
|
"${ChatColor.GRAY}Click to restore health and hunger"))
|
||||||
|
|
||||||
|
// Kick player
|
||||||
|
inventory.setItem(14, createGuiItem(Material.IRON_BOOTS, "${ChatColor.RED}Kick Player",
|
||||||
|
"${ChatColor.GRAY}Kick ${targetPlayer.name} from the server"))
|
||||||
|
|
||||||
|
// Ban player
|
||||||
|
inventory.setItem(15, createGuiItem(Material.BARRIER, "${ChatColor.DARK_RED}Ban Player",
|
||||||
|
"${ChatColor.GRAY}Ban ${targetPlayer.name} from the server"))
|
||||||
|
|
||||||
|
// Back button
|
||||||
|
inventory.setItem(26, createGuiItem(Material.ARROW, "${ChatColor.YELLOW}Back",
|
||||||
|
"${ChatColor.GRAY}Return to player list"))
|
||||||
|
|
||||||
|
player.openInventory(inventory)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cycleGamemode(player: Player, targetPlayer: Player) {
|
||||||
|
val currentGamemode = targetPlayer.gameMode
|
||||||
|
|
||||||
|
val newGamemode = when (currentGamemode) {
|
||||||
|
org.bukkit.GameMode.SURVIVAL -> org.bukkit.GameMode.CREATIVE
|
||||||
|
org.bukkit.GameMode.CREATIVE -> org.bukkit.GameMode.ADVENTURE
|
||||||
|
org.bukkit.GameMode.ADVENTURE -> org.bukkit.GameMode.SPECTATOR
|
||||||
|
org.bukkit.GameMode.SPECTATOR -> org.bukkit.GameMode.SURVIVAL
|
||||||
|
}
|
||||||
|
|
||||||
|
targetPlayer.gameMode = newGamemode
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Set ${targetPlayer.name}'s gamemode to $newGamemode.")
|
||||||
|
targetPlayer.sendMessage("${ChatColor.GREEN}Your gamemode was set to $newGamemode by ${player.name}.")
|
||||||
|
|
||||||
|
// Refresh the player options menu
|
||||||
|
openPlayerOptionsMenu(player, targetPlayer)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun healPlayer(player: Player, targetPlayer: Player) {
|
||||||
|
targetPlayer.health = targetPlayer.maxHealth
|
||||||
|
targetPlayer.foodLevel = 20
|
||||||
|
targetPlayer.saturation = 20f
|
||||||
|
targetPlayer.fireTicks = 0
|
||||||
|
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Healed ${targetPlayer.name}.")
|
||||||
|
targetPlayer.sendMessage("${ChatColor.GREEN}You were healed by ${player.name}.")
|
||||||
|
|
||||||
|
// Refresh the player options menu
|
||||||
|
openPlayerOptionsMenu(player, targetPlayer)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun kickPlayer(player: Player, targetPlayer: Player) {
|
||||||
|
if (targetPlayer.hasPermission("easyadmin.exempt")) {
|
||||||
|
player.sendMessage("${ChatColor.RED}You cannot kick ${targetPlayer.name} as they are exempt!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
targetPlayer.kickPlayer("${ChatColor.RED}You have been kicked by an administrator.")
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Kicked ${targetPlayer.name} from the server.")
|
||||||
|
player.closeInventory()
|
||||||
|
}
|
||||||
|
|
||||||
private fun openWorldManagement(player: Player) {
|
private fun openWorldManagement(player: Player) {
|
||||||
val inventory = Bukkit.createInventory(null, 27, "${ChatColor.GOLD}${ChatColor.BOLD}World Management")
|
val inventory = Bukkit.createInventory(null, 27, "${ChatColor.GOLD}${ChatColor.BOLD}World Management")
|
||||||
|
|
||||||
@@ -237,15 +446,19 @@ class Easyadmin : JavaPlugin(), Listener {
|
|||||||
"${ChatColor.GRAY}Click to cycle"))
|
"${ChatColor.GRAY}Click to cycle"))
|
||||||
|
|
||||||
// Toggle mob spawning
|
// Toggle mob spawning
|
||||||
|
val spawnMobs = player.world.getGameRuleValue(org.bukkit.GameRule.DO_MOB_SPAWNING) ?: true
|
||||||
inventory.setItem(12, createGuiItem(Material.SPAWNER, "${ChatColor.GREEN}Mob Spawning",
|
inventory.setItem(12, createGuiItem(Material.SPAWNER, "${ChatColor.GREEN}Mob Spawning",
|
||||||
|
"${ChatColor.GRAY}Current: ${if (spawnMobs) "${ChatColor.GREEN}Enabled" else "${ChatColor.RED}Disabled"}",
|
||||||
"${ChatColor.GRAY}Click to toggle mob spawning"))
|
"${ChatColor.GRAY}Click to toggle mob spawning"))
|
||||||
|
|
||||||
// PVP toggle
|
// PVP toggle
|
||||||
inventory.setItem(13, createGuiItem(Material.GOLDEN_SWORD, "${ChatColor.GOLD}PVP",
|
inventory.setItem(13, createGuiItem(Material.GOLDEN_SWORD, "${ChatColor.GOLD}PVP",
|
||||||
|
"${ChatColor.GRAY}Current: ${if (player.world.pvp) "${ChatColor.GREEN}Enabled" else "${ChatColor.RED}Disabled"}",
|
||||||
"${ChatColor.GRAY}Click to toggle PVP"))
|
"${ChatColor.GRAY}Click to toggle PVP"))
|
||||||
|
|
||||||
// Whitelist
|
// Whitelist
|
||||||
inventory.setItem(14, createGuiItem(Material.PAPER, "${ChatColor.WHITE}Whitelist",
|
inventory.setItem(14, createGuiItem(Material.PAPER, "${ChatColor.WHITE}Whitelist",
|
||||||
|
"${ChatColor.GRAY}Current: ${if (Bukkit.hasWhitelist()) "${ChatColor.GREEN}Enabled" else "${ChatColor.RED}Disabled"}",
|
||||||
"${ChatColor.GRAY}Click to toggle whitelist"))
|
"${ChatColor.GRAY}Click to toggle whitelist"))
|
||||||
|
|
||||||
// Save all worlds
|
// Save all worlds
|
||||||
@@ -260,6 +473,64 @@ class Easyadmin : JavaPlugin(), Listener {
|
|||||||
player.openInventory(inventory)
|
player.openInventory(inventory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun cycleDifficulty(player: Player) {
|
||||||
|
val world = player.world
|
||||||
|
val difficulty = world.difficulty
|
||||||
|
|
||||||
|
world.difficulty = when (difficulty) {
|
||||||
|
org.bukkit.Difficulty.PEACEFUL -> org.bukkit.Difficulty.EASY
|
||||||
|
org.bukkit.Difficulty.EASY -> org.bukkit.Difficulty.NORMAL
|
||||||
|
org.bukkit.Difficulty.NORMAL -> org.bukkit.Difficulty.HARD
|
||||||
|
org.bukkit.Difficulty.HARD -> org.bukkit.Difficulty.PEACEFUL
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Difficulty set to ${world.difficulty} in ${world.name}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cycleDefaultGamemode(player: Player) {
|
||||||
|
val currentGamemode = Bukkit.getDefaultGameMode()
|
||||||
|
|
||||||
|
val newGamemode = when (currentGamemode) {
|
||||||
|
org.bukkit.GameMode.SURVIVAL -> org.bukkit.GameMode.CREATIVE
|
||||||
|
org.bukkit.GameMode.CREATIVE -> org.bukkit.GameMode.ADVENTURE
|
||||||
|
org.bukkit.GameMode.ADVENTURE -> org.bukkit.GameMode.SPECTATOR
|
||||||
|
org.bukkit.GameMode.SPECTATOR -> org.bukkit.GameMode.SURVIVAL
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.setDefaultGameMode(newGamemode)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Default gamemode set to $newGamemode.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleMobSpawning(player: Player) {
|
||||||
|
val world = player.world
|
||||||
|
val currentValue = world.getGameRuleValue(org.bukkit.GameRule.DO_MOB_SPAWNING) ?: true
|
||||||
|
|
||||||
|
world.setGameRule(org.bukkit.GameRule.DO_MOB_SPAWNING, !currentValue)
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Mob spawning ${if (!currentValue) "enabled" else "disabled"} in ${world.name}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun togglePvP(player: Player) {
|
||||||
|
val world = player.world
|
||||||
|
world.pvp = !world.pvp
|
||||||
|
|
||||||
|
player.sendMessage("${ChatColor.GREEN}PvP ${if (world.pvp) "enabled" else "disabled"} in ${world.name}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleWhitelist(player: Player) {
|
||||||
|
val currentValue = Bukkit.hasWhitelist()
|
||||||
|
Bukkit.setWhitelist(!currentValue)
|
||||||
|
|
||||||
|
player.sendMessage("${ChatColor.GREEN}Whitelist ${if (!currentValue) "enabled" else "disabled"}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveAllWorlds(player: Player) {
|
||||||
|
for (world in Bukkit.getWorlds()) {
|
||||||
|
world.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendMessage("${ChatColor.GREEN}All worlds have been saved.")
|
||||||
|
}
|
||||||
|
|
||||||
private fun openPluginManagement(player: Player) {
|
private fun openPluginManagement(player: Player) {
|
||||||
val inventory = Bukkit.createInventory(null, 54, "${ChatColor.AQUA}${ChatColor.BOLD}Plugin Management")
|
val inventory = Bukkit.createInventory(null, 54, "${ChatColor.AQUA}${ChatColor.BOLD}Plugin Management")
|
||||||
|
|
||||||
@@ -283,4 +554,4 @@ class Easyadmin : JavaPlugin(), Listener {
|
|||||||
|
|
||||||
player.openInventory(inventory)
|
player.openInventory(inventory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user