Add some hover texts and clickable coords

This commit is contained in:
Brokkonaut
2019-12-20 05:15:45 +01:00
parent 169328e159
commit 31428d60e4
12 changed files with 85 additions and 50 deletions

View File

@ -101,11 +101,11 @@ public class BlockChange implements LookupCacheElement {
@Override
public String toString() {
return BaseComponent.toPlainText(getLogMessage());
return BaseComponent.toPlainText(getLogMessage(-1));
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
TextComponent msg = new TextComponent();
if (date > 0) {
msg.addExtra(prettyDate(date));
@ -132,108 +132,108 @@ public class BlockChange implements LookupCacheElement {
} else if (ca != null) {
if (ca.itemStack == null) {
msg.addExtra(createTextComponentWithColor("looked inside ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (ca.remove) {
msg.addExtra(createTextComponentWithColor("took ", DESTROY.getColor()));
msg.addExtra(BukkitUtils.toString(ca.itemStack));
msg.addExtra(createTextComponentWithColor(" from ", DESTROY.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else {
msg.addExtra(createTextComponentWithColor("put ", CREATE.getColor()));
msg.addExtra(BukkitUtils.toString(ca.itemStack));
msg.addExtra(createTextComponentWithColor(" into ", CREATE.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
}
} else if (type instanceof Waterlogged && ((Waterlogged) type).isWaterlogged() != ((Waterlogged) replaced).isWaterlogged()) {
if (((Waterlogged) type).isWaterlogged()) {
msg.addExtra(createTextComponentWithColor("waterlogged ", CREATE.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else {
msg.addExtra(createTextComponentWithColor("dried ", DESTROY.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
}
} else if (BukkitUtils.getContainerBlocks().contains(type.getMaterial())) {
msg.addExtra(createTextComponentWithColor("opened ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (type instanceof Openable && ((Openable) type).isOpen() != ((Openable) replaced).isOpen()) {
// Door, Trapdoor, Fence gate
msg.addExtra(createTextComponentWithColor(((Openable) type).isOpen() ? "opened " : "closed ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (type.getMaterial() == Material.LEVER && ((Switch) type).isPowered() != ((Switch) replaced).isPowered()) {
msg.addExtra(createTextComponentWithColor("switched ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(prettyState(((Switch) type).isPowered() ? " on" : " off"));
} else if (type instanceof Switch && ((Switch) type).isPowered() != ((Switch) replaced).isPowered()) {
msg.addExtra(createTextComponentWithColor("pressed ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (type.getMaterial() == Material.CAKE) {
msg.addExtra(createTextComponentWithColor("ate a piece of ", DESTROY.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (type.getMaterial() == Material.NOTE_BLOCK) {
Note note = ((NoteBlock) type).getNote();
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(" to ");
msg.addExtra(prettyState(note.getTone().name() + (note.isSharped() ? "#" : "")));
} else if (type.getMaterial() == Material.REPEATER) {
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(" to ");
msg.addExtra(prettyState(((Repeater) type).getDelay()));
msg.addExtra(createTextComponentWithColor(" ticks delay", DEFAULT.getColor()));
} else if (type.getMaterial() == Material.COMPARATOR) {
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(" to ");
msg.addExtra(prettyState(((Comparator) type).getMode()));
} else if (type.getMaterial() == Material.DAYLIGHT_DETECTOR) {
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(" to ");
msg.addExtra(prettyState(((DaylightDetector) type).isInverted() ? "inverted" : "normal"));
} else if (type instanceof Lectern) {
msg.addExtra(createTextComponentWithColor("changed the book on a ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(" to");
msg.addExtra(prettyState(typeDetails.length() == 0 ? " empty" : typeDetails));
} else if (type instanceof Powerable) {
msg.addExtra(createTextComponentWithColor("stepped on ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (type.getMaterial() == Material.TRIPWIRE) {
msg.addExtra(createTextComponentWithColor("ran into ", INTERACT.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
} else if (type instanceof Sign || type instanceof WallSign) {
msg.addExtra(createTextComponentWithColor("edited a ", CREATE.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(createTextComponentWithColor(" to ", CREATE.getColor()));
msg.addExtra(prettyState(typeDetails));
} else {
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
msg.addExtra(prettyMaterial(replaced.getMaterial()));
msg.addExtra(prettyMaterial(replaced));
msg.addExtra(prettyState(replacedDetails));
msg.addExtra(createTextComponentWithColor(" with ", CREATE.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(prettyState(typeDetails));
}
} else if (BukkitUtils.isEmpty(type.getMaterial())) {
msg.addExtra(createTextComponentWithColor("destroyed ", DESTROY.getColor()));
msg.addExtra(prettyMaterial(replaced.getMaterial()));
msg.addExtra(prettyMaterial(replaced));
msg.addExtra(prettyState(replacedDetails));
} else if (BukkitUtils.isEmpty(replaced.getMaterial())) {
msg.addExtra(createTextComponentWithColor("created ", CREATE.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(prettyState(typeDetails));
} else {
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
msg.addExtra(prettyMaterial(replaced.getMaterial()));
msg.addExtra(prettyMaterial(replaced));
msg.addExtra(prettyState(replacedDetails));
msg.addExtra(createTextComponentWithColor(" with ", CREATE.getColor()));
msg.addExtra(prettyMaterial(type.getMaterial()));
msg.addExtra(prettyMaterial(type));
msg.addExtra(prettyState(typeDetails));
}
if (loc != null) {
msg.addExtra(" at ");
msg.addExtra(prettyLocation(loc));
msg.addExtra(prettyLocation(loc, entry));
}
return new BaseComponent[] { msg };
}

View File

@ -39,7 +39,7 @@ public class ChatMessage implements LookupCacheElement {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
TextComponent msg = new TextComponent();
if (date > 0) {
msg.addExtra(prettyDate(date));

View File

@ -405,7 +405,7 @@ public class CommandsHandler implements CommandExecutor {
if (lookupElements[i].getLocation() != null) {
message.addExtra(new TextComponent("(" + (i + 1) + ") "));
}
for (BaseComponent component : lookupElements[i].getLogMessage()) {
for (BaseComponent component : lookupElements[i].getLogMessage(i + 1)) {
message.addExtra(component);
}
sender.spigot().sendMessage(message);

View File

@ -76,7 +76,7 @@ public class EntityChange implements LookupCacheElement {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
TextComponent msg = new TextComponent();
if (date > 0) {
msg.addExtra(prettyDate(date));
@ -123,7 +123,7 @@ public class EntityChange implements LookupCacheElement {
}
if (loc != null) {
msg.addExtra(" at ");
msg.addExtra(prettyLocation(loc));
msg.addExtra(prettyLocation(loc, entry));
}
return new BaseComponent[] { msg };
}

View File

@ -48,7 +48,7 @@ public class Kill implements LookupCacheElement {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
TextComponent msg = new TextComponent();
if (date > 0) {
msg.addExtra(prettyDate(date));
@ -58,7 +58,7 @@ public class Kill implements LookupCacheElement {
msg.addExtra(new TextComponent(victimName));
if (loc != null) {
msg.addExtra(" at ");
msg.addExtra(prettyLocation(loc));
msg.addExtra(prettyLocation(loc, entry));
}
if (weapon != 0) {
msg.addExtra(" with ");

View File

@ -6,5 +6,9 @@ import org.bukkit.Location;
public interface LookupCacheElement {
public Location getLocation();
public BaseComponent[] getLogMessage();
public default BaseComponent[] getLogMessage() {
return getLogMessage(-1);
}
public BaseComponent[] getLogMessage(int entry);
}

View File

@ -31,7 +31,7 @@ public class SummedBlockChanges implements LookupCacheElement {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
return MessagingUtil.formatSummarizedChanges(created, destroyed, actor != null ? new TextComponent(actor.getName()) : prettyMaterial(Objects.toString(MaterialConverter.getMaterial(type))), 10, 10, spaceFactor);
}
}

View File

@ -33,7 +33,7 @@ public class SummedEntityChanges implements LookupCacheElement {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
return MessagingUtil.formatSummarizedChanges(created, destroyed, actor != null ? new TextComponent(actor.getName()) : prettyMaterial(Objects.toString(EntityTypeConverter.getEntityType(type))), 10, 10, spaceFactor);
}
}

View File

@ -25,7 +25,7 @@ public class SummedKills implements LookupCacheElement {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
return MessagingUtil.formatSummarizedChanges(kills, killed, new TextComponent(player.getName()), 6, 7, spaceFactor);
}
}

View File

@ -476,7 +476,7 @@ public class WorldEditor implements Runnable {
}
@Override
public BaseComponent[] getLogMessage() {
public BaseComponent[] getLogMessage(int entry) {
return TextComponent.fromLegacyText(getMessage());
}
}

View File

@ -52,6 +52,7 @@ public class Config {
public static Set<String> hiddenPlayers;
public static List<String> ignoredChat;
public static SimpleDateFormat formatter;
public static SimpleDateFormat formatterShort;
public static boolean safetyIdCheck;
public static boolean debug;
public static boolean logEnvironmentalKills;
@ -121,11 +122,17 @@ public class Config {
def.put("lookup.linesLimit", 1500);
def.put("lookup.hardLinesLimit", 100000);
try {
formatter = new SimpleDateFormat(config.getString("lookup.dateFormat", "MM-dd HH:mm:ss"));
formatter = new SimpleDateFormat(config.getString("lookup.dateFormat", "yyyy-MM-dd HH:mm:ss"));
} catch (IllegalArgumentException e) {
throw new DataFormatException("Invalid specification for date format, please see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html : " + e.getMessage());
}
def.put("lookup.dateFormat", "MM-dd HH:mm:ss");
def.put("lookup.dateFormat", "yyyy-MM-dd HH:mm:ss");
try {
formatterShort = new SimpleDateFormat(config.getString("lookup.dateFormatShort", "MM-dd HH:mm"));
} catch (IllegalArgumentException e) {
throw new DataFormatException("Invalid specification for date format, please see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html : " + e.getMessage());
}
def.put("lookup.dateFormatShort", "MM-dd HH:mm");
def.put("questioner.askRollbacks", true);
def.put("questioner.askRedos", true);
def.put("questioner.askClearLogs", true);

View File

@ -8,9 +8,13 @@ import static de.diddiz.util.Utils.spaces;
import de.diddiz.LogBlock.config.Config;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EntityType;
public class MessagingUtil {
@ -36,7 +40,9 @@ public class MessagingUtil {
}
public static TextComponent prettyDate(long date) {
return brackets(BracketType.STANDARD, createTextComponentWithColor(Config.formatter.format(date), TypeColor.DATE.getColor()));
TextComponent tc = brackets(BracketType.STANDARD, createTextComponentWithColor(Config.formatterShort.format(date), TypeColor.DATE.getColor()));
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(Config.formatter.format(date)).create()));
return tc;
}
public static TextComponent prettyState(String stateName) {
@ -59,21 +65,39 @@ public class MessagingUtil {
return prettyMaterial(material.name());
}
public static TextComponent prettyMaterial(BlockData material) {
TextComponent tc = prettyMaterial(material.getMaterial());
String bdString = material.getAsString();
int bracket = bdString.indexOf("[");
if (bracket >= 0) {
int bracket2 = bdString.indexOf("]", bracket);
if (bracket2 >= 0) {
String state = bdString.substring(bracket + 1, bracket2).replace(',', '\n');
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(state).create()));
}
}
return tc;
}
public static TextComponent prettyEntityType(EntityType type) {
return prettyMaterial(type.name());
}
public static TextComponent prettyLocation(Location loc) {
return prettyLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
public static TextComponent prettyLocation(Location loc, int entryId) {
return prettyLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), entryId);
}
public static TextComponent prettyLocation(Number x, Number y, Number z) {
TextComponent tc = createTextComponentWithColor("X: ", DEFAULT.getColor());
tc.addExtra(createTextComponentWithColor(Integer.toString(x.intValue()), TypeColor.COORDINATE.getColor()));
tc.addExtra(createTextComponentWithColor(", Y: ", DEFAULT.getColor()));
tc.addExtra(createTextComponentWithColor(Integer.toString(y.intValue()), TypeColor.COORDINATE.getColor()));
tc.addExtra(createTextComponentWithColor(", Z: ", DEFAULT.getColor()));
tc.addExtra(createTextComponentWithColor(Integer.toString(z.intValue()), TypeColor.COORDINATE.getColor()));
public static TextComponent prettyLocation(int x, int y, int z, int entryId) {
TextComponent tc = createTextComponentWithColor("", DEFAULT.getColor());
tc.addExtra(createTextComponentWithColor(Integer.toString(x), TypeColor.COORDINATE.getColor()));
tc.addExtra(createTextComponentWithColor(", ", DEFAULT.getColor()));
tc.addExtra(createTextComponentWithColor(Integer.toString(y), TypeColor.COORDINATE.getColor()));
tc.addExtra(createTextComponentWithColor(", ", DEFAULT.getColor()));
tc.addExtra(createTextComponentWithColor(Integer.toString(z), TypeColor.COORDINATE.getColor()));
if (entryId > 0) {
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/lb tp " + entryId));
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Teleport here").create()));
}
return tc;
}