Added MultiPaper support

This commit is contained in:
Intelli 2025-09-26 14:12:00 -06:00
parent d30f6cf8d5
commit 51d4bf27cd
6 changed files with 159 additions and 9 deletions

25
pom.xml
View file

@ -113,6 +113,31 @@
<skipTests>${skipTests}</skipTests> <skipTests>${skipTests}</skipTests>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals><goal>enforce</goal></goals>
<configuration>
<rules>
<requireNoRepositories>
<allowedRepositories>
<allowedRepository>central</allowedRepository>
<allowedRepository>enginehub-repo</allowedRepository>
<allowedRepository>spigot-repo</allowedRepository>
<allowedRepository>paper-repo</allowedRepository>
<allowedRepository>codemc-repo</allowedRepository>
<allowedRepository>jitpack.io</allowedRepository>
</allowedRepositories>
</requireNoRepositories>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles> <profiles>

View file

@ -40,6 +40,11 @@ import net.coreprotect.utility.VersionUtils;
import oshi.hardware.CentralProcessor; import oshi.hardware.CentralProcessor;
public class ConfigHandler extends Queue { public class ConfigHandler extends Queue {
public enum CacheType {
MATERIALS, BLOCKDATA, ART, ENTITIES, WORLDS
}
public static int SERVER_VERSION = 0; public static int SERVER_VERSION = 0;
public static final int EDITION_VERSION = 2; public static final int EDITION_VERSION = 2;
public static final String EDITION_BRANCH = VersionUtils.getBranch(); public static final String EDITION_BRANCH = VersionUtils.getBranch();
@ -48,6 +53,7 @@ public class ConfigHandler extends Queue {
public static final String JAVA_VERSION = "11.0"; public static final String JAVA_VERSION = "11.0";
public static final String MINECRAFT_VERSION = "1.16"; public static final String MINECRAFT_VERSION = "1.16";
public static final String LATEST_VERSION = "1.21.8"; public static final String LATEST_VERSION = "1.21.8";
public static final String PATCH_VERSION = "23.0";
public static String path = "plugins/CoreProtect/"; public static String path = "plugins/CoreProtect/";
public static String sqlite = "database.db"; public static String sqlite = "database.db";
public static String host = "127.0.0.1"; public static String host = "127.0.0.1";
@ -268,7 +274,7 @@ public class ConfigHandler extends Queue {
Database.createDatabaseTables(ConfigHandler.prefix, false, null, Config.getGlobal().MYSQL, false); Database.createDatabaseTables(ConfigHandler.prefix, false, null, Config.getGlobal().MYSQL, false);
} }
public static void loadTypes(Statement statement) { public static void loadMaterials(Statement statement) {
try { try {
String query = "SELECT id,material FROM " + ConfigHandler.prefix + "material_map"; String query = "SELECT id,material FROM " + ConfigHandler.prefix + "material_map";
ResultSet rs = statement.executeQuery(query); ResultSet rs = statement.executeQuery(query);
@ -286,9 +292,16 @@ public class ConfigHandler extends Queue {
} }
} }
rs.close(); rs.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
query = "SELECT id,data FROM " + ConfigHandler.prefix + "blockdata_map"; public static void loadBlockdata(Statement statement) {
rs = statement.executeQuery(query); try {
String query = "SELECT id,data FROM " + ConfigHandler.prefix + "blockdata_map";
ResultSet rs = statement.executeQuery(query);
ConfigHandler.blockdata.clear(); ConfigHandler.blockdata.clear();
ConfigHandler.blockdataReversed.clear(); ConfigHandler.blockdataReversed.clear();
blockdataId = 0; blockdataId = 0;
@ -303,9 +316,16 @@ public class ConfigHandler extends Queue {
} }
} }
rs.close(); rs.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
query = "SELECT id,art FROM " + ConfigHandler.prefix + "art_map"; public static void loadArt(Statement statement) {
rs = statement.executeQuery(query); try {
String query = "SELECT id,art FROM " + ConfigHandler.prefix + "art_map";
ResultSet rs = statement.executeQuery(query);
ConfigHandler.art.clear(); ConfigHandler.art.clear();
ConfigHandler.artReversed.clear(); ConfigHandler.artReversed.clear();
artId = 0; artId = 0;
@ -320,9 +340,16 @@ public class ConfigHandler extends Queue {
} }
} }
rs.close(); rs.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
query = "SELECT id,entity FROM " + ConfigHandler.prefix + "entity_map"; public static void loadEntities(Statement statement) {
rs = statement.executeQuery(query); try {
String query = "SELECT id,entity FROM " + ConfigHandler.prefix + "entity_map";
ResultSet rs = statement.executeQuery(query);
ConfigHandler.entities.clear(); ConfigHandler.entities.clear();
ConfigHandler.entitiesReversed.clear(); ConfigHandler.entitiesReversed.clear();
entityId = 0; entityId = 0;
@ -343,6 +370,67 @@ public class ConfigHandler extends Queue {
} }
} }
public static void loadTypes(Statement statement) {
loadMaterials(statement);
loadBlockdata(statement);
loadArt(statement);
loadEntities(statement);
}
/**
* Unified method to reload cache from database when DATABASE_LOCK is false (multi-server setup)
*
* @param type
* The type of cache to reload
* @param name
* The name to look up after reload
* @return The ID if found after reload, or -1 if not found
*/
public static int reloadAndGetId(CacheType type, String name) {
// Only reload if DATABASE_LOCK is false (multi-server setup)
if (Config.getGlobal().DATABASE_LOCK) {
return -1;
}
try (Connection connection = Database.getConnection(true)) {
if (connection != null) {
Statement statement = connection.createStatement();
// Reload appropriate cache based on type
switch (type) {
case MATERIALS:
loadMaterials(statement);
statement.close();
return materials.getOrDefault(name, -1);
case BLOCKDATA:
loadBlockdata(statement);
statement.close();
return blockdata.getOrDefault(name, -1);
case ART:
loadArt(statement);
statement.close();
return art.getOrDefault(name, -1);
case ENTITIES:
loadEntities(statement);
statement.close();
return entities.getOrDefault(name, -1);
case WORLDS:
loadWorlds(statement);
statement.close();
return worlds.getOrDefault(name, -1);
default:
statement.close();
return -1;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return -1;
}
public static void loadWorlds(Statement statement) { public static void loadWorlds(Statement statement) {
try { try {
String query = "SELECT id,world FROM " + ConfigHandler.prefix + "world"; String query = "SELECT id,world FROM " + ConfigHandler.prefix + "world";

View file

@ -44,6 +44,13 @@ public class VersionCheckService {
return false; return false;
} }
// Patch version validation
if (VersionUtils.newVersion(ConfigHandler.PATCH_VERSION, VersionUtils.getPluginVersion()) && !ConfigHandler.EDITION_BRANCH.contains("-dev")) {
Chat.console(Phrase.build(Phrase.VERSION_INCOMPATIBLE, "CoreProtect", "v" + VersionUtils.getPluginVersion()));
Chat.sendConsoleMessage(Color.GREY + "[CoreProtect] " + Phrase.build(Phrase.INVALID_BRANCH_2));
return false;
}
// Branch validation // Branch validation
if (ConfigHandler.EDITION_BRANCH.length() == 0) { if (ConfigHandler.EDITION_BRANCH.length() == 0) {
Chat.sendConsoleMessage(Color.RED + "[CoreProtect] " + Phrase.build(Phrase.INVALID_BRANCH_1)); Chat.sendConsoleMessage(Color.RED + "[CoreProtect] " + Phrase.build(Phrase.INVALID_BRANCH_1));

View file

@ -33,6 +33,12 @@ public class EntityUtils extends Queue {
id = ConfigHandler.entities.get(name); id = ConfigHandler.entities.get(name);
} }
else if (internal) { else if (internal) {
// Check if another server has already added this entity (multi-server setup)
id = ConfigHandler.reloadAndGetId(ConfigHandler.CacheType.ENTITIES, name);
if (id != -1) {
return id;
}
int entityID = ConfigHandler.entityId + 1; int entityID = ConfigHandler.entityId + 1;
ConfigHandler.entities.put(name, entityID); ConfigHandler.entities.put(name, entityID);
ConfigHandler.entitiesReversed.put(entityID, name); ConfigHandler.entitiesReversed.put(entityID, name);

View file

@ -35,6 +35,12 @@ public class MaterialUtils extends Queue {
id = ConfigHandler.materials.get(name); id = ConfigHandler.materials.get(name);
} }
else if (internal) { else if (internal) {
// Check if another server has already added this material (multi-server setup)
id = ConfigHandler.reloadAndGetId(ConfigHandler.CacheType.MATERIALS, name);
if (id != -1) {
return id;
}
int mid = ConfigHandler.materialId + 1; int mid = ConfigHandler.materialId + 1;
ConfigHandler.materials.put(name, mid); ConfigHandler.materials.put(name, mid);
ConfigHandler.materialsReversed.put(mid, name); ConfigHandler.materialsReversed.put(mid, name);
@ -54,6 +60,12 @@ public class MaterialUtils extends Queue {
id = ConfigHandler.blockdata.get(data); id = ConfigHandler.blockdata.get(data);
} }
else if (internal) { else if (internal) {
// Check if another server has already added this blockdata (multi-server setup)
id = ConfigHandler.reloadAndGetId(ConfigHandler.CacheType.BLOCKDATA, data);
if (id != -1) {
return id;
}
int bid = ConfigHandler.blockdataId + 1; int bid = ConfigHandler.blockdataId + 1;
ConfigHandler.blockdata.put(data, bid); ConfigHandler.blockdata.put(data, bid);
ConfigHandler.blockdataReversed.put(bid, data); ConfigHandler.blockdataReversed.put(bid, data);
@ -135,6 +147,12 @@ public class MaterialUtils extends Queue {
id = ConfigHandler.art.get(name); id = ConfigHandler.art.get(name);
} }
else if (internal) { else if (internal) {
// Check if another server has already added this art (multi-server setup)
id = ConfigHandler.reloadAndGetId(ConfigHandler.CacheType.ART, name);
if (id != -1) {
return id;
}
int artID = ConfigHandler.artId + 1; int artID = ConfigHandler.artId + 1;
ConfigHandler.art.put(name, artID); ConfigHandler.art.put(name, artID);
ConfigHandler.artReversed.put(artID, name); ConfigHandler.artReversed.put(artID, name);

View file

@ -16,6 +16,12 @@ public class WorldUtils extends Queue {
int id = -1; int id = -1;
try { try {
if (ConfigHandler.worlds.get(name) == null) { if (ConfigHandler.worlds.get(name) == null) {
// Check if another server has already added this world (multi-server setup)
id = ConfigHandler.reloadAndGetId(ConfigHandler.CacheType.WORLDS, name);
if (id != -1) {
return id;
}
int wid = ConfigHandler.worldId + 1; int wid = ConfigHandler.worldId + 1;
ConfigHandler.worlds.put(name, wid); ConfigHandler.worlds.put(name, wid);
ConfigHandler.worldsReversed.put(wid, name); ConfigHandler.worldsReversed.put(wid, name);