Merge branch 'master' into 1.14pre

This commit is contained in:
Brokkonaut
2019-05-04 17:50:48 +02:00
5 changed files with 34 additions and 8 deletions

View File

@ -74,6 +74,9 @@ public class BlockChange implements LookupCacheElement {
public String toString() {
BlockData type = getBlockSet();
BlockData replaced = getBlockReplaced();
if (type == null || replaced == null) {
return "Unknown block modification";
}
String typeDetails = null;
if (BlockStateCodecs.hasCodec(type.getMaterial())) {
try {

View File

@ -55,7 +55,7 @@ public class EntityTypeConverter {
}
public static EntityType getEntityType(int entityTypeId) {
return idToEntityType[entityTypeId];
return entityTypeId >= 0 && entityTypeId < idToEntityType.length ? idToEntityType[entityTypeId] : null;
}
private static void reinitializeEntityTypesCatchException() {
@ -78,8 +78,15 @@ public class EntityTypeConverter {
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-entitytypes`");
while (rs.next()) {
int key = rs.getInt(1);
EntityType entityType = EntityType.valueOf(rs.getString(2));
internalAddEntityType(key, entityType);
try {
EntityType entityType = EntityType.valueOf(rs.getString(2));
internalAddEntityType(key, entityType);
} catch (IllegalArgumentException ignored) {
// the key is used, but not available in this version
if (nextEntityTypeId <= key) {
nextEntityTypeId = key + 1;
}
}
}
rs.close();
smt.close();

View File

@ -122,15 +122,27 @@ public class MaterialConverter {
}
public static BlockData getBlockData(int materialId, int blockStateId) {
String material = idToMaterial[materialId];
if (blockStateId >= 0) {
String material = materialId >= 0 && materialId < idToMaterial.length ? idToMaterial[materialId] : null;
if (material == null) {
return null;
}
if (blockStateId >= 0 && blockStateId < idToBlockState.length && idToBlockState[blockStateId] != null) {
material = material + idToBlockState[blockStateId];
}
return Bukkit.createBlockData(material);
try {
return Bukkit.createBlockData(material);
} catch (IllegalArgumentException ignored) {
// fall back to create the default block data for the material
try {
return Bukkit.createBlockData(idToMaterial[materialId]);
} catch (IllegalArgumentException ignored2) {
return null;
}
}
}
public static Material getMaterial(int materialId) {
return materialKeyToMaterial.get(idToMaterial[materialId]);
return materialId >= 0 && materialId < idToMaterial.length ? materialKeyToMaterial.get(idToMaterial[materialId]) : null;
}
private static void reinitializeMaterialsCatchException() {

View File

@ -5,6 +5,7 @@ import org.bukkit.Location;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Objects;
import static de.diddiz.util.Utils.spaces;
@ -30,6 +31,6 @@ public class SummedEntityChanges implements LookupCacheElement {
@Override
public String getMessage() {
return created + spaces((int) ((10 - String.valueOf(created).length()) / spaceFactor)) + destroyed + spaces((int) ((10 - String.valueOf(destroyed).length()) / spaceFactor)) + (actor != null ? actor.getName() : EntityTypeConverter.getEntityType(type).toString());
return created + spaces((int) ((10 - String.valueOf(created).length()) / spaceFactor)) + destroyed + spaces((int) ((10 - String.valueOf(destroyed).length()) / spaceFactor)) + (actor != null ? actor.getName() : Objects.toString(EntityTypeConverter.getEntityType(type)));
}
}

View File

@ -226,6 +226,9 @@ public class WorldEditor implements Runnable {
@Override
public PerformResult perform() throws WorldEditorException {
if (type == null) {
throw new WorldEditorException("Unkown entity type for entity " + entityUUID, loc);
}
if (changeType == (rollback ? EntityChangeType.KILL : EntityChangeType.CREATE)) {
// spawn entity
UUID uuid = getReplacedUUID(entityId, entityUUID);