changed admin claim to a bool cause it did more harm than good before

This commit is contained in:
Flemmli97 2020-08-27 01:17:09 +02:00
parent 9bb677a578
commit a4e37c7938
5 changed files with 24 additions and 19 deletions

View File

@ -30,6 +30,7 @@ public class Claim {
private int minX, minZ, maxX, maxZ, minY; private int minX, minZ, maxX, maxZ, minY;
private UUID owner; private UUID owner;
private boolean adminClaim;
private UUID claimID; private UUID claimID;
private final EnumMap<EnumPermission, Boolean> globalPerm = Maps.newEnumMap(EnumPermission.class); private final EnumMap<EnumPermission, Boolean> globalPerm = Maps.newEnumMap(EnumPermission.class);
@ -112,12 +113,16 @@ public class Claim {
this.setDirty(); this.setDirty();
} }
public void setAdminClaim() { public void toggleAdminClaim(boolean flag) {
this.owner = null; this.adminClaim = flag;
this.subClaims.forEach(claim->claim.owner = null); this.subClaims.forEach(claim->claim.adminClaim = flag);
this.setDirty(); this.setDirty();
} }
public boolean isAdminClaim(){
return this.adminClaim;
}
public int getPlane() { public int getPlane() {
return (this.maxX - this.minX) * (this.maxZ - this.minZ); return (this.maxX - this.minX) * (this.maxZ - this.minZ);
} }
@ -170,7 +175,7 @@ public class Claim {
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 ((this.owner==null && player.hasPermissionLevel(2)) || data.isAdminIgnoreClaim()) if ((this.adminClaim && 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)) {
@ -279,7 +284,7 @@ public class Claim {
} }
public boolean setPlayerGroup(UUID player, String group, boolean force) { public boolean setPlayerGroup(UUID player, String group, boolean force) {
if (this.owner != null && this.owner.equals(player)) if (this.owner.equals(player))
return false; return false;
if (group == null) { if (group == null) {
this.playersGroups.remove(player); this.playersGroups.remove(player);
@ -392,8 +397,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();
if(!obj.has("AdminClaim"))
this.owner = uuid; this.owner = uuid;
this.adminClaim = obj.has("AdminClaim")?obj.get("AdminClaim").getAsBoolean():false;
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();
@ -434,8 +439,7 @@ 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", this.adminClaim);
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()) {
@ -506,8 +510,8 @@ public class Claim {
boolean perms = this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()); boolean perms = this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos());
List<Text> l = Lists.newArrayList(); List<Text> l = Lists.newArrayList();
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN)); l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
GameProfile prof = this.owner != null ? player.getServer().getUserCache().getByUuid(this.owner) : null; GameProfile prof = player.getServer().getUserCache().getByUuid(this.owner);
String ownerName = this.owner == null ? "Admin" : prof != null ? prof.getName() : "<UNKNOWN>"; String ownerName = this.adminClaim ? "Admin" : prof != null ? prof.getName() : "<UNKNOWN>";
if(this.parent==null) if(this.parent==null)
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD)); l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD));
else else

View File

@ -180,7 +180,7 @@ public class ClaimStorage {
} }
public Collection<Claim> getAdminClaims(){ public Collection<Claim> getAdminClaims(){
return ImmutableSet.copyOf(this.claimUUIDMap.values().stream().filter(claim->claim.getOwner()==null).iterator()); return ImmutableSet.copyOf(this.claimUUIDMap.values().stream().filter(claim->claim.isAdminClaim()).iterator());
} }
public static int[] getChunkPos(Claim claim) { public static int[] getChunkPos(Claim claim) {

View File

@ -9,12 +9,13 @@ 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;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
@ -55,7 +56,7 @@ public class CommandClaim {
CommandManager.literal("switchMode").executes(CommandClaim::switchClaimMode), CommandManager.literal("switchMode").executes(CommandClaim::switchClaimMode),
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)).then(CommandManager.argument("toggle", BoolArgumentType.bool()).executes(CommandClaim::toggleAdminClaim)),
CommandManager.literal("listAdminClaims").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::listAdminClaims), 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())
@ -294,7 +295,7 @@ public class CommandClaim {
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
private static int setAdminClaim(CommandContext<ServerCommandSource> context) { private static int toggleAdminClaim(CommandContext<ServerCommandSource> context) {
ServerCommandSource src = context.getSource(); ServerCommandSource src = context.getSource();
ClaimStorage storage = ClaimStorage.get(src.getWorld()); ClaimStorage storage = ClaimStorage.get(src.getWorld());
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition())); Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
@ -302,8 +303,8 @@ public class CommandClaim {
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false); src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0; return 0;
} }
claim.setAdminClaim(); claim.toggleAdminClaim(BoolArgumentType.getBool(context, "toggle"));
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.setAdminClaim, Formatting.GOLD), true); src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.setAdminClaim, claim.isAdminClaim()), Formatting.GOLD), true);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }

View File

@ -55,7 +55,7 @@ public class LangConfig {
public String adminMode = "Adminmode (Ignore Claims) set to: %s"; public String adminMode = "Adminmode (Ignore Claims) set to: %s";
public String adminDeleteAll = "Deleted all claims for following players: %s"; public String adminDeleteAll = "Deleted all claims for following players: %s";
public String setAdminClaim = "Claim changed to an Adminclaim"; public String setAdminClaim = "Adminclaim of this claim now: %s";
public String readGriefpreventionData = "Reading data from GriefPrevention"; public String readGriefpreventionData = "Reading data from GriefPrevention";
public String readGriefpreventionDataSuccess = "Successfully read data"; public String readGriefpreventionDataSuccess = "Successfully read data";
public String readGriefpreventionDataFail = "Failed reading data for following claim files (Check the logs!): %s"; public String readGriefpreventionDataFail = "Failed reading data for following claim files (Check the logs!): %s";

View File

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