forked from LogBlock/LogBlock
Better display sign changes in log messages
This commit is contained in:
@ -82,11 +82,15 @@ public class BlockChange implements LookupCacheElement {
|
||||
}
|
||||
|
||||
private String getTypeDetails(BlockData type, byte[] typeState) {
|
||||
return getTypeDetails(type, typeState, null, null);
|
||||
}
|
||||
|
||||
private String getTypeDetails(BlockData type, byte[] typeState, BlockData oldType, byte[] oldTypeState) {
|
||||
String typeDetails = null;
|
||||
|
||||
if (BlockStateCodecs.hasCodec(type.getMaterial())) {
|
||||
try {
|
||||
typeDetails = BlockStateCodecs.toString(type.getMaterial(), Utils.deserializeYamlConfiguration(typeState));
|
||||
typeDetails = BlockStateCodecs.toString(type.getMaterial(), Utils.deserializeYamlConfiguration(typeState), type.equals(oldType) ? Utils.deserializeYamlConfiguration(oldTypeState) : null);
|
||||
} catch (Exception e) {
|
||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not parse BlockState for " + type.getMaterial(), e);
|
||||
}
|
||||
@ -123,7 +127,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
}
|
||||
|
||||
// Process type details once for later use.
|
||||
String typeDetails = getTypeDetails(type, typeState);
|
||||
String typeDetails = getTypeDetails(type, typeState, replaced, replacedState);
|
||||
String replacedDetails = getTypeDetails(replaced, replacedState);
|
||||
|
||||
if (type.getMaterial().equals(replaced.getMaterial())) {
|
||||
@ -205,7 +209,7 @@ public class BlockChange implements LookupCacheElement {
|
||||
} else if (type instanceof Sign || type instanceof WallSign) {
|
||||
msg.addExtra(createTextComponentWithColor("edited a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(createTextComponentWithColor(" to ", CREATE.getColor()));
|
||||
msg.addExtra(createTextComponentWithColor(" to", CREATE.getColor()));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
|
||||
|
@ -11,5 +11,5 @@ public interface BlockStateCodec {
|
||||
|
||||
void deserialize(BlockState state, YamlConfiguration conf);
|
||||
|
||||
String toString(YamlConfiguration conf);
|
||||
String toString(YamlConfiguration conf, YamlConfiguration oldState);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class BlockStateCodecBanner implements BlockStateCodec {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(YamlConfiguration conf) {
|
||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class BlockStateCodecLectern implements BlockStateCodec {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(YamlConfiguration conf) {
|
||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||
if (conf != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[").append("book").append("]");
|
||||
|
@ -60,7 +60,7 @@ public class BlockStateCodecShulkerBox implements BlockStateCodec {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(YamlConfiguration conf) {
|
||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||
if (conf != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[");
|
||||
|
@ -40,6 +40,9 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
||||
if (signColor != DyeColor.BLACK) {
|
||||
conf.set("color", signColor.name());
|
||||
}
|
||||
if (sign.isGlowingText()) {
|
||||
conf.set("glowing", true);
|
||||
}
|
||||
return conf;
|
||||
}
|
||||
}
|
||||
@ -60,6 +63,7 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
DyeColor signColor = DyeColor.BLACK;
|
||||
boolean glowing = false;
|
||||
List<String> lines = Collections.emptyList();
|
||||
if (conf != null) {
|
||||
if (conf.contains("lines")) {
|
||||
@ -72,24 +76,69 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
glowing = conf.getBoolean("glowing", false);
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String line = lines.size() > i && lines.get(i) != null ? lines.get(i) : "";
|
||||
sign.setLine(i, line);
|
||||
}
|
||||
sign.setColor(signColor);
|
||||
sign.setGlowingText(glowing);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(YamlConfiguration conf) {
|
||||
if (conf != null) {
|
||||
public String toString(YamlConfiguration state, YamlConfiguration oldState) {
|
||||
if (state != null) {
|
||||
List<String> lines = state.getStringList("lines");
|
||||
List<String> oldLines = Collections.emptyList();
|
||||
DyeColor signColor = DyeColor.BLACK;
|
||||
if (state.contains("color")) {
|
||||
try {
|
||||
signColor = DyeColor.valueOf(state.getString("color"));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
DyeColor oldSignColor = DyeColor.BLACK;
|
||||
boolean glowing = state.getBoolean("glowing", false);
|
||||
boolean oldGlowing = false;
|
||||
if (oldState != null) {
|
||||
oldLines = oldState.getStringList("lines");
|
||||
if (oldState.contains("color")) {
|
||||
try {
|
||||
oldSignColor = DyeColor.valueOf(oldState.getString("color"));
|
||||
} catch (IllegalArgumentException | NullPointerException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
oldGlowing = oldState.getBoolean("glowing", false);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String line : conf.getStringList("lines")) {
|
||||
if (!lines.equals(oldLines)) {
|
||||
for (String line : lines) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append("[").append(line).append("]");
|
||||
}
|
||||
}
|
||||
if (signColor != oldSignColor) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
sb.append("[").append(line).append("]");
|
||||
sb.append("(color: " + signColor.name().toLowerCase() + ")");
|
||||
}
|
||||
if (glowing != oldGlowing) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
if (glowing) {
|
||||
sb.append("(glowing)");
|
||||
} else {
|
||||
sb.append("(not glowing)");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class BlockStateCodecSkull implements BlockStateCodec {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(YamlConfiguration conf) {
|
||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||
UUID ownerId = conf == null ? null : UUID.fromString(conf.getString("owner"));
|
||||
if (ownerId != null) {
|
||||
OfflinePlayer owner = Bukkit.getOfflinePlayer(ownerId);
|
||||
|
@ -48,7 +48,7 @@ public class BlockStateCodecSpawner implements BlockStateCodec {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(YamlConfiguration conf) {
|
||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||
if (conf != null) {
|
||||
EntityType entity = EntityType.valueOf(conf.getString("spawnedType"));
|
||||
if (entity != null) {
|
||||
|
@ -51,10 +51,10 @@ public class BlockStateCodecs {
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(Material material, YamlConfiguration state) {
|
||||
public static String toString(Material material, YamlConfiguration state, YamlConfiguration oldState) {
|
||||
BlockStateCodec codec = codecs.get(material);
|
||||
if (codec != null) {
|
||||
return codec.toString(state);
|
||||
return codec.toString(state, oldState);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user