fix admin claims

This commit is contained in:
Flemmli97 2020-08-25 21:06:36 +02:00
parent e34714d0a9
commit 332595028e
5 changed files with 34 additions and 11 deletions

View File

@ -91,7 +91,7 @@ public class Claim {
return null; return null;
if (this.parentClaim == null) { if (this.parentClaim == null) {
ClaimStorage storage = ClaimStorage.get(this.world); ClaimStorage storage = ClaimStorage.get(this.world);
this.parentClaim = storage.claimUUIDMap.get(this.parent); this.parentClaim = storage.getFromUUID(this.parent);
} }
return this.parentClaim; return this.parentClaim;
} }
@ -155,13 +155,13 @@ public class Claim {
if (this.hasPerm(perm)) if (this.hasPerm(perm))
return true; return true;
if (message) if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
return false; return false;
} }
if (player.getUuid().equals(this.owner)) if (player.getUuid().equals(this.owner))
return true; return true;
PlayerClaimData data = PlayerClaimData.get(player); PlayerClaimData data = PlayerClaimData.get(player);
if (player.hasPermissionLevel(2) && data.isAdminIgnoreClaim()) if (player.hasPermissionLevel(2) || data.isAdminIgnoreClaim())
return true; return true;
for (Claim claim : this.subClaims) { for (Claim claim : this.subClaims) {
if (claim.insideClaim(pos)) { if (claim.insideClaim(pos)) {
@ -177,14 +177,14 @@ public class Claim {
if (map.get(perm)) if (map.get(perm))
return true; return true;
if (message) if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
return false; return false;
} }
} }
if (this.hasPerm(perm)) if (this.hasPerm(perm))
return true; return true;
if (message) if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), false); player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
return false; return false;
} }
@ -371,7 +371,8 @@ public class Claim {
this.minZ = pos.get(2).getAsInt(); this.minZ = pos.get(2).getAsInt();
this.maxZ = pos.get(3).getAsInt(); this.maxZ = pos.get(3).getAsInt();
this.minY = pos.get(4).getAsInt(); this.minY = pos.get(4).getAsInt();
this.owner = uuid; if(!obj.has("AdminClaim"))
this.owner = uuid;
this.claimID = UUID.fromString(obj.get("ID").getAsString()); this.claimID = UUID.fromString(obj.get("ID").getAsString());
this.globalPerm.clear(); this.globalPerm.clear();
this.permissions.clear(); this.permissions.clear();
@ -412,6 +413,8 @@ public class Claim {
pos.add(this.minY); pos.add(this.minY);
obj.add("PosxXzZY", pos); obj.add("PosxXzZY", pos);
obj.addProperty("ID", this.claimID.toString()); obj.addProperty("ID", this.claimID.toString());
if(this.owner==null)
obj.addProperty("AdminClaim", true);
if (this.parent != null) if (this.parent != null)
obj.addProperty("Parent", this.parent.toString()); obj.addProperty("Parent", this.parent.toString());
if (!this.globalPerm.isEmpty()) { if (!this.globalPerm.isEmpty()) {

View File

@ -37,9 +37,9 @@ import java.util.UUID;
public class ClaimStorage { public class ClaimStorage {
public final Long2ObjectArrayMap<List<Claim>> claims = new Long2ObjectArrayMap<>(); private final Long2ObjectArrayMap<List<Claim>> claims = new Long2ObjectArrayMap<>();
public final Map<UUID, Claim> claimUUIDMap = Maps.newHashMap(); private final Map<UUID, Claim> claimUUIDMap = Maps.newHashMap();
public final Map<UUID, Set<Claim>> playerClaimMap = Maps.newHashMap(); private final Map<UUID, Set<Claim>> playerClaimMap = Maps.newHashMap();
public static ClaimStorage get(ServerWorld world) { public static ClaimStorage get(ServerWorld world) {
return (ClaimStorage) ((IClaimData) world).getClaimData(); return (ClaimStorage) ((IClaimData) world).getClaimData();
@ -154,6 +154,10 @@ public class ClaimStorage {
return null; return null;
} }
public Claim getFromUUID(UUID uuid) {
return this.claimUUIDMap.get(uuid);
}
private void addClaim(Claim claim) { private void addClaim(Claim claim) {
int[] pos = getChunkPos(claim); int[] pos = getChunkPos(claim);
for (int x = pos[0]; x <= pos[1]; x++) for (int x = pos[0]; x <= pos[1]; x++)
@ -175,6 +179,10 @@ public class ClaimStorage {
return this.playerClaimMap.containsKey(player) ? ImmutableSet.copyOf(this.playerClaimMap.get(player)) : ImmutableSet.of(); return this.playerClaimMap.containsKey(player) ? ImmutableSet.copyOf(this.playerClaimMap.get(player)) : ImmutableSet.of();
} }
public Collection<Claim> getAdminClaims(){
return ImmutableSet.copyOf(this.claimUUIDMap.values().stream().filter(claim->claim.getOwner()==null).iterator());
}
public static int[] getChunkPos(Claim claim) { public static int[] getChunkPos(Claim claim) {
int[] dim = claim.getDimensions(); int[] dim = claim.getDimensions();
int[] pos = new int[4]; int[] pos = new int[4];

View File

@ -9,6 +9,7 @@ import com.flemmli97.flan.gui.ClaimMenuScreenHandler;
import com.flemmli97.flan.player.EnumDisplayType; import com.flemmli97.flan.player.EnumDisplayType;
import com.flemmli97.flan.player.EnumEditMode; import com.flemmli97.flan.player.EnumEditMode;
import com.flemmli97.flan.player.PlayerClaimData; import com.flemmli97.flan.player.PlayerClaimData;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
@ -54,6 +55,7 @@ public class CommandClaim {
CommandManager.literal("adminMode").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::switchAdminMode), CommandManager.literal("adminMode").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::switchAdminMode),
CommandManager.literal("readGriefPrevention").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::readGriefPreventionData), CommandManager.literal("readGriefPrevention").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::readGriefPreventionData),
CommandManager.literal("setAdminClaim").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::setAdminClaim), CommandManager.literal("setAdminClaim").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::setAdminClaim),
CommandManager.literal("listAdminClaims").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::listAdminClaims),
CommandManager.literal("adminDelete").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::adminDelete) CommandManager.literal("adminDelete").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::adminDelete)
.then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())) .then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()))
.executes(CommandClaim::adminDeleteAll)), .executes(CommandClaim::adminDeleteAll)),
@ -304,6 +306,15 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int listAdminClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource src = context.getSource();
Collection<Claim> claims = ClaimStorage.get(src.getWorld()).getAdminClaims();
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.listAdminClaims, src.getWorld().getRegistryKey().getValue()), Formatting.GOLD), false);
for (Claim claim : claims)
src.sendFeedback(PermHelper.simpleColoredText(claim.formattedClaim(), Formatting.YELLOW), false);
return Command.SINGLE_SUCCESS;
}
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context) { private static int readGriefPreventionData(CommandContext<ServerCommandSource> context) {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true); src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true);

View File

@ -19,6 +19,7 @@ public class LangConfig {
public String inspectNoClaim = "Nobody owns this block"; public String inspectNoClaim = "Nobody owns this block";
public String claimBlocksFormat = "Claim Blocks: %1$d + (Bonus) %2$d; Used: %3$d"; public String claimBlocksFormat = "Claim Blocks: %1$d + (Bonus) %2$d; Used: %3$d";
public String listClaims = "Listing all claims:"; public String listClaims = "Listing all claims:";
public String listAdminClaims = "Listing all admin-claims in %1:";
public String noPermission = "You don't have the required permissions to do that here!"; public String noPermission = "You don't have the required permissions to do that here!";
public String noPermissionSimple = "Sorry you can't do that here!"; public String noPermissionSimple = "Sorry you can't do that here!";

View File

@ -239,9 +239,9 @@ public class PlayerClaimData {
private int calculateUsedClaimBlocks() { private int calculateUsedClaimBlocks() {
int usedClaimsBlocks = 0; int usedClaimsBlocks = 0;
for (ServerWorld world : this.player.getServer().getWorlds()) { for (ServerWorld world : this.player.getServer().getWorlds()) {
Collection<Claim> claims = ClaimStorage.get(world).playerClaimMap.get(this.player.getUuid()); Collection<Claim> claims = ClaimStorage.get(world).allClaimsFromPlayer(this.player.getUuid());
if (claims != null) if (claims != null)
usedClaimsBlocks += claims.stream().mapToInt(Claim::getPlane).sum(); usedClaimsBlocks += claims.stream().filter(claim->claim.getOwner()!=null).mapToInt(Claim::getPlane).sum();
} }
return usedClaimsBlocks; return usedClaimsBlocks;
} }