Improve log messages when the block/entity type is unknown

This commit is contained in:
Brokkonaut
2019-05-31 18:00:55 +02:00
parent 72fc78b3c0
commit 05d7652bcc
2 changed files with 37 additions and 32 deletions

View File

@@ -73,10 +73,18 @@ public class BlockChange implements LookupCacheElement {
@Override @Override
public String toString() { public String toString() {
final StringBuilder msg = new StringBuilder();
if (date > 0) {
msg.append(Config.formatter.format(date)).append(" ");
}
if (actor != null) {
msg.append(actor.getName()).append(" ");
}
BlockData type = getBlockSet(); BlockData type = getBlockSet();
BlockData replaced = getBlockReplaced(); BlockData replaced = getBlockReplaced();
if (type == null || replaced == null) { if (type == null || replaced == null) {
return "Unknown block modification"; msg.append("did an unknown block modification");
return msg.toString();
} }
String typeDetails = null; String typeDetails = null;
if (BlockStateCodecs.hasCodec(type.getMaterial())) { if (BlockStateCodecs.hasCodec(type.getMaterial())) {
@@ -104,13 +112,6 @@ public class BlockChange implements LookupCacheElement {
} else { } else {
replacedDetails = " " + replacedDetails; replacedDetails = " " + replacedDetails;
} }
final StringBuilder msg = new StringBuilder();
if (date > 0) {
msg.append(Config.formatter.format(date)).append(" ");
}
if (actor != null) {
msg.append(actor.getName()).append(" ");
}
if (type.getMaterial().equals(replaced.getMaterial())) { if (type.getMaterial().equals(replaced.getMaterial())) {
if (BukkitUtils.isEmpty(type.getMaterial())) { if (BukkitUtils.isEmpty(type.getMaterial())) {
msg.append("did an unspecified action"); msg.append("did an unspecified action");

View File

@@ -71,32 +71,36 @@ public class EntityChange implements LookupCacheElement {
if (actor != null) { if (actor != null) {
msg.append(actor.getName()).append(" "); msg.append(actor.getName()).append(" ");
} }
if (type != null) { if (changeType == EntityChangeType.CREATE) {
boolean living = LivingEntity.class.isAssignableFrom(type.getEntityClass()) && !ArmorStand.class.isAssignableFrom(type.getDeclaringClass()); msg.append("created ");
if (changeType == EntityChangeType.CREATE) { } else if (changeType == EntityChangeType.KILL) {
msg.append("created "); boolean living = type != null && LivingEntity.class.isAssignableFrom(type.getEntityClass()) && !ArmorStand.class.isAssignableFrom(type.getDeclaringClass());
} else if (changeType == EntityChangeType.KILL) { msg.append(living ? "killed " : "destroyed ");
msg.append(living ? "killed " : "destroyed "); } else if (changeType == EntityChangeType.ADDEQUIP) {
} else if (changeType == EntityChangeType.ADDEQUIP) { YamlConfiguration conf = Utils.deserializeYamlConfiguration(data);
YamlConfiguration conf = Utils.deserializeYamlConfiguration(data); ItemStack stack = conf == null ? null : conf.getItemStack("item");
ItemStack stack = conf == null ? null : conf.getItemStack("item"); if (stack == null) {
if (stack == null) { msg.append("added an item to ");
msg.append("added an item to "); } else {
} else { msg.append("added " + stack.getType() + " to ");
msg.append("added " + stack.getType() + " to ");
}
} else if (changeType == EntityChangeType.REMOVEEQUIP) {
YamlConfiguration conf = Utils.deserializeYamlConfiguration(data);
ItemStack stack = conf == null ? null : conf.getItemStack("item");
if (stack == null) {
msg.append("removed an item from ");
} else {
msg.append("removed " + stack.getType() + " from ");
}
} else if (changeType == EntityChangeType.MODIFY) {
msg.append("modified ");
} }
} else if (changeType == EntityChangeType.REMOVEEQUIP) {
YamlConfiguration conf = Utils.deserializeYamlConfiguration(data);
ItemStack stack = conf == null ? null : conf.getItemStack("item");
if (stack == null) {
msg.append("removed an item from ");
} else {
msg.append("removed " + stack.getType() + " from ");
}
} else if (changeType == EntityChangeType.MODIFY) {
msg.append("modified ");
} else {
msg.append("did an unknown action to ");
}
if (type != null) {
msg.append(type.name()); msg.append(type.name());
} else {
msg.append("an unknown entity");
} }
if (loc != null) { if (loc != null) {
msg.append(" at ").append(loc.getBlockX()).append(":").append(loc.getBlockY()).append(":").append(loc.getBlockZ()); msg.append(" at ").append(loc.getBlockX()).append(":").append(loc.getBlockY()).append(":").append(loc.getBlockZ());