mirror of
https://github.com/5vl/Staff.git
synced 2025-07-09 18:36:57 +00:00
all should work now
This commit is contained in:
parent
344c4f2a95
commit
d407ce6e57
@ -3,14 +3,17 @@ package me.fivevl.staff
|
|||||||
import org.bukkit.configuration.file.FileConfiguration
|
import org.bukkit.configuration.file.FileConfiguration
|
||||||
|
|
||||||
object Config {
|
object Config {
|
||||||
var config: FileConfiguration? = null
|
private fun getConfig(): FileConfiguration {
|
||||||
val mustBePlayer = config?.getString("must-be-player")
|
return Utils.getConfig()
|
||||||
val noPermission = config?.getString("no-permission")
|
}
|
||||||
val toggleStaffmode = config?.getString("toggle-staffmode")
|
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 {
|
val staffmodeHotbar = HashMap<Int, String>().apply {
|
||||||
config?.getConfigurationSection("staffmode-hotbar")?.getKeys(false)?.forEach {
|
getConfig().getConfigurationSection("staffmode-hotbar")?.getKeys(false)?.forEach {
|
||||||
put(it.toInt(), config?.getString("staffmode-hotbar.$it")!!)
|
put(it.toInt(), getConfig().getString("staffmode-hotbar.$it")!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val toggleVanish = config?.getString("toggle-vanish")
|
val disableStaffmodeItem = getConfig().getString("disable-staffmode-item")!!
|
||||||
}
|
}
|
19
src/main/java/me/fivevl/staff/Items.kt
Normal file
19
src/main/java/me/fivevl/staff/Items.kt
Normal 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
|
||||||
|
}
|
@ -11,7 +11,6 @@ class Main : JavaPlugin() {
|
|||||||
Utils.instance = this
|
Utils.instance = this
|
||||||
|
|
||||||
saveDefaultConfig()
|
saveDefaultConfig()
|
||||||
Config.config = config
|
|
||||||
|
|
||||||
getCommand("staffmode")!!.setExecutor(StaffModeCommand())
|
getCommand("staffmode")!!.setExecutor(StaffModeCommand())
|
||||||
getCommand("vanish")!!.setExecutor(VanishCommand())
|
getCommand("vanish")!!.setExecutor(VanishCommand())
|
||||||
|
@ -4,6 +4,7 @@ import me.clip.placeholderapi.PlaceholderAPI
|
|||||||
import net.md_5.bungee.api.ChatColor
|
import net.md_5.bungee.api.ChatColor
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.PlayerInventory
|
import org.bukkit.inventory.PlayerInventory
|
||||||
@ -11,7 +12,7 @@ import java.util.regex.Pattern
|
|||||||
|
|
||||||
object Utils {
|
object Utils {
|
||||||
var instance: Main? = null
|
var instance: Main? = null
|
||||||
private val inStaffmode = HashMap<Player, PlayerInventory>()
|
val inStaffmode = HashMap<Player, PlayerInventory>()
|
||||||
val inVanish = ArrayList<Player>()
|
val inVanish = ArrayList<Player>()
|
||||||
@Suppress("deprecation")
|
@Suppress("deprecation")
|
||||||
fun hex(s: String): String {
|
fun hex(s: String): String {
|
||||||
@ -20,7 +21,7 @@ object Utils {
|
|||||||
var match = pattern.matcher(s)
|
var match = pattern.matcher(s)
|
||||||
while (match.find()) {
|
while (match.find()) {
|
||||||
val color = s.substring(match.start(), match.end())
|
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)
|
match = pattern.matcher(s2)
|
||||||
}
|
}
|
||||||
return ChatColor.translateAlternateColorCodes('&', s2)
|
return ChatColor.translateAlternateColorCodes('&', s2)
|
||||||
@ -39,31 +40,33 @@ object Utils {
|
|||||||
for (i: Int in Config.staffmodeHotbar.keys) {
|
for (i: Int in Config.staffmodeHotbar.keys) {
|
||||||
var item = ItemStack(Material.AIR)
|
var item = ItemStack(Material.AIR)
|
||||||
when (Config.staffmodeHotbar[i]) {
|
when (Config.staffmodeHotbar[i]) {
|
||||||
"DISABLE_STAFFMODE" -> item = ItemStack(Material.AIR)
|
"DISABLE_STAFFMODE" -> item = Items.DISABLE_STAFFMODE.item
|
||||||
"FREEZE_WAND" -> item = ItemStack(Material.AIR)
|
"FREEZE_WAND" -> item = Items.FREEZE_WAND.item
|
||||||
"INVENTORY_WAND" -> item = ItemStack(Material.AIR)
|
"INVENTORY_WAND" -> item = Items.INVENTORY_WAND.item
|
||||||
"KB_STICK" -> item = ItemStack(Material.AIR)
|
"KB_STICK" -> item = Items.KB_STICK.item
|
||||||
"VANISH_ITEM" -> item = ItemStack(Material.AIR)
|
"VANISH_ITEM" -> item = Items.VANISH_ITEM.item
|
||||||
}
|
}
|
||||||
p.inventory.setItem(i - 1, 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) {
|
fun toggleVanish(p: Player) {
|
||||||
if (inVanish.contains(p)) {
|
if (inVanish.contains(p)) {
|
||||||
for (ps in Bukkit.getOnlinePlayers()) {
|
for (ps in Bukkit.getOnlinePlayers()) {
|
||||||
ps.showPlayer(instance!!, p)
|
ps.showPlayer(instance!!, p)
|
||||||
}
|
}
|
||||||
inVanish.remove(p)
|
inVanish.remove(p)
|
||||||
p.sendMessage(hex(getPlaceholders(p, Config.toggleVanish!!)))
|
|
||||||
} else {
|
} else {
|
||||||
for (ps in Bukkit.getOnlinePlayers()) {
|
for (ps in Bukkit.getOnlinePlayers()) {
|
||||||
ps.hidePlayer(instance!!, p)
|
ps.hidePlayer(instance!!, p)
|
||||||
}
|
}
|
||||||
inVanish.add(p)
|
inVanish.add(p)
|
||||||
p.sendMessage(hex(getPlaceholders(p, Config.toggleVanish!!)))
|
|
||||||
}
|
}
|
||||||
|
p.sendMessage(hex(getPlaceholders(p, Config.toggleVanish)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getConfig(): FileConfiguration {
|
||||||
|
return instance!!.config
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,12 +10,12 @@ import org.bukkit.entity.Player
|
|||||||
class StaffModeCommand : CommandExecutor {
|
class StaffModeCommand : CommandExecutor {
|
||||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
||||||
if (sender !is Player) {
|
if (sender !is Player) {
|
||||||
sender.sendMessage(Utils.hex(Utils.getPlaceholders(null, Config.mustBePlayer!!)))
|
sender.sendMessage(Utils.hex(Utils.getPlaceholders(null, Config.mustBePlayer)))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
val p = sender.player!!
|
val p = sender.player!!
|
||||||
if (!p.hasPermission("staff.staffmode")) {
|
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
|
return true
|
||||||
}
|
}
|
||||||
Utils.toggleStaffmode(p)
|
Utils.toggleStaffmode(p)
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
package me.fivevl.staff.commands
|
package me.fivevl.staff.commands
|
||||||
|
|
||||||
|
import me.fivevl.staff.Config
|
||||||
|
import me.fivevl.staff.Utils
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
class VanishCommand : CommandExecutor {
|
class VanishCommand : CommandExecutor {
|
||||||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,13 +4,30 @@ import me.fivevl.staff.Utils
|
|||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
|
|
||||||
class JoinListener : Listener {
|
class JoinListener : Listener {
|
||||||
|
@Suppress("deprecation")
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onJoin(e: PlayerJoinEvent) {
|
fun onJoin(e: PlayerJoinEvent) {
|
||||||
|
e.joinMessage = null
|
||||||
val p = e.player
|
val p = e.player
|
||||||
for (ps in Utils.inVanish) {
|
for (ps in Utils.inVanish) {
|
||||||
p.hidePlayer(Utils.instance!!, ps)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,3 +16,4 @@ staffmode-hotbar: # List of items to give the player when they toggle staffmode,
|
|||||||
7: "AIR"
|
7: "AIR"
|
||||||
8: "AIR"
|
8: "AIR"
|
||||||
9: "AIR"
|
9: "AIR"
|
||||||
|
disable-staffmode-item: "&aDisable staffmode" # Item name of the item that disables staffmode
|
@ -4,6 +4,8 @@ main: me.fivevl.staff.Main
|
|||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
authors: [ 5vl ]
|
authors: [ 5vl ]
|
||||||
description: A staffing plugin.
|
description: A staffing plugin.
|
||||||
|
depend:
|
||||||
|
- PlaceholderAPI
|
||||||
commands:
|
commands:
|
||||||
staffmode:
|
staffmode:
|
||||||
description: The command to go into staffmode.
|
description: The command to go into staffmode.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user