change global definition getter
This commit is contained in:
parent
5ebb73568e
commit
0cbb5a576a
@ -192,15 +192,13 @@ public class Claim implements IPermissionContainer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!this.isAdminClaim() && ConfigHandler.config.globalDefaultPerms.containsKey(this.world.getRegistryKey().getValue().toString())) {
|
Boolean global = ConfigHandler.config.getGlobal(this.world, perm);
|
||||||
Map<ClaimPermission, Boolean> permMap = ConfigHandler.config.globalDefaultPerms.get(this.world.getRegistryKey().getValue().toString());
|
if (!this.isAdminClaim() && global != null) {
|
||||||
if (permMap.containsKey(perm)) {
|
if (global || this.isAdminIgnore(player))
|
||||||
if (permMap.get(perm) || this.isAdminIgnore(player))
|
return true;
|
||||||
return true;
|
if (message)
|
||||||
if (message)
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (PermissionRegistry.globalPerms().contains(perm)) {
|
if (PermissionRegistry.globalPerms().contains(perm)) {
|
||||||
for (Claim claim : this.subClaims) {
|
for (Claim claim : this.subClaims) {
|
||||||
|
@ -19,15 +19,13 @@ public class GlobalClaim implements IPermissionContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos, boolean message) {
|
public boolean canInteract(ServerPlayerEntity player, ClaimPermission perm, BlockPos pos, boolean message) {
|
||||||
if (ConfigHandler.config.globalDefaultPerms.containsKey(this.world.getRegistryKey().getValue().toString())) {
|
Boolean global = ConfigHandler.config.getGlobal(this.world, perm);
|
||||||
Map<ClaimPermission, Boolean> permMap = ConfigHandler.config.globalDefaultPerms.get(this.world.getRegistryKey().getValue().toString());
|
if (global != null) {
|
||||||
if (permMap.containsKey(perm)) {
|
if (global)
|
||||||
if (permMap.get(perm))
|
return true;
|
||||||
return true;
|
if (message)
|
||||||
if (message)
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -495,10 +495,8 @@ public class CommandClaim {
|
|||||||
ServerWorld world = context.getSource().getWorld();
|
ServerWorld world = context.getSource().getWorld();
|
||||||
Claim claim = ClaimStorage.get(world).getClaimAt(new BlockPos(context.getSource().getPosition()));
|
Claim claim = ClaimStorage.get(world).getClaimAt(new BlockPos(context.getSource().getPosition()));
|
||||||
boolean admin = claim != null && claim.isAdminClaim();
|
boolean admin = claim != null && claim.isAdminClaim();
|
||||||
String serverWorld = world.getRegistryKey().getValue().toString();
|
|
||||||
Map<ClaimPermission, Boolean> global = ConfigHandler.config.globalDefaultPerms.get(serverWorld);
|
|
||||||
for (ClaimPermission perm : PermissionRegistry.getPerms()) {
|
for (ClaimPermission perm : PermissionRegistry.getPerms()) {
|
||||||
if (!admin && global != null && global.containsKey(perm)) {
|
if (!admin && ConfigHandler.config.globallyDefined(world, perm)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!group || !PermissionRegistry.globalPerms().contains(perm))
|
if (!group || !PermissionRegistry.globalPerms().contains(perm))
|
||||||
|
@ -33,6 +33,7 @@ public class Config {
|
|||||||
|
|
||||||
public String[] blacklistedWorlds = new String[0];
|
public String[] blacklistedWorlds = new String[0];
|
||||||
public boolean worldWhitelist;
|
public boolean worldWhitelist;
|
||||||
|
public boolean allowMobSpawnToggle;
|
||||||
|
|
||||||
public Item claimingItem = Items.GOLDEN_HOE;
|
public Item claimingItem = Items.GOLDEN_HOE;
|
||||||
public Item inspectionItem = Items.STICK;
|
public Item inspectionItem = Items.STICK;
|
||||||
@ -42,7 +43,7 @@ public class Config {
|
|||||||
|
|
||||||
public boolean log;
|
public boolean log;
|
||||||
|
|
||||||
public final Map<String, Map<ClaimPermission, Boolean>> globalDefaultPerms = Maps.newHashMap();
|
private final Map<String, Map<ClaimPermission, Boolean>> globalDefaultPerms = Maps.newHashMap();
|
||||||
|
|
||||||
public Config(MinecraftServer server) {
|
public Config(MinecraftServer server) {
|
||||||
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
||||||
@ -76,6 +77,7 @@ public class Config {
|
|||||||
for (int i = 0; i < arr.size(); i++)
|
for (int i = 0; i < arr.size(); i++)
|
||||||
this.blacklistedWorlds[i] = arr.get(i).getAsString();
|
this.blacklistedWorlds[i] = arr.get(i).getAsString();
|
||||||
this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist);
|
this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist);
|
||||||
|
this.allowMobSpawnToggle = ConfigHandler.fromJson(obj, "allowMobSpawnToggle", false);
|
||||||
if (obj.has("claimingItem"))
|
if (obj.has("claimingItem"))
|
||||||
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
||||||
if (obj.has("inspectionItem"))
|
if (obj.has("inspectionItem"))
|
||||||
@ -118,6 +120,7 @@ public class Config {
|
|||||||
arr.add(this.blacklistedWorlds[i]);
|
arr.add(this.blacklistedWorlds[i]);
|
||||||
obj.add("blacklistedWorlds", arr);
|
obj.add("blacklistedWorlds", arr);
|
||||||
obj.addProperty("worldWhitelist", this.worldWhitelist);
|
obj.addProperty("worldWhitelist", this.worldWhitelist);
|
||||||
|
obj.addProperty("allowMobSpawnToggle", this.allowMobSpawnToggle);
|
||||||
obj.addProperty("claimingItem", Registry.ITEM.getId(this.claimingItem).toString());
|
obj.addProperty("claimingItem", Registry.ITEM.getId(this.claimingItem).toString());
|
||||||
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
||||||
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
||||||
@ -140,7 +143,13 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean globallyDefined(ServerWorld world, ClaimPermission perm) {
|
public boolean globallyDefined(ServerWorld world, ClaimPermission perm) {
|
||||||
Map<ClaimPermission, Boolean> global = ConfigHandler.config.globalDefaultPerms.get(world.getRegistryKey().getValue().toString());
|
return getGlobal(world, perm) != null;
|
||||||
return global != null && global.containsKey(perm);
|
}
|
||||||
|
|
||||||
|
public Boolean getGlobal(ServerWorld world, ClaimPermission perm){
|
||||||
|
if(perm == PermissionRegistry.MOBSPAWN && !this.allowMobSpawnToggle)
|
||||||
|
return Boolean.FALSE;
|
||||||
|
Map<ClaimPermission, Boolean> permMap = ConfigHandler.config.globalDefaultPerms.get(world.getRegistryKey().getValue().toString());
|
||||||
|
return permMap == null ? null : permMap.getOrDefault(perm, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,11 @@ public class ServerScreenHelper {
|
|||||||
ListTag lore = new ListTag();
|
ListTag lore = new ListTag();
|
||||||
Text trans = new LiteralText(perm.desc).setStyle(Style.EMPTY.withFormatting(Formatting.YELLOW));
|
Text trans = new LiteralText(perm.desc).setStyle(Style.EMPTY.withFormatting(Formatting.YELLOW));
|
||||||
lore.add(StringTag.of(Text.Serializer.toJson(trans)));
|
lore.add(StringTag.of(Text.Serializer.toJson(trans)));
|
||||||
Map<ClaimPermission, Boolean> global = ConfigHandler.config.globalDefaultPerms.get(claim.getWorld().getRegistryKey().getValue().toString());
|
Boolean global = ConfigHandler.config.getGlobal(claim.getWorld(), perm);
|
||||||
if (!claim.isAdminClaim() && global != null && global.containsKey(perm)) {
|
if (!claim.isAdminClaim() && global != null) {
|
||||||
Text text = new LiteralText("Non Editable.").setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED));
|
Text text = new LiteralText("Non Editable.").setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED));
|
||||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||||
String permFlag = global.get(perm).toString();
|
String permFlag = global.toString();
|
||||||
Text text2 = new LiteralText("Enabled: " + permFlag).setStyle(Style.EMPTY.withFormatting(permFlag.equals("true") ? Formatting.GREEN : Formatting.RED));
|
Text text2 = new LiteralText("Enabled: " + permFlag).setStyle(Style.EMPTY.withFormatting(permFlag.equals("true") ? Formatting.GREEN : Formatting.RED));
|
||||||
lore.add(StringTag.of(Text.Serializer.toJson(text2)));
|
lore.add(StringTag.of(Text.Serializer.toJson(text2)));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user