1.5.1
This commit is contained in:
parent
829ed6d96c
commit
f2f89c62bb
15 changed files with 485 additions and 0 deletions
|
|
@ -0,0 +1,40 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GStatsCommand;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GStatsBaseCommand implements CommandExecutor {
|
||||
public GStatsBaseCommand() {
|
||||
}
|
||||
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
boolean var10000;
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "self_history":
|
||||
var10000 = SelfHistory.subCommand(player, args);
|
||||
break;
|
||||
case "others_history":
|
||||
var10000 = OthersHistory.subCommand(player, args);
|
||||
break;
|
||||
case "commands":
|
||||
var10000 = player.performCommand("grimmsserver:grimmsServerCommands");
|
||||
break;
|
||||
default:
|
||||
var10000 = false;
|
||||
}
|
||||
|
||||
return var10000;
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Only players can use this command.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GStatsCommand;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GStatsTabCompleter implements TabCompleter {
|
||||
private static final List<String> SUBCOMMANDS = Arrays.asList("self_history", "others_history", "commands");
|
||||
private static final List<String> TIME_RANGES = Arrays.asList("hour", "day", "week", "month", "all");
|
||||
|
||||
public GStatsTabCompleter() {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
String partial = args[0].toLowerCase();
|
||||
List<String> suggestions = new ArrayList();
|
||||
|
||||
for (String subcommand : SUBCOMMANDS) {
|
||||
if (subcommand.startsWith(partial)) {
|
||||
suggestions.add(subcommand);
|
||||
}
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
} else if (args.length == 2) {
|
||||
String subcommand = args[0].toLowerCase();
|
||||
if (subcommand.equals("others_history")) {
|
||||
String partialPlayer = args[1].toLowerCase();
|
||||
List<String> playerSuggestions = new ArrayList();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.getName().toLowerCase().startsWith(partialPlayer)) {
|
||||
playerSuggestions.add(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return playerSuggestions;
|
||||
} else if (subcommand.equals("self_history")) {
|
||||
String partialTime = args[1].toLowerCase();
|
||||
List<String> timeSuggestions = new ArrayList();
|
||||
|
||||
for (String timeRange : TIME_RANGES) {
|
||||
if (timeRange.startsWith(partialTime)) {
|
||||
timeSuggestions.add(timeRange);
|
||||
}
|
||||
}
|
||||
|
||||
return timeSuggestions;
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
String subcommand = args[0].toLowerCase();
|
||||
if (subcommand.equals("others_history")) {
|
||||
String partialTime = args[2].toLowerCase();
|
||||
List<String> timeSuggestions = new ArrayList();
|
||||
|
||||
for (String timeRange : TIME_RANGES) {
|
||||
if (timeRange.startsWith(partialTime)) {
|
||||
timeSuggestions.add(timeRange);
|
||||
}
|
||||
}
|
||||
|
||||
return timeSuggestions;
|
||||
} else if (subcommand.equals("self_history")) {
|
||||
String partialStat = args[2].toLowerCase();
|
||||
List<String> statSuggestions = new ArrayList();
|
||||
|
||||
for (String stat : PlayerStats.StatOrder) {
|
||||
if (stat.startsWith(partialStat)) {
|
||||
statSuggestions.add(stat);
|
||||
}
|
||||
}
|
||||
|
||||
return statSuggestions;
|
||||
}
|
||||
} else if (args.length == 4) {
|
||||
String subcommand = args[0].toLowerCase();
|
||||
if (subcommand.equals("others_history")) {
|
||||
String partialStat = args[3].toLowerCase();
|
||||
List<String> statSuggestions = new ArrayList();
|
||||
|
||||
for (String stat : PlayerStats.StatOrder) {
|
||||
if (stat.startsWith(partialStat)) {
|
||||
statSuggestions.add(stat);
|
||||
}
|
||||
}
|
||||
|
||||
return statSuggestions;
|
||||
}
|
||||
}
|
||||
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GStatsCommand;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Manage.GeneralChatHandler;
|
||||
import org.gsdistance.grimmsServer.Stats.HistoricalStatsSnapshot;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerHistoricalStats;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OthersHistory {
|
||||
public OthersHistory() {
|
||||
}
|
||||
|
||||
public static boolean subCommand(Player player, String[] args) {
|
||||
if (!player.hasPermission("grimmsserver.stats.other")) {
|
||||
player.sendMessage(ChatColor.RED + "You don't have permission to view other players' history.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /gStats others_history <player> [timeRange] [stat]");
|
||||
return true;
|
||||
}
|
||||
|
||||
String targetPlayerName = args[1];
|
||||
OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(targetPlayerName);
|
||||
|
||||
if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline()) {
|
||||
player.sendMessage(ChatColor.RED + "Player '" + targetPlayerName + "' not found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
UUID targetUUID = targetPlayer.getUniqueId();
|
||||
PlayerHistoricalStats historicalStats = PlayerHistoricalStats.getPlayerHistoricalStats(targetUUID);
|
||||
|
||||
if (historicalStats.allTimeSnapshots.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + "No historical data available for " + targetPlayerName + ".");
|
||||
player.sendMessage(ChatColor.YELLOW + "Data is recorded when players join, quit, and hourly while online.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String timeRange = "all";
|
||||
String specificStat = null;
|
||||
|
||||
if (args.length >= 3) {
|
||||
timeRange = args[2].toLowerCase();
|
||||
}
|
||||
if (args.length >= 4) {
|
||||
specificStat = args[3].toLowerCase();
|
||||
}
|
||||
|
||||
List<HistoricalStatsSnapshot> snapshots = SelfHistory.filterSnapshotsByTime(historicalStats.allTimeSnapshots, timeRange);
|
||||
|
||||
if (snapshots.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + "No data available for the specified time range.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.GOLD + "=== " + targetPlayerName + "'s Stats History ===");
|
||||
|
||||
if (specificStat != null && PlayerStats.Stats.get(specificStat) != null) {
|
||||
SelfHistory.displaySingleStatGraph(player, snapshots, specificStat, timeRange);
|
||||
} else {
|
||||
SelfHistory.displayAllStatsGraph(player, snapshots, timeRange);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
package org.gsdistance.grimmsServer.Commands.GStatsCommand;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Manage.GeneralChatHandler;
|
||||
import org.gsdistance.grimmsServer.Shared;
|
||||
import org.gsdistance.grimmsServer.Stats.HistoricalStatsSnapshot;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerHistoricalStats;
|
||||
import org.gsdistance.grimmsServer.Stats.PlayerStats;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SelfHistory {
|
||||
public SelfHistory() {
|
||||
}
|
||||
|
||||
public static boolean subCommand(Player player, String[] args) {
|
||||
if (!player.hasPermission("grimmsserver.stats.self")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerHistoricalStats historicalStats = PlayerHistoricalStats.getPlayerHistoricalStats(player);
|
||||
|
||||
if (historicalStats.allTimeSnapshots.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + "No historical data available yet.");
|
||||
player.sendMessage(ChatColor.YELLOW + "Data is recorded when you join, quit, and hourly while online.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String timeRange = "all";
|
||||
String specificStat = null;
|
||||
|
||||
if (args.length >= 2) {
|
||||
timeRange = args[1].toLowerCase();
|
||||
}
|
||||
if (args.length >= 3) {
|
||||
specificStat = args[2].toLowerCase();
|
||||
}
|
||||
|
||||
List<HistoricalStatsSnapshot> snapshots = filterSnapshotsByTime(historicalStats.allTimeSnapshots, timeRange);
|
||||
|
||||
if (snapshots.isEmpty()) {
|
||||
player.sendMessage(ChatColor.RED + "No data available for the specified time range.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (specificStat != null && !PlayerStats.Stats.get(specificStat).equals(null)) {
|
||||
displaySingleStatGraph(player, snapshots, specificStat, timeRange);
|
||||
} else {
|
||||
displayAllStatsGraph(player, snapshots, timeRange);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<HistoricalStatsSnapshot> filterSnapshotsByTime(List<HistoricalStatsSnapshot> allSnapshots, String timeRange) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
List<HistoricalStatsSnapshot> filtered = new ArrayList<>();
|
||||
|
||||
for (HistoricalStatsSnapshot snapshot : allSnapshots) {
|
||||
try {
|
||||
LocalDateTime snapshotTime = LocalDateTime.parse(snapshot.getTimestamp());
|
||||
long hoursDiff = java.time.Duration.between(snapshotTime, now).toHours();
|
||||
|
||||
switch (timeRange) {
|
||||
case "hour":
|
||||
if (hoursDiff <= 1) filtered.add(snapshot);
|
||||
break;
|
||||
case "day":
|
||||
if (hoursDiff <= 24) filtered.add(snapshot);
|
||||
break;
|
||||
case "week":
|
||||
if (hoursDiff <= 168) filtered.add(snapshot);
|
||||
break;
|
||||
case "month":
|
||||
if (hoursDiff <= 720) filtered.add(snapshot);
|
||||
break;
|
||||
case "all":
|
||||
default:
|
||||
filtered.add(snapshot);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
filtered.add(snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static void displaySingleStatGraph(Player player, List<HistoricalStatsSnapshot> snapshots, String statName, String timeRange) {
|
||||
ArrayList<String> messages = new ArrayList<>();
|
||||
String displayName = PlayerStats.StatNames.get(statName);
|
||||
|
||||
messages.add(ChatColor.GOLD + "=== " + displayName + " History (" + timeRange + ") ===");
|
||||
messages.add(ChatColor.GRAY + "Showing " + snapshots.size() + " data points");
|
||||
|
||||
if (snapshots.size() < 2) {
|
||||
messages.add(ChatColor.YELLOW + "Not enough data points to display graph.");
|
||||
for (HistoricalStatsSnapshot snapshot : snapshots) {
|
||||
Object value = snapshot.getStat(statName);
|
||||
String formattedValue = formatStatValue(statName, value);
|
||||
messages.add(ChatColor.WHITE + formatTimestamp(snapshot.getTimestamp()) + ": " + ChatColor.GREEN + formattedValue);
|
||||
}
|
||||
} else {
|
||||
double[] values = new double[snapshots.size()];
|
||||
double minValue = Double.MAX_VALUE;
|
||||
double maxValue = Double.MIN_VALUE;
|
||||
|
||||
for (int i = 0; i < snapshots.size(); i++) {
|
||||
Object value = snapshots.get(i).getStat(statName);
|
||||
double numValue = convertToDouble(value);
|
||||
values[i] = numValue;
|
||||
if (numValue < minValue) minValue = numValue;
|
||||
if (numValue > maxValue) maxValue = numValue;
|
||||
}
|
||||
|
||||
if (maxValue == minValue) {
|
||||
maxValue += 1;
|
||||
}
|
||||
|
||||
int graphHeight = 10;
|
||||
int graphWidth = Math.min(snapshots.size(), 40);
|
||||
|
||||
messages.add(ChatColor.GRAY + "Min: " + ChatColor.AQUA + formatStatValue(statName, minValue) +
|
||||
ChatColor.GRAY + " | Max: " + ChatColor.AQUA + formatStatValue(statName, maxValue));
|
||||
|
||||
for (int row = graphHeight; row >= 0; row--) {
|
||||
StringBuilder line = new StringBuilder();
|
||||
double threshold = minValue + (maxValue - minValue) * ((double) row / graphHeight);
|
||||
|
||||
line.append(ChatColor.GRAY).append(String.format("%8s", formatStatValue(statName, threshold))).append(" ");
|
||||
|
||||
for (int col = 0; col < graphWidth; col++) {
|
||||
int snapshotIndex = (int) ((double) col / graphWidth * (snapshots.size() - 1));
|
||||
double value = values[snapshotIndex];
|
||||
|
||||
if (value >= threshold) {
|
||||
line.append(ChatColor.GREEN).append("█");
|
||||
} else {
|
||||
line.append(ChatColor.DARK_GRAY).append("░");
|
||||
}
|
||||
}
|
||||
|
||||
messages.add(line.toString());
|
||||
}
|
||||
|
||||
messages.add(ChatColor.GRAY + "Time: " + formatTimestamp(snapshots.get(0).getTimestamp()) +
|
||||
" → " + formatTimestamp(snapshots.get(snapshots.size() - 1).getTimestamp()));
|
||||
}
|
||||
|
||||
messages.add(ChatColor.GOLD + "=====================================");
|
||||
GeneralChatHandler.sendArray(player, messages.toArray(new String[0]));
|
||||
}
|
||||
|
||||
public static void displayAllStatsGraph(Player player, List<HistoricalStatsSnapshot> snapshots, String timeRange) {
|
||||
ArrayList<String> messages = new ArrayList<>();
|
||||
|
||||
messages.add(ChatColor.GOLD + "=== All Stats History (" + timeRange + ") ===");
|
||||
messages.add(ChatColor.GRAY + "Showing " + snapshots.size() + " data points");
|
||||
messages.add(ChatColor.YELLOW + "Use /gStats self_history " + timeRange + " <stat> for detailed graph");
|
||||
|
||||
HistoricalStatsSnapshot first = snapshots.get(0);
|
||||
HistoricalStatsSnapshot last = snapshots.get(snapshots.size() - 1);
|
||||
|
||||
messages.add("");
|
||||
messages.add(ChatColor.AQUA + "Comparison: First vs Last Snapshot");
|
||||
messages.add(ChatColor.GRAY + "First: " + formatTimestamp(first.getTimestamp()));
|
||||
messages.add(ChatColor.GRAY + "Last: " + formatTimestamp(last.getTimestamp()));
|
||||
messages.add("");
|
||||
|
||||
for (String stat : PlayerStats.StatOrder) {
|
||||
Object firstValue = first.getStat(stat);
|
||||
Object lastValue = last.getStat(stat);
|
||||
|
||||
if (firstValue != null && lastValue != null) {
|
||||
String displayName = PlayerStats.StatNames.get(stat);
|
||||
double firstNum = convertToDouble(firstValue);
|
||||
double lastNum = convertToDouble(lastValue);
|
||||
double change = lastNum - firstNum;
|
||||
double percentChange = firstNum != 0 ? (change / firstNum) * 100 : 0;
|
||||
|
||||
ChatColor changeColor = change > 0 ? ChatColor.GREEN : (change < 0 ? ChatColor.RED : ChatColor.GRAY);
|
||||
String changeSymbol = change > 0 ? "+" : "";
|
||||
|
||||
messages.add(ChatColor.WHITE + displayName + ": " +
|
||||
ChatColor.AQUA + formatStatValue(stat, firstValue) +
|
||||
ChatColor.GRAY + " → " +
|
||||
ChatColor.AQUA + formatStatValue(stat, lastValue) +
|
||||
changeColor + " (" + changeSymbol + formatStatValue(stat, change) +
|
||||
ChatColor.GRAY + ", " + changeSymbol + String.format("%.1f", percentChange) + "%)");
|
||||
}
|
||||
}
|
||||
|
||||
messages.add(ChatColor.GOLD + "=====================================");
|
||||
GeneralChatHandler.sendArray(player, messages.toArray(new String[0]));
|
||||
}
|
||||
|
||||
private static String formatTimestamp(String timestamp) {
|
||||
try {
|
||||
LocalDateTime dateTime = LocalDateTime.parse(timestamp);
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd HH:mm");
|
||||
return dateTime.format(formatter);
|
||||
} catch (Exception e) {
|
||||
return timestamp.substring(0, Math.min(16, timestamp.length()));
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatStatValue(String statName, Object value) {
|
||||
if (value == null) return "N/A";
|
||||
|
||||
if (value instanceof Double) {
|
||||
return Shared.formatNumber((Double) value);
|
||||
} else if (value instanceof Long) {
|
||||
return Shared.formatNumber((double) ((Long) value));
|
||||
} else if (value instanceof Integer) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
private static double convertToDouble(Object value) {
|
||||
if (value instanceof Double) return (Double) value;
|
||||
if (value instanceof Long) return ((Long) value).doubleValue();
|
||||
if (value instanceof Integer) return ((Integer) value).doubleValue();
|
||||
if (value instanceof Boolean) return ((Boolean) value) ? 1.0 : 0.0;
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,8 @@ import org.gsdistance.grimmsServer.Commands.GHelpCommand.GHelp;
|
|||
import org.gsdistance.grimmsServer.Commands.GHelpCommand.GHelpTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GLogCommand.GLogBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Commands.GLogCommand.GLogTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GStatsCommand.GStatsBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Commands.GStatsCommand.GStatsTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.GUtilCommand.GUtilBaseCommand;
|
||||
import org.gsdistance.grimmsServer.Commands.GUtilCommand.GUtilTabCompleter;
|
||||
import org.gsdistance.grimmsServer.Commands.HomeCommand.HomeBaseCommand;
|
||||
|
|
@ -86,6 +88,11 @@ public class CommandRegistry {
|
|||
gLogCmd.setExecutor(new GLogBaseCommand());
|
||||
gLogCmd.setTabCompleter(new GLogTabCompleter());
|
||||
}
|
||||
PluginCommand gStatsCmd = GrimmsServer.instance.getCommand("gStats");
|
||||
if (gStatsCmd != null) {
|
||||
gStatsCmd.setExecutor(new GStatsBaseCommand());
|
||||
gStatsCmd.setTabCompleter(new GStatsTabCompleter());
|
||||
}
|
||||
PluginCommand gDimCmd = GrimmsServer.instance.getCommand("gDim");
|
||||
if (gDimCmd != null) {
|
||||
gDimCmd.setExecutor(new GDimBaseCommand());
|
||||
|
|
|
|||
|
|
@ -67,6 +67,10 @@ commands:
|
|||
description: View statistics for yourself, other players, worlds, or leaderboards
|
||||
usage: /gLog <self_stats|other_stats|self_titles|other_titles|world|leaderboard|commands|chunk> [args]
|
||||
permission: grimmsserver.log
|
||||
gStats:
|
||||
description: View historical statistics and growth graphs for yourself or other players
|
||||
usage: /gStats <self_history|others_history> [args]
|
||||
permission: grimmsserver.stats
|
||||
gDim:
|
||||
description: Manage custom dimensions - create, delete, teleport, list, or get info
|
||||
usage: /gDim <create|delete|tp|list|info> [args]
|
||||
|
|
@ -157,6 +161,15 @@ permissions:
|
|||
grimmsserver.log.other:
|
||||
description: Allows viewing other players' statistics (admin only)
|
||||
default: op
|
||||
grimmsserver.stats:
|
||||
description: Allows viewing historical statistics and growth graphs
|
||||
default: true
|
||||
grimmsserver.stats.self:
|
||||
description: Allows viewing your own historical statistics
|
||||
default: true
|
||||
grimmsserver.stats.other:
|
||||
description: Allows viewing other players' statistics (admin only)
|
||||
default: op
|
||||
grimmsserver.dimensions:
|
||||
description: Allows managing custom dimensions (admin only)
|
||||
default: op
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue