broadcast message to all players that are OP's

This commit is contained in:
rattatwinko
2025-04-27 18:43:24 +02:00
parent e1ecf19527
commit b2a927915e

View File

@@ -1,6 +1,8 @@
package org.plughide.plughide
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
@@ -29,6 +31,22 @@ class PlugHide : JavaPlugin(), Listener {
logger.info("PlugHide has been disabled!")
}
private fun notifyOps(message: String) {
val opPlayersExist = Bukkit.getOnlinePlayers().any { it.isOp }
if (opPlayersExist) {
// Send notification to all online OP players
Bukkit.getOnlinePlayers()
.filter { it.isOp }
.forEach {
it.sendMessage("${ChatColor.DARK_RED}[PlugHide] ${ChatColor.YELLOW}$message")
}
}
// Always log to console
logger.info(message)
}
@EventHandler(priority = EventPriority.HIGHEST)
fun onPlayerCommand(event: PlayerCommandPreprocessEvent) {
val player = event.player
@@ -40,8 +58,10 @@ class PlugHide : JavaPlugin(), Listener {
// Block restricted commands for non-OPs
if (blockedCommands.contains(command)) {
event.isCancelled = true
player.sendMessage("§cInsufficient Permission!.")
logger.info("Player ${player.name} attempted to use blocked command: $command")
player.sendMessage("${ChatColor.RED}Insufficient Permissions: ${ChatColor.RED}$command")
// Notify all online OP players
notifyOps("Player ${player.name} attempted to use blocked command: $command")
}
}
@@ -71,6 +91,11 @@ class PlugHide : JavaPlugin(), Listener {
}
event.completions = filtered
// If this appears to be an attempt to discover plugins, notify OPs
if (sender is Player && (buffer.contains("plugin") || buffer.contains("pl"))) {
notifyOps("Player ${sender.name} may be attempting to discover plugins via tab completion: $buffer")
}
}
}
}