From 385695a610566f50d1aef5708ae3bbe4ff64f5ca Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 18 Oct 2023 12:24:32 -0400 Subject: [PATCH] Load collection from db --- src/engine/db/handlers/dbBuildingHandler.java | 35 +++++++++++++++++-- src/engine/gameManager/BuildingManager.java | 7 ++-- .../OpenFriendsCondemnListMsgHandler.java | 2 +- .../client/msg/OpenFriendsCondemnListMsg.java | 14 ++++---- src/engine/objects/BuildingFriends.java | 20 +++-------- src/engine/server/world/WorldServer.java | 3 ++ 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index 0c88a5d6..8d5c331d 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -13,6 +13,7 @@ import engine.Enum; import engine.Enum.DbObjectType; import engine.Enum.ProtectionState; import engine.Enum.TaxType; +import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -423,6 +424,34 @@ public class dbBuildingHandler extends dbHandlerBase { return false; } + public void LOAD_BUILDING_FRIENDS() { + + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + BuildingFriends friend = new BuildingFriends(rs); + + switch (friend.friendType) { + case 7: + BuildingManager._buildingFriends.get(friend.buildingUID).put(friend.playerUID, friend); + break; + case 8: + case 9: + BuildingManager._buildingFriends.get(friend.buildingUID).put(friend.guildUID, friend); + break; + } + } + + } catch (SQLException e) { + Logger.error(e); + } + + } + public void LOAD_ALL_FRIENDS_FOR_BUILDING(Building building) { if (building == null) @@ -436,13 +465,13 @@ public class dbBuildingHandler extends dbHandlerBase { while (rs.next()) { BuildingFriends friend = new BuildingFriends(rs); - switch (friend.getFriendType()) { + switch (friend.friendType) { case 7: - building.getFriends().put(friend.getPlayerUID(), friend); + building.getFriends().put(friend.playerUID, friend); break; case 8: case 9: - building.getFriends().put(friend.getGuildUID(), friend); + building.getFriends().put(friend.guildUID, friend); break; } } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index d603a4ce..c3524069 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -31,6 +31,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; public enum BuildingManager { @@ -40,6 +41,8 @@ public enum BuildingManager { public static HashMap> _stuckLocations = new HashMap<>(); public static HashMap> _slotLocations = new HashMap<>(); + public static HashMap> _buildingFriends = new HashMap<>(); + public static int getAvailableSlot(Building building) { ArrayList slotLocations = _slotLocations.get(building.meshUUID); @@ -127,11 +130,11 @@ public enum BuildingManager { return true; if (building.getFriends().get(player.getGuild().getObjectUUID()) != null - && building.getFriends().get(player.getGuild().getObjectUUID()).getFriendType() == 8) + && building.getFriends().get(player.getGuild().getObjectUUID()).friendType == 8) return true; if (building.getFriends().get(player.getGuild().getObjectUUID()) != null - && building.getFriends().get(player.getGuild().getObjectUUID()).getFriendType() == 9 + && building.getFriends().get(player.getGuild().getObjectUUID()).friendType == 9 && GuildStatusController.isInnerCouncil(player.getGuildStatus())) return true; diff --git a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java index ccb93609..a5d260b3 100644 --- a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java +++ b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java @@ -354,7 +354,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { if (friend == null) return true; - if (!DbManager.BuildingQueries.REMOVE_FROM_FRIENDS_LIST(sourceBuilding.getObjectUUID(), friend.getPlayerUID(), friend.getGuildUID(), friend.getFriendType())) { + if (!DbManager.BuildingQueries.REMOVE_FROM_FRIENDS_LIST(sourceBuilding.getObjectUUID(), friend.playerUID, friend.guildUID, friend.friendType)) { Logger.debug("Failed to remove Friend: " + msg.getRemoveFriendID() + " from Building With UID " + sourceBuilding.getObjectUUID()); return true; } diff --git a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java index f6eaefad..0503b5ca 100644 --- a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java +++ b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java @@ -619,22 +619,22 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { writer.putInt(listSize); for (BuildingFriends friend : this.friends.values()) { - pc = PlayerCharacter.getFromCache(friend.getPlayerUID()); - guild = Guild.getGuild(friend.getGuildUID()); - if (friend.getFriendType() == 7) { + pc = PlayerCharacter.getFromCache(friend.playerUID); + guild = Guild.getGuild(friend.guildUID); + if (friend.friendType == 7) { if (pc != null) name = pc.getCombinedName(); } else if (guild != null) name = guild.getName(); writer.put((byte) 1); - if (friend.getFriendType() == 7) { + if (friend.friendType == 7) { writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(friend.getPlayerUID()); + writer.putInt(friend.playerUID); } else { writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(friend.getGuildUID()); + writer.putInt(friend.guildUID); } - writer.putInt(friend.getFriendType()); + writer.putInt(friend.friendType); writer.putInt(0); writer.putInt(0); diff --git a/src/engine/objects/BuildingFriends.java b/src/engine/objects/BuildingFriends.java index b5308978..67914261 100644 --- a/src/engine/objects/BuildingFriends.java +++ b/src/engine/objects/BuildingFriends.java @@ -14,10 +14,10 @@ import java.sql.SQLException; public class BuildingFriends { - private int playerUID; - private int buildingUID; - private int guildUID; - private int friendType; + public int playerUID; + public int buildingUID; + public int guildUID; + public int friendType; /** * ResultSet Constructor @@ -38,16 +38,4 @@ public class BuildingFriends { this.friendType = friendType; } - public int getPlayerUID() { - return playerUID; - } - - public int getGuildUID() { - return guildUID; - } - - public int getFriendType() { - return friendType; - } - } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 853ac58b..daf7b59d 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -318,6 +318,9 @@ public class WorldServer { Logger.info("Initializing Player Friends"); DbManager.PlayerCharacterQueries.LOAD_PLAYER_FRIENDS(); + Logger.info("Initializing Building Friends"); + DbManager.BuildingQueries.LOAD_BUILDING_FRIENDS(); + Logger.info("Initializing NPC Profits"); DbManager.NPCQueries.LOAD_NPC_PROFITS();