add global defined permission
This commit is contained in:
parent
cf1e9730fb
commit
82e5f0e6c3
@ -1,3 +1,9 @@
|
||||
Flan 1.1.0
|
||||
======================
|
||||
- Add global per world perms
|
||||
- Fail safe for config reading just in case the config contains "bad values"
|
||||
- Some more logs
|
||||
|
||||
Flan 1.0.9
|
||||
======================
|
||||
- Add some logging stuff. Mostly with read/saving things
|
||||
|
@ -38,4 +38,7 @@ public class Flan implements ModInitializer {
|
||||
logger.info(msg, o);
|
||||
}
|
||||
|
||||
public static void debug(String msg, Object... o){
|
||||
logger.debug(msg, o);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@ -24,7 +25,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Claim {
|
||||
public class Claim implements IPermissionContainer{
|
||||
|
||||
private boolean dirty;
|
||||
private int minX, minZ, maxX, maxZ, minY;
|
||||
@ -92,6 +93,10 @@ public class Claim {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
public ServerWorld getWorld(){
|
||||
return this.world;
|
||||
}
|
||||
|
||||
public Claim parentClaim() {
|
||||
if (this.parent == null)
|
||||
return null;
|
||||
@ -164,11 +169,17 @@ public class Claim {
|
||||
return this.removed;
|
||||
}
|
||||
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos) {
|
||||
return this.canInteract(player, perm, pos, false);
|
||||
}
|
||||
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message) {
|
||||
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()) {
|
||||
for (Claim claim : this.subClaims) {
|
||||
if (claim.insideClaim(pos)) {
|
||||
@ -181,10 +192,7 @@ public class Claim {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
if (player.getUuid().equals(this.owner))
|
||||
return true;
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if ((this.isAdminClaim() && player.hasPermissionLevel(2)) || data.isAdminIgnoreClaim())
|
||||
if (this.isAdminIgnore(player) || player.getUuid().equals(this.owner))
|
||||
return true;
|
||||
if (perm != EnumPermission.EDITCLAIM && perm != EnumPermission.EDITPERMS)
|
||||
for (Claim claim : this.subClaims) {
|
||||
@ -209,6 +217,10 @@ public class Claim {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isAdminIgnore(ServerPlayerEntity player){
|
||||
return player == null || ((this.isAdminClaim() && player.hasPermissionLevel(2)) || PlayerClaimData.get(player).isAdminIgnoreClaim());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return -1 for default, 0 for false, 1 for true
|
||||
*/
|
||||
@ -322,7 +334,9 @@ public class Claim {
|
||||
return names;
|
||||
}
|
||||
|
||||
public void editGlobalPerms(EnumPermission toggle, int mode) {
|
||||
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;
|
||||
if (mode > 1)
|
||||
mode = -1;
|
||||
if (mode == -1)
|
||||
@ -330,6 +344,7 @@ public class Claim {
|
||||
else
|
||||
this.globalPerm.put(toggle, mode == 1);
|
||||
this.setDirty(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean editPerms(ServerPlayerEntity player, String group, EnumPermission perm, int mode) {
|
||||
@ -343,7 +358,7 @@ public class Claim {
|
||||
* @return If editing was successful or not
|
||||
*/
|
||||
public boolean editPerms(ServerPlayerEntity player, String group, EnumPermission perm, int mode, boolean griefPrevention) {
|
||||
if (perm.isAlwaysGlobalPerm())
|
||||
if (perm.isAlwaysGlobalPerm() || (!this.isAdminClaim() && ConfigHandler.config.globallyDefined(this.world, perm)))
|
||||
return false;
|
||||
if (griefPrevention || this.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
||||
if (mode > 1)
|
||||
|
@ -49,12 +49,13 @@ public class ClaimStorage {
|
||||
private final Map<UUID, Claim> claimUUIDMap = Maps.newHashMap();
|
||||
private final Map<UUID, Set<Claim>> playerClaimMap = Maps.newHashMap();
|
||||
private final Set<UUID> dirty = Sets.newHashSet();
|
||||
|
||||
private final GlobalClaim globalClaim;
|
||||
public static ClaimStorage get(ServerWorld world) {
|
||||
return (ClaimStorage) ((IClaimData) world).getClaimData();
|
||||
}
|
||||
|
||||
public ClaimStorage(MinecraftServer server, ServerWorld world) {
|
||||
this.globalClaim = new GlobalClaim(world);
|
||||
this.read(server, world);
|
||||
}
|
||||
|
||||
@ -173,6 +174,13 @@ public class ClaimStorage {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IPermissionContainer getForPermissionCheck(BlockPos pos){
|
||||
Claim claim = this.getClaimAt(pos);
|
||||
if(claim != null)
|
||||
return claim;
|
||||
return this.globalClaim;
|
||||
}
|
||||
|
||||
public Claim getFromUUID(UUID uuid) {
|
||||
return this.claimUUIDMap.get(uuid);
|
||||
}
|
||||
@ -240,14 +248,15 @@ public class ClaimStorage {
|
||||
UUID uuid = realName.equals(adminClaimString) ? null : UUID.fromString(file.getName().replace(".json", ""));
|
||||
FileReader reader = new FileReader(file);
|
||||
JsonArray arr = ConfigHandler.GSON.fromJson(reader, JsonArray.class);
|
||||
reader.close();
|
||||
if (arr == null)
|
||||
continue;
|
||||
Flan.debug("Reading claim data from json {} for player uuid {}", arr, uuid);
|
||||
arr.forEach(el -> {
|
||||
if (el.isJsonObject()) {
|
||||
this.addClaim(Claim.fromJson((JsonObject) el, uuid, world));
|
||||
}
|
||||
});
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -264,6 +273,7 @@ public class ClaimStorage {
|
||||
for (Map.Entry<UUID, Set<Claim>> e : this.playerClaimMap.entrySet()) {
|
||||
String owner = e.getKey() == null ? adminClaimString : e.getKey().toString();
|
||||
File file = new File(dir, owner + ".json");
|
||||
Flan.debug("Attempting saving claim data for player uuid {}", owner);
|
||||
boolean dirty = false;
|
||||
if (!file.exists()) {
|
||||
if (e.getValue().isEmpty())
|
||||
@ -284,6 +294,7 @@ public class ClaimStorage {
|
||||
if (dirty) {
|
||||
JsonArray arr = new JsonArray();
|
||||
e.getValue().forEach(claim -> arr.add(claim.toJson(new JsonObject())));
|
||||
Flan.debug("Attempting saving changed claim data {} for player uuid {}", arr, owner);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
ConfigHandler.GSON.toJson(arr, writer);
|
||||
writer.close();
|
||||
@ -403,7 +414,7 @@ public class ClaimStorage {
|
||||
if (builders.contains("public")) {
|
||||
perms.get("builders").forEach(perm -> {
|
||||
if (!perm.isAlwaysGlobalPerm())
|
||||
claim.editGlobalPerms(perm, 1);
|
||||
claim.editGlobalPerms(null, perm, 1);
|
||||
});
|
||||
} else {
|
||||
perms.get("builders").forEach(perm -> claim.editPerms(null, "Builders", perm, 1, true));
|
||||
@ -414,7 +425,7 @@ public class ClaimStorage {
|
||||
if (managers.contains("public")) {
|
||||
perms.get("managers").forEach(perm -> {
|
||||
if (!perm.isAlwaysGlobalPerm())
|
||||
claim.editGlobalPerms(perm, 1);
|
||||
claim.editGlobalPerms(null, perm, 1);
|
||||
});
|
||||
} else {
|
||||
perms.get("managers").forEach(perm -> claim.editPerms(null, "Managers", perm, 1, true));
|
||||
@ -425,7 +436,7 @@ public class ClaimStorage {
|
||||
if (containers.contains("public")) {
|
||||
perms.get("containers").forEach(perm -> {
|
||||
if (!perm.isAlwaysGlobalPerm())
|
||||
claim.editGlobalPerms(perm, 1);
|
||||
claim.editGlobalPerms(null, perm, 1);
|
||||
});
|
||||
} else {
|
||||
perms.get("containers").forEach(perm -> claim.editPerms(null, "Containers", perm, 1, true));
|
||||
@ -436,7 +447,7 @@ public class ClaimStorage {
|
||||
if (accessors.contains("public")) {
|
||||
perms.get("accessors").forEach(perm -> {
|
||||
if (!perm.isAlwaysGlobalPerm())
|
||||
claim.editGlobalPerms(perm, 1);
|
||||
claim.editGlobalPerms(null, perm, 1);
|
||||
});
|
||||
} else {
|
||||
perms.get("accessors").forEach(perm -> claim.editPerms(null, "Accessors", perm, 1, true));
|
||||
|
32
src/main/java/com/flemmli97/flan/claim/GlobalClaim.java
Normal file
32
src/main/java/com/flemmli97/flan/claim/GlobalClaim.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
public class GlobalClaim implements IPermissionContainer{
|
||||
|
||||
private final ServerWorld world;
|
||||
public GlobalClaim(ServerWorld world){
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message) {
|
||||
if(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))
|
||||
return true;
|
||||
if (message)
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.flemmli97.flan.claim;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public interface IPermissionContainer {
|
||||
|
||||
default boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos){
|
||||
return this.canInteract(player, perm, pos, false);
|
||||
}
|
||||
|
||||
boolean canInteract(ServerPlayerEntity player, EnumPermission perm, BlockPos pos, boolean message);
|
||||
|
||||
}
|
@ -37,6 +37,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -492,7 +493,15 @@ public class CommandClaim {
|
||||
}
|
||||
|
||||
private static CompletableFuture<Suggestions> permSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder build, boolean group) {
|
||||
ServerWorld world = context.getSource().getWorld();
|
||||
Claim claim = ClaimStorage.get(world).getClaimAt(new BlockPos(context.getSource().getPosition()));
|
||||
boolean admin = claim != null && claim.isAdminClaim();
|
||||
String serverWorld = world.getRegistryKey().getValue().toString();
|
||||
EnumMap<EnumPermission,Boolean> global = ConfigHandler.config.globalDefaultPerms.get(serverWorld);
|
||||
for (EnumPermission perm : EnumPermission.values()) {
|
||||
if(!admin && global!=null && global.containsKey(perm)) {
|
||||
continue;
|
||||
}
|
||||
if (!group || !perm.isAlwaysGlobalPerm())
|
||||
build.suggest(perm.toString());
|
||||
}
|
||||
@ -560,7 +569,7 @@ public class CommandClaim {
|
||||
}
|
||||
String setPerm = mode == 1 ? "true" : mode == 0 ? "false" : "default";
|
||||
if (group == null) {
|
||||
claim.editGlobalPerms(perm, mode);
|
||||
claim.editGlobalPerms(player, perm, mode);
|
||||
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editPerm, perm, setPerm), Formatting.GOLD), false);
|
||||
} else {
|
||||
claim.editPerms(player, group, perm, mode);
|
||||
|
@ -1,18 +1,26 @@
|
||||
package com.flemmli97.flan.config;
|
||||
|
||||
import com.flemmli97.flan.Flan;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.lwjgl.system.CallbackI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class Config {
|
||||
|
||||
@ -35,6 +43,8 @@ public class Config {
|
||||
|
||||
public boolean log;
|
||||
|
||||
public Map<String,EnumMap<EnumPermission,Boolean>> globalDefaultPerms = Maps.newHashMap();
|
||||
|
||||
public Config(MinecraftServer server) {
|
||||
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
|
||||
//.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
|
||||
@ -56,22 +66,39 @@ public class Config {
|
||||
FileReader reader = new FileReader(this.config);
|
||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||
reader.close();
|
||||
this.startingBlocks = obj.get("startingBlocks").getAsInt();
|
||||
this.maxClaimBlocks = obj.get("maxClaimBlocks").getAsInt();
|
||||
this.ticksForNextBlock = obj.get("ticksForNextBlock").getAsInt();
|
||||
this.minClaimsize = obj.get("minClaimsize").getAsInt();
|
||||
this.defaultClaimDepth = obj.get("defaultClaimDepth").getAsInt();
|
||||
JsonArray arr = obj.getAsJsonArray("blacklistedWorlds");
|
||||
this.startingBlocks = ConfigHandler.fromJson(obj, "startingBlocks", this.startingBlocks);
|
||||
this.maxClaimBlocks = ConfigHandler.fromJson(obj, "maxClaimBlocks", this.maxClaimBlocks);
|
||||
this.ticksForNextBlock = ConfigHandler.fromJson(obj, "ticksForNextBlock", this.ticksForNextBlock);
|
||||
this.minClaimsize = ConfigHandler.fromJson(obj, "minClaimsize", this.minClaimsize);
|
||||
this.defaultClaimDepth = ConfigHandler.fromJson(obj, "defaultClaimDepth", this.defaultClaimDepth);
|
||||
JsonArray arr = ConfigHandler.arryFromJson(obj, "blacklistedWorlds");
|
||||
this.blacklistedWorlds = new String[arr.size()];
|
||||
for (int i = 0; i < arr.size(); i++)
|
||||
this.blacklistedWorlds[i] = arr.get(i).getAsString();
|
||||
this.worldWhitelist = obj.get("worldWhitelist").getAsBoolean();
|
||||
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
||||
this.inspectionItem = Registry.ITEM.get(new Identifier((obj.get("inspectionItem").getAsString())));
|
||||
this.claimDisplayTime = obj.get("claimDisplayTime").getAsInt();
|
||||
this.log = obj.has("enableLogs") && obj.get("enableLogs").getAsBoolean();
|
||||
if (obj.has("permissionLevel"))
|
||||
this.permissionLevel = obj.get("permissionLevel").getAsInt();
|
||||
this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist);
|
||||
if(obj.has("claimingItem"))
|
||||
this.claimingItem = Registry.ITEM.get(new Identifier((obj.get("claimingItem").getAsString())));
|
||||
if(obj.has("inspectionItem"))
|
||||
this.inspectionItem = Registry.ITEM.get(new Identifier((obj.get("inspectionItem").getAsString())));
|
||||
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
|
||||
this.globalDefaultPerms.clear();
|
||||
JsonObject glob = ConfigHandler.fromJson(obj, "globalDefaultPerms");
|
||||
glob.entrySet().forEach(e->{
|
||||
EnumMap<EnumPermission, Boolean> perms = new EnumMap<>(EnumPermission.class);
|
||||
if(e.getValue().isJsonObject()){
|
||||
e.getValue().getAsJsonObject().entrySet().forEach(jperm->{
|
||||
try{
|
||||
perms.put(EnumPermission.valueOf(jperm.getKey()), jperm.getValue().getAsBoolean());
|
||||
}
|
||||
catch (IllegalArgumentException ex){
|
||||
Flan.log("No permmission with name {}", jperm.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
this.globalDefaultPerms.put(e.getKey(), perms);
|
||||
});
|
||||
this.log = ConfigHandler.fromJson(obj, "enableLogs", this.log);
|
||||
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -80,6 +107,7 @@ public class Config {
|
||||
|
||||
private void save() {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("__comment", "For help with the config refer to https://github.com/Flemmli97/Flan/wiki/Config");
|
||||
obj.addProperty("startingBlocks", this.startingBlocks);
|
||||
obj.addProperty("maxClaimBlocks", this.maxClaimBlocks);
|
||||
obj.addProperty("ticksForNextBlock", this.ticksForNextBlock);
|
||||
@ -92,6 +120,13 @@ public class Config {
|
||||
obj.addProperty("inspectionItem", Registry.ITEM.getId(this.inspectionItem).toString());
|
||||
obj.addProperty("claimDisplayTime", this.claimDisplayTime);
|
||||
obj.addProperty("permissionLevel", this.permissionLevel);
|
||||
JsonObject global = new JsonObject();
|
||||
this.globalDefaultPerms.entrySet().forEach(e->{
|
||||
JsonObject perm = new JsonObject();
|
||||
e.getValue().entrySet().forEach(eperm->perm.addProperty(eperm.getKey().toString(), eperm.getValue().toString()));
|
||||
global.add(e.getKey(), perm);
|
||||
});
|
||||
obj.add("globalDefaultPerms", global);
|
||||
obj.addProperty("enableLogs", this.log);
|
||||
try {
|
||||
FileWriter writer = new FileWriter(this.config);
|
||||
@ -101,4 +136,11 @@ public class Config {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean globallyDefined(ServerWorld world, EnumPermission perm){
|
||||
EnumMap<EnumPermission,Boolean> global = ConfigHandler.config.globalDefaultPerms.get(world.getRegistryKey().getValue().toString());
|
||||
if(global!=null && global.containsKey(perm)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}}
|
||||
|
@ -2,6 +2,8 @@ package com.flemmli97.flan.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class ConfigHandler {
|
||||
@ -21,4 +23,49 @@ public class ConfigHandler {
|
||||
config.load();
|
||||
lang.load();
|
||||
}
|
||||
|
||||
public static int fromJson(JsonObject obj, String key, int fallback){
|
||||
try {
|
||||
return obj.get(key).getAsInt();
|
||||
}
|
||||
catch (NullPointerException | UnsupportedOperationException e){
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fromJson(JsonObject obj, String key, boolean fallback){
|
||||
try {
|
||||
return obj.get(key).getAsBoolean();
|
||||
}
|
||||
catch (NullPointerException | UnsupportedOperationException e){
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static String fromJson(JsonObject obj, String key, String fallback){
|
||||
try {
|
||||
return obj.get(key).getAsString();
|
||||
}
|
||||
catch (NullPointerException | UnsupportedOperationException e){
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonObject fromJson(JsonObject obj, String key){
|
||||
try {
|
||||
return obj.get(key).getAsJsonObject();
|
||||
}
|
||||
catch (NullPointerException | UnsupportedOperationException e){
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonArray arryFromJson(JsonObject obj, String key){
|
||||
try {
|
||||
return obj.get(key).getAsJsonArray();
|
||||
}
|
||||
catch (NullPointerException | UnsupportedOperationException e){
|
||||
return new JsonArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.gui.LockedLecternScreenHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
@ -36,7 +37,7 @@ public class BlockInteractEvents {
|
||||
return true;
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (!claim.canInteract(player, EnumPermission.BREAK, pos, true)) {
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
@ -61,7 +62,7 @@ public class BlockInteractEvents {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(hitResult.getBlockPos());
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(hitResult.getBlockPos());
|
||||
if (claim != null) {
|
||||
boolean emptyHand = !player.getMainHandStack().isEmpty() || !player.getOffHandStack().isEmpty();
|
||||
boolean cancelBlockInteract = player.shouldCancelInteraction() && emptyHand;
|
||||
@ -114,7 +115,7 @@ public class BlockInteractEvents {
|
||||
if (perm != EnumPermission.PRESSUREPLATE && perm != EnumPermission.PORTAL)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, perm, pos, false);
|
||||
} else if (entity instanceof ProjectileEntity) {
|
||||
@ -124,7 +125,7 @@ public class BlockInteractEvents {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, pos, false);
|
||||
}
|
||||
@ -137,7 +138,7 @@ public class BlockInteractEvents {
|
||||
return false;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
Claim claim = storage.getClaimAt(landedPosition);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
|
||||
if(claim==null)
|
||||
return false;
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
@ -147,7 +148,7 @@ public class BlockInteractEvents {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
|
||||
Claim claim = storage.getClaimAt(landedPosition);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
|
||||
EnumPermission perm = BlockToPermissionMap.getFromBlock(landedState.getBlock());
|
||||
if (perm == EnumPermission.TRAMPLE)
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition, true);
|
||||
@ -162,7 +163,7 @@ public class BlockInteractEvents {
|
||||
ServerWorld serverWorld = (ServerWorld) world;
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if(claim==null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) entity, EnumPermission.TRAMPLE, pos, true);
|
||||
@ -170,7 +171,7 @@ public class BlockInteractEvents {
|
||||
Entity owner = ((ProjectileEntity) entity).getOwner();
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if(claim==null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos, true);
|
||||
@ -179,7 +180,7 @@ public class BlockInteractEvents {
|
||||
Entity owner = serverWorld.getEntity(((ItemEntity) entity).getThrower());
|
||||
if (owner instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get(serverWorld);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if(claim==null)
|
||||
return false;
|
||||
return !claim.canInteract((ServerPlayerEntity) owner, EnumPermission.TRAMPLE, pos, true);
|
||||
|
@ -4,6 +4,7 @@ import com.flemmli97.flan.claim.BlockToPermissionMap;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.mixin.IPersistentProjectileVars;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -46,7 +47,7 @@ public class EntityInteractEvents {
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof ArmorStandEntity) {
|
||||
if (!claim.canInteract((ServerPlayerEntity) player, EnumPermission.ARMORSTAND, pos, true))
|
||||
@ -62,7 +63,7 @@ public class EntityInteractEvents {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof BoatEntity)
|
||||
return claim.canInteract(player, EnumPermission.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
@ -101,7 +102,7 @@ public class EntityInteractEvents {
|
||||
if (perm != EnumPermission.ENDERPEARL && perm != EnumPermission.TARGETBLOCK && perm != EnumPermission.PROJECTILES)
|
||||
return false;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return false;
|
||||
boolean flag = !claim.canInteract(player, perm, pos, true);
|
||||
@ -129,7 +130,7 @@ public class EntityInteractEvents {
|
||||
} else if (res.getType() == HitResult.Type.ENTITY) {
|
||||
if (proj instanceof EnderPearlEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
|
||||
Claim claim = storage.getClaimAt(proj.getBlockPos());
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(proj.getBlockPos());
|
||||
return claim.canInteract(player, EnumPermission.ENDERPEARL, proj.getBlockPos(), true);
|
||||
}
|
||||
return attackSimple(player, ((EntityHitResult) res).getEntity(), true) != ActionResult.PASS;
|
||||
@ -142,7 +143,7 @@ public class EntityInteractEvents {
|
||||
if (source.getAttacker() instanceof ServerPlayerEntity)
|
||||
return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, false) != ActionResult.PASS;
|
||||
else if (source.isExplosive() && !entity.world.isClient) {
|
||||
Claim claim = ClaimStorage.get((ServerWorld) entity.world).getClaimAt(entity.getBlockPos());
|
||||
IPermissionContainer claim = ClaimStorage.get((ServerWorld) entity.world).getForPermissionCheck(entity.getBlockPos());
|
||||
return claim != null && !claim.canInteract(null, EnumPermission.EXPLOSIONS, entity.getBlockPos());
|
||||
}
|
||||
return false;
|
||||
@ -156,7 +157,7 @@ public class EntityInteractEvents {
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) p;
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
BlockPos pos = entity.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null) {
|
||||
if (entity instanceof ArmorStandEntity || entity instanceof MinecartEntity || entity instanceof BoatEntity || entity instanceof ItemFrameEntity)
|
||||
return claim.canInteract(player, EnumPermission.BREAKNONLIVING, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
|
||||
@ -171,7 +172,7 @@ public class EntityInteractEvents {
|
||||
if (player instanceof ServerPlayerEntity) {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract((ServerPlayerEntity) player, EnumPermission.XP, pos, false);
|
||||
}
|
||||
@ -184,7 +185,7 @@ public class EntityInteractEvents {
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) wither.world);
|
||||
for (int x = -1; x <= 1; x++)
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if (storage.getClaimAt(wither.getBlockPos().add(x, 0, z)) != null)
|
||||
if (storage.getForPermissionCheck(wither.getBlockPos().add(x, 0, z)) != null)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -3,6 +3,7 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import com.flemmli97.flan.player.EnumDisplayType;
|
||||
@ -59,7 +60,7 @@ public class ItemInteractEvents {
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
BlockPos pos = player.getBlockPos();
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim == null)
|
||||
return TypedActionResult.pass(stack);
|
||||
if (stack.getItem() == Items.ENDER_PEARL)
|
||||
@ -76,12 +77,12 @@ public class ItemInteractEvents {
|
||||
return ActionResult.PASS;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld());
|
||||
BlockPos placePos = new ItemPlacementContext(context).getBlockPos();
|
||||
Claim claim = storage.getClaimAt(placePos.add(0, 255, 0));
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(placePos.add(0, 255, 0));
|
||||
if (claim == null)
|
||||
return ActionResult.PASS;
|
||||
if (blackListedItems.contains(context.getStack().getItem()))
|
||||
return ActionResult.PASS;
|
||||
boolean actualInClaim = placePos.getY() >= claim.getDimensions()[4];
|
||||
boolean actualInClaim = !(claim instanceof Claim) || placePos.getY() >= ((Claim) claim).getDimensions()[4];
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
|
||||
if (context.getStack().getItem() == Items.END_CRYSTAL) {
|
||||
if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, false))
|
||||
@ -93,7 +94,7 @@ public class ItemInteractEvents {
|
||||
}
|
||||
if (claim.canInteract(player, EnumPermission.PLACE, placePos, false)) {
|
||||
if (!actualInClaim && context.getStack().getItem() instanceof BlockItem) {
|
||||
claim.extendDownwards(placePos);
|
||||
((Claim) claim).extendDownwards(placePos);
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
} else if (actualInClaim) {
|
||||
|
@ -3,6 +3,7 @@ package com.flemmli97.flan.event;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@ -18,7 +19,7 @@ public class WorldEvents {
|
||||
public static void modifyExplosion(Explosion explosion, ServerWorld world) {
|
||||
ClaimStorage storage = ClaimStorage.get(world);
|
||||
explosion.getAffectedBlocks().removeIf(pos -> {
|
||||
Claim claim = storage.getClaimAt(pos);
|
||||
IPermissionContainer claim = storage.getForPermissionCheck(pos);
|
||||
if (claim != null)
|
||||
return !claim.canInteract(null, EnumPermission.EXPLOSIONS, pos);
|
||||
return false;
|
||||
@ -31,15 +32,15 @@ public class WorldEvents {
|
||||
boolean empty = state.isAir() || state.getPistonBehavior() == PistonBehavior.DESTROY;
|
||||
BlockPos dirPos = blockPos.offset(direction);
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim from = storage.getClaimAt(blockPos);
|
||||
Claim to = storage.getClaimAt(dirPos);
|
||||
IPermissionContainer from = storage.getForPermissionCheck(blockPos);
|
||||
IPermissionContainer to = storage.getForPermissionCheck(dirPos);
|
||||
boolean flag = true;
|
||||
if (!empty) {
|
||||
if ((from != null && !from.equals(to)) || (from == null && to != null))
|
||||
flag = false;
|
||||
}
|
||||
if (from != null && from.equals(to)) {
|
||||
Claim opp = storage.getClaimAt(blockPos.offset(direction.getOpposite()));
|
||||
IPermissionContainer opp = storage.getForPermissionCheck(blockPos.offset(direction.getOpposite()));
|
||||
flag = from.equals(opp);
|
||||
}
|
||||
if (!flag) {
|
||||
@ -54,8 +55,8 @@ public class WorldEvents {
|
||||
if (!(world instanceof ServerWorld) || direction == Direction.UP || direction == Direction.DOWN)
|
||||
return true;
|
||||
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
|
||||
Claim from = storage.getClaimAt(blockPos);
|
||||
Claim to = storage.getClaimAt(blockPos.offset(direction));
|
||||
IPermissionContainer from = storage.getForPermissionCheck(blockPos);
|
||||
IPermissionContainer to = storage.getForPermissionCheck(blockPos.offset(direction));
|
||||
boolean fl = from == null && to == null;
|
||||
if (from != null)
|
||||
fl = from.equals(to);
|
||||
@ -63,12 +64,12 @@ public class WorldEvents {
|
||||
}
|
||||
|
||||
public static boolean canStartRaid(ServerPlayerEntity player) {
|
||||
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
||||
IPermissionContainer claim = ClaimStorage.get(player.getServerWorld()).getForPermissionCheck(player.getBlockPos());
|
||||
return claim == null || claim.canInteract(player, EnumPermission.RAID, player.getBlockPos());
|
||||
}
|
||||
|
||||
public static boolean canFireSpread(ServerWorld world, BlockPos pos) {
|
||||
Claim claim = ClaimStorage.get(world).getClaimAt(pos);
|
||||
IPermissionContainer claim = ClaimStorage.get(world).getForPermissionCheck(pos);
|
||||
return claim == null || claim.canInteract(null, EnumPermission.FIRESPREAD, pos);
|
||||
}
|
||||
}
|
||||
|
@ -159,17 +159,21 @@ public class PermissionScreenHandler extends ServerOnlyScreenHandler {
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
boolean success;
|
||||
if (this.group == null) {
|
||||
int mode;
|
||||
if (this.claim.parentClaim() == null)
|
||||
mode = this.claim.permEnabled(perm) == 1 ? -1 : 1;
|
||||
else
|
||||
mode = this.claim.permEnabled(perm) + 1;
|
||||
this.claim.editGlobalPerms(perm, mode);
|
||||
success = this.claim.editGlobalPerms(player, perm, mode);
|
||||
} else
|
||||
this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1);
|
||||
success = this.claim.editPerms(player, this.group, perm, this.claim.groupHasPerm(this.group, perm) + 1);
|
||||
slot.setStack(ServerScreenHelper.fromPermission(this.claim, perm, this.group));
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
if(success)
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BLOCK_NOTE_BLOCK_PLING, 1, 1.2f);
|
||||
else
|
||||
ServerScreenHelper.playSongToPlayer(player, SoundEvents.ENTITY_VILLAGER_NO, 1, 1f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.flemmli97.flan.gui;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.EnumPermission;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
@ -16,6 +17,8 @@ import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
public class ServerScreenHelper {
|
||||
|
||||
public static ItemStack emptyFiller() {
|
||||
@ -30,12 +33,34 @@ public class ServerScreenHelper {
|
||||
ListTag lore = new ListTag();
|
||||
Text trans = new LiteralText(perm.translation).setStyle(Style.EMPTY.withFormatting(Formatting.YELLOW));
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(trans)));
|
||||
String permFlag;
|
||||
if (group == null) {
|
||||
if (claim.parentClaim() == null)
|
||||
permFlag = "" + (claim.permEnabled(perm) == 1);
|
||||
else {
|
||||
switch (claim.permEnabled(perm)) {
|
||||
EnumMap<EnumPermission,Boolean> global = ConfigHandler.config.globalDefaultPerms.get(claim.getWorld().getRegistryKey().getValue().toString());
|
||||
if(!claim.isAdminClaim() && global!=null && global.containsKey(perm)){
|
||||
Text text = new LiteralText("Non Editable.").setStyle(Style.EMPTY.withFormatting(Formatting.DARK_RED));
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||
String permFlag = global.get(perm).toString();
|
||||
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)));
|
||||
}
|
||||
else {
|
||||
String permFlag;
|
||||
if (group == null) {
|
||||
if (claim.parentClaim() == null)
|
||||
permFlag = "" + (claim.permEnabled(perm) == 1);
|
||||
else {
|
||||
switch (claim.permEnabled(perm)) {
|
||||
case -1:
|
||||
permFlag = "default";
|
||||
break;
|
||||
case 1:
|
||||
permFlag = "true";
|
||||
break;
|
||||
default:
|
||||
permFlag = "false";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (claim.groupHasPerm(group, perm)) {
|
||||
case -1:
|
||||
permFlag = "default";
|
||||
break;
|
||||
@ -47,21 +72,9 @@ public class ServerScreenHelper {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (claim.groupHasPerm(group, perm)) {
|
||||
case -1:
|
||||
permFlag = "default";
|
||||
break;
|
||||
case 1:
|
||||
permFlag = "true";
|
||||
break;
|
||||
default:
|
||||
permFlag = "false";
|
||||
break;
|
||||
}
|
||||
Text text = new LiteralText("Enabled: " + permFlag).setStyle(Style.EMPTY.withFormatting(permFlag.equals("true") ? Formatting.GREEN : Formatting.RED));
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||
}
|
||||
Text text = new LiteralText("Enabled: " + permFlag).setStyle(Style.EMPTY.withFormatting(permFlag.equals("true") ? Formatting.GREEN : Formatting.RED));
|
||||
lore.add(StringTag.of(Text.Serializer.toJson(text)));
|
||||
stack.getOrCreateSubTag("display").put("Lore", lore);
|
||||
return stack;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.flemmli97.flan.Flan;
|
||||
import com.flemmli97.flan.IClaimData;
|
||||
import com.flemmli97.flan.claim.Claim;
|
||||
import com.flemmli97.flan.claim.ClaimStorage;
|
||||
import com.flemmli97.flan.claim.IPermissionContainer;
|
||||
import com.flemmli97.flan.claim.ParticleIndicators;
|
||||
import com.flemmli97.flan.claim.PermHelper;
|
||||
import com.flemmli97.flan.config.ConfigHandler;
|
||||
@ -120,11 +121,14 @@ public class PlayerClaimData {
|
||||
this.editingClaim = claim;
|
||||
}
|
||||
|
||||
public void addDisplayClaim(Claim claim, EnumDisplayType type, int height) {
|
||||
this.displayToAdd.add(new ClaimDisplay(claim, type, height));
|
||||
if (type == EnumDisplayType.MAIN)
|
||||
for (Claim sub : claim.getAllSubclaims())
|
||||
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB, height));
|
||||
public void addDisplayClaim(IPermissionContainer cont, EnumDisplayType type, int height) {
|
||||
if(cont instanceof Claim) {
|
||||
Claim claim = (Claim) cont;
|
||||
this.displayToAdd.add(new ClaimDisplay(claim, type, height));
|
||||
if (type == EnumDisplayType.MAIN)
|
||||
for (Claim sub : claim.getAllSubclaims())
|
||||
this.displayToAdd.add(new ClaimDisplay(sub, EnumDisplayType.SUB, height));
|
||||
}
|
||||
}
|
||||
|
||||
public EnumEditMode getEditMode() {
|
||||
@ -235,6 +239,7 @@ public class PlayerClaimData {
|
||||
}
|
||||
FileReader reader = new FileReader(file);
|
||||
JsonObject obj = ConfigHandler.GSON.fromJson(reader, JsonObject.class);
|
||||
Flan.debug("Read following json data {} from file {}", obj, file.getName());
|
||||
this.claimBlocks = obj.get("ClaimBlocks").getAsInt();
|
||||
this.additionalClaimBlocks = obj.get("AdditionalBlocks").getAsInt();
|
||||
reader.close();
|
||||
@ -259,6 +264,7 @@ public class PlayerClaimData {
|
||||
obj = new JsonObject();
|
||||
int additionalBlocks = obj.get("AdditionalBlocks").getAsInt();
|
||||
obj.addProperty("AdditionalBlocks", additionalBlocks + additionalClaimBlocks);
|
||||
Flan.debug("Attempting to write following json data {} to file {}", obj, file.getName());
|
||||
FileWriter writer = new FileWriter(file);
|
||||
ConfigHandler.GSON.toJson(obj, writer);
|
||||
writer.close();
|
||||
@ -278,6 +284,7 @@ public class PlayerClaimData {
|
||||
}
|
||||
|
||||
public static void readGriefPreventionPlayerData(MinecraftServer server, ServerCommandSource src) {
|
||||
Flan.log("Reading grief prevention data");
|
||||
File griefPrevention = server.getSavePath(WorldSavePath.ROOT).resolve("plugins/GriefPreventionData/PlayerData").toFile();
|
||||
if (!griefPrevention.exists())
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user