From 301d8a026144caa5baade86d60d0db237a7c4fd1 Mon Sep 17 00:00:00 2001 From: froobynooby Date: Fri, 26 Apr 2024 18:05:15 +0930 Subject: [PATCH] Don't keep trying to use getBoatType if it has already failed --- .../controller/entity/SnapshotEntity.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java b/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java index d6961ae..05ea114 100644 --- a/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java +++ b/src/main/java/com/froobworld/farmcontrol/controller/entity/SnapshotEntity.java @@ -8,8 +8,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; public class SnapshotEntity { + private static final AtomicBoolean useWoodType = new AtomicBoolean(false); private final Entity entity; private final int entityId; private final Vector location; @@ -50,9 +52,14 @@ public SnapshotEntity(Entity entity) { } if (entity instanceof Boat) { // try to add boat type, falling back to wood type for version < 1.19 - try { - classifications.add(((Boat) entity).getBoatType()); - } catch (Throwable throwable) { + if (!SnapshotEntity.useWoodType.get()) { + try { + classifications.add(((Boat) entity).getBoatType()); + } catch (Throwable throwable) { + useWoodType.set(true); + } + } + if (SnapshotEntity.useWoodType.get()) { //noinspection deprecation classifications.add(((Boat) entity).getWoodType()); }