flan/src/main/java/com/flemmli97/flan/claim/Claim.java

570 lines
22 KiB
Java
Raw Normal View History

2020-08-23 12:52:36 +00:00
package com.flemmli97.flan.claim;
import com.flemmli97.flan.config.ConfigHandler;
2020-08-23 12:52:36 +00:00
import com.flemmli97.flan.player.PlayerClaimData;
import com.google.common.collect.ImmutableList;
2020-08-23 12:52:36 +00:00
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
2020-08-24 20:32:29 +00:00
import com.google.common.collect.Sets;
2020-08-23 12:52:36 +00:00
import com.google.gson.JsonArray;
2020-08-24 19:03:06 +00:00
import com.google.gson.JsonElement;
2020-08-23 12:52:36 +00:00
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
2020-08-24 19:03:06 +00:00
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
2020-08-23 12:52:36 +00:00
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
2020-08-23 12:52:36 +00:00
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
2020-08-24 20:32:29 +00:00
import java.util.Set;
2020-08-23 12:52:36 +00:00
import java.util.UUID;
2020-10-30 14:09:57 +00:00
public class Claim implements IPermissionContainer{
2020-08-23 12:52:36 +00:00
private boolean dirty;
private int minX, minZ, maxX, maxZ, minY;
private UUID owner;
2020-08-23 12:52:36 +00:00
private UUID claimID;
2020-08-24 19:03:06 +00:00
private final EnumMap<EnumPermission, Boolean> globalPerm = Maps.newEnumMap(EnumPermission.class);
2020-08-23 12:52:36 +00:00
private final Map<String, EnumMap<EnumPermission, Boolean>> permissions = Maps.newHashMap();
private final Map<UUID, String> playersGroups = Maps.newHashMap();
private final List<Claim> subClaims = Lists.newArrayList();
2020-08-24 19:03:06 +00:00
private UUID parent;
private Claim parentClaim;
2020-08-23 12:52:36 +00:00
/**
* Flag for players tracking this claim
*/
private boolean removed;
2020-08-24 19:03:06 +00:00
private final ServerWorld world;
private Claim(ServerWorld world) {
this.world = world;
2020-08-23 12:52:36 +00:00
}
2020-08-24 19:03:06 +00:00
public Claim(BlockPos pos1, BlockPos pos2, UUID creator, ServerWorld world) {
this(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ(), Math.min(pos1.getY(), pos2.getY()), creator, world);
2020-08-23 12:52:36 +00:00
}
2020-08-24 19:03:06 +00:00
public Claim(int x1, int x2, int z1, int z2, int minY, UUID creator, ServerWorld world) {
2020-08-23 12:52:36 +00:00
this.minX = Math.min(x1, x2);
this.minZ = Math.min(z1, z2);
this.maxX = Math.max(x1, x2);
this.maxZ = Math.max(z1, z2);
this.minY = Math.max(0, minY);
this.owner = creator;
2020-08-24 19:03:06 +00:00
this.world = world;
this.setDirty(true);
2020-08-23 12:52:36 +00:00
}
2020-08-24 19:03:06 +00:00
public static Claim fromJson(JsonObject obj, UUID owner, ServerWorld world) {
Claim claim = new Claim(world);
2020-08-23 12:52:36 +00:00
claim.readJson(obj, owner);
return claim;
}
public void setClaimID(UUID uuid) {
this.claimID = uuid;
this.setDirty(true);
2020-08-23 12:52:36 +00:00
}
2020-09-02 13:36:58 +00:00
public void extendDownwards(BlockPos pos) {
this.minY = pos.getY();
this.setDirty(true);
}
2020-08-23 12:52:36 +00:00
public UUID getClaimID() {
return this.claimID;
}
public UUID getOwner() {
return this.owner;
}
2020-10-30 14:09:57 +00:00
public ServerWorld getWorld(){
return this.world;
}
2020-08-25 17:43:52 +00:00
public Claim parentClaim() {
if (this.parent == null)
2020-08-24 19:03:06 +00:00
return null;
2020-08-25 17:43:52 +00:00
if (this.parentClaim == null) {
2020-08-24 19:03:06 +00:00
ClaimStorage storage = ClaimStorage.get(this.world);
2020-08-25 19:06:36 +00:00
this.parentClaim = storage.getFromUUID(this.parent);
2020-08-24 19:03:06 +00:00
}
return this.parentClaim;
}
2020-08-25 17:43:52 +00:00
public void copySizes(Claim claim) {
2020-08-24 19:03:06 +00:00
this.minX = claim.minX;
this.maxX = claim.maxX;
this.minZ = claim.minZ;
this.maxZ = claim.maxZ;
this.minY = claim.minY;
this.removed = false;
this.setDirty(true);
2020-08-24 19:03:06 +00:00
}
public void toggleAdminClaim(ServerPlayerEntity player, boolean flag) {
2020-09-02 13:36:58 +00:00
if (!flag)
2020-09-03 16:00:37 +00:00
this.transferOwner(player.getUuid());
else {
this.owner = null;
this.subClaims.forEach(claim -> claim.owner = null);
}
this.setDirty(true);
}
2020-09-02 13:36:58 +00:00
public boolean isAdminClaim() {
return this.owner == null;
}
2020-09-03 16:00:37 +00:00
public void transferOwner(UUID player) {
this.owner = player;
this.subClaims.forEach(claim -> claim.owner = player);
this.setDirty(true);
}
2020-08-23 12:52:36 +00:00
public int getPlane() {
return (this.maxX - this.minX) * (this.maxZ - this.minZ);
}
/**
* @return The claims dimension in order: x, X, z, Z, y
*/
public int[] getDimensions() {
return new int[]{this.minX, this.maxX, this.minZ, this.maxZ, this.minY};
}
public boolean insideClaim(BlockPos pos) {
return this.minX <= pos.getX() && this.maxX >= pos.getX() && this.minZ <= pos.getZ() && this.maxZ >= pos.getZ() && this.minY <= pos.getY();
}
public boolean intersects(Claim other) {
return this.minX <= other.maxX && this.maxX >= other.minX && this.minZ <= other.maxZ && this.maxZ >= other.minZ;
2020-08-23 12:52:36 +00:00
}
public boolean isCorner(BlockPos pos) {
return (pos.getX() == this.minX && pos.getZ() == this.minZ) || (pos.getX() == this.minX && pos.getZ() == this.maxZ)
|| (pos.getX() == this.maxX && pos.getZ() == this.minZ) || (pos.getX() == this.maxX && pos.getZ() == this.maxZ);
}
public void remove() {
this.removed = true;
}
public boolean isRemoved() {
return this.removed;
}
2020-08-24 19:03:06 +00:00
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message) {
2020-10-30 14:09:57 +00:00
if(!this.isAdminClaim() && ConfigHandler.config.globalDefaultPerms.containsKey(this.world.getRegistryKey().getValue().toString())){
EnumMap<EnumPermission, Boolean> permMap = ConfigHandler.config.globalDefaultPerms.get(this.world.getRegistryKey().getValue().toString());
if(permMap.containsKey(perm)) {
if (permMap.get(perm) || this.isAdminIgnore(player))
return true;
if (message)
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
return false;
}
}
if (perm.isAlwaysGlobalPerm()) {
2020-08-23 12:52:36 +00:00
for (Claim claim : this.subClaims) {
if (claim.insideClaim(pos)) {
2020-08-24 19:03:06 +00:00
return claim.canInteract(player, perm, pos, message);
2020-08-23 12:52:36 +00:00
}
}
2020-08-25 17:43:52 +00:00
if (this.hasPerm(perm))
2020-08-24 19:03:06 +00:00
return true;
2020-08-25 17:43:52 +00:00
if (message)
2020-08-25 19:06:36 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
2020-08-24 19:03:06 +00:00
return false;
2020-08-23 12:52:36 +00:00
}
2020-10-30 14:09:57 +00:00
if (this.isAdminIgnore(player) || player.getUuid().equals(this.owner))
2020-08-23 12:52:36 +00:00
return true;
2020-09-03 16:00:37 +00:00
if (perm != EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS)
for (Claim claim : this.subClaims) {
if (claim.insideClaim(pos)) {
2020-08-24 19:03:06 +00:00
return claim.canInteract(player, perm, pos, message);
2020-09-03 16:00:37 +00:00
}
2020-08-23 12:52:36 +00:00
}
if (this.playersGroups.containsKey(player.getUuid())) {
EnumMap<EnumPermission, Boolean> map = this.permissions.get(this.playersGroups.get(player.getUuid()));
2020-08-24 19:03:06 +00:00
if (map != null && map.containsKey(perm)) {
2020-08-25 17:43:52 +00:00
if (map.get(perm))
2020-08-24 19:03:06 +00:00
return true;
2020-08-25 17:43:52 +00:00
if (message)
2020-08-25 19:06:36 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
2020-08-24 19:03:06 +00:00
return false;
}
2020-08-23 12:52:36 +00:00
}
2020-08-25 17:43:52 +00:00
if (this.hasPerm(perm))
2020-08-24 19:03:06 +00:00
return true;
2020-08-25 17:43:52 +00:00
if (message)
2020-08-25 19:06:36 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
2020-08-24 19:03:06 +00:00
return false;
}
2020-10-30 14:09:57 +00:00
private boolean isAdminIgnore(ServerPlayerEntity player){
return player == null || ((this.isAdminClaim() && player.hasPermissionLevel(2)) || PlayerClaimData.get(player).isAdminIgnoreClaim());
}
2020-08-24 19:03:06 +00:00
/**
* @return -1 for default, 0 for false, 1 for true
*/
public int permEnabled(EnumPermission perm) {
2020-08-25 17:43:52 +00:00
return !this.globalPerm.containsKey(perm) ? -1 : this.globalPerm.get(perm) ? 1 : 0;
2020-08-23 12:52:36 +00:00
}
2020-08-25 17:43:52 +00:00
private boolean hasPerm(EnumPermission perm) {
if (this.parentClaim() == null)
2020-08-24 19:03:06 +00:00
return this.permEnabled(perm) == 1;
2020-08-25 17:43:52 +00:00
if (this.permEnabled(perm) == -1)
return this.parentClaim().permEnabled(perm) == 1;
2020-08-24 19:03:06 +00:00
return this.permEnabled(perm) == 1;
}
private UUID generateUUID() {
UUID uuid = UUID.randomUUID();
for (Claim claim : this.subClaims)
2020-08-25 17:43:52 +00:00
if (claim.claimID.equals(uuid)) {
2020-10-30 14:38:24 +00:00
return this.generateUUID();
2020-08-24 19:03:06 +00:00
}
return uuid;
2020-08-23 12:52:36 +00:00
}
2020-08-24 20:32:29 +00:00
public Set<Claim> tryCreateSubClaim(BlockPos pos1, BlockPos pos2) {
2020-08-24 19:03:06 +00:00
Claim sub = new Claim(pos1, new BlockPos(pos2.getX(), 0, pos2.getZ()), this.owner, this.world);
sub.setClaimID(this.generateUUID());
2020-08-24 20:32:29 +00:00
Set<Claim> conflicts = Sets.newHashSet();
2020-08-25 17:43:52 +00:00
for (Claim other : this.subClaims)
if (sub.intersects(other)) {
conflicts.add(other);
}
2020-08-25 17:43:52 +00:00
if (conflicts.isEmpty()) {
2020-08-24 20:32:29 +00:00
sub.parent = this.claimID;
sub.parentClaim = this;
this.subClaims.add(sub);
this.setDirty(true);
2020-08-24 20:32:29 +00:00
}
return conflicts;
2020-08-23 12:52:36 +00:00
}
2020-08-25 17:43:52 +00:00
public void addSubClaimGriefprevention(Claim claim) {
2020-08-24 19:03:06 +00:00
claim.setClaimID(this.generateUUID());
claim.parent = this.claimID;
claim.parentClaim = this;
this.subClaims.add(claim);
this.setDirty(true);
2020-08-24 19:03:06 +00:00
}
2020-08-23 12:52:36 +00:00
public Claim getSubClaim(BlockPos pos) {
for (Claim claim : this.subClaims)
if (claim.insideClaim(pos))
return claim;
return null;
}
2020-08-25 17:43:52 +00:00
public boolean deleteSubClaim(Claim claim) {
2020-08-25 19:50:41 +00:00
claim.remove();
this.setDirty(true);
2020-08-24 19:03:06 +00:00
return this.subClaims.remove(claim);
}
2020-08-25 17:43:52 +00:00
public List<Claim> getAllSubclaims() {
return ImmutableList.copyOf(this.subClaims);
}
2020-08-25 17:43:52 +00:00
public Set<Claim> resizeSubclaim(Claim claim, BlockPos from, BlockPos to) {
2020-08-24 19:03:06 +00:00
int[] dims = claim.getDimensions();
2020-08-25 17:43:52 +00:00
BlockPos opposite = new BlockPos(dims[0] == from.getX() ? dims[1] : dims[0], dims[4], dims[2] == from.getZ() ? dims[3] : dims[2]);
2020-08-24 19:03:06 +00:00
Claim newClaim = new Claim(opposite, to, claim.claimID, this.world);
2020-08-24 20:32:29 +00:00
Set<Claim> conflicts = Sets.newHashSet();
2020-08-25 17:43:52 +00:00
for (Claim other : this.subClaims)
2020-08-24 19:03:06 +00:00
if (!claim.equals(other) && newClaim.intersects(other))
2020-08-24 20:32:29 +00:00
conflicts.add(other);
2020-08-25 19:50:41 +00:00
if (conflicts.isEmpty()) {
2020-08-24 20:32:29 +00:00
claim.copySizes(newClaim);
this.setDirty(true);
2020-08-25 19:50:41 +00:00
}
2020-08-24 20:32:29 +00:00
return conflicts;
2020-08-24 19:03:06 +00:00
}
2020-08-23 12:52:36 +00:00
public boolean setPlayerGroup(UUID player, String group, boolean force) {
if (player.equals(this.owner))
return false;
2020-08-23 12:52:36 +00:00
if (group == null) {
this.playersGroups.remove(player);
this.setDirty(true);
2020-08-23 12:52:36 +00:00
return true;
}
if (!this.playersGroups.containsKey(player) || force) {
this.playersGroups.put(player, group);
this.setDirty(true);
2020-08-23 12:52:36 +00:00
return true;
}
return false;
}
public List<String> playersFromGroup(MinecraftServer server, String group) {
List<UUID> l = Lists.newArrayList();
this.playersGroups.forEach((uuid, g) -> {
if (g.equals(group))
l.add(uuid);
});
List<String> names = Lists.newArrayList();
l.forEach(uuid -> {
GameProfile prof = server.getUserCache().getByUuid(uuid);
if (prof != null)
names.add(prof.getName());
});
names.sort(null);
return names;
}
2020-10-30 14:09:57 +00:00
public boolean editGlobalPerms(ServerPlayerEntity player, EnumPermission toggle, int mode) {
if((player!= null && !this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) || (!this.isAdminClaim() && ConfigHandler.config.globallyDefined(this.world, toggle)))
return false;
2020-08-24 19:03:06 +00:00
if (mode > 1)
mode = -1;
if (mode == -1)
2020-08-23 12:52:36 +00:00
this.globalPerm.remove(toggle);
else
2020-08-24 19:03:06 +00:00
this.globalPerm.put(toggle, mode == 1);
this.setDirty(true);
2020-10-30 14:09:57 +00:00
return true;
2020-08-23 12:52:36 +00:00
}
public boolean editPerms(ServerPlayerEntity player, String group, EnumPermission perm, int mode) {
return this.editPerms(player, group, perm, mode, false);
}
2020-09-02 13:36:58 +00:00
2020-08-23 12:52:36 +00:00
/**
* Edit the permissions for a group. If not defined for the group creates a new default permission map for that group
*
* @param mode -1 = makes it resort to the global perm, 0 = deny perm, 1 = allow perm
* @return If editing was successful or not
*/
public boolean editPerms(ServerPlayerEntity player, String group, EnumPermission perm, int mode, boolean griefPrevention) {
2020-10-30 14:09:57 +00:00
if (perm.isAlwaysGlobalPerm() || (!this.isAdminClaim() && ConfigHandler.config.globallyDefined(this.world, perm)))
return false;
if (griefPrevention || this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
2020-08-23 12:52:36 +00:00
if (mode > 1)
mode = -1;
2020-08-23 13:16:26 +00:00
boolean has = this.permissions.containsKey(group);
EnumMap<EnumPermission, Boolean> perms = has ? this.permissions.get(group) : new EnumMap<>(EnumPermission.class);
2020-08-23 12:52:36 +00:00
if (mode == -1)
perms.remove(perm);
else
perms.put(perm, mode == 1);
if (!has)
this.permissions.put(group, perms);
this.setDirty(true);
2020-08-23 12:52:36 +00:00
return true;
}
return false;
}
public boolean removePermGroup(ServerPlayerEntity player, String group) {
if (this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
2020-08-23 12:52:36 +00:00
this.permissions.remove(group);
List<UUID> toRemove = Lists.newArrayList();
this.playersGroups.forEach((uuid, g) -> {
if (g.equals(group))
toRemove.add(uuid);
});
2020-08-23 13:16:26 +00:00
toRemove.forEach(this.playersGroups::remove);
this.setDirty(true);
2020-08-23 12:52:36 +00:00
return true;
}
return false;
}
public int groupHasPerm(String rank, EnumPermission perm) {
if (!this.permissions.containsKey(rank) || !this.permissions.get(rank).containsKey(perm))
return -1;
return this.permissions.get(rank).get(perm) ? 1 : 0;
}
public List<String> groups() {
List<String> l = Lists.newArrayList(this.permissions.keySet());
l.sort(null);
return l;
}
2020-08-25 19:50:41 +00:00
/**
* Only marks non sub claims
*/
public void setDirty(boolean flag) {
2020-09-02 13:36:58 +00:00
if (this.parentClaim() != null)
this.parentClaim().setDirty(flag);
2020-08-25 19:50:41 +00:00
else
this.dirty = flag;
2020-08-23 12:52:36 +00:00
}
public boolean isDirty() {
return this.dirty;
}
public void readJson(JsonObject obj, UUID uuid) {
this.claimID = UUID.fromString(obj.get("ID").getAsString());
2020-08-23 12:52:36 +00:00
JsonArray pos = obj.getAsJsonArray("PosxXzZY");
this.minX = pos.get(0).getAsInt();
this.maxX = pos.get(1).getAsInt();
this.minZ = pos.get(2).getAsInt();
this.maxZ = pos.get(3).getAsInt();
this.minY = pos.get(4).getAsInt();
2020-09-03 16:00:37 +00:00
if (obj.has("AdminClaim") && obj.get("AdminClaim").getAsBoolean())
this.owner = null;
else
this.owner = uuid;
2020-08-23 12:52:36 +00:00
this.globalPerm.clear();
this.permissions.clear();
this.subClaims.clear();
2020-08-25 17:43:52 +00:00
if (obj.has("Parent"))
2020-08-24 19:03:06 +00:00
this.parent = UUID.fromString(obj.get("Parent").getAsString());
2020-08-23 12:52:36 +00:00
if (obj.has("GlobalPerms")) {
2020-08-25 17:43:52 +00:00
if (this.parent == null) {
obj.getAsJsonArray("GlobalPerms").forEach(perm -> this.globalPerm.put(EnumPermission.valueOf(perm.getAsString()), true));
} else {
obj.getAsJsonObject("GlobalPerms").entrySet().forEach(entry -> this.globalPerm.put(EnumPermission.valueOf(entry.getKey()), entry.getValue().getAsBoolean()));
2020-08-24 19:03:06 +00:00
}
2020-08-23 12:52:36 +00:00
}
if (obj.has("PermGroup")) {
JsonObject perms = obj.getAsJsonObject("PermGroup");
perms.entrySet().forEach(key -> {
2020-08-23 13:16:26 +00:00
EnumMap<EnumPermission, Boolean> map = new EnumMap<>(EnumPermission.class);
2020-08-23 12:52:36 +00:00
JsonObject group = key.getValue().getAsJsonObject();
group.entrySet().forEach(gkey -> map.put(EnumPermission.valueOf(gkey.getKey()), gkey.getValue().getAsBoolean()));
this.permissions.put(key.getKey(), map);
});
}
if (obj.has("PlayerPerms")) {
JsonObject pl = obj.getAsJsonObject("PlayerPerms");
pl.entrySet().forEach(key -> this.playersGroups.put(UUID.fromString(key.getKey()), key.getValue().getAsString()));
}
if (obj.has("SubClaims")) {
2020-08-24 19:03:06 +00:00
obj.getAsJsonArray("SubClaims").forEach(sub -> this.subClaims.add(Claim.fromJson(sub.getAsJsonObject(), this.owner, this.world)));
2020-08-23 12:52:36 +00:00
}
}
public JsonObject toJson(JsonObject obj) {
obj.addProperty("ID", this.claimID.toString());
2020-08-23 12:52:36 +00:00
JsonArray pos = new JsonArray();
pos.add(this.minX);
pos.add(this.maxX);
pos.add(this.minZ);
pos.add(this.maxZ);
pos.add(this.minY);
obj.add("PosxXzZY", pos);
2020-08-25 17:43:52 +00:00
if (this.parent != null)
2020-08-24 19:03:06 +00:00
obj.addProperty("Parent", this.parent.toString());
2020-08-23 12:52:36 +00:00
if (!this.globalPerm.isEmpty()) {
2020-08-24 19:03:06 +00:00
JsonElement gPerm;
2020-08-25 17:43:52 +00:00
if (this.parent == null) {
2020-08-24 19:03:06 +00:00
gPerm = new JsonArray();
this.globalPerm.forEach((perm, bool) -> {
if (bool)
((JsonArray) gPerm).add(perm.toString());
});
2020-08-25 17:43:52 +00:00
} else {
2020-08-24 19:03:06 +00:00
gPerm = new JsonObject();
2020-08-25 17:43:52 +00:00
this.globalPerm.forEach((perm, bool) -> ((JsonObject) gPerm).addProperty(perm.toString(), bool));
2020-08-24 19:03:06 +00:00
}
2020-08-23 12:52:36 +00:00
obj.add("GlobalPerms", gPerm);
}
if (!this.permissions.isEmpty()) {
JsonObject perms = new JsonObject();
this.permissions.forEach((s, pmap) -> {
JsonObject group = new JsonObject();
pmap.forEach((perm, bool) -> group.addProperty(perm.toString(), bool));
perms.add(s, group);
});
obj.add("PermGroup", perms);
}
if (!this.playersGroups.isEmpty()) {
JsonObject pl = new JsonObject();
this.playersGroups.forEach((uuid, s) -> pl.addProperty(uuid.toString(), s));
obj.add("PlayerPerms", pl);
}
if (!this.subClaims.isEmpty()) {
JsonArray list = new JsonArray();
this.subClaims.forEach(p -> list.add(p.toJson(new JsonObject())));
obj.add("SubClaims", list);
}
return obj;
}
@Override
public int hashCode() {
2020-08-25 17:43:52 +00:00
return this.claimID == null ? Arrays.hashCode(this.getDimensions()) : this.claimID.hashCode();
2020-08-23 12:52:36 +00:00
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj instanceof Claim) {
Claim other = (Claim) obj;
2020-08-25 17:43:52 +00:00
if (this.claimID == null && other.claimID == null)
return Arrays.equals(this.getDimensions(), ((Claim) obj).getDimensions());
2020-08-25 17:43:52 +00:00
if (this.claimID != null)
return this.claimID.equals(((Claim) obj).claimID);
}
2020-08-23 12:52:36 +00:00
return false;
}
@Override
public String toString() {
return String.format("Claim:[ID=%s, Owner=%s, from: [x=%d,z=%d], to: [x=%d,z=%d]", this.claimID != null ? this.claimID.toString() : "null", this.owner != null ? this.owner.toString() : "Admin", this.minX, this.minZ, this.maxX, this.maxZ);
2020-08-23 12:52:36 +00:00
}
public String formattedClaim() {
return String.format("[x=%d,z=%d] - [x=%d,z=%d]", this.minX, this.minZ, this.maxX, this.maxZ);
}
2020-08-25 17:43:52 +00:00
public List<Text> infoString(ServerPlayerEntity player) {
boolean perms = this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos());
List<Text> l = Lists.newArrayList();
2020-08-24 19:03:06 +00:00
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
2020-09-02 13:36:58 +00:00
GameProfile prof = this.owner != null ? player.getServer().getUserCache().getByUuid(this.owner) : null;
String ownerName = this.isAdminClaim() ? "Admin" : prof != null ? prof.getName() : "<UNKNOWN>";
2020-09-02 13:36:58 +00:00
if (this.parent == null)
2020-08-25 19:32:00 +00:00
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfo, ownerName, this.minX, this.minZ, this.maxX, this.maxZ, this.subClaims.size()), Formatting.GOLD));
else
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBasicInfoSub, ownerName, this.minX, this.minZ, this.maxX, this.maxZ), Formatting.GOLD));
2020-08-25 17:43:52 +00:00
if (perms) {
2020-08-24 19:03:06 +00:00
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimInfoPerms, this.globalPerm), Formatting.RED));
l.add(PermHelper.simpleColoredText(ConfigHandler.lang.claimGroupInfoHeader, Formatting.RED));
Map<String, List<String>> nameToGroup = Maps.newHashMap();
for (Map.Entry<UUID, String> e : this.playersGroups.entrySet()) {
GameProfile pgroup = player.getServer().getUserCache().getByUuid(e.getKey());
if (prof != null) {
nameToGroup.merge(e.getValue(), Lists.newArrayList(pgroup.getName()), (old, val) -> {
old.add(pgroup.getName());
return old;
});
}
}
for (Map.Entry<String, EnumMap<EnumPermission, Boolean>> e : this.permissions.entrySet()) {
2020-08-24 19:03:06 +00:00
l.add(PermHelper.simpleColoredText(String.format(" %s:", e.getKey()), Formatting.DARK_RED));
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPerms, e.getValue()), Formatting.RED));
l.add(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimGroupPlayers, nameToGroup.getOrDefault(e.getKey(), Lists.newArrayList())), Formatting.RED));
}
}
2020-08-24 19:03:06 +00:00
l.add(PermHelper.simpleColoredText("=============================================", Formatting.GREEN));
return l;
2020-08-23 12:52:36 +00:00
}
}