Add perm check when changing claim type to town.

* sponge: Fix expiration cleanup interval not being passed to task.
This commit is contained in:
bloodshot 2020-03-31 01:58:08 -04:00
parent 80964978bc
commit c1e5843482
3 changed files with 29 additions and 5 deletions

View File

@ -1961,6 +1961,11 @@ public class GDClaim implements Claim {
isAdmin = true;
}
GDPermissionUser user = null;
if (newOwnerUUID != null) {
user = PermissionHolderCache.getInstance().getOrCreateUser(newOwnerUUID);
}
if (type == ClaimTypes.ADMIN) {
if (!isAdmin) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CHANGE_NOT_ADMIN,
@ -1995,14 +2000,14 @@ public class GDClaim implements Claim {
if (this.parent == null) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CREATE_DENY,
ImmutableMap.of(
"type", TextComponent.of("SUBDIVISION", TextColor.AQUA),
"type", this.getFriendlyNameType(true),
"target_type", TextComponent.of("WILDERNESS", TextColor.GREEN)));
return new GDClaimResult(ClaimResultType.WRONG_CLAIM_TYPE, message);
}
if (this.isAdminClaim() && newOwnerUUID == null) {
return new GDClaimResult(ClaimResultType.REQUIRES_OWNER, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_REQUIRES_OWNER,
ImmutableMap.of(
"type", TextComponent.of("ADMIN", TextColor.RED),
"type", this.getFriendlyNameType(true),
"target_type", TextComponent.of("SUBDIVISION", TextColor.AQUA))));
}
} else if (type == ClaimTypes.TOWN) {
@ -2011,6 +2016,13 @@ public class GDClaim implements Claim {
ImmutableMap.of("type", TextComponent.of("TOWN").color(TextColor.GREEN)));
return new GDClaimResult(ClaimResultType.WRONG_CLAIM_TYPE, message);
}
if (!isAdmin && user != null && !PermissionUtil.getInstance().holderHasPermission(user, GDPermissions.CLAIM_CREATE_TOWN)) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CREATE_DENY,
ImmutableMap.of(
"type", this.getFriendlyNameType(true),
"target_type", TextComponent.of("TOWN", TextColor.GREEN)));
return new GDClaimResult(ClaimResultType.WRONG_CLAIM_TYPE, message);
}
} else if (type == ClaimTypes.WILDERNESS) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CHANGE_DENY,
ImmutableMap.of("type", TextComponent.of("WILDERNESS").color(TextColor.GREEN)));

View File

@ -574,7 +574,7 @@ public class GriefDefenderPlugin {
int cleanupTaskInterval = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.expirationCleanupInterval;
if (cleanupTaskInterval > 0) {
ClaimCleanupTask cleanupTask = new ClaimCleanupTask();
Sponge.getScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(cleanupTask)
Sponge.getScheduler().createTaskBuilder().interval(cleanupTaskInterval, TimeUnit.SECONDS).execute(cleanupTask)
.submit(GDBootstrap.getInstance());
}
}

View File

@ -1978,6 +1978,11 @@ public class GDClaim implements Claim {
isAdmin = true;
}
GDPermissionUser user = null;
if (newOwnerUUID != null) {
user = PermissionHolderCache.getInstance().getOrCreateUser(newOwnerUUID);
}
if (type == ClaimTypes.ADMIN) {
if (!isAdmin) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CHANGE_NOT_ADMIN,
@ -2012,14 +2017,14 @@ public class GDClaim implements Claim {
if (this.parent == null) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CREATE_DENY,
ImmutableMap.of(
"type", TextComponent.of("SUBDIVISION", TextColor.AQUA),
"type", this.getFriendlyNameType(true),
"target_type", TextComponent.of("WILDERNESS", TextColor.GREEN)));
return new GDClaimResult(ClaimResultType.WRONG_CLAIM_TYPE, message);
}
if (this.isAdminClaim() && newOwnerUUID == null) {
return new GDClaimResult(ClaimResultType.REQUIRES_OWNER, MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_REQUIRES_OWNER,
ImmutableMap.of(
"type", TextComponent.of("ADMIN", TextColor.RED),
"type", this.getFriendlyNameType(true),
"target_type", TextComponent.of("SUBDIVISION", TextColor.AQUA))));
}
} else if (type == ClaimTypes.TOWN) {
@ -2028,6 +2033,13 @@ public class GDClaim implements Claim {
ImmutableMap.of("type", TextComponent.of("TOWN").color(TextColor.GREEN)));
return new GDClaimResult(ClaimResultType.WRONG_CLAIM_TYPE, message);
}
if (!isAdmin && user != null && !PermissionUtil.getInstance().holderHasPermission(user, GDPermissions.CLAIM_CREATE_TOWN)) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CREATE_DENY,
ImmutableMap.of(
"type", this.getFriendlyNameType(true),
"target_type", TextComponent.of("TOWN", TextColor.GREEN)));
return new GDClaimResult(ClaimResultType.WRONG_CLAIM_TYPE, message);
}
} else if (type == ClaimTypes.WILDERNESS) {
final Component message = MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.RESULT_TYPE_CHANGE_DENY,
ImmutableMap.of("type", TextComponent.of("WILDERNESS").color(TextColor.GREEN)));