Skip to content

Commit 08e49e4

Browse files
committed
Allow /rsc to be ran in main claims to restrict future subdivision permisions
- Add inheritNothingForNewSubdivisions field for claim data - Allow /rsc to be ran in main claims, restricting their future subdivision permissions - Add new MainClaimSubdivisionInheritDisabled and Enabled messages
1 parent cfeb685 commit 08e49e4

File tree

7 files changed

+79
-6
lines changed

7 files changed

+79
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<groupId>com.griefprevention</groupId>
1010
<artifactId>GriefPrevention</artifactId>
11-
<version>17.2.0</version>
11+
<version>17.2.1</version>
1212

1313
<name>GriefPrevention</name>
1414
<description>The official self-service anti-griefing Bukkit plugin for Minecraft servers since 2011.</description>

src/main/java/me/ryanhamshire/GriefPrevention/Claim.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public class Claim
9595

9696
// intended for subclaims - they inherit no permissions
9797
private boolean inheritNothing = false;
98+
99+
// for main claims - when true, future subdivisions will NOT inherit permissions
100+
private boolean inheritNothingForNewSubdivisions = false;
98101

99102
//children (subdivisions)
100103
//note subdivisions themselves never have children
@@ -262,6 +265,16 @@ public void setSubclaimRestrictions(boolean inheritNothing)
262265
{
263266
this.inheritNothing = inheritNothing;
264267
}
268+
269+
public boolean getInheritNothingForNewSubdivisions()
270+
{
271+
return this.inheritNothingForNewSubdivisions;
272+
}
273+
274+
public void setInheritNothingForNewSubdivisions(boolean inheritNothingForNewSubdivisions)
275+
{
276+
this.inheritNothingForNewSubdivisions = inheritNothingForNewSubdivisions;
277+
}
265278

266279
//distance check for claims, distance in this case is a band around the outside of the claim rather then euclidean distance
267280
public boolean isNear(Location location, int howNear)

src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public abstract class DataStore {
9393
final static String bannedWordsFilePath = dataLayerFolderPath + File.separator + "bannedWords.txt";
9494

9595
// the latest version of the data schema implemented here
96-
protected static final int latestSchemaVersion = 5;
96+
protected static final int latestSchemaVersion = 6;
9797

9898
// reading and writing the schema version to the data store
9999
abstract int getSchemaVersionFromStorage();
@@ -1215,7 +1215,9 @@ synchronized public CreateClaimResult createClaim(World world, int x1, int x2, i
12151215
if (parent != null) {
12161216
// First-child subdivisions inherit from parent; nested subdivisions do not.
12171217
boolean isNested = parent.parent != null;
1218-
newClaim.setSubclaimRestrictions(isNested);
1218+
// Also check if parent has inheritNothingForNewSubdivisions set
1219+
boolean parentRestrictsFutureSubdivisions = parent.getInheritNothingForNewSubdivisions();
1220+
newClaim.setSubclaimRestrictions(isNested || parentRestrictsFutureSubdivisions);
12191221
claimsToCheck = newClaim.parent.children;
12201222
} else {
12211223
claimsToCheck = this.claims;

src/main/java/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void initialize() throws Exception
109109
{
110110
//ensure the data tables exist
111111
statement.execute("CREATE TABLE IF NOT EXISTS griefprevention_nextclaimid (nextid INTEGER)");
112-
statement.execute("CREATE TABLE IF NOT EXISTS griefprevention_claimdata (id INTEGER, owner VARCHAR(50), lessercorner VARCHAR(100), greatercorner VARCHAR(100), builders TEXT, containers TEXT, accessors TEXT, managers TEXT, inheritnothing BOOLEAN, parentid INTEGER, expiration BIGINT)");
112+
statement.execute("CREATE TABLE IF NOT EXISTS griefprevention_claimdata (id INTEGER, owner VARCHAR(50), lessercorner VARCHAR(100), greatercorner VARCHAR(100), builders TEXT, containers TEXT, accessors TEXT, managers TEXT, inheritnothing BOOLEAN, parentid INTEGER, expiration BIGINT, explosivesallowed BOOLEAN, inheritnothingfornewsubdivisions BOOLEAN)");
113113
statement.execute("CREATE TABLE IF NOT EXISTS griefprevention_playerdata (name VARCHAR(50), lastlogin DATETIME, accruedblocks INTEGER, bonusblocks INTEGER)");
114114
statement.execute("CREATE TABLE IF NOT EXISTS griefprevention_schemaversion (version INTEGER)");
115115

@@ -278,6 +278,12 @@ void initialize() throws Exception
278278
statement.execute(SQL_UPDATE_SCHEMA_ADD_EXPLOSIVES);
279279
}
280280

281+
if (this.getSchemaVersion() <= 5)
282+
{
283+
statement = this.databaseConnection.createStatement();
284+
statement.execute("ALTER TABLE griefprevention_claimdata ADD inheritNothingForNewSubdivisions BOOLEAN DEFAULT 0 AFTER inheritNothing");
285+
}
286+
281287
//load claims data into memory
282288

283289
results = statement.executeQuery("SELECT * FROM griefprevention_claimdata");
@@ -297,6 +303,7 @@ void initialize() throws Exception
297303
long parentId = results.getLong("parentid");
298304
claimID = results.getLong("id");
299305
boolean inheritNothing = results.getBoolean("inheritnothing");
306+
boolean inheritNothingForNewSubdivisions = results.getBoolean("inheritnothingfornewsubdivisions");
300307

301308
//expiration date
302309
long expirationDate = results.getLong("expiration");
@@ -375,6 +382,7 @@ else if (this.getSchemaVersion() < 1)
375382
Claim claim = new Claim(lesserBoundaryCorner, greaterBoundaryCorner, ownerID, builderNames, containerNames, accessorNames, managerNames, inheritNothing, claimID, false);
376383
claim.setExpirationDate(expirationDate);
377384
claim.areExplosivesAllowed = explosivesAllowed;
385+
claim.setInheritNothingForNewSubdivisions(inheritNothingForNewSubdivisions);
378386

379387
if (removeClaim)
380388
{
@@ -476,6 +484,7 @@ synchronized private void writeClaimData(Claim claim) throws SQLException
476484
String accessorsString = this.storageStringBuilder(accessors);
477485
String managersString = this.storageStringBuilder(managers);
478486
boolean inheritNothing = claim.getSubclaimRestrictions();
487+
boolean inheritNothingForNewSubdivisions = claim.getInheritNothingForNewSubdivisions();
479488
long parentId = claim.parent == null ? -1 : claim.parent.id;
480489
long expirationDate = claim.getExpirationDate();
481490
boolean explosivesAllowed = claim.areExplosivesAllowed;
@@ -495,6 +504,7 @@ synchronized private void writeClaimData(Claim claim) throws SQLException
495504
insertStmt.setLong(10, parentId);
496505
insertStmt.setLong(11, expirationDate);
497506
insertStmt.setBoolean(12, explosivesAllowed);
507+
insertStmt.setBoolean(13, inheritNothingForNewSubdivisions);
498508
insertStmt.executeUpdate();
499509
}
500510
catch (SQLException e)

src/main/java/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ Claim loadClaim(String input, ArrayList<Long> out_parentID, long lastModifiedDat
554554

555555
boolean inheritNothing = yaml.getBoolean("inheritNothing");
556556

557+
// Load inheritNothingForNewSubdivisions setting (default false = inherit)
558+
boolean inheritNothingForNewSubdivisions = yaml.getBoolean("inheritNothingForNewSubdivisions", false);
559+
557560
out_parentID.add(yaml.getLong("Parent Claim ID", -1L));
558561

559562
// Add is3D flag
@@ -567,6 +570,7 @@ Claim loadClaim(String input, ArrayList<Long> out_parentID, long lastModifiedDat
567570
claim.modifiedDate = new Date(lastModifiedDate);
568571
claim.id = claimID;
569572
claim.areExplosivesAllowed = explosivesAllowed;
573+
claim.setInheritNothingForNewSubdivisions(inheritNothingForNewSubdivisions);
570574

571575
ConfigurationSection childrenSection = yaml.getConfigurationSection("Children");
572576
if (childrenSection != null)
@@ -711,6 +715,7 @@ private void populateYamlForClaim(Claim claim, ConfigurationSection section)
711715

712716
section.set("Parent Claim ID", claim.parent == null ? -1L : claim.parent.id);
713717
section.set("inheritNothing", claim.getSubclaimRestrictions());
718+
section.set("inheritNothingForNewSubdivisions", claim.getInheritNothingForNewSubdivisions());
714719
section.set("Is3D", claim.is3D());
715720
section.set("Explosives Allowed", claim.areExplosivesAllowed);
716721
section.set("Modified Date", claim.modifiedDate != null ? claim.modifiedDate.getTime() : System.currentTimeMillis());

src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,11 +1859,31 @@ else if (cmd.getName().equalsIgnoreCase("permissiontrust") && player != null) {
18591859
else if (cmd.getName().equalsIgnoreCase("restrictsubclaim") && player != null) {
18601860
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
18611861
Claim claim = this.dataStore.getClaimAt(player.getLocation(), true, playerData.lastClaim);
1862-
if (claim == null || claim.parent == null) {
1862+
if (claim == null) {
18631863
GriefPrevention.sendMessage(player, TextMode.Err, Messages.StandInSubclaim);
18641864
return true;
18651865
}
18661866

1867+
// If in a main claim (no parent), toggle the flag for future subdivisions
1868+
if (claim.parent == null) {
1869+
// If admin claim, fail if this user is not an admin
1870+
// If not an admin claim, fail if this user is not the owner
1871+
if (!playerData.ignoreClaims && (claim.isAdminClaim() ? !player.hasPermission("griefprevention.adminclaims") : !player.getUniqueId().equals(claim.ownerID))) {
1872+
GriefPrevention.sendMessage(player, TextMode.Err, Messages.OnlyOwnersModifyClaims, claim.getOwnerName());
1873+
return true;
1874+
}
1875+
1876+
if (claim.getInheritNothingForNewSubdivisions()) {
1877+
claim.setInheritNothingForNewSubdivisions(false);
1878+
GriefPrevention.sendMessage(player, TextMode.Success, Messages.MainClaimSubdivisionInheritEnabled);
1879+
} else {
1880+
claim.setInheritNothingForNewSubdivisions(true);
1881+
GriefPrevention.sendMessage(player, TextMode.Success, Messages.MainClaimSubdivisionInheritDisabled);
1882+
}
1883+
this.dataStore.saveClaim(claim);
1884+
return true;
1885+
}
1886+
18671887
// If player has /ignoreclaims on, continue
18681888
// If admin claim, fail if this user is not an admin
18691889
// If not an admin claim, fail if this user is not the owner
@@ -4133,11 +4153,32 @@ public boolean handleRestrictSubclaimCommand(CommandSender sender, String[] args
41334153
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
41344154
Claim claim = this.dataStore.getClaimAt(player.getLocation(), true, playerData.lastClaim);
41354155

4136-
if (claim == null || claim.parent == null) {
4156+
if (claim == null) {
41374157
GriefPrevention.sendMessage(player, TextMode.Err, Messages.StandInSubclaim);
41384158
return true;
41394159
}
41404160

4161+
// If in a main claim (no parent), toggle the flag for future subdivisions
4162+
if (claim.parent == null) {
4163+
// If admin claim, fail if this user is not an admin
4164+
// If not an admin claim, fail if this user is not the owner
4165+
if (!playerData.ignoreClaims && (claim.isAdminClaim() ? !player.hasPermission("griefprevention.adminclaims") : !player.getUniqueId().equals(claim.ownerID))) {
4166+
GriefPrevention.sendMessage(player, TextMode.Err, Messages.OnlyOwnersModifyClaims, claim.getOwnerName());
4167+
return true;
4168+
}
4169+
4170+
if (claim.getInheritNothingForNewSubdivisions()) {
4171+
claim.setInheritNothingForNewSubdivisions(false);
4172+
GriefPrevention.sendMessage(player, TextMode.Success, Messages.MainClaimSubdivisionInheritEnabled);
4173+
} else {
4174+
claim.setInheritNothingForNewSubdivisions(true);
4175+
GriefPrevention.sendMessage(player, TextMode.Success, Messages.MainClaimSubdivisionInheritDisabled);
4176+
}
4177+
this.dataStore.saveClaim(claim);
4178+
return true;
4179+
}
4180+
4181+
// Original logic for subdivisions
41414182
if (claim.getSubclaimRestrictions()) {
41424183
claim.setSubclaimRestrictions(false);
41434184
GriefPrevention.sendMessage(player, TextMode.Success, Messages.SubclaimUnrestricted);

src/main/java/me/ryanhamshire/GriefPrevention/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ public enum Messages
242242
StandInSubclaim("You need to be standing in a subclaim to restrict it"),
243243
SubclaimRestricted("This subclaim's permissions will no longer inherit from the parent claim"),
244244
SubclaimUnrestricted("This subclaim's permissions will now inherit from the parent claim"),
245+
MainClaimSubdivisionInheritDisabled("Future subdivisions in this claim will NOT inherit permissions."),
246+
MainClaimSubdivisionInheritEnabled("Future subdivisions in this claim will inherit permissions."),
245247
NetherPortalTrapDetectionMessage("It seems you might be stuck inside a nether portal. We will rescue you in a few seconds if that is the case!", "Sent to player on join, if they left while inside a nether portal."),
246248
ClaimHelpHeader("Available /claim commands:"),
247249
ClaimHelpLegend("<> - Required, [] - Optional."),

0 commit comments

Comments
 (0)