forked from LogBlock/LogBlock
improve block state display
This commit is contained in:
@ -83,25 +83,27 @@ public class BlockChange implements LookupCacheElement {
|
|||||||
ca = catemp;
|
ca = catemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTypeDetails(BlockData type, byte[] typeState) {
|
private BaseComponent getTypeDetails(BlockData type, byte[] typeState) {
|
||||||
return getTypeDetails(type, typeState, null, null);
|
return getTypeDetails(type, typeState, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTypeDetails(BlockData type, byte[] typeState, BlockData oldType, byte[] oldTypeState) {
|
private BaseComponent getTypeDetails(BlockData type, byte[] typeState, BlockData oldType, byte[] oldTypeState) {
|
||||||
String typeDetails = null;
|
BaseComponent typeDetails = null;
|
||||||
|
|
||||||
if (BlockStateCodecs.hasCodec(type.getMaterial())) {
|
if (BlockStateCodecs.hasCodec(type.getMaterial())) {
|
||||||
try {
|
try {
|
||||||
typeDetails = BlockStateCodecs.toString(type.getMaterial(), Utils.deserializeYamlConfiguration(typeState), type.equals(oldType) ? Utils.deserializeYamlConfiguration(oldTypeState) : null);
|
typeDetails = BlockStateCodecs.getChangesAsComponent(type.getMaterial(), Utils.deserializeYamlConfiguration(typeState), type.equals(oldType) ? Utils.deserializeYamlConfiguration(oldTypeState) : null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not parse BlockState for " + type.getMaterial(), e);
|
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not parse BlockState for " + type.getMaterial(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeDetails == null) {
|
if (typeDetails == null) {
|
||||||
return "";
|
return new TextComponent("");
|
||||||
} else {
|
} else {
|
||||||
return " " + typeDetails;
|
TextComponent component = new TextComponent(" ");
|
||||||
|
component.addExtra(typeDetails);
|
||||||
|
return component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +131,8 @@ public class BlockChange implements LookupCacheElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process type details once for later use.
|
// Process type details once for later use.
|
||||||
String typeDetails = getTypeDetails(type, typeState, replaced, replacedState);
|
BaseComponent typeDetails = getTypeDetails(type, typeState, replaced, replacedState);
|
||||||
String replacedDetails = getTypeDetails(replaced, replacedState);
|
BaseComponent replacedDetails = getTypeDetails(replaced, replacedState);
|
||||||
|
|
||||||
if (type.getMaterial().equals(replaced.getMaterial()) || (type.getMaterial() == Material.CAKE && BukkitUtils.isCandleCake(replaced.getMaterial()))) {
|
if (type.getMaterial().equals(replaced.getMaterial()) || (type.getMaterial() == Material.CAKE && BukkitUtils.isCandleCake(replaced.getMaterial()))) {
|
||||||
if (BukkitUtils.isEmpty(type.getMaterial())) {
|
if (BukkitUtils.isEmpty(type.getMaterial())) {
|
||||||
@ -201,7 +203,7 @@ public class BlockChange implements LookupCacheElement {
|
|||||||
msg.addExtra(createTextComponentWithColor("changed the book on a ", INTERACT.getColor()));
|
msg.addExtra(createTextComponentWithColor("changed the book on a ", INTERACT.getColor()));
|
||||||
msg.addExtra(prettyMaterial(type));
|
msg.addExtra(prettyMaterial(type));
|
||||||
msg.addExtra(" to");
|
msg.addExtra(" to");
|
||||||
msg.addExtra(prettyState(typeDetails.length() == 0 ? " empty" : typeDetails));
|
msg.addExtra(prettyState(typeDetails));
|
||||||
} else if (type instanceof Powerable) {
|
} else if (type instanceof Powerable) {
|
||||||
msg.addExtra(createTextComponentWithColor("stepped on ", INTERACT.getColor()));
|
msg.addExtra(createTextComponentWithColor("stepped on ", INTERACT.getColor()));
|
||||||
msg.addExtra(prettyMaterial(type));
|
msg.addExtra(prettyMaterial(type));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package de.diddiz.LogBlock.blockstate;
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -11,5 +12,5 @@ public interface BlockStateCodec {
|
|||||||
|
|
||||||
void deserialize(BlockState state, YamlConfiguration conf);
|
void deserialize(BlockState state, YamlConfiguration conf);
|
||||||
|
|
||||||
String toString(YamlConfiguration conf, YamlConfiguration oldState);
|
BaseComponent getChangesAsComponent(YamlConfiguration conf, YamlConfiguration oldState);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.diddiz.LogBlock.blockstate;
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Banner;
|
import org.bukkit.block.Banner;
|
||||||
@ -64,7 +64,7 @@ public class BlockStateCodecBanner implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
public BaseComponent getChangesAsComponent(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.diddiz.LogBlock.blockstate;
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Lectern;
|
import org.bukkit.block.Lectern;
|
||||||
@ -43,12 +45,10 @@ public class BlockStateCodecLectern implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
public BaseComponent getChangesAsComponent(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||||
if (conf != null) {
|
if (conf != null) {
|
||||||
StringBuilder sb = new StringBuilder();
|
return new TextComponent("[book]");
|
||||||
sb.append("[").append("book").append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
return null;
|
return new TextComponent("empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
|||||||
import de.diddiz.LogBlock.Logging;
|
import de.diddiz.LogBlock.Logging;
|
||||||
import de.diddiz.LogBlock.config.WorldConfig;
|
import de.diddiz.LogBlock.config.WorldConfig;
|
||||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.ShulkerBox;
|
import org.bukkit.block.ShulkerBox;
|
||||||
@ -60,7 +62,7 @@ public class BlockStateCodecShulkerBox implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
public BaseComponent getChangesAsComponent(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||||
if (conf != null) {
|
if (conf != null) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("[");
|
sb.append("[");
|
||||||
@ -78,7 +80,7 @@ public class BlockStateCodecShulkerBox implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
return anySlot ? sb.toString() : null;
|
return anySlot ? new TextComponent(sb.toString()) : null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,13 @@ package de.diddiz.LogBlock.blockstate;
|
|||||||
|
|
||||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||||
import de.diddiz.LogBlock.util.Reflections;
|
import de.diddiz.LogBlock.util.Reflections;
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -123,20 +127,21 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(YamlConfiguration state, YamlConfiguration oldState) {
|
public BaseComponent getChangesAsComponent(YamlConfiguration state, YamlConfiguration oldState) {
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
StringBuilder sb = new StringBuilder();
|
TextComponent tc = new TextComponent();
|
||||||
|
// StringBuilder sb = new StringBuilder();
|
||||||
boolean isWaxed = state.getBoolean("waxed");
|
boolean isWaxed = state.getBoolean("waxed");
|
||||||
boolean oldWaxed = oldState != null && oldState.getBoolean("waxed");
|
boolean oldWaxed = oldState != null && oldState.getBoolean("waxed");
|
||||||
if (isWaxed != oldWaxed) {
|
if (isWaxed != oldWaxed) {
|
||||||
sb.append(isWaxed ? "(waxed)" : "(not waxed)");
|
tc.addExtra(isWaxed ? "(waxed)" : "(not waxed)");
|
||||||
}
|
}
|
||||||
for (Side side : Side.values()) {
|
for (Side side : Side.values()) {
|
||||||
ConfigurationSection sideSection = side == Side.FRONT ? state : state.getConfigurationSection(side.name().toLowerCase());
|
ConfigurationSection sideSection = side == Side.FRONT ? state : state.getConfigurationSection(side.name().toLowerCase());
|
||||||
if (!sb.isEmpty()) {
|
if (tc.getExtra() != null && !tc.getExtra().isEmpty()) {
|
||||||
sb.append(" ");
|
tc.addExtra(" ");
|
||||||
}
|
}
|
||||||
sb.append(side.name()).append(":");
|
tc.addExtra(side.name() + ":");
|
||||||
|
|
||||||
List<String> lines = sideSection == null ? Collections.emptyList() : sideSection.getStringList("lines");
|
List<String> lines = sideSection == null ? Collections.emptyList() : sideSection.getStringList("lines");
|
||||||
List<String> oldLines = Collections.emptyList();
|
List<String> oldLines = Collections.emptyList();
|
||||||
@ -168,30 +173,38 @@ public class BlockStateCodecSign implements BlockStateCodec {
|
|||||||
|
|
||||||
if (!lines.equals(oldLines)) {
|
if (!lines.equals(oldLines)) {
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
if (sb.length() > 0) {
|
if (tc.getExtra() != null && !tc.getExtra().isEmpty()) {
|
||||||
sb.append(" ");
|
tc.addExtra(" ");
|
||||||
}
|
}
|
||||||
sb.append("[").append(line).append("]");
|
tc.addExtra("[");
|
||||||
|
if (line != null && !line.isEmpty()) {
|
||||||
|
tc.addExtra(new TextComponent(TextComponent.fromLegacyText(line)));
|
||||||
|
}
|
||||||
|
tc.addExtra("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (signColor != oldSignColor) {
|
if (signColor != oldSignColor) {
|
||||||
if (sb.length() > 0) {
|
if (tc.getExtra() != null && !tc.getExtra().isEmpty()) {
|
||||||
sb.append(" ");
|
tc.addExtra(" ");
|
||||||
}
|
}
|
||||||
sb.append("(color: " + signColor.name().toLowerCase() + ")");
|
tc.addExtra("(color: ");
|
||||||
|
TextComponent colorText = new TextComponent(signColor.name().toLowerCase());
|
||||||
|
colorText.setColor(ChatColor.of(new Color(signColor.getColor().asARGB())));
|
||||||
|
tc.addExtra(colorText);
|
||||||
|
tc.addExtra(")");
|
||||||
}
|
}
|
||||||
if (glowing != oldGlowing) {
|
if (glowing != oldGlowing) {
|
||||||
if (sb.length() > 0) {
|
if (tc.getExtra() != null && !tc.getExtra().isEmpty()) {
|
||||||
sb.append(" ");
|
tc.addExtra(" ");
|
||||||
}
|
}
|
||||||
if (glowing) {
|
if (glowing) {
|
||||||
sb.append("(glowing)");
|
tc.addExtra("(glowing)");
|
||||||
} else {
|
} else {
|
||||||
sb.append("(not glowing)");
|
tc.addExtra("(not glowing)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return tc;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package de.diddiz.LogBlock.blockstate;
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -65,18 +68,22 @@ public class BlockStateCodecSkull implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
public BaseComponent getChangesAsComponent(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||||
if (HAS_PROFILE_API && conf != null) {
|
if (HAS_PROFILE_API && conf != null) {
|
||||||
PlayerProfile profile = (PlayerProfile) conf.get("profile");
|
PlayerProfile profile = (PlayerProfile) conf.get("profile");
|
||||||
if (profile != null) {
|
if (profile != null) {
|
||||||
return "[" + (profile.getName() != null ? profile.getName() : (profile.getUniqueId() != null ? profile.getUniqueId().toString() : "~unknown~")) + "]";
|
TextComponent tc = new TextComponent("[" + (profile.getName() != null ? profile.getName() : (profile.getUniqueId() != null ? profile.getUniqueId().toString() : "~unknown~")) + "]");
|
||||||
|
if (profile.getName() != null) {
|
||||||
|
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("UUID: " + profile.getUniqueId().toString())));
|
||||||
|
}
|
||||||
|
return tc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String ownerIdString = conf == null ? null : conf.getString("owner");
|
String ownerIdString = conf == null ? null : conf.getString("owner");
|
||||||
UUID ownerId = ownerIdString == null ? null : UUID.fromString(ownerIdString);
|
UUID ownerId = ownerIdString == null ? null : UUID.fromString(ownerIdString);
|
||||||
if (ownerId != null) {
|
if (ownerId != null) {
|
||||||
OfflinePlayer owner = Bukkit.getOfflinePlayer(ownerId);
|
OfflinePlayer owner = Bukkit.getOfflinePlayer(ownerId);
|
||||||
return "[" + (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "]";
|
return new TextComponent("[" + (owner.getName() != null ? owner.getName() : owner.getUniqueId().toString()) + "]");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.diddiz.LogBlock.blockstate;
|
package de.diddiz.LogBlock.blockstate;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
@ -48,11 +50,11 @@ public class BlockStateCodecSpawner implements BlockStateCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(YamlConfiguration conf, YamlConfiguration oldState) {
|
public BaseComponent getChangesAsComponent(YamlConfiguration conf, YamlConfiguration oldState) {
|
||||||
if (conf != null) {
|
if (conf != null) {
|
||||||
EntityType entity = EntityType.valueOf(conf.getString("spawnedType"));
|
EntityType entity = EntityType.valueOf(conf.getString("spawnedType"));
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
return "[" + entity + "]";
|
return new TextComponent("[" + entity.getKey().getKey() + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -2,7 +2,7 @@ package de.diddiz.LogBlock.blockstate;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
@ -51,10 +51,10 @@ public class BlockStateCodecs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toString(Material material, YamlConfiguration state, YamlConfiguration oldState) {
|
public static BaseComponent getChangesAsComponent(Material material, YamlConfiguration state, YamlConfiguration oldState) {
|
||||||
BlockStateCodec codec = codecs.get(material);
|
BlockStateCodec codec = codecs.get(material);
|
||||||
if (codec != null) {
|
if (codec != null) {
|
||||||
return codec.toString(state, oldState);
|
return codec.getChangesAsComponent(state, oldState);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,15 @@ public class MessagingUtil {
|
|||||||
return createTextComponentWithColor(stateName, TypeColor.STATE.getColor());
|
return createTextComponentWithColor(stateName, TypeColor.STATE.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TextComponent prettyState(BaseComponent stateName) {
|
||||||
|
TextComponent tc = new TextComponent();
|
||||||
|
tc.setColor(TypeColor.STATE.getColor());
|
||||||
|
if (stateName != null) {
|
||||||
|
tc.addExtra(stateName);
|
||||||
|
}
|
||||||
|
return tc;
|
||||||
|
}
|
||||||
|
|
||||||
public static TextComponent prettyState(int stateValue) {
|
public static TextComponent prettyState(int stateValue) {
|
||||||
return prettyState(Integer.toString(stateValue));
|
return prettyState(Integer.toString(stateValue));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user