From d48cf39493b9154fef4e1d2382da24e8e81a22ac Mon Sep 17 00:00:00 2001 From: rbluer <665978+rbluer@users.noreply.github.com> Date: Sun, 22 Sep 2024 00:11:52 -0400 Subject: [PATCH] WorldGuard Regions: Updated the configs to include placeholders for the world, and updated the code to support it too. --- docs/changelog_v3.3.x.md | 3 + .../prison/mines/commands/MinesCommands.java | 78 ++++++++++++++++--- prison-spigot/src/main/resources/config.yml | 55 ++++++------- 3 files changed, 97 insertions(+), 39 deletions(-) diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md index 6e14541e5..04acb748b 100644 --- a/docs/changelog_v3.3.x.md +++ b/docs/changelog_v3.3.x.md @@ -17,6 +17,9 @@ These change logs represent the work that has been going on within prison. # 3.3.0-alpha.19c 2024-09-22 +* **WorldGuard Regions: Updated the configs to include placeholders for the world, and updated the code to support it too.** + + * **Custom placeholders: Fix an issue with the custom placeholders changes being able to correctly count the aliases in the command `/prison commands list`.** diff --git a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java index 0e230288c..7f5833673 100644 --- a/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java +++ b/prison-mines/src/main/java/tech/mcprison/prison/mines/commands/MinesCommands.java @@ -36,6 +36,7 @@ import tech.mcprison.prison.commands.Wildcard; import tech.mcprison.prison.internal.CommandSender; import tech.mcprison.prison.internal.Player; +import tech.mcprison.prison.internal.World; import tech.mcprison.prison.internal.block.Block; import tech.mcprison.prison.internal.block.MineResetType; import tech.mcprison.prison.internal.block.PrisonBlock; @@ -5429,11 +5430,13 @@ public void commandWorldGuardRegionsGlobalInfo(CommandSender sender, + "specified and ran from console, it will only list the " + "commands and will not try to run them.") String playerName, @Arg(name = "options", def = "view", - description = "Options: default 'view' [view, run]. The option 'view' will generate the " + description = "Options: default 'view' [view, run, world-name]. The option 'view' will generate the " + "list of commands and display them in the console. The 'run' will submit them " + "to be ran as the player, who must be online. They will be " + "teleported to the mine's spawn point to ensure they are in the correct " - + "world.") @Wildcard String options) { + + "world. If running from console, you must supply the world name, or these " + + "commands cannot be ran from the console." + ) @Wildcard String options) { String cmd = "globalInfo"; @@ -5456,11 +5459,14 @@ public void commandWorldGuardRegionsGlobalDefine(CommandSender sender, + "specified and ran from console, it will only list the " + "commands and will not try to run them.") String playerName, @Arg(name = "options", def = "view", - description = "Options: default 'view' [view, run]. The option 'view' will generate the " + description = "Options: default 'view' [view, run, world-name]. " + + "The option 'view' will generate the " + "list of commands and display them in the console. The 'run' will submit them " + "to be ran as the player, who must be online. They will be " + "teleported to the mine's spawn point to ensure they are in the correct " - + "world.") @Wildcard String options) { + + "world. If running from console, you must supply the world name, or these " + + "commands cannot be ran from the console." + ) @Wildcard String options) { String cmd = "globalDefine"; @@ -5482,11 +5488,13 @@ public void commandWorldGuardRegionsGlobalMobSpawningDeny(CommandSender sender, + "specified and ran from console, it will only list the " + "commands and will not try to run them.") String playerName, @Arg(name = "options", def = "view", - description = "Options: default 'view' [view, run]. The option 'view' will generate the " + description = "Options: default 'view' [view, run, world-name]. The option 'view' will generate the " + "list of commands and display them in the console. The 'run' will submit them " + "to be ran as the player, who must be online. They will be " + "teleported to the mine's spawn point to ensure they are in the correct " - + "world.") @Wildcard String options) { + + "world. If running from console, you must supply the world name, or these " + + "commands cannot be ran from the console. " + ) @Wildcard String options) { String cmd = "globalMobSpawningDeny"; @@ -5494,6 +5502,7 @@ public void commandWorldGuardRegionsGlobalMobSpawningDeny(CommandSender sender, String mineName = "*global*"; + worldGuardRegions( sender, wgSetting, mineName, playerName, options, cmd ); } @@ -5608,20 +5617,40 @@ public void commandWorldGuardRegionsMineAreaSelect(CommandSender sender, } +// public void worldGuardRegions( CommandSender sender, String wbSetting, +// String mineName, String playerName, String options, +// String command ) { +// +// worldGuardRegions(sender, wbSetting, mineName, playerName, options, command, null); +// } + public void worldGuardRegions( CommandSender sender, String wbSetting, - String mineName, String playerName, String options, String command ) { + String mineName, String playerName, String options, + String command ) { PrisonMines pMines = PrisonMines.getInstance(); Mine mine = "*global*".equalsIgnoreCase(mineName) ? null : pMines.getMine( mineName ); Player player = null; boolean run = false; + String world = null; if ( mine == null && !"*global*".equalsIgnoreCase(mineName) ) { sender.sendMessage( "A valid mine name is required. Try again.");; return; } + // First check to make sure the playerName does not contain the world parameter: + if ( playerName != null ) { + Optional wOpt = Prison.get().getPlatform().getWorld( playerName ); + if ( wOpt.isPresent() ) { + // Player name is a world name, so use it: + world = playerName; + playerName = ""; + } + } + + if ( playerName.equalsIgnoreCase("run") ) { if ( sender.isPlayer() ) { @@ -5632,7 +5661,7 @@ public void worldGuardRegions( CommandSender sender, String wbSetting, sender.sendMessage( "A valid player name must be provided if this command is ran from the console."); } } - else if ( playerName.equalsIgnoreCase( "view" ) || options.equalsIgnoreCase( "view" ) ) { + else if ( playerName.equalsIgnoreCase( "view" ) || options.toLowerCase().contains( "view" ) ) { run = false; } else { @@ -5641,11 +5670,28 @@ else if ( playerName.equalsIgnoreCase( "view" ) || options.equalsIgnoreCase( "vi if ( player == null ) { } - if ( options.equalsIgnoreCase( "run" ) ) { + if ( options.toLowerCase().contains( "run" ) ) { run = true; } } + if ( options != null ) { + + // If a world name is supplied, then it should be what's left after you remove any possible + // values for 'view' or 'run'. + String worldName = options.replace("view", "").replace("run", "").trim(); + + if ( worldName != null && worldName.length() > 0 ) { + Optional wOpt = Prison.get().getPlatform().getWorld( worldName ); + if ( wOpt.isPresent() ) { + // Player name is a world name, so use it: + world = worldName; + + // Do not change options... it's not used anymore: + } + } + } + String mode = run ? "Running" : "Viewing"; ChatDisplay display = new ChatDisplay("WorldGuard Region Commands - " + mode); @@ -5668,11 +5714,13 @@ else if ( "*global*".equalsIgnoreCase(mineName) ) { teleportPlayer(player, mine, "spawn"); } - String world = mine != null && !mine.isVirtual() ? + String worldName = mine != null && !mine.isVirtual() ? mine.getWorldName() : + world != null ? world : player != null ? player.getLocation().getWorld().getName() : "world-not-set"; - display.addText( "&3World: &7%s", world ); + + display.addText( "&3World: &7%s", worldName ); display.addText(""); @@ -5684,6 +5732,11 @@ else if ( "*global*".equalsIgnoreCase(mineName) ) { List cmds = new ArrayList<>(); + String worldPlaceholder = worldName.equals("world-not-set") ? "" : + !sender.isPlayer() ? "-w " + worldName : + ""; + + String regionMineName = Prison.get().getPlatform().getConfigString( "prison-mines.world-guard.region-mine.region-mine-name", "prison_mine_{mine}"); String regionGroupPerms = Prison.get().getPlatform().getConfigString( @@ -5708,7 +5761,8 @@ else if ( "*global*".equalsIgnoreCase(mineName) ) { String msg = cmd.replace("{mine-pos1}", minePos1) .replace("{mine-pos2}", minePos2) .replace("{region-mine-name}", regionMineName) - .replace("{region-group-permission}", regionGroupPerms); + .replace("{region-group-permission}", regionGroupPerms) + .replace("{world}", worldPlaceholder); cmds.add( msg ); display.addText( "&4 %s", msg ); diff --git a/prison-spigot/src/main/resources/config.yml b/prison-spigot/src/main/resources/config.yml index 61a72fbfc..84fc36502 100644 --- a/prison-spigot/src/main/resources/config.yml +++ b/prison-spigot/src/main/resources/config.yml @@ -389,55 +389,56 @@ prison-mines: prevent-usage-in-mines: - GoldMine - SampleMineName + world-guard: - WARNING: WorldGuard support is not yet available. Coming soon. + WARNING: WorldGuard may not be fully supported yet. global-region-commands: info: - - '/rg list' - - '/rg info __global__' + - '/rg list {world}' + - '/rg info {world} __global__' define: - - '/rg flag __global__ passthrough deny' + - '/rg flag {world} __global__ passthrough deny' deny-mob-spawning: - - 'rg flag __global__ mob-spawning deny' + - 'rg flag {world} __global__ mob-spawning deny' - '/gamerule doMobSpawning false' mine-region-commands: info: - - '/rg list' - - '/rg info {region-mine-name}' + - '/rg list {world}' + - '/rg info {world} {region-mine-name}' redefine: - '//pos1 {mine-pos1}' - '//pos2 {mine-pos2}' - - '//region redefine {region-mine-name}' + - '//region redefine {world} {region-mine-name}' define: - - '/region define {region-mine-name}' - - '/region addmember {region-mine-name} {region-group-permission}' - - '/region setpriority {region-mine-name} 20' - - '/region flag {region-mine-name} block-break allow' - - '/region flag {region-mine-name} item-pickup allow' - - '/region flag {region-mine-name} exp-drops allow' - - '/region flag {region-mine-name} item-drop allow' + - '/region define {world} {region-mine-name}' + - '/region addmember {world} {region-mine-name} {region-group-permission}' + - '/region setpriority {world} {region-mine-name} 20' + - '/region flag {world} {region-mine-name} block-break allow' + - '/region flag {world} {region-mine-name} item-pickup allow' + - '/region flag {world} {region-mine-name} exp-drops allow' + - '/region flag {world} {region-mine-name} item-drop allow' select: - - '/region select {region-mine-name}' + - '/region select {world} {region-mine-name}' mine-area-region-commands: info: - - '/rg list' - - '/rg info {region-mine-area-name}' + - '/rg list {world}' + - '/rg info {world} {region-mine-area-name}' redefine: - '//pos1 {mine-area-pos1}' - '//pos2 {mine-area-pos2}' - - '/region redefine {region-mine-area-name}' + - '/region redefine {world} {region-mine-area-name}' define: - - '/region define {region-mine-area-name}' - - '/region addmember {region-mine-area-name} {region-group-permission}' - - '/region setpriority {region-mine-area-name} 10' - - '/region flag {region-mine-area-name} block-break deny' - - '/region flag {region-mine-area-name} item-pickup allow' - - '/region flag {region-mine-area-name} exp-drops allow' - - '/region flag {region-mine-area-name} item-drop allow' + - '/region define {world} {region-mine-area-name}' + - '/region addmember {world} {region-mine-area-name} {region-group-permission}' + - '/region setpriority {world} {region-mine-area-name} 10' + - '/region flag {world} {region-mine-area-name} block-break deny' + - '/region flag {world} {region-mine-area-name} item-pickup allow' + - '/region flag {world} {region-mine-area-name} exp-drops allow' + - '/region flag {world} {region-mine-area-name} item-drop allow' select: - - '/region select {region-mine-area-name}' + - '/region select {world} {region-mine-area-name}' region-mine: enable: true