Skip to content

Commit

Permalink
Merge pull request #729 from Emirlol/chocolate-factory-hotfix
Browse files Browse the repository at this point in the history
Fix egg found message being sent twice
  • Loading branch information
AzureAaron authored May 29, 2024
2 parents 0451352 + 382525b commit a14017a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

public class EggFinder {
private static final Pattern eggFoundPattern = Pattern.compile("^(?:HOPPITY'S HUNT You found a Chocolate|You have already collected this Chocolate) (Breakfast|Lunch|Dinner)");
private static final Pattern newEggPattern = Pattern.compile("^HOPPITY'S HUNT A Chocolate (Breakfast|Lunch|Dinner) Egg has appeared!$");
private static final Logger logger = LoggerFactory.getLogger("Skyblocker Egg Finder");
private static final LinkedList<ArmorStandEntity> armorStandQueue = new LinkedList<>();
private static final Location[] possibleLocations = {Location.CRIMSON_ISLE, Location.CRYSTAL_HOLLOWS, Location.DUNGEON_HUB, Location.DWARVEN_MINES, Location.HUB, Location.THE_END, Location.THE_PARK, Location.GOLD_MINE};
Expand Down Expand Up @@ -146,16 +145,6 @@ private static void onChatMessage(Text text, boolean overlay) {
logger.error("[Skyblocker Egg Finder] Failed to find egg type for egg found message. Tried to match against: " + matcher.group(0), e);
}
}

//There's only one egg of the same type at any given time, so we can set the changed egg to null
matcher = newEggPattern.matcher(text.getString());
if (matcher.find()) {
try {
EggType.valueOf(matcher.group(1).toUpperCase()).egg.setValue(null);
} catch (IllegalArgumentException e) {
logger.error("[Skyblocker Egg Finder] Failed to find egg type for egg spawn message. Tried to match against: " + matcher.group(0), e);
}
}
}

record Egg(ArmorStandEntity entity, Waypoint waypoint) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.Message;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.events.SkyblockEvents;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.Utils;
Expand Down Expand Up @@ -49,16 +50,17 @@ public static void checkIfTimeTower(Message message, boolean overlay) {
}

try (FileWriter writer = new FileWriter(tempFile)) {
writer.write(String.valueOf(System.currentTimeMillis()));
writer.write(String.valueOf(System.currentTimeMillis())); //Overwrites the file so no need to handle case where the file already exists and has text
} catch (IOException e) {
LOGGER.error("[Skyblocker Time Tower Reminder] Failed to write to temp file for Time Tower Reminder!", e);
}
}

private static void sendMessage() {
if (MinecraftClient.getInstance().player == null || !Utils.isOnSkyblock()) return;
MinecraftClient.getInstance().player.sendMessage(Constants.PREFIX.get().append(Text.literal("Your Chocolate Factory's Time Tower has deactivated!").formatted(Formatting.RED)));

if (SkyblockerConfigManager.get().helpers.chocolateFactory.enableTimeTowerReminder) {
MinecraftClient.getInstance().player.sendMessage(Constants.PREFIX.get().append(Text.literal("Your Chocolate Factory's Time Tower has deactivated!").formatted(Formatting.RED)));
}
File tempFile = SkyblockerMod.CONFIG_DIR.resolve(TIME_TOWER_FILE).toFile();
try {
scheduled = false;
Expand Down

0 comments on commit a14017a

Please sign in to comment.