4040import oshi .hardware .CentralProcessor ;
4141
4242public class ConfigHandler extends Queue {
43+
44+ public enum CacheType {
45+ MATERIALS , BLOCKDATA , ART , ENTITIES , WORLDS
46+ }
47+
4348 public static int SERVER_VERSION = 0 ;
4449 public static final int EDITION_VERSION = 2 ;
4550 public static final String EDITION_BRANCH = VersionUtils .getBranch ();
@@ -48,6 +53,7 @@ public class ConfigHandler extends Queue {
4853 public static final String JAVA_VERSION = "11.0" ;
4954 public static final String MINECRAFT_VERSION = "1.16" ;
5055 public static final String LATEST_VERSION = "1.21.8" ;
56+ public static final String PATCH_VERSION = "23.0" ;
5157 public static String path = "plugins/CoreProtect/" ;
5258 public static String sqlite = "database.db" ;
5359 public static String host = "127.0.0.1" ;
@@ -268,7 +274,7 @@ public static void loadDatabase() {
268274 Database .createDatabaseTables (ConfigHandler .prefix , false , null , Config .getGlobal ().MYSQL , false );
269275 }
270276
271- public static void loadTypes (Statement statement ) {
277+ public static void loadMaterials (Statement statement ) {
272278 try {
273279 String query = "SELECT id,material FROM " + ConfigHandler .prefix + "material_map" ;
274280 ResultSet rs = statement .executeQuery (query );
@@ -286,9 +292,16 @@ public static void loadTypes(Statement statement) {
286292 }
287293 }
288294 rs .close ();
295+ }
296+ catch (Exception e ) {
297+ e .printStackTrace ();
298+ }
299+ }
289300
290- query = "SELECT id,data FROM " + ConfigHandler .prefix + "blockdata_map" ;
291- rs = statement .executeQuery (query );
301+ public static void loadBlockdata (Statement statement ) {
302+ try {
303+ String query = "SELECT id,data FROM " + ConfigHandler .prefix + "blockdata_map" ;
304+ ResultSet rs = statement .executeQuery (query );
292305 ConfigHandler .blockdata .clear ();
293306 ConfigHandler .blockdataReversed .clear ();
294307 blockdataId = 0 ;
@@ -303,9 +316,16 @@ public static void loadTypes(Statement statement) {
303316 }
304317 }
305318 rs .close ();
319+ }
320+ catch (Exception e ) {
321+ e .printStackTrace ();
322+ }
323+ }
306324
307- query = "SELECT id,art FROM " + ConfigHandler .prefix + "art_map" ;
308- rs = statement .executeQuery (query );
325+ public static void loadArt (Statement statement ) {
326+ try {
327+ String query = "SELECT id,art FROM " + ConfigHandler .prefix + "art_map" ;
328+ ResultSet rs = statement .executeQuery (query );
309329 ConfigHandler .art .clear ();
310330 ConfigHandler .artReversed .clear ();
311331 artId = 0 ;
@@ -320,9 +340,16 @@ public static void loadTypes(Statement statement) {
320340 }
321341 }
322342 rs .close ();
343+ }
344+ catch (Exception e ) {
345+ e .printStackTrace ();
346+ }
347+ }
323348
324- query = "SELECT id,entity FROM " + ConfigHandler .prefix + "entity_map" ;
325- rs = statement .executeQuery (query );
349+ public static void loadEntities (Statement statement ) {
350+ try {
351+ String query = "SELECT id,entity FROM " + ConfigHandler .prefix + "entity_map" ;
352+ ResultSet rs = statement .executeQuery (query );
326353 ConfigHandler .entities .clear ();
327354 ConfigHandler .entitiesReversed .clear ();
328355 entityId = 0 ;
@@ -343,6 +370,67 @@ public static void loadTypes(Statement statement) {
343370 }
344371 }
345372
373+ public static void loadTypes (Statement statement ) {
374+ loadMaterials (statement );
375+ loadBlockdata (statement );
376+ loadArt (statement );
377+ loadEntities (statement );
378+ }
379+
380+ /**
381+ * Unified method to reload cache from database when DATABASE_LOCK is false (multi-server setup)
382+ *
383+ * @param type
384+ * The type of cache to reload
385+ * @param name
386+ * The name to look up after reload
387+ * @return The ID if found after reload, or -1 if not found
388+ */
389+ public static int reloadAndGetId (CacheType type , String name ) {
390+ // Only reload if DATABASE_LOCK is false (multi-server setup)
391+ if (Config .getGlobal ().DATABASE_LOCK ) {
392+ return -1 ;
393+ }
394+
395+ try (Connection connection = Database .getConnection (true )) {
396+ if (connection != null ) {
397+ Statement statement = connection .createStatement ();
398+
399+ // Reload appropriate cache based on type
400+ switch (type ) {
401+ case MATERIALS :
402+ loadMaterials (statement );
403+ statement .close ();
404+ return materials .getOrDefault (name , -1 );
405+ case BLOCKDATA :
406+ loadBlockdata (statement );
407+ statement .close ();
408+ return blockdata .getOrDefault (name , -1 );
409+ case ART :
410+ loadArt (statement );
411+ statement .close ();
412+ return art .getOrDefault (name , -1 );
413+ case ENTITIES :
414+ loadEntities (statement );
415+ statement .close ();
416+ return entities .getOrDefault (name , -1 );
417+ case WORLDS :
418+ loadWorlds (statement );
419+ statement .close ();
420+ return worlds .getOrDefault (name , -1 );
421+ default :
422+ statement .close ();
423+ return -1 ;
424+ }
425+ }
426+ }
427+ catch (Exception e ) {
428+ e .printStackTrace ();
429+ }
430+
431+ return -1 ;
432+ }
433+
346434 public static void loadWorlds (Statement statement ) {
347435 try {
348436 String query = "SELECT id,world FROM " + ConfigHandler .prefix + "world" ;
0 commit comments