forked from LogBlock/LogBlock
Not every material has a BlockData
This commit is contained in:
@ -21,6 +21,16 @@ public class MaterialConverter {
|
|||||||
private static HashMap<String, Integer> blockStateToID = new HashMap<>();
|
private static HashMap<String, Integer> blockStateToID = new HashMap<>();
|
||||||
private static int nextBlockStateId;
|
private static int nextBlockStateId;
|
||||||
|
|
||||||
|
private static HashMap<String, Material> materialKeyToMaterial = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (Material m : Material.values()) {
|
||||||
|
if (!m.name().startsWith("LEGACY_") && m.getKey() != null) {
|
||||||
|
materialKeyToMaterial.put(m.getKey().toString(), m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized static int getOrAddMaterialId(NamespacedKey nameSpaceKey) {
|
public synchronized static int getOrAddMaterialId(NamespacedKey nameSpaceKey) {
|
||||||
return getOrAddMaterialId(nameSpaceKey.toString());
|
return getOrAddMaterialId(nameSpaceKey.toString());
|
||||||
}
|
}
|
||||||
@ -80,7 +90,11 @@ public class MaterialConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Material getMaterial(int materialId) {
|
public static Material getMaterial(int materialId) {
|
||||||
return getBlockData(materialId, -1).getMaterial();
|
String material = idToMaterial[materialId];
|
||||||
|
if (materialId >= 0) {
|
||||||
|
material = material + idToBlockState[materialId];
|
||||||
|
}
|
||||||
|
return materialKeyToMaterial.get(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initializeMaterials(Connection connection) throws SQLException {
|
public static void initializeMaterials(Connection connection) throws SQLException {
|
||||||
|
@ -158,6 +158,9 @@ public class WorldEditor implements Runnable {
|
|||||||
PerformResult perform() throws WorldEditorException {
|
PerformResult perform() throws WorldEditorException {
|
||||||
BlockData replacedBlock = MaterialConverter.getBlockData(this.replacedMaterial, replacedData);
|
BlockData replacedBlock = MaterialConverter.getBlockData(this.replacedMaterial, replacedData);
|
||||||
BlockData setBlock = MaterialConverter.getBlockData(this.typeMaterial, typeData);
|
BlockData setBlock = MaterialConverter.getBlockData(this.typeMaterial, typeData);
|
||||||
|
if (replacedBlock == null || setBlock == null) {
|
||||||
|
throw new WorldEditorException("Could not parse the material", loc.clone());
|
||||||
|
}
|
||||||
// action: set to replaced
|
// action: set to replaced
|
||||||
|
|
||||||
if (dontRollback.contains(replacedBlock.getMaterial())) {
|
if (dontRollback.contains(replacedBlock.getMaterial())) {
|
||||||
|
Reference in New Issue
Block a user