forked from LogBlock/LogBlock
Make MaterialConverter and EntityTypeConverter thread safe
This commit is contained in:
@ -16,7 +16,7 @@ public class EntityTypeConverter {
|
||||
private static HashMap<EntityType, Integer> entityTypeToId = new HashMap<>();
|
||||
private static int nextEntityTypeId;
|
||||
|
||||
public static int getOrAddEntityTypeId(EntityType entityType) {
|
||||
public synchronized static int getOrAddEntityTypeId(EntityType entityType) {
|
||||
Integer key = entityTypeToId.get(entityType);
|
||||
int tries = 0;
|
||||
while (key == null && tries < 10) {
|
||||
@ -54,7 +54,7 @@ public class EntityTypeConverter {
|
||||
return key.intValue();
|
||||
}
|
||||
|
||||
public static EntityType getEntityType(int entityTypeId) {
|
||||
public synchronized static EntityType getEntityType(int entityTypeId) {
|
||||
return entityTypeId >= 0 && entityTypeId < idToEntityType.length ? idToEntityType[entityTypeId] : null;
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ public class EntityTypeConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeEntityTypes(Connection connection) throws SQLException {
|
||||
protected synchronized static void initializeEntityTypes(Connection connection) throws SQLException {
|
||||
Statement smt = connection.createStatement();
|
||||
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-entitytypes`");
|
||||
while (rs.next()) {
|
||||
@ -93,7 +93,7 @@ public class EntityTypeConverter {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private synchronized static void internalAddEntityType(int key, EntityType entityType) {
|
||||
private static void internalAddEntityType(int key, EntityType entityType) {
|
||||
entityTypeToId.put(entityType, key);
|
||||
int length = idToEntityType.length;
|
||||
while (length <= key) {
|
||||
|
@ -30,11 +30,11 @@ public class MaterialConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getOrAddMaterialId(BlockData blockData) {
|
||||
public synchronized static int getOrAddMaterialId(BlockData blockData) {
|
||||
return getOrAddMaterialId(blockData == null ? Material.AIR : blockData.getMaterial());
|
||||
}
|
||||
|
||||
public static int getOrAddMaterialId(Material material) {
|
||||
public synchronized static int getOrAddMaterialId(Material material) {
|
||||
if (material == null) {
|
||||
material = Material.AIR;
|
||||
}
|
||||
@ -76,7 +76,7 @@ public class MaterialConverter {
|
||||
return key.intValue();
|
||||
}
|
||||
|
||||
public static int getOrAddBlockStateId(BlockData blockData) {
|
||||
public synchronized static int getOrAddBlockStateId(BlockData blockData) {
|
||||
if (blockData == null) {
|
||||
blockData = Material.AIR.createBlockData();
|
||||
}
|
||||
@ -123,7 +123,7 @@ public class MaterialConverter {
|
||||
return key.intValue();
|
||||
}
|
||||
|
||||
public static BlockData getBlockData(int materialId, int blockStateId) {
|
||||
public synchronized static BlockData getBlockData(int materialId, int blockStateId) {
|
||||
String material = materialId >= 0 && materialId < idToMaterial.length ? idToMaterial[materialId] : null;
|
||||
if (material == null) {
|
||||
return null;
|
||||
@ -143,7 +143,7 @@ public class MaterialConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public static Material getMaterial(int materialId) {
|
||||
public synchronized static Material getMaterial(int materialId) {
|
||||
return materialId >= 0 && materialId < idToMaterial.length ? materialKeyToMaterial.get(idToMaterial[materialId]) : null;
|
||||
}
|
||||
|
||||
@ -162,7 +162,7 @@ public class MaterialConverter {
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeMaterials(Connection connection) throws SQLException {
|
||||
protected synchronized static void initializeMaterials(Connection connection) throws SQLException {
|
||||
Statement smt = connection.createStatement();
|
||||
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-materials`");
|
||||
while (rs.next()) {
|
||||
@ -182,7 +182,7 @@ public class MaterialConverter {
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private synchronized static void internalAddMaterial(int key, String materialString) {
|
||||
private static void internalAddMaterial(int key, String materialString) {
|
||||
materialToID.put(materialString, key);
|
||||
int length = idToMaterial.length;
|
||||
while (length <= key) {
|
||||
@ -197,7 +197,7 @@ public class MaterialConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized static void internalAddBlockState(int key, String materialString) {
|
||||
private static void internalAddBlockState(int key, String materialString) {
|
||||
blockStateToID.put(materialString, key);
|
||||
int length = idToBlockState.length;
|
||||
while (length <= key) {
|
||||
|
Reference in New Issue
Block a user