Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/org/mintype/logging/DataBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ public static JsonObject explosion(

return json;
}

public static JsonObject itemChange(
String action,
String item,
int amount
) {
JsonObject json = new JsonObject();

json.addProperty("action", action);
json.addProperty("item", item);
json.addProperty("amount", amount);

return json;
}
}
203 changes: 115 additions & 88 deletions src/main/java/org/mintype/logging/LogFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,9 @@
public class LogFormatter {

private static final int ORANGE = 0xFF9900;
private static final int GRAY = 0x808080;

// public static Component format(LogEntry log) {
//
// MutableComponent message = Component.empty();
//
// // ----- [Forensic] ----- (x:y:z)
// message.append(
// Component.literal("----- ")
// );
//
// message.append(
// Component.literal("[Forensic]")
// .withColor(ORANGE)
// );
//
// message.append(
// Component.literal(
// " ----- (x:" +
// log.x() +
// "/y:" +
// log.y() +
// "/z:" +
// log.z() +
// ")"
// ).withColor(GRAY)
// );
//
//
// // Time ago
// message.append(
// Component.literal(
// "\n" + formatTime(log.timestamp()) + " ago - "
// ).withColor(GRAY)
// );
//
//
// // Player
// if (log.player() != null) {
// message.append(
// Component.literal(
// log.player().toString()
// ).withColor(ORANGE)
// );
// } else {
// message.append(
// Component.literal("Unknown")
// );
// }
//
//
// // Action
// message.append(
// Component.literal(
// " " + formatAction(log)
// )
// );
//
//
// // Block
// if (log.data() != null && log.data().has("block")) {
//
// message.append(
// Component.literal(" (")
// );
//
// message.append(
// Component.literal(
// log.data()
// .get("block")
// .getAsString()
// ).withColor(ORANGE)
// );
//
// message.append(
// Component.literal(")")
// );
// }
//
//
// return message;
// }
private static final int GRAY = 0x808080;
private static final int GREEN = 0x00FF00;
private static final int RED = 0xFF0000;

private static String formatAction(LogEntry log) {

Expand Down Expand Up @@ -171,6 +92,7 @@ public static Component formatLogs(List<LogEntry> logs) {
// Header once
message.append(
Component.literal("----- ")
.withColor(GRAY)
);

message.append(
Expand Down Expand Up @@ -208,6 +130,117 @@ public static Component formatLogs(List<LogEntry> logs) {

private static Component formatEntry(LogEntry log) {

return switch (log.action()) {
case EXPLOSION -> formatExplosion(log);
case CONTAINER_OPEN -> formatContainerOpen(log);
case CONTAINER_CHANGE -> formatContainerChange(log);
default -> formatNormal(log);
};
}

private static Component formatContainerOpen(LogEntry log) {

MutableComponent message = Component.empty();

message.append(
Component.literal(
formatTime(log.timestamp()) + " ago - "
).withColor(GRAY)
);

if (log.playerName() != null) {
message.append(
Component.literal(log.playerName())
.withColor(ORANGE)
);
} else {
message.append(
Component.literal("Unknown")
);
}

message.append(
Component.literal(" opened ")
);

if (log.data() != null && log.data().has("block")) {
message.append(
Component.literal(
log.data().get("block").getAsString()
).withColor(ORANGE)
);
} else {
message.append(
Component.literal("container")
);
}

return message;
}

private static Component formatContainerChange(LogEntry log) {

MutableComponent message = Component.empty();

message.append(
Component.literal(
formatTime(log.timestamp()) + " ago - "
).withColor(GRAY)
);

if (log.playerName() != null) {
message.append(
Component.literal(log.playerName())
.withColor(ORANGE)
);
} else {
message.append(Component.literal("Unknown"));
}

String action = log.data().get("action").getAsString();

int amountColor = GREEN;

switch (action) {

case "inserted" ->
message.append(Component.literal(" inserted "));

case "removed" -> {
message.append(Component.literal(" removed "));
amountColor = RED;
}

case "changed" ->
message.append(Component.literal(" changed "));

default ->
message.append(Component.literal(" modified "));
}

String item = log.data().get("item").getAsString();

if (item.contains(":")) {
item = item.substring(item.indexOf(':') + 1);
}

int amount = log.data().get("amount").getAsInt();

message.append(
Component.literal(amount + " ")
.withColor(amountColor)
);

message.append(
Component.literal(item)
.withColor(ORANGE)
);

return message;
}

private static Component formatNormal(LogEntry log) {

if (log.action() == ActionType.EXPLOSION) {
return formatExplosion(log);
}
Expand Down Expand Up @@ -247,10 +280,6 @@ private static Component formatEntry(LogEntry log) {
.getAsString()
).withColor(ORANGE)
);

// message.append(
// Component.literal(")")
// );
}

return message;
Expand All @@ -268,8 +297,6 @@ private static Component formatExplosion(LogEntry log) {

String block = log.data().get("block").getAsString();

// message.append(Component.literal("("));

message.append(
Component.literal(block)
.withColor(ORANGE)
Expand Down
Loading