Browse Source

Load collection from db

combat-2
MagicBot 1 year ago
parent
commit
385695a610
  1. 35
      src/engine/db/handlers/dbBuildingHandler.java
  2. 7
      src/engine/gameManager/BuildingManager.java
  3. 2
      src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java
  4. 14
      src/engine/net/client/msg/OpenFriendsCondemnListMsg.java
  5. 20
      src/engine/objects/BuildingFriends.java
  6. 3
      src/engine/server/world/WorldServer.java

35
src/engine/db/handlers/dbBuildingHandler.java

@ -13,6 +13,7 @@ import engine.Enum;
import engine.Enum.DbObjectType; import engine.Enum.DbObjectType;
import engine.Enum.ProtectionState; import engine.Enum.ProtectionState;
import engine.Enum.TaxType; import engine.Enum.TaxType;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.objects.*; import engine.objects.*;
@ -423,6 +424,34 @@ public class dbBuildingHandler extends dbHandlerBase {
return false; 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) { public void LOAD_ALL_FRIENDS_FOR_BUILDING(Building building) {
if (building == null) if (building == null)
@ -436,13 +465,13 @@ public class dbBuildingHandler extends dbHandlerBase {
while (rs.next()) { while (rs.next()) {
BuildingFriends friend = new BuildingFriends(rs); BuildingFriends friend = new BuildingFriends(rs);
switch (friend.getFriendType()) { switch (friend.friendType) {
case 7: case 7:
building.getFriends().put(friend.getPlayerUID(), friend); building.getFriends().put(friend.playerUID, friend);
break; break;
case 8: case 8:
case 9: case 9:
building.getFriends().put(friend.getGuildUID(), friend); building.getFriends().put(friend.guildUID, friend);
break; break;
} }
} }

7
src/engine/gameManager/BuildingManager.java

@ -31,6 +31,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public enum BuildingManager { public enum BuildingManager {
@ -40,6 +41,8 @@ public enum BuildingManager {
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations = new HashMap<>(); public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations = new HashMap<>();
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>(); public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
public static HashMap<Integer, ConcurrentHashMap<Integer, BuildingFriends>> _buildingFriends = new HashMap<>();
public static int getAvailableSlot(Building building) { public static int getAvailableSlot(Building building) {
ArrayList<BuildingLocation> slotLocations = _slotLocations.get(building.meshUUID); ArrayList<BuildingLocation> slotLocations = _slotLocations.get(building.meshUUID);
@ -127,11 +130,11 @@ public enum BuildingManager {
return true; return true;
if (building.getFriends().get(player.getGuild().getObjectUUID()) != null 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; return true;
if (building.getFriends().get(player.getGuild().getObjectUUID()) != null 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())) && GuildStatusController.isInnerCouncil(player.getGuildStatus()))
return true; return true;

2
src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java

@ -354,7 +354,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler {
if (friend == null) if (friend == null)
return true; 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()); Logger.debug("Failed to remove Friend: " + msg.getRemoveFriendID() + " from Building With UID " + sourceBuilding.getObjectUUID());
return true; return true;
} }

14
src/engine/net/client/msg/OpenFriendsCondemnListMsg.java

@ -619,22 +619,22 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
writer.putInt(listSize); writer.putInt(listSize);
for (BuildingFriends friend : this.friends.values()) { for (BuildingFriends friend : this.friends.values()) {
pc = PlayerCharacter.getFromCache(friend.getPlayerUID()); pc = PlayerCharacter.getFromCache(friend.playerUID);
guild = Guild.getGuild(friend.getGuildUID()); guild = Guild.getGuild(friend.guildUID);
if (friend.getFriendType() == 7) { if (friend.friendType == 7) {
if (pc != null) if (pc != null)
name = pc.getCombinedName(); name = pc.getCombinedName();
} else if (guild != null) } else if (guild != null)
name = guild.getName(); name = guild.getName();
writer.put((byte) 1); writer.put((byte) 1);
if (friend.getFriendType() == 7) { if (friend.friendType == 7) {
writer.putInt(GameObjectType.PlayerCharacter.ordinal()); writer.putInt(GameObjectType.PlayerCharacter.ordinal());
writer.putInt(friend.getPlayerUID()); writer.putInt(friend.playerUID);
} else { } else {
writer.putInt(GameObjectType.Guild.ordinal()); 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);
writer.putInt(0); writer.putInt(0);

20
src/engine/objects/BuildingFriends.java

@ -14,10 +14,10 @@ import java.sql.SQLException;
public class BuildingFriends { public class BuildingFriends {
private int playerUID; public int playerUID;
private int buildingUID; public int buildingUID;
private int guildUID; public int guildUID;
private int friendType; public int friendType;
/** /**
* ResultSet Constructor * ResultSet Constructor
@ -38,16 +38,4 @@ public class BuildingFriends {
this.friendType = friendType; this.friendType = friendType;
} }
public int getPlayerUID() {
return playerUID;
}
public int getGuildUID() {
return guildUID;
}
public int getFriendType() {
return friendType;
}
} }

3
src/engine/server/world/WorldServer.java

@ -318,6 +318,9 @@ public class WorldServer {
Logger.info("Initializing Player Friends"); Logger.info("Initializing Player Friends");
DbManager.PlayerCharacterQueries.LOAD_PLAYER_FRIENDS(); DbManager.PlayerCharacterQueries.LOAD_PLAYER_FRIENDS();
Logger.info("Initializing Building Friends");
DbManager.BuildingQueries.LOAD_BUILDING_FRIENDS();
Logger.info("Initializing NPC Profits"); Logger.info("Initializing NPC Profits");
DbManager.NPCQueries.LOAD_NPC_PROFITS(); DbManager.NPCQueries.LOAD_NPC_PROFITS();

Loading…
Cancel
Save