-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Scope
- Server admins should be able to define a list of commands that are blocked (or allowed) within faction-claimed territory, based on the viewer's relationship to the owning faction (e.g., enemies can't use
/home,/tpa, or/backin enemy territory) - The system should support both a blocklist (default allow, specific commands denied) and an allowlist (default deny, specific commands allowed) mode
- Command blocking should apply to admin zones (SafeZones/WarZones) as well, configurable per-zone via the existing zone flags system
- Command blocking should respect bypass permissions (
hyperfactions.bypass.commandblock) - The feature should be configurable both via the config file and the GUI (TBD on exact GUI placement — see Risks section)
- Command matching should support both exact commands (
/home) and wildcard prefixes (/home *to block all subcommands)
Implementation Details
-
Event Interception: Use
PlayerChatEvent(which fires for both chat and commands starting with/) to intercept and cancel blocked commands. Register atEventPriority.HIGHto intercept before command dispatch. -
Suggested config structure (
config.jsonterritory section):{ "commandBlocking": { "enabled": true, "mode": "BLOCKLIST", "territoryRules": { "ENEMY": { "blockedCommands": ["/home", "/tpa", "/back", "/warp", "/spawn"] }, "NEUTRAL": { "blockedCommands": ["/home"] }, "ALLY": { "blockedCommands": [] }, "OWN": { "blockedCommands": [] }, "WILDERNESS": { "blockedCommands": [] } } } } -
Zone flag integration: Add a new zone flag
command_blocking(boolean toggle) toZoneFlags.javaunder a new "Commands" category. When enabled on a zone, use the zone-specific blocked command list. Zone-level blocked commands would be stored as aList<String>in theZonerecord (separate from boolean flags). -
Suggested API methods:
CommandBlockingManager#isCommandBlocked(UUID player, String command, String world, int chunkX, int chunkZ)— main check methodCommandBlockingManager#getBlockedCommands(RelationType relation)— get blocked list for a relationConfigManager#getCommandBlockingConfig()— access config
-
Suggested permission nodes:
hyperfactions.bypass.commandblock— bypass all command blockinghyperfactions.admin.commandblock— manage command blocking config via commands/GUI
-
Listener registration (in
HyperFactionsPlugin.java):eventBus.register(EventPriority.HIGH, PlayerChatEvent.class, event -> { String content = event.getContent(); if (content.startsWith("/")) { String command = content.split(" ")[0].toLowerCase(); // Check player location, territory, relation, then cancel if blocked if (commandBlockingManager.isCommandBlocked(player, command, world, chunkX, chunkZ)) { event.setCancelled(true); // Send denial message } } });
Risks and Alternatives
-
Risk — GUI complexity: Adding per-relation command lists to the GUI is non-trivial. The Faction Settings page is already dense with two columns. Options include:
- A dedicated "Command Rules" sub-page accessible from Settings
- A modal dialog triggered from a "Command Blocking" button in Settings
- An admin-only configuration (no faction leader GUI, only server config + admin GUI)
- Recommendation: Start with config-file-only + admin GUI, add faction leader GUI later if needed
-
Risk — PlayerChatEvent ordering: Other plugins (chat formatters, etc.) also listen to
PlayerChatEvent. UsingEventPriority.HIGHensures we intercept early, but if another plugin cancels the event first at a higher priority, our check won't fire. This is acceptable since cancelled events shouldn't execute commands anyway. -
Challenge — Command aliases: Players may use command aliases (e.g.,
/hfor/home). The blocklist should document that admins need to include all known aliases. A future enhancement could resolve aliases to canonical command names. -
Alternative — Per-faction customizable blocklists: Instead of server-wide relation-based rules, allow faction leaders to customize which commands are blocked in their territory. This adds significant complexity but gives factions more control. Could be a Phase 2 enhancement.
-
Challenge — Zone command lists: Boolean flags are simple, but command lists require a different storage approach. The
Zonerecord'sflagsmap (Map<String, Boolean>) would need a parallelMap<String, List<String>>or similar for list-type zone properties.
References and Media
- Minecraft Factions (FactionsUUID) has a similar feature with
territoryDenyCommandsandterritoryDenyCommandsOnRelation: https://github.com/drtshock/Factions - Current HyperFactions zone flags system (
ZoneFlags.java) provides the pattern for boolean zone flags — this feature extends the concept to command-level granularity - Hytale
PlayerChatEventdocumentation: commands are dispatched through chat, so intercepting at the chat event level is the correct approach (seeHytaleServerDocs/docs/reference/events.md)