forked from MagicBane/Server
Begin refactor location collections.
This commit is contained in:
@@ -20,8 +20,17 @@ public class dbBuildingLocationHandler extends dbHandlerBase {
|
|||||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
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() {
|
public ArrayList<BuildingLocation> LOAD_ALL_BUILDING_LOCATIONS() {
|
||||||
prepareCallable("SELECT * FROM `static_building_location`;");
|
prepareCallable("SELECT * FROM `static_building_location`;");
|
||||||
return getObjectList();
|
return getObjectList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,17 @@ import org.pmw.tinylog.Logger;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public enum BuildingManager {
|
public enum BuildingManager {
|
||||||
|
|
||||||
BUILDINGMANAGER;
|
BUILDINGMANAGER;
|
||||||
|
|
||||||
|
public static HashMap<Integer, ArrayList<BuildingLocation>> _stuckLocations;
|
||||||
|
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations;
|
||||||
|
|
||||||
public static boolean playerCanManage(PlayerCharacter player, Building building) {
|
public static boolean playerCanManage(PlayerCharacter player, Building building) {
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
|
|||||||
@@ -9,12 +9,16 @@
|
|||||||
|
|
||||||
package engine.objects;
|
package engine.objects;
|
||||||
|
|
||||||
|
import engine.gameManager.BuildingManager;
|
||||||
import engine.gameManager.DbManager;
|
import engine.gameManager.DbManager;
|
||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
|
||||||
@@ -122,6 +126,35 @@ public class BuildingLocation extends AbstractGameObject {
|
|||||||
public void updateDatabase() {
|
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() {
|
public static void loadAllLocations() {
|
||||||
ArrayList<BuildingLocation> bls = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS();
|
ArrayList<BuildingLocation> bls = DbManager.BuildingLocationQueries.LOAD_ALL_BUILDING_LOCATIONS();
|
||||||
|
|||||||
@@ -338,6 +338,7 @@ public class WorldServer {
|
|||||||
|
|
||||||
Logger.info("Loading building mountpoint data.");
|
Logger.info("Loading building mountpoint data.");
|
||||||
BuildingLocation.loadAllLocations();
|
BuildingLocation.loadAllLocations();
|
||||||
|
BuildingLocation.loadBuildingLocations();
|
||||||
|
|
||||||
// Starting before loading of structures/guilds/characters
|
// Starting before loading of structures/guilds/characters
|
||||||
// so the database connections are available to write
|
// so the database connections are available to write
|
||||||
|
|||||||
Reference in New Issue
Block a user