Refactor permission removal on claim deletion.

* Fix meta not being removed on claim deletion.
This commit is contained in:
bloodshot 2020-01-31 10:15:41 -05:00
parent 9b821609f6
commit 352f8ceb32
16 changed files with 85 additions and 45 deletions

View File

@ -41,8 +41,6 @@
import com.griefdefender.api.permission.option.Options;
import com.griefdefender.configuration.ClaimDataConfig;
import com.griefdefender.configuration.ClaimStorageData;
import com.griefdefender.configuration.GriefDefenderConfig;
import com.griefdefender.configuration.PlayerStorageData;
import com.griefdefender.event.GDRemoveClaimEvent;
import com.griefdefender.internal.tracking.PlayerIndexStorage;
import com.griefdefender.internal.tracking.chunk.GDChunk;
@ -81,7 +79,6 @@ public class GDClaimManager implements ClaimManager {
private static final BaseStorage DATASTORE = GriefDefenderPlugin.getInstance().dataStore;
private UUID worldUniqueId;
private String worldName;
private GriefDefenderConfig<?> activeConfig;
// Player UUID -> player data
private Map<UUID, GDPlayerData> playerDataList = Maps.newHashMap();
@ -100,7 +97,6 @@ public class GDClaimManager implements ClaimManager {
public GDClaimManager(World world) {
this.worldUniqueId = world.getUID();
this.worldName = world.getName();
this.activeConfig = GriefDefenderPlugin.getActiveConfig(this.worldUniqueId);
this.playerIndexStorage = new PlayerIndexStorage(world);
}

View File

@ -49,7 +49,6 @@
import com.griefdefender.permission.GDPermissionUser;
import com.griefdefender.permission.GDPermissions;
import com.griefdefender.text.action.GDCallbackHolder;
import com.griefdefender.util.PermissionUtil;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.adapter.bukkit.TextAdapter;
@ -176,8 +175,6 @@ private static Consumer<CommandSender> createConfirmationConsumer(Player player,
}
playerData.onClaimDelete();
// remove all context permissions
PermissionUtil.getInstance().clearPermissions(claim);
playerData.revertActiveVisual(player);
if (claim.isTown()) {

View File

@ -47,7 +47,6 @@
import com.griefdefender.permission.GDPermissionUser;
import com.griefdefender.permission.GDPermissions;
import com.griefdefender.text.action.GDCallbackHolder;
import com.griefdefender.util.PermissionUtil;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.adapter.bukkit.TextAdapter;
@ -135,8 +134,6 @@ private static Consumer<CommandSender> createConfirmationConsumer(GDPermissionUs
double refund = 0;
// adjust claim blocks
for (Claim claim : allowedClaims) {
// remove all context permissions
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
if (claim.isSubdivision() || claim.isAdminClaim() || claim.isWilderness()) {
continue;
}

View File

@ -40,7 +40,6 @@
import com.griefdefender.event.GDCauseStackManager;
import com.griefdefender.permission.GDPermissions;
import com.griefdefender.text.action.GDCallbackHolder;
import com.griefdefender.util.PermissionUtil;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.adapter.bukkit.TextAdapter;
@ -107,7 +106,6 @@ private static Consumer<CommandSender> createConfirmationConsumer(Player player,
}
playerData.onClaimDelete();
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
playerData.revertActiveVisual(player);
if (claim.isTown()) {

View File

@ -306,11 +306,48 @@ public void addActiveContexts(Set<Context> contexts, GDPermissionHolder permissi
}
public void clearPermissions(GDClaim claim) {
Map<Set<Context>, Map<String, Boolean>> permissionMap = this.getPermanentPermissions(GriefDefenderPlugin.DEFAULT_HOLDER);
// check default holder
this.clearPermission(claim.getUniqueId(), GriefDefenderPlugin.DEFAULT_HOLDER);
// check loaded groups
for (Group group : this.luckPermsApi.getGroupManager().getLoadedGroups()) {
if (group.getName().equalsIgnoreCase("default")) {
continue;
}
final GDPermissionHolder holder = PermissionHolderCache.getInstance().getOrCreateGroup(group.getName());
if (holder == null) {
continue;
}
this.clearPermission(claim.getUniqueId(), holder);
}
// check user trusts
for (UUID uuid : claim.getUserTrusts()) {
if (uuid.equals(GriefDefenderPlugin.PUBLIC_UUID) || uuid.equals(GriefDefenderPlugin.WORLD_USER_UUID) || uuid.equals(GriefDefenderPlugin.ADMIN_USER_UUID)) {
continue;
}
final GDPermissionHolder holder = PermissionHolderCache.getInstance().getOrCreateUser(uuid);
if (holder == null) {
continue;
}
this.clearPermission(claim.getUniqueId(), holder);
}
}
private void clearPermission(UUID claimUniqueId, GDPermissionHolder holder) {
Map<Set<Context>, Map<String, Boolean>> permissionMap = this.getPermanentPermissions(holder);
for (Entry<Set<Context>, Map<String, Boolean>> mapEntry : permissionMap.entrySet()) {
for (Context context : mapEntry.getKey()) {
if (context.getKey().equalsIgnoreCase("gd_claim") && context.getValue().equalsIgnoreCase(claim.getUniqueId().toString())) {
this.clearPermissions(GriefDefenderPlugin.DEFAULT_HOLDER, mapEntry.getKey());
if (context.getKey().equalsIgnoreCase("gd_claim") && context.getValue().equalsIgnoreCase(claimUniqueId.toString())) {
this.clearPermissions(holder, mapEntry.getKey());
break;
}
}
}
Map<Set<Context>, Map<String, String>> optionMap = this.getPermanentOptions(holder);
for (Entry<Set<Context>, Map<String, String>> mapEntry : optionMap.entrySet()) {
for (Context context : mapEntry.getKey()) {
if (context.getKey().equalsIgnoreCase("gd_claim") && context.getValue().equalsIgnoreCase(claimUniqueId.toString())) {
this.clearPermissions(holder, mapEntry.getKey());
break;
}
}

View File

@ -182,7 +182,6 @@ public ClaimResult deleteAllAdminClaims(CommandSender src, World world) {
}
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
claimWorldManager.deleteClaimInternal(claim, true);
}
@ -196,7 +195,6 @@ public ClaimResult deleteClaim(Claim claim, boolean deleteChildren) {
public void abandonClaimsForPlayer(GDPermissionUser user, Set<Claim> claimsToDelete) {
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
GDClaimManager claimWorldManager = this.claimWorldManagers.get(claim.getWorldUniqueId());
claimWorldManager.deleteClaimInternal(claim, true);
}
@ -209,7 +207,6 @@ public void deleteClaimsForPlayer(UUID playerID) {
final GDPlayerData playerData = BaseStorage.GLOBAL_PLAYER_DATA.get(playerID);
List<Claim> claimsToDelete = new ArrayList<>(playerData.getInternalClaims());
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
GDClaimManager claimWorldManager = this.claimWorldManagers.get(claim.getWorldUniqueId());
claimWorldManager.deleteClaimInternal(claim, true);
}
@ -232,7 +229,6 @@ public void deleteClaimsForPlayer(UUID playerID) {
}
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions(GriefDefenderPlugin.DEFAULT_HOLDER, ImmutableSet.of(claim.getContext()));
claimWorldManager.deleteClaimInternal(claim, true);
claims.remove(claim);
}

View File

@ -46,6 +46,7 @@
import com.griefdefender.migrator.GriefPreventionMigrator;
import com.griefdefender.migrator.PlayerDataMigrator;
import com.griefdefender.migrator.WorldGuardMigrator;
import com.griefdefender.util.PermissionUtil;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
@ -466,6 +467,7 @@ public ClaimResult deleteClaimFromStorage(GDClaim claim) {
}
}
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
return new GDClaimResult(claim, ClaimResultType.SUCCESS);
} catch (IOException e) {
e.printStackTrace();

View File

@ -56,7 +56,7 @@
public class ClaimCleanupTask extends BukkitRunnable {
public ClaimCleanupTask(int interval) {
this.runTaskTimer(GDBootstrap.getInstance(), 1L, interval);
this.runTaskTimer(GDBootstrap.getInstance(), 1L, interval * 20 * 60);
}
@Override
@ -105,8 +105,6 @@ public void run() {
if (!schematicRestore && activeConfig.getConfig().claim.claimAutoNatureRestore) {
BlockUtil.getInstance().restoreClaim(claim);
}
// remove all context permissions
PermissionUtil.getInstance().clearPermissions(claim);
}
return;
}
@ -147,8 +145,6 @@ public void run() {
if (!schematicRestore && activeConfig.getConfig().claim.claimAutoNatureRestore) {
BlockUtil.getInstance().restoreClaim(claim);
}
// remove all context permissions
PermissionUtil.getInstance().clearPermissions(claim);
}
}
}

View File

@ -41,8 +41,6 @@
import com.griefdefender.api.permission.option.Options;
import com.griefdefender.configuration.ClaimDataConfig;
import com.griefdefender.configuration.ClaimStorageData;
import com.griefdefender.configuration.GriefDefenderConfig;
import com.griefdefender.configuration.PlayerStorageData;
import com.griefdefender.event.GDRemoveClaimEvent;
import com.griefdefender.internal.util.BlockUtil;
import com.griefdefender.internal.util.VecHelper;
@ -79,7 +77,6 @@ public class GDClaimManager implements ClaimManager {
private static final BaseStorage DATASTORE = GriefDefenderPlugin.getInstance().dataStore;
private UUID worldUniqueId;
private String worldName;
private GriefDefenderConfig<?> activeConfig;
// Player UUID -> player data
private Map<UUID, GDPlayerData> playerDataList = Maps.newHashMap();
@ -94,7 +91,6 @@ public class GDClaimManager implements ClaimManager {
public GDClaimManager(World world) {
this.worldUniqueId = world.getUniqueId();
this.worldName = world.getName();
this.activeConfig = GriefDefenderPlugin.getActiveConfig(this.worldUniqueId);
}
public GDPlayerData getOrCreatePlayerData(UUID playerUniqueId) {

View File

@ -49,7 +49,6 @@
import com.griefdefender.permission.GDPermissionUser;
import com.griefdefender.permission.GDPermissions;
import com.griefdefender.text.action.GDCallbackHolder;
import com.griefdefender.util.PermissionUtil;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.adapter.spongeapi.TextAdapter;
@ -179,8 +178,6 @@ private static Consumer<CommandSource> createConfirmationConsumer(Player player,
}
playerData.onClaimDelete();
// remove all context permissions
PermissionUtil.getInstance().clearPermissions(claim);
playerData.revertActiveVisual(player);
if (claim.isTown()) {

View File

@ -48,7 +48,6 @@
import com.griefdefender.permission.GDPermissionUser;
import com.griefdefender.permission.GDPermissions;
import com.griefdefender.text.action.GDCallbackHolder;
import com.griefdefender.util.PermissionUtil;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.adapter.spongeapi.TextAdapter;
@ -139,8 +138,6 @@ private static Consumer<CommandSource> createConfirmationConsumer(GDPermissionUs
double refund = 0;
// adjust claim blocks
for (Claim claim : allowedClaims) {
// remove all context permissions
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
if (claim.isSubdivision() || claim.isAdminClaim() || claim.isWilderness()) {
continue;
}

View File

@ -40,7 +40,6 @@
import com.griefdefender.event.GDCauseStackManager;
import com.griefdefender.permission.GDPermissions;
import com.griefdefender.text.action.GDCallbackHolder;
import com.griefdefender.util.PermissionUtil;
import net.kyori.text.Component;
import net.kyori.text.TextComponent;
import net.kyori.text.adapter.spongeapi.TextAdapter;
@ -106,7 +105,6 @@ private static Consumer<CommandSource> createConfirmationConsumer(Player player,
}
playerData.onClaimDelete();
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
playerData.revertActiveVisual(player);
if (claim.isTown()) {

View File

@ -305,11 +305,48 @@ public void addActiveContexts(Set<Context> contexts, GDPermissionHolder permissi
}
public void clearPermissions(GDClaim claim) {
Map<Set<Context>, Map<String, Boolean>> permissionMap = this.getPermanentPermissions(GriefDefenderPlugin.DEFAULT_HOLDER);
// check default holder
this.clearPermission(claim.getUniqueId(), GriefDefenderPlugin.DEFAULT_HOLDER);
// check loaded groups
for (Group group : this.luckPermsApi.getGroupManager().getLoadedGroups()) {
if (group.getName().equalsIgnoreCase("default")) {
continue;
}
final GDPermissionHolder holder = PermissionHolderCache.getInstance().getOrCreateGroup(group.getName());
if (holder == null) {
continue;
}
this.clearPermission(claim.getUniqueId(), holder);
}
// check user trusts
for (UUID uuid : claim.getUserTrusts()) {
if (uuid.equals(GriefDefenderPlugin.PUBLIC_UUID) || uuid.equals(GriefDefenderPlugin.WORLD_USER_UUID) || uuid.equals(GriefDefenderPlugin.ADMIN_USER_UUID)) {
continue;
}
final GDPermissionHolder holder = PermissionHolderCache.getInstance().getOrCreateUser(uuid);
if (holder == null) {
continue;
}
this.clearPermission(claim.getUniqueId(), holder);
}
}
private void clearPermission(UUID claimUniqueId, GDPermissionHolder holder) {
Map<Set<Context>, Map<String, Boolean>> permissionMap = this.getPermanentPermissions(holder);
for (Entry<Set<Context>, Map<String, Boolean>> mapEntry : permissionMap.entrySet()) {
for (Context context : mapEntry.getKey()) {
if (context.getKey().equalsIgnoreCase("gd_claim") && context.getValue().equalsIgnoreCase(claim.getUniqueId().toString())) {
this.clearPermissions(GriefDefenderPlugin.DEFAULT_HOLDER, mapEntry.getKey());
if (context.getKey().equalsIgnoreCase("gd_claim") && context.getValue().equalsIgnoreCase(claimUniqueId.toString())) {
this.clearPermissions(holder, mapEntry.getKey());
break;
}
}
}
Map<Set<Context>, Map<String, String>> optionMap = this.getPermanentOptions(holder);
for (Entry<Set<Context>, Map<String, String>> mapEntry : optionMap.entrySet()) {
for (Context context : mapEntry.getKey()) {
if (context.getKey().equalsIgnoreCase("gd_claim") && context.getValue().equalsIgnoreCase(claimUniqueId.toString())) {
this.clearPermissions(holder, mapEntry.getKey());
break;
}
}

View File

@ -180,7 +180,6 @@ public ClaimResult deleteAllAdminClaims(CommandSource src, World world) {
}
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
claimWorldManager.deleteClaimInternal(claim, true);
}
@ -194,7 +193,6 @@ public ClaimResult deleteClaim(Claim claim, boolean deleteChildren) {
public void abandonClaimsForPlayer(GDPermissionUser user, Set<Claim> claimsToDelete) {
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
GDClaimManager claimWorldManager = this.claimWorldManagers.get(claim.getWorldUniqueId());
claimWorldManager.deleteClaimInternal(claim, true);
}
@ -207,7 +205,6 @@ public void deleteClaimsForPlayer(UUID playerID) {
final GDPlayerData playerData = BaseStorage.GLOBAL_PLAYER_DATA.get(playerID);
List<Claim> claimsToDelete = new ArrayList<>(playerData.getInternalClaims());
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
GDClaimManager claimWorldManager = this.claimWorldManagers.get(claim.getWorldUniqueId());
claimWorldManager.deleteClaimInternal(claim, true);
}
@ -233,7 +230,6 @@ public void deleteClaimsForPlayer(UUID playerID) {
}
for (Claim claim : claimsToDelete) {
PermissionUtil.getInstance().clearPermissions(GriefDefenderPlugin.DEFAULT_HOLDER, ImmutableSet.of(claim.getContext()));
claimWorldManager.deleteClaimInternal(claim, true);
claims.remove(claim);
}

View File

@ -46,6 +46,7 @@
import com.griefdefender.migrator.GPBukkitMigrator;
import com.griefdefender.migrator.PlayerDataMigrator;
import com.griefdefender.migrator.WorldGuardMigrator;
import com.griefdefender.util.PermissionUtil;
import org.apache.commons.io.FileUtils;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.scheduler.Task;
@ -473,6 +474,7 @@ public ClaimResult deleteClaimFromStorage(GDClaim claim) {
}
}
PermissionUtil.getInstance().clearPermissions((GDClaim) claim);
return new GDClaimResult(claim, ClaimResultType.SUCCESS);
} catch (IOException e) {
e.printStackTrace();

View File

@ -143,8 +143,6 @@ public void run() {
if (!schematicRestore && activeConfig.getConfig().claim.claimAutoNatureRestore) {
BlockUtil.getInstance().restoreClaim(claim);
}
// remove all context permissions
PermissionUtil.getInstance().clearPermissions(claim);
}
}
}