all should work now

This commit is contained in:
5vl 2022-04-12 08:47:02 +02:00
parent 344c4f2a95
commit d407ce6e57
No known key found for this signature in database
GPG Key ID: DA8938F22548E4D5
9 changed files with 78 additions and 21 deletions

View File

@ -3,14 +3,17 @@ package me.fivevl.staff
import org.bukkit.configuration.file.FileConfiguration
object Config {
var config: FileConfiguration? = null
val mustBePlayer = config?.getString("must-be-player")
val noPermission = config?.getString("no-permission")
val toggleStaffmode = config?.getString("toggle-staffmode")
private fun getConfig(): FileConfiguration {
return Utils.getConfig()
}
val mustBePlayer = getConfig().getString("must-be-player")!!
val noPermission = getConfig().getString("no-permission")!!
val toggleStaffmode = getConfig().getString("toggle-staffmode")!!
val toggleVanish = getConfig().getString("toggle-vanish")!!
val staffmodeHotbar = HashMap<Int, String>().apply {
config?.getConfigurationSection("staffmode-hotbar")?.getKeys(false)?.forEach {
put(it.toInt(), config?.getString("staffmode-hotbar.$it")!!)
getConfig().getConfigurationSection("staffmode-hotbar")?.getKeys(false)?.forEach {
put(it.toInt(), getConfig().getString("staffmode-hotbar.$it")!!)
}
}
val toggleVanish = config?.getString("toggle-vanish")
val disableStaffmodeItem = getConfig().getString("disable-staffmode-item")!!
}

View File

@ -0,0 +1,19 @@
package me.fivevl.staff
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
enum class Items(val item: ItemStack) {
DISABLE_STAFFMODE(getStaffmodeItem()),
FREEZE_WAND(ItemStack(Material.STICK)),
INVENTORY_WAND(ItemStack(Material.STICK)),
KB_STICK(ItemStack(Material.STICK)),
VANISH_ITEM(ItemStack(Material.STICK)),
}
@Suppress("deprecation")
private fun getStaffmodeItem(): ItemStack {
val item = ItemStack(Material.LIME_DYE)
val meta = item.itemMeta
meta.setDisplayName(Utils.hex(Utils.getPlaceholders(null, Config.disableStaffmodeItem)))
return item
}

View File

@ -11,7 +11,6 @@ class Main : JavaPlugin() {
Utils.instance = this
saveDefaultConfig()
Config.config = config
getCommand("staffmode")!!.setExecutor(StaffModeCommand())
getCommand("vanish")!!.setExecutor(VanishCommand())

View File

@ -4,6 +4,7 @@ import me.clip.placeholderapi.PlaceholderAPI
import net.md_5.bungee.api.ChatColor
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.PlayerInventory
@ -11,7 +12,7 @@ import java.util.regex.Pattern
object Utils {
var instance: Main? = null
private val inStaffmode = HashMap<Player, PlayerInventory>()
val inStaffmode = HashMap<Player, PlayerInventory>()
val inVanish = ArrayList<Player>()
@Suppress("deprecation")
fun hex(s: String): String {
@ -20,7 +21,7 @@ object Utils {
var match = pattern.matcher(s)
while (match.find()) {
val color = s.substring(match.start(), match.end())
s2 = s2.replace(color, ChatColor.of(color).toString() + "")
s2 = s2.replace(color, ChatColor.of(color).toString())
match = pattern.matcher(s2)
}
return ChatColor.translateAlternateColorCodes('&', s2)
@ -39,31 +40,33 @@ object Utils {
for (i: Int in Config.staffmodeHotbar.keys) {
var item = ItemStack(Material.AIR)
when (Config.staffmodeHotbar[i]) {
"DISABLE_STAFFMODE" -> item = ItemStack(Material.AIR)
"FREEZE_WAND" -> item = ItemStack(Material.AIR)
"INVENTORY_WAND" -> item = ItemStack(Material.AIR)
"KB_STICK" -> item = ItemStack(Material.AIR)
"VANISH_ITEM" -> item = ItemStack(Material.AIR)
"DISABLE_STAFFMODE" -> item = Items.DISABLE_STAFFMODE.item
"FREEZE_WAND" -> item = Items.FREEZE_WAND.item
"INVENTORY_WAND" -> item = Items.INVENTORY_WAND.item
"KB_STICK" -> item = Items.KB_STICK.item
"VANISH_ITEM" -> item = Items.VANISH_ITEM.item
}
p.inventory.setItem(i - 1, item)
}
}
p.sendMessage(hex(getPlaceholders(p, Config.toggleStaffmode!!)))
p.sendMessage(hex(getPlaceholders(p, Config.toggleStaffmode)))
}
fun toggleVanish(p: Player) {
if (inVanish.contains(p)) {
for (ps in Bukkit.getOnlinePlayers()) {
ps.showPlayer(instance!!, p)
}
inVanish.remove(p)
p.sendMessage(hex(getPlaceholders(p, Config.toggleVanish!!)))
} else {
for (ps in Bukkit.getOnlinePlayers()) {
ps.hidePlayer(instance!!, p)
}
inVanish.add(p)
p.sendMessage(hex(getPlaceholders(p, Config.toggleVanish!!)))
}
p.sendMessage(hex(getPlaceholders(p, Config.toggleVanish)))
}
fun getConfig(): FileConfiguration {
return instance!!.config
}
}

View File

@ -10,12 +10,12 @@ import org.bukkit.entity.Player
class StaffModeCommand : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender !is Player) {
sender.sendMessage(Utils.hex(Utils.getPlaceholders(null, Config.mustBePlayer!!)))
sender.sendMessage(Utils.hex(Utils.getPlaceholders(null, Config.mustBePlayer)))
return true
}
val p = sender.player!!
if (!p.hasPermission("staff.staffmode")) {
p.sendMessage(Utils.hex(Utils.getPlaceholders(p, Config.noPermission!!)))
p.sendMessage(Utils.hex(Utils.getPlaceholders(p, Config.noPermission)))
return true
}
Utils.toggleStaffmode(p)

View File

@ -1,11 +1,24 @@
package me.fivevl.staff.commands
import me.fivevl.staff.Config
import me.fivevl.staff.Utils
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
class VanishCommand : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender !is Player) {
sender.sendMessage(Utils.hex(Utils.getPlaceholders(null, Config.mustBePlayer)))
return true
}
val p = sender.player!!
if (!p.hasPermission("staff.vanish")) {
p.sendMessage(Utils.hex(Utils.getPlaceholders(p, Config.noPermission)))
return true
}
Utils.toggleVanish(p)
return true
}

View File

@ -4,13 +4,30 @@ import me.fivevl.staff.Utils
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
class JoinListener : Listener {
@Suppress("deprecation")
@EventHandler
fun onJoin(e: PlayerJoinEvent) {
e.joinMessage = null
val p = e.player
for (ps in Utils.inVanish) {
p.hidePlayer(Utils.instance!!, ps)
}
}
@Suppress("deprecation")
@EventHandler
fun onLeave (e: PlayerQuitEvent) {
e.quitMessage = null
val p = e.player
if (Utils.inVanish.contains(p)) {
Utils.inVanish.remove(p)
}
if (Utils.inStaffmode.contains(p)) {
p.inventory.clear()
p.inventory.contents = Utils.inStaffmode[p]!!.contents
Utils.inStaffmode.remove(p)
}
}
}

View File

@ -16,3 +16,4 @@ staffmode-hotbar: # List of items to give the player when they toggle staffmode,
7: "AIR"
8: "AIR"
9: "AIR"
disable-staffmode-item: "&aDisable staffmode" # Item name of the item that disables staffmode

View File

@ -4,6 +4,8 @@ main: me.fivevl.staff.Main
api-version: 1.18
authors: [ 5vl ]
description: A staffing plugin.
depend:
- PlaceholderAPI
commands:
staffmode:
description: The command to go into staffmode.