diff --git a/src/engine/db/handlers/dbBuildingHandler.java b/src/engine/db/handlers/dbBuildingHandler.java index c81003b7..e2becf1e 100644 --- a/src/engine/db/handlers/dbBuildingHandler.java +++ b/src/engine/db/handlers/dbBuildingHandler.java @@ -427,7 +427,6 @@ public class dbBuildingHandler extends dbHandlerBase { public void LOAD_BUILDING_FRIENDS() { - try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends`")) { @@ -458,6 +457,38 @@ public class dbBuildingHandler extends dbHandlerBase { } + public void LOAD_BUILDING_CONDEMNED() { + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_condemned`")) { + + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) { + + Condemned condemned = new Condemned(rs); + + // Create map if it does not yet exist + + if (!BuildingManager._buildingCondemned.containsKey(condemned.buildingUUID)) + BuildingManager._buildingCondemned.put(condemned.buildingUUID, new ConcurrentHashMap<>()); + + switch (condemned.friendType) { + case 2: + BuildingManager._buildingCondemned.get(condemned.buildingUUID).put(condemned.playerUID, condemned); + break; + case 4: + case 5: + BuildingManager._buildingCondemned.get(condemned.buildingUUID).put(condemned.guildUID, condemned); + break; + } + } + + } catch (SQLException e) { + Logger.error(e); + } + } + public void LOAD_ALL_CONDEMNED_FOR_BUILDING(Building building) { if (building == null) @@ -471,13 +502,13 @@ public class dbBuildingHandler extends dbHandlerBase { while (rs.next()) { Condemned condemned = new Condemned(rs); - switch (condemned.getFriendType()) { + switch (condemned.friendType) { case 2: - building.getCondemned().put(condemned.getPlayerUID(), condemned); + building.getCondemned().put(condemned.playerUID, condemned); break; case 4: case 5: - building.getCondemned().put(condemned.getGuildUID(), condemned); + building.getCondemned().put(condemned.guildUID, condemned); break; } } @@ -725,10 +756,10 @@ public class dbBuildingHandler extends dbHandlerBase { + "WHERE`buildingUID` = ? AND `playerUID` = ? AND `guildUID` = ? AND `friendType` = ?")) { preparedStatement.setBoolean(1, active); - preparedStatement.setInt(2, condemn.getParent()); - preparedStatement.setInt(3, condemn.getPlayerUID()); - preparedStatement.setInt(4, condemn.getGuildUID()); - preparedStatement.setInt(5, condemn.getFriendType()); + preparedStatement.setInt(2, condemn.buildingUUID); + preparedStatement.setInt(3, condemn.playerUID); + preparedStatement.setInt(4, condemn.guildUID); + preparedStatement.setInt(5, condemn.friendType); return (preparedStatement.executeUpdate() > 0); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index c3524069..180504cf 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -42,7 +42,7 @@ public enum BuildingManager { public static HashMap> _slotLocations = new HashMap<>(); public static HashMap> _buildingFriends = new HashMap<>(); - + public static HashMap> _buildingCondemned = new HashMap<>(); public static int getAvailableSlot(Building building) { ArrayList slotLocations = _slotLocations.get(building.meshUUID); @@ -497,18 +497,18 @@ public enum BuildingManager { Condemned condemn = building.getCondemned().get(player.getObjectUUID()); - if (condemn != null && condemn.isActive()) + if (condemn != null && condemn.active) return true; if (player.getGuild() != null) { Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID()); - if (guildCondemn != null && guildCondemn.isActive()) + if (guildCondemn != null && guildCondemn.active) return true; Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID()); - return nationCondemn != null && nationCondemn.isActive() && nationCondemn.getFriendType() == Condemned.NATION; + return nationCondemn != null && nationCondemn.active && nationCondemn.friendType == Condemned.NATION; } else { //TODO ADD ERRANT KOS CHECK } @@ -516,18 +516,18 @@ public enum BuildingManager { Condemned condemn = building.getCondemned().get(player.getObjectUUID()); - if (condemn != null && condemn.isActive()) + if (condemn != null && condemn.active) return false; if (player.getGuild() != null) { Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID()); - if (guildCondemn != null && guildCondemn.isActive()) + if (guildCondemn != null && guildCondemn.active) return false; Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID()); - return nationCondemn == null || !nationCondemn.isActive() || nationCondemn.getFriendType() != Condemned.NATION; + return nationCondemn == null || !nationCondemn.active || nationCondemn.friendType != Condemned.NATION; } else { //TODO ADD ERRANT KOS CHECK } diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 8a925021..0fa3d462 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -1175,17 +1175,17 @@ public class MobAI { //target is listed individually - if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive()) + if (entry.getValue().playerUID == target.getObjectUUID() && entry.getValue().active) return false; //target's guild is listed - if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild()) + if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild()) return false; //target's nation is listed - if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation()) + if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild().getNation()) return false; } return true; @@ -1197,17 +1197,17 @@ public class MobAI { //target is listed individually - if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive()) + if (entry.getValue().playerUID == target.getObjectUUID() && entry.getValue().active) return true; //target's guild is listed - if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild()) + if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild()) return true; //target's nation is listed - if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation()) + if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild().getNation()) return true; } } diff --git a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java index a5d260b3..6d70d4a2 100644 --- a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java +++ b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java @@ -151,7 +151,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { if (removeCondemn == null) return true; - if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.getParent(), removeCondemn.getPlayerUID(), removeCondemn.getGuildUID(), removeCondemn.getFriendType())) + if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.buildingUUID, removeCondemn.playerUID, removeCondemn.guildUID, removeCondemn.friendType)) return true; sourceBuilding.getCondemned().remove(msg.getRemoveFriendID()); @@ -175,7 +175,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { return true; condemn.setActive(msg.isReverseKOS()); - openFriendsCondemnListMsg.setReverseKOS(condemn.isActive()); + openFriendsCondemnListMsg.setReverseKOS(condemn.active); dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); break; diff --git a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java index 0503b5ca..c014a95f 100644 --- a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java +++ b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java @@ -513,17 +513,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { writer.put((byte) 1); - switch (condemned.getFriendType()) { + switch (condemned.friendType) { case 2: - PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getObject(engine.Enum.GameObjectType.PlayerCharacter, condemned.getPlayerUID()); + PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getObject(engine.Enum.GameObjectType.PlayerCharacter, condemned.playerUID); guild = playerCharacter.getGuild(); writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(condemned.getPlayerUID()); - writer.putInt(condemned.getFriendType()); + writer.putInt(condemned.playerUID); + writer.putInt(condemned.friendType); writer.putInt(GameObjectType.PlayerCharacter.ordinal()); - writer.putInt(condemned.getPlayerUID()); + writer.putInt(condemned.playerUID); writer.putInt(0); writer.putInt(0); writer.putInt(GameObjectType.Guild.ordinal()); @@ -531,9 +531,9 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { writer.putInt(guild.getObjectUUID()); else writer.putInt(0); - writer.put(condemned.isActive() ? (byte) 1 : (byte) 0); + writer.put(condemned.active ? (byte) 1 : (byte) 0); writer.put((byte) 0); - writer.put(condemned.isActive() ? (byte) 1 : (byte) 0); + writer.put(condemned.active ? (byte) 1 : (byte) 0); if (playerCharacter != null) writer.putString(playerCharacter.getFirstName()); @@ -547,16 +547,16 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { } break; case 4: - guild = Guild.getGuild(condemned.getGuildUID()); + guild = Guild.getGuild(condemned.guildUID); writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(condemned.getGuildUID()); - writer.putInt(condemned.getFriendType()); + writer.putInt(condemned.guildUID); + writer.putInt(condemned.friendType); writer.putLong(0); writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(condemned.getGuildUID()); + writer.putInt(condemned.guildUID); writer.putLong(0); writer.put((byte) 0); - writer.put(condemned.isActive() ? (byte) 1 : (byte) 0); + writer.put(condemned.active ? (byte) 1 : (byte) 0); writer.put((byte) 0); if (guild != null) writer.putString(guild.getName()); @@ -570,17 +570,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { GuildTag._serializeForDisplay(GuildTag.ERRANT, writer); break; case 5: - guild = Guild.getGuild(condemned.getGuildUID()); + guild = Guild.getGuild(condemned.guildUID); writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(condemned.getGuildUID()); - writer.putInt(condemned.getFriendType()); + writer.putInt(condemned.guildUID); + writer.putInt(condemned.friendType); writer.putLong(0); writer.putLong(0); writer.putInt(GameObjectType.Guild.ordinal()); - writer.putInt(condemned.getGuildUID()); + writer.putInt(condemned.guildUID); writer.put((byte) 0); writer.put((byte) 0); - writer.put(condemned.isActive() ? (byte) 1 : (byte) 0); + writer.put(condemned.active ? (byte) 1 : (byte) 0); if (guild != null) writer.putString(guild.getName()); else diff --git a/src/engine/objects/Condemned.java b/src/engine/objects/Condemned.java index bdcb59a6..3f89bccb 100644 --- a/src/engine/objects/Condemned.java +++ b/src/engine/objects/Condemned.java @@ -14,72 +14,45 @@ import engine.gameManager.DbManager; import java.sql.ResultSet; import java.sql.SQLException; - public class Condemned { public static final int INDIVIDUAL = 2; public static final int GUILD = 4; public static final int NATION = 5; - private int ID; - private int playerUID; - private int parent; - private int guildUID; - private int friendType; - private boolean active; + public int playerUID; + public int buildingUUID; + public int guildUID; + public int friendType; + public boolean active; /** * ResultSet Constructor */ public Condemned(ResultSet rs) throws SQLException { this.playerUID = rs.getInt("playerUID"); - this.parent = rs.getInt("buildingUID"); + this.buildingUUID = rs.getInt("buildingUID"); this.guildUID = rs.getInt("guildUID"); this.friendType = rs.getInt("friendType"); this.active = rs.getBoolean("active"); } - - public Condemned(int playerUID, int parent, int guildUID, int friendType) { + public Condemned(int playerUID, int buildingUUID, int guildUID, int friendType) { super(); this.playerUID = playerUID; - this.parent = parent; + this.buildingUUID = buildingUUID; this.guildUID = guildUID; this.friendType = friendType; this.active = false; } - - public int getPlayerUID() { - return playerUID; - } - - - public int getParent() { - return parent; - } - - - public int getGuildUID() { - return guildUID; - } - - - public int getFriendType() { - return friendType; - } - - public boolean isActive() { - return active; - } - - public boolean setActive(boolean active) { + if (!DbManager.BuildingQueries.updateActiveCondemn(this, active)) return false; + this.active = active; return true; } - } diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index daf7b59d..e79b2d07 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -321,6 +321,9 @@ public class WorldServer { Logger.info("Initializing Building Friends"); DbManager.BuildingQueries.LOAD_BUILDING_FRIENDS(); + Logger.info("Initializing Building Condemned"); + DbManager.BuildingQueries.LOAD_BUILDING_CONDEMNED(); + Logger.info("Initializing NPC Profits"); DbManager.NPCQueries.LOAD_NPC_PROFITS();