diff --git a/Changelog.txt b/Changelog.txt index 3854fb1..a0eeeed 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,6 +3,8 @@ Flan 1.6.1 - Improve performance - Support for Money and Sign Shops currency (forge) - Fix unusable admin cmd with FTBRanks if its not defined in Ranks +- Change lockItems config to a permission + Global default is ALLTRUE Flan 1.6.0 ====================== diff --git a/common/src/main/java/io/github/flemmli97/flan/api/permission/PermissionRegistry.java b/common/src/main/java/io/github/flemmli97/flan/api/permission/PermissionRegistry.java index 527d6d4..7df869a 100644 --- a/common/src/main/java/io/github/flemmli97/flan/api/permission/PermissionRegistry.java +++ b/common/src/main/java/io/github/flemmli97/flan/api/permission/PermissionRegistry.java @@ -85,6 +85,7 @@ public class PermissionRegistry { public static ClaimPermission MOBSPAWN = global(new ClaimPermission("MOBSPAWN", () -> new ItemStack(Items.ZOMBIE_SPAWN_EGG), "Prevent hostile mobspawn in claim")); public static ClaimPermission ANIMALSPAWN = global(new ClaimPermission("ANIMALSPAWN", () -> new ItemStack(Items.PIG_SPAWN_EGG), "Prevent other spawn in claim")); public static ClaimPermission LIGHTNING = global(new ClaimPermission("LIGHTNING", () -> new ItemStack(Items.TRIDENT), "Allow lightning to affect claims", "e.g. set blocks on fire", "or affect animals (mobs are excluded)")); + public static ClaimPermission LOCKITEMS = global(new ClaimPermission("LOCKITEMS", () -> new ItemStack(Items.FIREWORK_STAR), true, "If items should be locked on death")); private static ClaimPermission register(ClaimPermission perm) { if (locked) { diff --git a/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java b/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java index b097c42..aea1e15 100644 --- a/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java +++ b/common/src/main/java/io/github/flemmli97/flan/claim/Claim.java @@ -13,7 +13,6 @@ import io.github.flemmli97.flan.api.permission.ClaimPermission; import io.github.flemmli97.flan.api.permission.PermissionRegistry; import io.github.flemmli97.flan.config.Config; import io.github.flemmli97.flan.config.ConfigHandler; -import io.github.flemmli97.flan.config.ConfigUpdater; import io.github.flemmli97.flan.player.PlayerClaimData; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; @@ -103,7 +102,7 @@ public class Claim implements IPermissionContainer { public static Claim fromJson(JsonObject obj, UUID owner, ServerWorld world) { Claim claim = new Claim(world); claim.readJson(obj, owner); - ConfigUpdater.updateClaim(claim); + ClaimUpdater.updateClaim(claim); return claim; } @@ -727,4 +726,18 @@ public class Claim implements IPermissionContainer { GLOBAL, GROUP } + + interface ClaimUpdater { + + Map updater = Config.createHashMap(map -> { + map.put(2, claim -> claim.globalPerm.put(PermissionRegistry.LOCKITEMS, true)); + }); + + static void updateClaim(Claim claim) { + updater.entrySet().stream().filter(e -> e.getKey() > ConfigHandler.config.preConfigVersion).map(Map.Entry::getValue) + .forEach(up -> up.update(claim)); + } + + void update(Claim claim); + } } 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 025ce09..1bb1dff 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 @@ -59,7 +59,6 @@ public class Config { public int sellPrice = -1; public int buyPrice = -1; - public boolean lockDrops = true; public int dropTicks = 6000; public int inactivityTime = 30; @@ -67,7 +66,7 @@ public class Config { public boolean log; - public int configVersion = 1; + public int configVersion = 2; public int preConfigVersion; public Map> defaultGroups = createHashMap(map -> { @@ -87,12 +86,13 @@ public class Config { })); }); - private final Map> globalDefaultPerms = createHashMap(map -> map.put("*", createHashMap(perms -> { + protected final Map> globalDefaultPerms = createHashMap(map -> map.put("*", createHashMap(perms -> { perms.put(PermissionRegistry.FLIGHT, GlobalType.ALLTRUE); perms.put(PermissionRegistry.MOBSPAWN, GlobalType.ALLFALSE); perms.put(PermissionRegistry.TELEPORT, GlobalType.ALLFALSE); perms.put(PermissionRegistry.NOHUNGER, GlobalType.ALLFALSE); perms.put(PermissionRegistry.EDITPOTIONS, GlobalType.ALLFALSE); + perms.put(PermissionRegistry.LOCKITEMS, GlobalType.ALLTRUE); }))); public Config(MinecraftServer server) { @@ -178,7 +178,6 @@ public class Config { this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel); this.sellPrice = ConfigHandler.fromJson(obj, "sellPrice", this.sellPrice); this.buyPrice = ConfigHandler.fromJson(obj, "buyPrice", this.buyPrice); - this.lockDrops = ConfigHandler.fromJson(obj, "lockDrops", this.lockDrops); this.dropTicks = ConfigHandler.fromJson(obj, "dropTicks", this.dropTicks); this.inactivityTime = ConfigHandler.fromJson(obj, "inactivityTimeDays", this.inactivityTime); this.inactivityBlocksMax = ConfigHandler.fromJson(obj, "inactivityBlocksMax", this.inactivityBlocksMax); @@ -238,7 +237,6 @@ public class Config { obj.addProperty("enableLogs", this.log); obj.addProperty("sellPrice", this.sellPrice); obj.addProperty("buyPrice", this.buyPrice); - obj.addProperty("lockDrops", this.lockDrops); obj.addProperty("dropTicks", this.dropTicks); obj.addProperty("inactivityTimeDays", this.inactivityTime); obj.addProperty("inactivityBlocksMax", this.inactivityBlocksMax); 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 49b175b..01a722e 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,13 +1,24 @@ package io.github.flemmli97.flan.config; -import io.github.flemmli97.flan.claim.Claim; +import io.github.flemmli97.flan.Flan; +import io.github.flemmli97.flan.api.permission.PermissionRegistry; import java.util.Map; public class ConfigUpdater { private static final Map updater = Config.createHashMap(map -> { - + map.put(2, () -> { + Flan.debug("Updating config to version 2"); + ConfigHandler.config.globalDefaultPerms.compute("*", (k, v) -> { + if (v == null) { + return Config.createHashMap(map1 -> map1.put(PermissionRegistry.LOCKITEMS, Config.GlobalType.ALLTRUE)); + } else { + v.put(PermissionRegistry.LOCKITEMS, Config.GlobalType.ALLTRUE); + return v; + } + }); + }); }); public static void updateConfig(int preVersion) { @@ -15,16 +26,9 @@ public class ConfigUpdater { .forEach(Updater::configUpdater); } - public static void updateClaim(Claim claim) { - updater.entrySet().stream().filter(e -> e.getKey() > ConfigHandler.config.preConfigVersion).map(Map.Entry::getValue) - .forEach(up -> up.claimUpdater(claim)); - } - interface Updater { void configUpdater(); - void claimUpdater(Claim claim); - } -} +} \ No newline at end of file diff --git a/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java b/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java index c836e27..85cb12b 100644 --- a/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java +++ b/common/src/main/java/io/github/flemmli97/flan/event/EntityInteractEvents.java @@ -228,7 +228,7 @@ public class EntityInteractEvents { ServerPlayerEntity sPlayer = (ServerPlayerEntity) player; if (entity instanceof ItemEntity) { IOwnedItem ownedItem = (IOwnedItem) entity; - if (ownedItem.getDeathPlayer() != null && ConfigHandler.config.lockDrops) { + if (ownedItem.getDeathPlayer() != null) { ServerPlayerEntity other = sPlayer.getServer().getPlayerManager().getPlayer(ownedItem.getDeathPlayer()); if (other == null) return false; diff --git a/common/src/main/java/io/github/flemmli97/flan/mixin/ItemEntityMixin.java b/common/src/main/java/io/github/flemmli97/flan/mixin/ItemEntityMixin.java index 93804d5..5a8e948 100644 --- a/common/src/main/java/io/github/flemmli97/flan/mixin/ItemEntityMixin.java +++ b/common/src/main/java/io/github/flemmli97/flan/mixin/ItemEntityMixin.java @@ -1,9 +1,11 @@ package io.github.flemmli97.flan.mixin; import io.github.flemmli97.flan.player.IOwnedItem; +import io.github.flemmli97.flan.player.PlayerClaimData; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.network.ServerPlayerEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -35,7 +37,7 @@ public abstract class ItemEntityMixin implements IOwnedItem { @Override public void setOriginPlayer(PlayerEntity player) { this.playerOrigin = player.getUuid(); - if (player.isDead()) + if (player instanceof ServerPlayerEntity && PlayerClaimData.get((ServerPlayerEntity) player).setDeathItemOwner()) this.deathPlayerOrigin = this.playerOrigin; } diff --git a/common/src/main/java/io/github/flemmli97/flan/player/PlayerClaimData.java b/common/src/main/java/io/github/flemmli97/flan/player/PlayerClaimData.java index 6402bec..3956dfc 100644 --- a/common/src/main/java/io/github/flemmli97/flan/player/PlayerClaimData.java +++ b/common/src/main/java/io/github/flemmli97/flan/player/PlayerClaimData.java @@ -75,6 +75,8 @@ public class PlayerClaimData implements IPlayerData { private final Map> defaultGroups = new HashMap<>(); + private boolean shouldProtectDrop, calculateShouldDrop = true; + public PlayerClaimData(ServerPlayerEntity player) { this.player = player; this.claimBlocks = ConfigHandler.config.startingBlocks; @@ -320,6 +322,8 @@ public class PlayerClaimData implements IPlayerData { } } this.deathPickupTick--; + if (!this.player.isDead()) + this.calculateShouldDrop = true; } public void unlockDeathItems() { @@ -335,7 +339,7 @@ public class PlayerClaimData implements IPlayerData { this.additionalClaimBlocks = data.additionalClaimBlocks; this.defaultGroups.clear(); this.defaultGroups.putAll(data.defaultGroups); - if (ConfigHandler.config.lockDrops) + if (data.setDeathItemOwner()) this.player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDropsCmd, "/flan unlockDrops"), Formatting.GOLD), false); } @@ -371,6 +375,18 @@ public class PlayerClaimData implements IPlayerData { return usedClaimsBlocks; } + public boolean setDeathItemOwner() { + if (!this.player.isDead()) + return false; + if (this.calculateShouldDrop) { + BlockPos rounded = TeleportUtils.roundedBlockPos(this.player.getPos().add(0, this.player.getActiveEyeHeight(this.player.getPose(), this.player.getDimensions(this.player.getPose())), 0)); + this.shouldProtectDrop = ClaimStorage.get(this.player.getServerWorld()).getForPermissionCheck(rounded) + .canInteract(this.player, PermissionRegistry.LOCKITEMS, rounded); + this.calculateShouldDrop = false; + } + return this.shouldProtectDrop; + } + public void save(MinecraftServer server) { Flan.log("Saving player data for player {} with uuid {}", this.player.getName(), this.player.getUuid()); Path dir = ConfigHandler.getPlayerSavePath(server);