From 4274e6a148d3cd73a09d7e2aa5c4069f656e099e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 19 Oct 2023 07:59:44 -0400 Subject: [PATCH] Cleanup of friend and condemned initialization. --- src/engine/gameManager/BuildingManager.java | 35 +++++++++------------ src/engine/objects/Building.java | 19 ++++++++--- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 6e591cc4..3dcd8bb6 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -18,7 +18,6 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.UpgradeBuildingJob; import engine.math.Bounds; -import engine.math.Vector2f; import engine.math.Vector3fImmutable; import engine.net.client.ClientConnection; import engine.net.client.msg.ErrorPopupMsg; @@ -27,9 +26,7 @@ import engine.net.client.msg.PlaceAssetMsg; import engine.objects.*; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; -import org.w3c.dom.css.Rect; -import java.awt.*; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; @@ -110,7 +107,6 @@ public enum BuildingManager { if (building == null) return false; - if (building.getRank() == -1) return false; @@ -121,22 +117,21 @@ public enum BuildingManager { if (building.getFriends() != null && building.getFriends().get(player.getObjectUUID()) != null) return true; - //Admin's can access stuff + //Admins can access stuff if (player.isCSR()) return true; //Guild stuff - - if (building.getGuild() != null && building.getGuild().isGuildLeader(player.getObjectUUID())) + if (building.getGuild().isGuildLeader(player.getObjectUUID())) return true; - if (building.getFriends() != null && building.getFriends().get(player.getGuild().getObjectUUID()) != null + if (building.getFriends().get(player.getGuild().getObjectUUID()) != null && building.getFriends().get(player.getGuild().getObjectUUID()).friendType == 8) return true; - if (building.getFriends() != null && building.getFriends().get(player.getGuild().getObjectUUID()) != null + if (building.getFriends().get(player.getGuild().getObjectUUID()) != null && building.getFriends().get(player.getGuild().getObjectUUID()).friendType == 9 && GuildStatusController.isInnerCouncil(player.getGuildStatus())) return true; @@ -948,22 +943,20 @@ public enum BuildingManager { building.isDeranking.compareAndSet(true, false); } - public static Building getBuildingAtLocation(Vector3fImmutable loc){ - for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(loc,64,MBServerStatics.MASK_BUILDING)){ - Building building = (Building)awo; - if(building == null) + + public static Building getBuildingAtLocation(Vector3fImmutable loc) { + + for (AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(loc, 64, MBServerStatics.MASK_BUILDING)) { + Building building = (Building) awo; + + if (building == null) continue; - float minX = building.loc.x - building.getBounds().getHalfExtents().x; - float maxX = building.loc.x + building.getBounds().getHalfExtents().x; - float minZ = building.loc.z - building.getBounds().getHalfExtents().y; - float maxZ = building.loc.z + building.getBounds().getHalfExtents().y; - - boolean meetsX = loc.x > minX && loc.x < maxX; - boolean meetsY = loc.z > minZ && loc.z < maxZ; - if(meetsX && meetsY) + + if (Bounds.collide(loc, building)) return building; } return null; } + } diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 3acefafb..2b85d26d 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -95,7 +95,7 @@ public class Building extends AbstractWorldObject { private ConcurrentHashMap timers = null; private ConcurrentHashMap timestamps = null; private ConcurrentHashMap friends; - private ConcurrentHashMap condemned = new ConcurrentHashMap<>(); + private ConcurrentHashMap condemned; public ProtectionState protectionState = ProtectionState.NONE; private ArrayList children = null; @@ -969,17 +969,28 @@ public class Building extends AbstractWorldObject { // Reference friend and condemn lists from BuildingManager this.friends = BuildingManager._buildingFriends.get(this.getObjectUUID()); + + if (this.friends == null) { + this.friends = new ConcurrentHashMap<>(); + BuildingManager._buildingFriends.put(this.getObjectUUID(), this.friends); + } + this.condemned = BuildingManager._buildingCondemned.get(this.getObjectUUID()); + if (this.condemned == null) { + this.condemned = new ConcurrentHashMap<>(); + BuildingManager._buildingCondemned.put(this.getObjectUUID(), this.condemned); + } + //LOad Owners in Cache so we do not have to continuely look in the db for owner. if (this.ownerIsNPC) { if (NPC.getNPC(this.ownerUUID) == null) Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); - } else if (this.ownerUUID != 0) { - if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null) { - Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); + } else if (this.ownerUUID != 0) { + if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null) { + Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); } }