Begin refactor location collections.

This commit is contained in:
2023-04-24 15:37:30 -04:00
parent d729fbb287
commit 7c079c3998
4 changed files with 48 additions and 0 deletions
@@ -20,8 +20,17 @@ public class dbBuildingLocationHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
prepareCallable("select * from static_building_location " +
"where type = 6 or type = 8 " +
"GROUP BY buildingID, slot " +
"ORDER BY buildingID, slot ASC;");
return getObjectList();
}
public ArrayList<BuildingLocation> LOAD_ALL_BUILDING_LOCATIONS() {
prepareCallable("SELECT * FROM `static_building_location`;");
return getObjectList();
}
}
@@ -25,12 +25,17 @@ import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ThreadLocalRandom;
public enum BuildingManager {
BUILDINGMANAGER;
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations;
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations;
public static boolean playerCanManage(PlayerCharacter player, Building building) {
if (player == null)
+33
View File
@@ -9,12 +9,16 @@
package engine.objects;
import engine.gameManager.BuildingManager;
import engine.gameManager.DbManager;
import engine.math.Vector3fImmutable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@@ -122,6 +126,35 @@ public class BuildingLocation extends AbstractGameObject {
public void updateDatabase() {
}
public static void loadBuildingLocations() {
ArrayList<BuildingLocation> buildingLocations = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS();
HashMap<Integer, ArrayList<BuildingLocation>> locationCollection = new HashMap<>();
// Only slot locations and stuck locations are currently loaded.
for (BuildingLocation buildingLocation : buildingLocations) {
switch (buildingLocation.type) {
case 6:
locationCollection = BuildingManager._slotLocations;
break;
case 8:
locationCollection = BuildingManager._stuckLocations;
break;
}
// Add location to the collection in BuildingManager
if (locationCollection.containsKey(buildingLocation.buildingUUID))
locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation);
else {
locationCollection.put(buildingLocation.buildingUUID, new ArrayList<>());
locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation);
}
}
}
public static void loadAllLocations() {
ArrayList<BuildingLocation> bls = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS();
+1
View File
@@ -338,6 +338,7 @@ public class WorldServer {
Logger.info("Loading building mountpoint data.");
BuildingLocation.loadAllLocations();
BuildingLocation.loadBuildingLocations();
// Starting before loading of structures/guilds/characters
// so the database connections are available to write