forked from MagicBane/Server
Load collection from db
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Integer, ArrayList<BuildingLocation>> _stuckLocations = 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) {
|
||||
|
||||
ArrayList<BuildingLocation> 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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user