Allows claimed regions to inherit from a template region (#1864)

* Allows claimed regions to inherit from a template region

* Replace template-when-claiming with set-parent-on-claim

* Make the set-parent-on-claim option check secure
This commit is contained in:
Cristobal Lopez 2022-01-02 16:07:00 +01:00 committed by GitHub
parent 46251f5ffa
commit b59da5992f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -281,6 +281,7 @@ public void loadConfiguration() {
regionWand = convertLegacyItem(getString("regions.wand", ItemTypes.LEATHER.getId()));
maxClaimVolume = getInt("regions.max-claim-volume", 30000);
claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false);
setParentOnClaim = getString("regions.set-parent-on-claim", "");
boundedLocationFlags = getBoolean("regions.location-flags-only-inside-regions", false);
maxRegionCountPerPlayer = getInt("regions.max-region-count-per-player.default", 7);

View File

@ -21,6 +21,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
@ -281,7 +282,7 @@ public void claim(CommandContext args, Actor sender) throws CommandException {
}
}
// We have to check whether this region violates the space of any other reion
// We have to check whether this region violates the space of any other region
ApplicableRegionSet regions = manager.getApplicableRegions(region);
// Check if this region overlaps any other region
@ -314,6 +315,18 @@ public void claim(CommandContext args, Actor sender) throws CommandException {
}
}
// Inherit from a template region
if (!Strings.isNullOrEmpty(wcfg.setParentOnClaim)) {
ProtectedRegion templateRegion = manager.getRegion(wcfg.setParentOnClaim);
if (templateRegion != null) {
try {
region.setParent(templateRegion);
} catch (CircularInheritanceException e) {
throw new CommandException(e.getMessage());
}
}
}
RegionAdder task = new RegionAdder(manager, region);
task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
task.setOwnersInput(new String[]{player.getName()});

View File

@ -129,6 +129,7 @@ public abstract class WorldConfiguration {
public boolean allowTamedSpawns;
public int maxClaimVolume;
public boolean claimOnlyInsideExistingRegions;
public String setParentOnClaim;
public int maxRegionCountPerPlayer;
public boolean antiWolfDumbness;
public boolean signChestProtection;