From 88a2f8687b677afc3837f09898dc8f81957188bf Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 25 Aug 2024 07:45:54 -0400 Subject: [PATCH] New atomic boolean to lock down destruction --- src/engine/objects/Building.java | 7 +++++-- src/engine/objects/City.java | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 5367c8f7..46860526 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -505,6 +505,11 @@ public class Building extends AbstractWorldObject { return; } + if (this.isDeranking.compareAndSet(false, true) == false) { + Logger.error("Attempt to derank tol twice"); + return; + } + bane = city.getBane(); // We need to collect the spires and shrines on the citygrid in case @@ -600,8 +605,6 @@ public class Building extends AbstractWorldObject { newOwner = Guild.GetGL(bane.getOwner().getGuild()); - this.isDeranking.compareAndSet(false, true); - if ((bane.getOwner().getGuild().getGuildState() == GuildState.Sovereign) || (bane.getOwner().getGuild().getGuildState() == GuildState.Protectorate) || (bane.getOwner().getGuild().getGuildState() == GuildState.Province) || diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 8f674de8..81239b2c 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -41,6 +41,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; public class City extends AbstractWorldObject { @@ -80,6 +81,7 @@ public class City extends AbstractWorldObject { private String hash; public Warehouse warehouse; public Realm realm; + public AtomicBoolean isDestroyed = new AtomicBoolean(); /** * ResultSet Constructor @@ -1102,9 +1104,14 @@ public class City extends AbstractWorldObject { public final void destroy() { + if (this.isDestroyed.compareAndSet(false, true) == false) { + Logger.error("Attempt to destroy tol twice"); + return; + } + Thread destroyCityThread = new Thread(new DestroyCityThread(this)); - destroyCityThread.setName("destroyCity:" + this.getName()); + destroyCityThread.setName("destroyCity: " + this.getName()); destroyCityThread.start(); }