Skip to content

Commit

Permalink
feat(data): ✨ debug message
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jun 17, 2024
1 parent 078c114 commit bdc3032
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static LiteralCommandNode<CommandSource> createDataCommand(AltairVelocity
.executes(context -> {
context.getSource().sendMessage(
Component.text("----- Data Command Help -----\n", NamedTextColor.GREEN)
.append(Component.text("/altair data update - Update data", NamedTextColor.WHITE))
.append(Component.text("/altair data update - Update data\n", NamedTextColor.WHITE))
.append(Component.text("/altair data debug - Show debug info\n", NamedTextColor.WHITE))
);
return Command.SINGLE_SUCCESS;
})
Expand All @@ -41,6 +42,14 @@ public static LiteralCommandNode<CommandSource> createDataCommand(AltairVelocity
})
.build()
)
.then(
BrigadierCommand.literalArgumentBuilder("debug")
.executes(context -> {
context.getSource().sendMessage(Component.text(altairVelocity.getDataManager().getDebugInfo()));
return Command.SINGLE_SUCCESS;
})
.build()
)
.build();
}
}
26 changes: 16 additions & 10 deletions src/main/java/org/bsrserver/altair/velocity/data/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ public DataManager(AltairVelocity altairVelocity) {
);
}

private Cache getCache() {
return Cache
.builder()
.accountHashMap(accountHashMap)
.quotations(quotations)
.minecraftProfileHashMap(minecraftProfileHashMap)
.serverInfoHashMap(serverInfoHashMap)
.serverGroups(serverGroups)
.build();
}

private void saveToFile() {
try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(cacheFile))) {
objectOutputStream.writeObject(
Cache
.builder()
.accountHashMap(accountHashMap)
.quotations(quotations)
.minecraftProfileHashMap(minecraftProfileHashMap)
.serverInfoHashMap(serverInfoHashMap)
.serverGroups(serverGroups)
.build()
);
objectOutputStream.writeObject(getCache());
} catch (IOException e) {
logger.error("Failed to save cache to file.", e);
}
Expand Down Expand Up @@ -278,6 +280,10 @@ synchronized public void updateData() {
fillServerGroups();
}

public String getDebugInfo() {
return "Cache: " + getCache().toString();
}

public Optional<ServerInfo> getServerInfo(String serverName) {
return Optional.ofNullable(serverInfoHashMap.get(serverName));
}
Expand Down

0 comments on commit bdc3032

Please sign in to comment.