diff --git a/src/main/java/me/fivevl/staff/Config.kt b/src/main/java/me/fivevl/staff/Config.kt index 48a9fcf..221b15f 100644 --- a/src/main/java/me/fivevl/staff/Config.kt +++ b/src/main/java/me/fivevl/staff/Config.kt @@ -12,4 +12,5 @@ object Config { put(it.toInt(), config?.getString("staffmode-hotbar.$it")!!) } } + val toggleVanish = config?.getString("toggle-vanish") } \ No newline at end of file diff --git a/src/main/java/me/fivevl/staff/Main.kt b/src/main/java/me/fivevl/staff/Main.kt index 3ee4ed0..fbdf0e0 100644 --- a/src/main/java/me/fivevl/staff/Main.kt +++ b/src/main/java/me/fivevl/staff/Main.kt @@ -1,13 +1,20 @@ package me.fivevl.staff import me.fivevl.staff.commands.StaffModeCommand +import me.fivevl.staff.listeners.JoinListener +import org.bukkit.Bukkit import org.bukkit.plugin.java.JavaPlugin class Main : JavaPlugin() { override fun onEnable() { + Utils.instance = this + saveDefaultConfig() Config.config = config + getCommand("staffmode")!!.setExecutor(StaffModeCommand()) + + Bukkit.getPluginManager().registerEvents(JoinListener(), this) logger.info("Staff plugin enabled.") } @@ -20,6 +27,7 @@ class Main : JavaPlugin() { FEATURES: DONE: - PlaceholderAPI support + - Config NOT DONE: - Staff mode (Invisibility/vanish, fly, items) - Freeze (Command and freeze wand in staff mode) diff --git a/src/main/java/me/fivevl/staff/Utils.kt b/src/main/java/me/fivevl/staff/Utils.kt index 2954070..c1f8b2f 100644 --- a/src/main/java/me/fivevl/staff/Utils.kt +++ b/src/main/java/me/fivevl/staff/Utils.kt @@ -2,6 +2,7 @@ package me.fivevl.staff import me.clip.placeholderapi.PlaceholderAPI import net.md_5.bungee.api.ChatColor +import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack @@ -9,7 +10,9 @@ import org.bukkit.inventory.PlayerInventory import java.util.regex.Pattern object Utils { + var instance: Main? = null private val inStaffmode = HashMap() + val inVanish = ArrayList() @Suppress("deprecation") fun hex(s: String): String { var s2 = s @@ -47,4 +50,20 @@ object Utils { } 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!!))) + } + } } \ No newline at end of file diff --git a/src/main/java/me/fivevl/staff/listeners/JoinListener.kt b/src/main/java/me/fivevl/staff/listeners/JoinListener.kt new file mode 100644 index 0000000..17c5a51 --- /dev/null +++ b/src/main/java/me/fivevl/staff/listeners/JoinListener.kt @@ -0,0 +1,16 @@ +package me.fivevl.staff.listeners + +import me.fivevl.staff.Utils +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent + +class JoinListener : Listener { + @EventHandler + fun onJoin(e: PlayerJoinEvent) { + val p = e.player + for (ps in Utils.inVanish) { + p.hidePlayer(Utils.instance!!, ps) + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9119086..2484f2d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,11 @@ +# In this section of the config you can change all the messages in the plugin. must-be-player: "&cYou must be a player to use this command!" # Message shown when a player tries to use a command that requires them to be a player no-permission: "&cYou don't have permission to use this command!" # Message shown when a player tries to use a command that they don't have permission to use toggle-staffmode: "&aToggled staffmode!" # Message shown when a player toggles staffmode +toggle-vanish: "&aToggled vanish!" # Message shown when a player toggles vanish +toggle-fly: "&aToggled fly!" # Message shown when a player toggles fly + +# In this section of the config you can change the items given to you in staffmode. staffmode-hotbar: # List of items to give the player when they toggle staffmode, available items: "AIR", "DISABLE_STAFFMODE", "FREEZE_WAND", "INVENTORY_WAND", "KB_STICK", "VANISH_ITEM" 1: "AIR" 2: "AIR"