From 7dd189660e77afc716d575522b3d6a0fa73a8f09 Mon Sep 17 00:00:00 2001 From: Brett Hewitson Date: Fri, 7 Jan 2022 13:37:07 +1000 Subject: [PATCH] Grace Period Bug Fix Fixed a crashing bug when setting the thief's grace period. Added a config option to set the grace period. --- .../java/bletch/tektopiathief/core/ModConfig.java | 5 +++++ .../bletch/tektopiathief/entities/EntityThief.java | 2 +- .../tektopiathief/schedulers/ThiefScheduler.java | 14 +++++++++++++- .../resources/assets/tektopiathief/lang/en_US.lang | 3 ++- src/main/updateforge.json | 7 ++++--- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/src/main/java/bletch/tektopiathief/core/ModConfig.java b/src/main/src/main/java/bletch/tektopiathief/core/ModConfig.java index b5e8107..42d04ab 100644 --- a/src/main/src/main/java/bletch/tektopiathief/core/ModConfig.java +++ b/src/main/src/main/java/bletch/tektopiathief/core/ModConfig.java @@ -52,6 +52,11 @@ public static class Thief { @Config.LangKey("config.thief.thiefdetectsplayer") public Boolean thiefdetectsplayer = false; + @Config.Comment("The number of days before the thief visits the village again after they were successful. Set the 0 to disable to grace period. Default: 2") + @Config.LangKey("config.thief.thiefgraceperiod") + @Config.RangeInt(min = 0, max = 365) + public int thiefgraceperiod = 2; + } } diff --git a/src/main/src/main/java/bletch/tektopiathief/entities/EntityThief.java b/src/main/src/main/java/bletch/tektopiathief/entities/EntityThief.java index b24961c..ff79ab4 100644 --- a/src/main/src/main/java/bletch/tektopiathief/entities/EntityThief.java +++ b/src/main/src/main/java/bletch/tektopiathief/entities/EntityThief.java @@ -397,7 +397,7 @@ protected void setupAITasks() { ItemStack aquiredItem = this.getAquiredItem(); if (aquiredItem != null && !aquiredItem.isEmpty()) { - ThiefScheduler.setGracePeriod(this.village, 2); + ThiefScheduler.resetGracePeriod(this.village); String aquiredItemDescription = aquiredItem.getDisplayName(); if (aquiredItem.getCount() > 1) { diff --git a/src/main/src/main/java/bletch/tektopiathief/schedulers/ThiefScheduler.java b/src/main/src/main/java/bletch/tektopiathief/schedulers/ThiefScheduler.java index 1db688c..21bcac0 100644 --- a/src/main/src/main/java/bletch/tektopiathief/schedulers/ThiefScheduler.java +++ b/src/main/src/main/java/bletch/tektopiathief/schedulers/ThiefScheduler.java @@ -14,6 +14,7 @@ import net.tangotek.tektopia.structures.VillageStructure; import net.tangotek.tektopia.structures.VillageStructureType; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -120,7 +121,18 @@ public static int getGracePeriod(Village village) { } public static void reduceGracePeriods() { - gracePeriods.forEach((v, p) -> setGracePeriod(v, p - 1)); + List villages = new ArrayList(gracePeriods.keySet()); + + for (int index = villages.size() - 1; index >= 0; index--) { + setGracePeriod(villages.get(index), gracePeriods.getOrDefault(villages.get(index), 0) - 1); + } + } + + public static void resetGracePeriod(Village village) { + if (village == null) + return; + + setGracePeriod(village, ModConfig.thief.thiefgraceperiod); } public static void setGracePeriod(Village village, int gracePeriod) { diff --git a/src/main/src/main/resources/assets/tektopiathief/lang/en_US.lang b/src/main/src/main/resources/assets/tektopiathief/lang/en_US.lang index 9493144..829c707 100644 --- a/src/main/src/main/resources/assets/tektopiathief/lang/en_US.lang +++ b/src/main/src/main/resources/assets/tektopiathief/lang/en_US.lang @@ -53,7 +53,8 @@ config.thief.thiefspawnswhenpeaceful=Thief Spawns on Peaceful Difficulty config.thief.thiefspawnswhenpeaceful.tooltop=If enabled, the Thief will spawn even if the difficulty is set to Peaceful. config.thief.thiefdetectsplayer=Thief Detects Players config.thief.thiefdetectsplayer.tooltop=If enabled, the Thief will detect players and flee from them. - +config.thief.thiefgraceperiod=Thief Grace Period +config.thief.thiefgraceperiod.tooltip=The number of days before the thief visits the village again after they were successful. Set the 0 to disable to grace period. #============ #= Commands = diff --git a/src/main/updateforge.json b/src/main/updateforge.json index 35f7ba7..7260833 100644 --- a/src/main/updateforge.json +++ b/src/main/updateforge.json @@ -1,12 +1,13 @@ { "homepage": "https://minecraft.curseforge.com/projects/tektopia-thief", "promos": { - "1.12.2-latest": "1.2.0", - "1.12.2-recommended": "1.2.0" + "1.12.2-latest": "1.2.1", + "1.12.2-recommended": "1.2.1" }, "1.12.2":{ "1.0.0": "Initial alpha release.", "1.1.0": "Updated entity models.\nAdded config option for Thief to detect players.\nFixed escape notification.\nWhen killed will notify player of any dropped items.\nSpawn and Kill command clean-up.", - "1.2.0": "Added glowing effect to the thief when seen or injured.\nMinor adjustments to the desire counts.\nChanged start time of thief to 10:00pm.\nAdded a grace period of 2 days after the thief successfully steals an item from the village." + "1.2.0": "Added glowing effect to the thief when seen or injured.\nMinor adjustments to the desire counts.\nChanged start time of thief to 10:00pm.\nAdded a grace period of 2 days after the thief successfully steals an item from the village.", + "1.2.1": "Fixed a crashing bug when setting the thief's grace period.\nAdded a config option to set the grace period." } }