Skip to content

Commit

Permalink
WorldGuard Regions: Updated the configs to include placeholders for t…
Browse files Browse the repository at this point in the history
…he world, and updated the code to support it too.
  • Loading branch information
rbluer committed Sep 22, 2024
1 parent 7c42c51 commit d48cf39
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 39 deletions.
3 changes: 3 additions & 0 deletions docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.**


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";

Expand All @@ -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";

Expand All @@ -5482,18 +5488,21 @@ 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";

String wgSetting = "prison-mines.world-guard.global-region-commands.deny-mob-spawning";

String mineName = "*global*";


worldGuardRegions( sender, wgSetting, mineName, playerName, options, cmd );
}

Expand Down Expand Up @@ -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<World> 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() ) {
Expand All @@ -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 {
Expand All @@ -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<World> 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);
Expand All @@ -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("");

Expand All @@ -5684,6 +5732,11 @@ else if ( "*global*".equalsIgnoreCase(mineName) ) {
List<String> 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(
Expand All @@ -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 );
Expand Down
55 changes: 28 additions & 27 deletions prison-spigot/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d48cf39

Please sign in to comment.