diff --git a/Changelog.md b/Changelog.md index b88a2a1..90889f6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,9 @@ Flan 1.6.3 - Add option to use up all unused claimblocks to create a square claim /flan addClaim all - Fix some stuff not using translation (e.g. Claim-Group menu title) +- Split ignoredBlocks config into breakBlockBlacklist and interactBlockBlacklist. + For shops which should be right clickable and unbreakable or graves which should just be breakable +- Split blockEntityTagIgnore into breakBlockEntityTagBlacklist and interactBlockEntityTagBlacklist Flan 1.6.2 ====================== diff --git a/common/src/main/java/io/github/flemmli97/flan/config/Config.java b/common/src/main/java/io/github/flemmli97/flan/config/Config.java index 2e94790..8f8e304 100644 --- a/common/src/main/java/io/github/flemmli97/flan/config/Config.java +++ b/common/src/main/java/io/github/flemmli97/flan/config/Config.java @@ -47,17 +47,24 @@ public class Config { public int buyPrice = -1; public boolean lenientBlockEntityCheck; - public List ignoredBlocks = Lists.newArrayList( + public List breakBlockBlacklist = Lists.newArrayList( "universal_graves:grave" ); - public List ignoredEntityTypes = Lists.newArrayList( - "corpse:corpse" + public List interactBlockBlacklist = Lists.newArrayList( + "universal_graves:grave" ); - public List blockEntityTagIgnore = Lists.newArrayList( + + public List breakBETagBlacklist = Lists.newArrayList( + ); + public List interactBETagBlacklist = Lists.newArrayList( "IsDeathChest", //vanilla death chest "gunpowder.owner", //gunpowder "shop-activated" //dicemc-money ); + + public List ignoredEntityTypes = Lists.newArrayList( + "corpse:corpse" + ); public List entityTagIgnore = Lists.newArrayList( "graves.marker" //vanilla tweaks ); @@ -73,7 +80,7 @@ public class Config { public boolean log; - public int configVersion = 2; + public int configVersion = 3; public int preConfigVersion; public Map> defaultGroups = createHashMap(map -> { @@ -147,12 +154,16 @@ public class Config { this.buyPrice = ConfigHandler.fromJson(obj, "buyPrice", this.buyPrice); this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck); - this.ignoredBlocks.clear(); - ConfigHandler.arryFromJson(obj, "ignoredBlocks").forEach(e -> this.ignoredBlocks.add(e.getAsString())); + this.breakBlockBlacklist.clear(); + ConfigHandler.arryFromJson(obj, "breakBlockBlacklist").forEach(e -> this.breakBlockBlacklist.add(e.getAsString())); + this.interactBlockBlacklist.clear(); + ConfigHandler.arryFromJson(obj, "interactBlockBlacklist").forEach(e -> this.interactBlockBlacklist.add(e.getAsString())); + this.breakBETagBlacklist.clear(); + ConfigHandler.arryFromJson(obj, "breakBlockEntityTagBlacklist").forEach(e -> this.breakBETagBlacklist.add(e.getAsString())); + this.interactBETagBlacklist.clear(); + ConfigHandler.arryFromJson(obj, "interactBlockEntityTagBlacklist").forEach(e -> this.interactBETagBlacklist.add(e.getAsString())); this.ignoredEntityTypes.clear(); ConfigHandler.arryFromJson(obj, "ignoredEntities").forEach(e -> this.ignoredEntityTypes.add(e.getAsString())); - this.blockEntityTagIgnore.clear(); - ConfigHandler.arryFromJson(obj, "blockEntityTagIgnore").forEach(e -> this.blockEntityTagIgnore.add(e.getAsString())); this.entityTagIgnore.clear(); ConfigHandler.arryFromJson(obj, "entityTagIgnore").forEach(e -> this.entityTagIgnore.add(e.getAsString())); @@ -197,10 +208,10 @@ public class Config { } this.globalDefaultPerms.put(e.getKey(), perms); }); + ConfigUpdater.updateConfig(this.preConfigVersion, obj); } catch (IOException e) { e.printStackTrace(); } - ConfigUpdater.updateConfig(this.preConfigVersion); this.save(); } @@ -229,16 +240,22 @@ public class Config { obj.addProperty("sellPrice", this.sellPrice); obj.addProperty("buyPrice", this.buyPrice); - JsonArray blocks = new JsonArray(); - this.ignoredBlocks.forEach(blocks::add); - obj.add("ignoredBlocks", blocks); + obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck); + JsonArray blocksBreak = new JsonArray(); + this.breakBlockBlacklist.forEach(blocksBreak::add); + obj.add("breakBlockBlacklist", blocksBreak); + JsonArray blocksInteract = new JsonArray(); + this.interactBlockBlacklist.forEach(blocksInteract::add); + obj.add("interactBlockBlacklist", blocksInteract); + JsonArray blocksEntities = new JsonArray(); + this.breakBETagBlacklist.forEach(blocksEntities::add); + obj.add("breakBlockEntityTagBlacklist", blocksEntities); + JsonArray blocksEntitiesInteract = new JsonArray(); + this.interactBETagBlacklist.forEach(blocksEntitiesInteract::add); + obj.add("interactBlockEntityTagBlacklist", blocksEntitiesInteract); JsonArray entities = new JsonArray(); this.ignoredEntityTypes.forEach(entities::add); obj.add("ignoredEntities", entities); - obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck); - JsonArray blocksEntities = new JsonArray(); - this.blockEntityTagIgnore.forEach(blocksEntities::add); - obj.add("blockEntityTagIgnore", blocksEntities); JsonArray entitiesTags = new JsonArray(); this.entityTagIgnore.forEach(entitiesTags::add); obj.add("entityTagIgnore", entitiesTags); diff --git a/common/src/main/java/io/github/flemmli97/flan/config/ConfigUpdater.java b/common/src/main/java/io/github/flemmli97/flan/config/ConfigUpdater.java index 01a722e..a10afec 100644 --- a/common/src/main/java/io/github/flemmli97/flan/config/ConfigUpdater.java +++ b/common/src/main/java/io/github/flemmli97/flan/config/ConfigUpdater.java @@ -1,5 +1,6 @@ package io.github.flemmli97.flan.config; +import com.google.gson.JsonObject; import io.github.flemmli97.flan.Flan; import io.github.flemmli97.flan.api.permission.PermissionRegistry; @@ -8,7 +9,7 @@ import java.util.Map; public class ConfigUpdater { private static final Map updater = Config.createHashMap(map -> { - map.put(2, () -> { + map.put(2, old -> { Flan.debug("Updating config to version 2"); ConfigHandler.config.globalDefaultPerms.compute("*", (k, v) -> { if (v == null) { @@ -19,16 +20,31 @@ public class ConfigUpdater { } }); }); + map.put(3, old -> { + Flan.debug("Updating config to version 3"); + ConfigHandler.arryFromJson(old, "ignoredBlocks").forEach(e -> { + if (!ConfigHandler.config.breakBlockBlacklist.contains(e.getAsString())) + ConfigHandler.config.breakBlockBlacklist.add(e.getAsString()); + }); + ConfigHandler.arryFromJson(old, "ignoredBlocks").forEach(e -> { + if (!ConfigHandler.config.interactBlockBlacklist.contains(e.getAsString())) + ConfigHandler.config.interactBlockBlacklist.add(e.getAsString()); + }); + ConfigHandler.arryFromJson(old, "blockEntityTagIgnore").forEach(e -> { + if (!ConfigHandler.config.interactBETagBlacklist.contains(e.getAsString())) + ConfigHandler.config.interactBETagBlacklist.add(e.getAsString()); + }); + }); }); - public static void updateConfig(int preVersion) { + public static void updateConfig(int preVersion, JsonObject oldVals) { updater.entrySet().stream().filter(e -> e.getKey() > preVersion).map(Map.Entry::getValue) - .forEach(Updater::configUpdater); + .forEach(u -> u.configUpdater(oldVals)); } interface Updater { - void configUpdater(); + void configUpdater(JsonObject oldVals); } } \ No newline at end of file diff --git a/common/src/main/java/io/github/flemmli97/flan/event/BlockInteractEvents.java b/common/src/main/java/io/github/flemmli97/flan/event/BlockInteractEvents.java index 77ec80a..c39ba1d 100644 --- a/common/src/main/java/io/github/flemmli97/flan/event/BlockInteractEvents.java +++ b/common/src/main/java/io/github/flemmli97/flan/event/BlockInteractEvents.java @@ -33,6 +33,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; +import java.util.List; + public class BlockInteractEvents { public static ActionResult startBreakBlocks(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) { @@ -47,7 +49,7 @@ public class BlockInteractEvents { IPermissionContainer claim = storage.getForPermissionCheck(pos); if (claim != null) { Identifier id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock()); - if (alwaysAllowBlock(id, world.getBlockEntity(pos))) + if (contains(id, world.getBlockEntity(pos), ConfigHandler.config.breakBlockBlacklist, ConfigHandler.config.breakBETagBlacklist)) return true; if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) { PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY()); @@ -77,7 +79,7 @@ public class BlockInteractEvents { BlockState state = world.getBlockState(hitResult.getBlockPos()); Identifier id = CrossPlatformStuff.registryBlocks().getIDFrom(state.getBlock()); BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos()); - if (alwaysAllowBlock(id, blockEntity)) + if (contains(id, blockEntity, ConfigHandler.config.interactBlockBlacklist, ConfigHandler.config.interactBETagBlacklist)) return ActionResult.PASS; ClaimPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock()); if (perm == PermissionRegistry.PROJECTILES) @@ -119,13 +121,13 @@ public class BlockInteractEvents { return ActionResult.PASS; } - public static boolean alwaysAllowBlock(Identifier id, BlockEntity blockEntity) { - if (ConfigHandler.config.ignoredBlocks.contains(id.getNamespace()) - || ConfigHandler.config.ignoredBlocks.contains(id.toString())) + public static boolean contains(Identifier id, BlockEntity blockEntity, List idList, List tagList) { + if (idList.contains(id.getNamespace()) + || idList.contains(id.toString())) return true; - if (blockEntity != null) { + if (blockEntity != null && !tagList.isEmpty()) { CompoundTag nbt = blockEntity.toTag(new CompoundTag()); - return ConfigHandler.config.blockEntityTagIgnore.stream().anyMatch(tag -> CrossPlatformStuff.blockDataContains(nbt, tag)); + return tagList.stream().anyMatch(tag -> CrossPlatformStuff.blockDataContains(nbt, tag)); } return false; }