diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java index 47d8a96..d15d36a 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/Main.java @@ -24,7 +24,7 @@ public class Main extends JavaPlugin { this.getCommand("statistic").setExecutor(new StatCommand(outputFormatter, statManager, this)); this.getCommand("statistic").setTabCompleter(new TabCompleter( enumHandler, statManager,this)); - this.getCommand("statisticreload").setExecutor(new ReloadCommand(config)); + this.getCommand("statisticreload").setExecutor(new ReloadCommand(config, outputFormatter)); Bukkit.getPluginManager().registerEvents(new JoinListener(), this); this.getLogger().info("Enabled PlayerStats!"); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java index f169b0c..70f4fd0 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/StatManager.java @@ -45,6 +45,7 @@ public class StatManager { //returns the integer associated with a certain statistic for a player public int getStatistic(String statName, String subStatEntryName, String playerName) throws IllegalArgumentException, NullPointerException { long time = System.currentTimeMillis(); + OfflinePlayer player = offlinePlayerHandler.getOfflinePlayer(playerName); plugin.getLogger().info("StatManager 51: " + (System.currentTimeMillis() - time)); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ReloadCommand.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ReloadCommand.java index f4787a8..2702d55 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ReloadCommand.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ReloadCommand.java @@ -1,6 +1,7 @@ package com.gmail.artemis.the.gr8.playerstats.commands; import com.gmail.artemis.the.gr8.playerstats.ConfigHandler; +import com.gmail.artemis.the.gr8.playerstats.utils.OutputFormatter; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -10,14 +11,17 @@ import org.jetbrains.annotations.NotNull; public class ReloadCommand implements CommandExecutor { private final ConfigHandler config; + private final OutputFormatter outputFormatter; - public ReloadCommand(ConfigHandler c) { + public ReloadCommand(ConfigHandler c, OutputFormatter o) { + outputFormatter = o; config = c; } @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (config.reloadConfig()) { + outputFormatter.updateOutputColors(); sender.sendMessage(ChatColor.GREEN + "Config reloaded!"); return true; } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java index 07cf53b..5f82ec9 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/StatCommand.java @@ -10,7 +10,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import java.time.Instant; public class StatCommand implements CommandExecutor { @@ -30,7 +29,8 @@ public class StatCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { long time = System.currentTimeMillis(); - plugin.getLogger().info("onCommand 33: " + time); + long startTime = System.currentTimeMillis(); + if (args.length >= 2) { String statName = null; @@ -84,10 +84,18 @@ public class StatCommand implements CommandExecutor { try { plugin.getLogger().info("onCommand 85: " + (System.currentTimeMillis() - time)); time = System.currentTimeMillis(); - sender.sendMessage(outputFormatter.formatPlayerStat(playerName, statName, subStatEntry, - statManager.getStatistic(statName, subStatEntry, playerName))); + + int stat = statManager.getStatistic(statName, subStatEntry, playerName); plugin.getLogger().info("onCommand 89: " + (System.currentTimeMillis() - time)); time = System.currentTimeMillis(); + + String msg = outputFormatter.formatPlayerStat(playerName, statName, subStatEntry, stat); + plugin.getLogger().info("onCommand 93: " + (System.currentTimeMillis() - time)); + time = System.currentTimeMillis(); + + sender.sendMessage(msg); + plugin.getLogger().info("onCommand 97: " + (System.currentTimeMillis() - time)); + time = System.currentTimeMillis(); } catch (Exception e) { sender.sendMessage(e.toString()); @@ -95,7 +103,8 @@ public class StatCommand implements CommandExecutor { } } - plugin.getLogger().info("onCommand 98: " + (System.currentTimeMillis() - time)); + plugin.getLogger().info("onCommand 106: " + (System.currentTimeMillis() - time)); + plugin.getLogger().info("Total time elapsed: " + (System.currentTimeMillis() - startTime)); return true; } } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java index 7c2effb..b19db79 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OfflinePlayerHandler.java @@ -11,7 +11,7 @@ public class OfflinePlayerHandler { private static OfflinePlayerHandler instance; private List offlinePlayers; private List offlinePlayerNames; - private HashMap offlinePlayerUUIDs; + private HashMap offlinePlayerMap; private OfflinePlayerHandler() { updateOfflinePlayers(); @@ -30,15 +30,10 @@ public class OfflinePlayerHandler { public OfflinePlayer getOfflinePlayer(String playerName) { long time = System.currentTimeMillis(); - System.out.println(("OfflinePlayerHandler 34: " + (System.currentTimeMillis() - time))); - time = System.currentTimeMillis(); - Optional player = offlinePlayers.stream().filter(offlinePlayer -> - offlinePlayer.getName() != null && offlinePlayer.getName().equalsIgnoreCase(playerName)).findAny(); - - System.out.println(("OfflinePlayerHandler 40: " + (System.currentTimeMillis() - time))); - time = System.currentTimeMillis(); - return player.orElse(null); + OfflinePlayer player = offlinePlayerMap.get(playerName); + System.out.println(("OfflinePlayerHandler 35: " + (System.currentTimeMillis() - time))); + return player; } public List getAllOfflinePlayers() { @@ -50,9 +45,10 @@ public class OfflinePlayerHandler { } public void updateOfflinePlayers() { + offlinePlayerMap = new HashMap<>(); offlinePlayers = Arrays.stream(Bukkit.getOfflinePlayers()).filter(offlinePlayer -> offlinePlayer.getName() != null && offlinePlayer.hasPlayedBefore()).collect(Collectors.toList()); offlinePlayerNames = offlinePlayers.stream().map(OfflinePlayer::getName).collect(Collectors.toList()); - offlinePlayers.forEach(offlinePlayer -> offlinePlayerUUIDs.put(offlinePlayer.getName(), offlinePlayer.getUniqueId())); + offlinePlayers.forEach(offlinePlayer -> offlinePlayerMap.put(offlinePlayer.getName(), offlinePlayer)); } } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OutputFormatter.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OutputFormatter.java index 51773b3..beb4ca6 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OutputFormatter.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/OutputFormatter.java @@ -1,6 +1,7 @@ package com.gmail.artemis.the.gr8.playerstats.utils; import com.gmail.artemis.the.gr8.playerstats.ConfigHandler; +import com.gmail.artemis.the.gr8.playerstats.Main; import org.bukkit.ChatColor; import java.util.HashMap; @@ -13,11 +14,12 @@ public class OutputFormatter { //statNames(Ranked) //subStatNames(Ranked) //numbers(Ranked) - - private final HashMap chatColors; + private final ConfigHandler config; + private HashMap chatColors; public OutputFormatter(ConfigHandler c) { - chatColors = c.getChatColors(); + config = c; + updateOutputColors(); } public String formatTopStats(LinkedHashMap topStats) { @@ -29,10 +31,24 @@ public class OutputFormatter { } public String formatPlayerStat(String playerName, String statName, String subStatEntryName, int stat) { + long time = System.currentTimeMillis(); + System.out.println("OutputFormatter 33: " + (System.currentTimeMillis() - time)); + time = System.currentTimeMillis(); + String subStat = subStatEntryName != null ? chatColors.get("subStatNames") + " (" + subStatEntryName.toLowerCase().replace("_", " ") + ")" : ""; - return chatColors.get("playerNames") + playerName + chatColors.get("numbers") + ": " + stat + " " + + System.out.println("OutputFormatter 39: " + (System.currentTimeMillis() - time)); + time = System.currentTimeMillis(); + + String msg = chatColors.get("playerNames") + playerName + chatColors.get("numbers") + ": " + stat + " " + chatColors.get("statNames") + statName.toLowerCase().replace("_", " ") + subStat; + + System.out.println("OutputFormatter 45: " + (System.currentTimeMillis() - time)); + return msg; + } + + public void updateOutputColors() { + chatColors = config.getChatColors(); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2bbabb3..e1a083c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,12 +4,12 @@ # supports: all default Minecraft colors individual-statistics: player-names: gold - stat-names: dark_aqua - sub-stat-names: blue + stat-names: yellow + sub-stat-names: yellow numbers: white ranked-list: player-names: gold - stat-names: dark_aqua - sub-stat-names: blue + stat-names: yellow + sub-stat-names: yellow numbers: white \ No newline at end of file