diff --git a/README.md b/README.md index 8dd2ec8..f7f8297 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,11 @@ I made this plugin by request of a friend, and because I didn't have anything to - /staffmode - staff.staffmode - /freeze - staff.freeze - /openinv - staff.openinv +- /vanish - /v - staff.vanish # Staff mode items: -- Disable staffmode - staff.staffmode +- Disable staffmode item - staff.staffmode - Freeze wand - staff.freeze.wand - Inventory wand - staff.openinv.wand -- Knockback Stick - staff.kbstick \ No newline at end of file +- Knockback Stick - staff.kbstick +- Vanish item - staff.vanish.item \ No newline at end of file diff --git a/src/main/java/me/fivevl/staff/Config.kt b/src/main/java/me/fivevl/staff/Config.kt index b559c7a..48a9fcf 100644 --- a/src/main/java/me/fivevl/staff/Config.kt +++ b/src/main/java/me/fivevl/staff/Config.kt @@ -6,4 +6,10 @@ 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") + val staffmodeHotbar = HashMap().apply { + config?.getConfigurationSection("staffmode-hotbar")?.getKeys(false)?.forEach { + put(it.toInt(), config?.getString("staffmode-hotbar.$it")!!) + } + } } \ No newline at end of file diff --git a/src/main/java/me/fivevl/staff/Utils.kt b/src/main/java/me/fivevl/staff/Utils.kt index 65e3334..2954070 100644 --- a/src/main/java/me/fivevl/staff/Utils.kt +++ b/src/main/java/me/fivevl/staff/Utils.kt @@ -1,12 +1,15 @@ package me.fivevl.staff - import me.clip.placeholderapi.PlaceholderAPI import net.md_5.bungee.api.ChatColor +import org.bukkit.Material import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.PlayerInventory import java.util.regex.Pattern object Utils { + private val inStaffmode = HashMap() @Suppress("deprecation") fun hex(s: String): String { var s2 = s @@ -22,4 +25,26 @@ object Utils { fun getPlaceholders(p: Player?, s: String): String { return PlaceholderAPI.setPlaceholders(p, s) } + fun toggleStaffmode(p: Player) { + if (inStaffmode.containsKey(p)) { + p.inventory.clear() + p.inventory.contents = inStaffmode[p]!!.contents + inStaffmode.remove(p) + } else { + inStaffmode[p] = p.inventory + p.inventory.clear() + 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) + } + p.inventory.setItem(i - 1, item) + } + } + p.sendMessage(hex(getPlaceholders(p, Config.toggleStaffmode!!))) + } } \ No newline at end of file diff --git a/src/main/java/me/fivevl/staff/commands/StaffModeCommand.kt b/src/main/java/me/fivevl/staff/commands/StaffModeCommand.kt index 069a63e..d62953a 100644 --- a/src/main/java/me/fivevl/staff/commands/StaffModeCommand.kt +++ b/src/main/java/me/fivevl/staff/commands/StaffModeCommand.kt @@ -18,6 +18,7 @@ class StaffModeCommand : CommandExecutor { p.sendMessage(Utils.hex(Utils.getPlaceholders(p, Config.noPermission!!))) return true } + Utils.toggleStaffmode(p) return true } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 48d330a..9119086 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,2 +1,13 @@ -must-be-player: "&cYou must be a player to use this command!" -no-permission: "&cYou don't have permission to use this command!" \ No newline at end of file +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 +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" + 3: "AIR" + 4: "AIR" + 5: "AIR" + 6: "AIR" + 7: "AIR" + 8: "AIR" + 9: "AIR"