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 0b20c79..a61210b 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 @@ -4,9 +4,7 @@ import com.gmail.artemis.the.gr8.playerstats.commands.ReloadCommand; import com.gmail.artemis.the.gr8.playerstats.commands.StatCommand; import com.gmail.artemis.the.gr8.playerstats.commands.TabCompleter; import com.gmail.artemis.the.gr8.playerstats.filehandlers.ConfigHandler; -import com.gmail.artemis.the.gr8.playerstats.filehandlers.TestFileHandler; import com.gmail.artemis.the.gr8.playerstats.listeners.JoinListener; -import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler; import com.gmail.artemis.the.gr8.playerstats.utils.MessageFactory; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Bukkit; @@ -35,7 +33,6 @@ public class Main extends JavaPlugin { //get instances of the classes that should be initialized ConfigHandler config = new ConfigHandler(this); - TestFileHandler test = new TestFileHandler(this); MessageFactory messageFactory = new MessageFactory(config); ThreadManager threadManager = new ThreadManager(this, adventure(), config, messageFactory); 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 f0ae2d5..adbb352 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 @@ -1,6 +1,7 @@ package com.gmail.artemis.the.gr8.playerstats.commands; import com.gmail.artemis.the.gr8.playerstats.ThreadManager; +import com.gmail.artemis.the.gr8.playerstats.enums.Query; import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler; import com.gmail.artemis.the.gr8.playerstats.statistic.StatRequest; import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler; @@ -29,29 +30,99 @@ public class StatCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - //part 1: collecting all relevant information from the args - if (args.length >= 1) { + if (args.length >= 1) { //part 1: collecting all relevant information from the args StatRequest request = generateRequest(sender, args); - //part 2: sending the information to the StatThread, or give feedback if request is invalid - if (isValidStatRequest(request)) { + if (isValidStatRequest(request)) { //part 2: sending the information to the StatThread threadManager.startStatThread(request); return true; } - - else { + else { //part 2: or give feedback if request is invalid adventure.sender(sender).sendMessage(getRelevantFeedback(request)); return false; } } - //in case of less than 1 argument, always display the help message - else { + else { //in case of less than 1 argument, display the help message adventure.sender(sender).sendMessage(messageFactory.helpMsg()); return false; } } + //create a StatRequest Object with all the relevant information from the args + private StatRequest generateRequest(CommandSender sender, String[] args) { + StatRequest request = new StatRequest(sender); + + for (String arg : args) { + //check for statName + if (EnumHandler.isStatistic(arg) && request.getStatName() == null) { + request.setStatName(arg); + } + //check for subStatEntry and playerFlag + else if (EnumHandler.isSubStatEntry(arg)) { + if (arg.equalsIgnoreCase("player") && !request.playerFlag()) { + request.setPlayerFlag(true); + } + else { + if (request.getSubStatEntry() == null) request.setSubStatEntry(arg); + } + } + //check for selection + else if (request.getSelection() == null) { + if (arg.equalsIgnoreCase("top")) { + request.setSelection(Query.TOP); + } + else if (arg.equalsIgnoreCase("server")) { + request.setSelection(Query.SERVER); + } + else if (arg.equalsIgnoreCase("me") && sender instanceof Player) { + request.setPlayerName(sender.getName()); + request.setSelection(Query.PLAYER); + } + else if (OfflinePlayerHandler.isOfflinePlayerName(arg) && request.getPlayerName() == null) { + request.setPlayerName(arg); + request.setSelection(Query.PLAYER); + } + } + } + return request; + } + + //part 2: check whether all necessary ingredients are present to proceed with a lookup + private boolean isValidStatRequest(StatRequest request) { + if (request.getStatName() != null) { + if (request.playerFlag()) unpackPlayerFlag(request); + if (request.getSelection() == null) assumeTopAsDefault(request); + if (request.getSubStatEntry() != null) verifySubStat(request); + + return EnumHandler.isValidStatEntry(request.getStatType(), request.getSubStatEntry()); + } + return false; + } + + //account for the fact that "player" could be either a subStatEntry, a flag to indicate the target for the lookup, or both + private void unpackPlayerFlag(StatRequest request) { + if (request.getStatType() == Statistic.Type.ENTITY && request.getSubStatEntry() == null) { + request.setSubStatEntry("player"); + } + if (request.getSelection() == null) { + request.setSelection(Query.PLAYER); + } + } + + //in case the statistic is untyped, set the unnecessary subStatEntry to null + private void verifySubStat(StatRequest request) { + if (request.getSubStatEntry() != null && request.getStatType() == Statistic.Type.UNTYPED) { + request.setSubStatEntry(null); + } + } + + //if no playerName was provided, and there is no topFlag or serverFlag, substitute a top flag + private void assumeTopAsDefault(StatRequest request) { + request.setSelection(Query.TOP); + } + + //call this method when isValidStatRequest has returned false to get a relevant error-message private TextComponent getRelevantFeedback(@NotNull StatRequest request) { if (request.getStatName() == null) { return messageFactory.missingStatName(); @@ -62,92 +133,9 @@ public class StatCommand implements CommandExecutor { else if (!EnumHandler.isValidStatEntry(request.getStatType(), request.getSubStatEntry())){ return messageFactory.wrongSubStatType(request.getStatType(), request.getSubStatEntry()); } - else if (!request.topFlag()) { - if (!request.playerFlag()) { - return messageFactory.missingTarget(); - } - else { - return messageFactory.missingPlayerName(); - } + else if (request.getSelection() == Query.PLAYER && request.getPlayerName() == null) { + return messageFactory.missingPlayerName(); } return messageFactory.unknownError(); } - - //part 1: create a StatRequest Object with all the relevant information from the args - private StatRequest generateRequest(CommandSender sender, String[] args) { - StatRequest request = new StatRequest(sender); - - for (String arg : args) { - if (EnumHandler.isStatistic(arg) && request.getStatName() == null) { - request.setStatName(arg); - } - else if (EnumHandler.isSubStatEntry(arg)) { - if (arg.equalsIgnoreCase("player")) { - if (request.playerFlag()) { - if (request.getSubStatEntry() == null) request.setSubStatEntry(arg); - } - else { - request.setPlayerFlag(true); - } - } - else { - if (request.getSubStatEntry() == null) request.setSubStatEntry(arg); - } - } - else if (arg.equalsIgnoreCase("top")) { - request.setTopFlag(true); - } - else if (arg.equalsIgnoreCase("server")) { - request.setServerFlag(true); - } - else if (arg.equalsIgnoreCase("me") && sender instanceof Player) { - request.setPlayerName(sender.getName()); - } - else if (OfflinePlayerHandler.isOfflinePlayerName(arg) && request.getPlayerName() == null) { - request.setPlayerName(arg); - } - } - return request; - } - - //part 2: check whether all necessary ingredients are present to proceed with a lookup - private boolean isValidStatRequest(StatRequest request) { - validatePlayerFlag(request); - removeUnnecessarySubStat(request); - - if (request.getStatName() != null) { - if (!(request.topFlag() || request.serverFlag()) && request.getPlayerName() == null) { - assumeTopAsDefault(request); - } - else if (request.topFlag() && request.serverFlag()) { - assumeServerFlag(request); - } - return EnumHandler.isValidStatEntry(request.getStatType(), request.getSubStatEntry()); - } - return false; - } - - //account for the fact that "player" could be either a subStatEntry or a flag to indicate the target for the lookup, and correct the request if necessary - private void validatePlayerFlag(StatRequest request) { - if (request.getStatType() == Statistic.Type.ENTITY && request.getSubStatEntry() == null && request.playerFlag()) { - request.setSubStatEntry("player"); - } - } - - //in case the statistic is untyped, remove any subStatEntry that might be present - private void removeUnnecessarySubStat(StatRequest request) { - if (request.getSubStatEntry() != null && request.getStatType() == Statistic.Type.UNTYPED) { - request.setSubStatEntry(null); - } - } - - //if no playerName was provided, and there is no topFlag or serverFlag, substitute a top flag - private void assumeTopAsDefault(StatRequest request) { - request.setTopFlag(true); - } - - //if both a topFlag and serverFlag are present, keep the serverFlag and reset the topFlag - private void assumeServerFlag(StatRequest request) { - request.setTopFlag(false); - } } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/enums/CommandOption.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/enums/Query.java similarity index 51% rename from src/main/java/com/gmail/artemis/the/gr8/playerstats/enums/CommandOption.java rename to src/main/java/com/gmail/artemis/the/gr8/playerstats/enums/Query.java index 0ef3bb4..bd42b32 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/enums/CommandOption.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/enums/Query.java @@ -1,6 +1,6 @@ package com.gmail.artemis.the.gr8.playerstats.enums; -public enum CommandOption { - PLAYER, SERVER, TOP; +public enum Query { + PLAYER, SERVER, TOP } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/filehandlers/ConfigHandler.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/filehandlers/ConfigHandler.java index a501d30..a950008 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/filehandlers/ConfigHandler.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/filehandlers/ConfigHandler.java @@ -1,7 +1,7 @@ package com.gmail.artemis.the.gr8.playerstats.filehandlers; import com.gmail.artemis.the.gr8.playerstats.Main; -import com.gmail.artemis.the.gr8.playerstats.enums.CommandOption; +import com.gmail.artemis.the.gr8.playerstats.enums.Query; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -19,6 +19,7 @@ public class ConfigHandler { public ConfigHandler(Main p) { plugin = p; saveDefaultConfig(); + config = YamlConfiguration.loadConfiguration(configFile); } /** Reloads the config from file, or creates a new file with default values if there is none. */ @@ -68,9 +69,9 @@ public class ConfigHandler { /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "green" or "gold" for Color (for top or individual color). */ - public String getPlayerNameFormatting(CommandOption selection, boolean isStyle) { + public String getPlayerNameFormatting(Query selection, boolean isStyle) { String def; - if (selection == CommandOption.TOP) { + if (selection == Query.TOP) { def = "green"; } else { @@ -80,7 +81,7 @@ public class ConfigHandler { } public boolean playerNameIsBold() { - ConfigurationSection style = getRelevantSection(CommandOption.PLAYER); + ConfigurationSection style = getRelevantSection(Query.PLAYER); if (style != null) { String styleString = style.getString("player-names"); @@ -91,21 +92,21 @@ public class ConfigHandler { /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "yellow" for Color. */ - public String getStatNameFormatting(CommandOption selection, boolean isStyle) { + public String getStatNameFormatting(Query selection, boolean isStyle) { return getStringFromConfig(selection, isStyle, "yellow", "stat-names"); } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "#FFD52B" for Color. */ - public String getSubStatNameFormatting(CommandOption selection, boolean isStyle) { + public String getSubStatNameFormatting(Query selection, boolean isStyle) { return getStringFromConfig(selection, isStyle, "#FFD52B", "sub-stat-names"); } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "#55AAFF" or "#ADE7FF" for Color (for the top or individual/server color). */ - public String getStatNumberFormatting(CommandOption selection, boolean isStyle) { + public String getStatNumberFormatting(Query selection, boolean isStyle) { String def; - if (selection == CommandOption.TOP) { + if (selection == Query.TOP) { def = "#55AAFF"; } else { @@ -115,37 +116,44 @@ public class ConfigHandler { } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, - and "yellow" for Color. */ - public String getTitleFormatting(CommandOption selection, boolean isStyle) { - return getStringFromConfig(selection, isStyle, "yellow", "title"); + and "yellow" or "gold" for Color (for top/server). */ + public String getTitleFormatting(Query selection, boolean isStyle) { + String def; + if (selection == Query.TOP) { + def = "yellow"; + } + else { + def = "gold"; + } + return getStringFromConfig(selection, isStyle, def, "title"); } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "gold" for Color. */ public String getTitleNumberFormatting(boolean isStyle) { - return getStringFromConfig(CommandOption.TOP, isStyle, "gold", "title-number"); + return getStringFromConfig(Query.TOP, isStyle, "gold", "title-number"); } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "#FFB80E" for Color. */ public String getServerNameFormatting(boolean isStyle) { - return getStringFromConfig(CommandOption.SERVER, isStyle, "#FFB80E", "server-name"); + return getStringFromConfig(Query.SERVER, isStyle, "#FFB80E", "server-name"); } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "gold" for Color. */ public String getRankNumberFormatting(boolean isStyle) { - return getStringFromConfig(CommandOption.TOP, isStyle, "gold", "rank-numbers"); + return getStringFromConfig(Query.TOP, isStyle, "gold", "rank-numbers"); } /** Returns a String that represents either a Chat Color, hex color code, or Style. Default values are "none" for Style, and "dark_gray" for Color. */ public String getDotsFormatting(boolean isStyle) { - return getStringFromConfig(CommandOption.TOP, isStyle, "dark_gray", "dots"); + return getStringFromConfig(Query.TOP, isStyle, "dark_gray", "dots"); } /** Returns the config value for a color or style option in string-format, the supplied default value, or null if no configSection was found. */ - private @Nullable String getStringFromConfig(CommandOption selection, boolean isStyle, String def, String pathName){ + private @Nullable String getStringFromConfig(Query selection, boolean isStyle, String def, String pathName){ String path = isStyle ? pathName + "-style" : pathName; String defaultValue = isStyle ? "none" : def; @@ -154,7 +162,7 @@ public class ConfigHandler { } /** Returns the config section that contains the relevant color or style option. */ - private @Nullable ConfigurationSection getRelevantSection(CommandOption selection) { + private @Nullable ConfigurationSection getRelevantSection(Query selection) { switch (selection) { case TOP -> { return config.getConfigurationSection("top-list"); diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadAction.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadAction.java index f4714e7..af81ea8 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadAction.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadAction.java @@ -1,10 +1,8 @@ package com.gmail.artemis.the.gr8.playerstats.reload; import com.gmail.artemis.the.gr8.playerstats.utils.UnixTimeHandler; -import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import java.util.ConcurrentModificationException; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.RecursiveAction; diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadThread.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadThread.java index cdfc42f..77a1201 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadThread.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/reload/ReloadThread.java @@ -107,7 +107,7 @@ public class ReloadThread extends Thread { } catch (ConcurrentModificationException e) { throw new ConcurrentModificationException(e.toString()); } - return generateFakeExtraPlayers(playerMap, 10); + return playerMap; } private ConcurrentHashMap generateFakeExtraPlayers(ConcurrentHashMap realPlayers, int loops) { diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatRequest.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatRequest.java index 553c69f..5a4a38c 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatRequest.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatRequest.java @@ -1,5 +1,6 @@ package com.gmail.artemis.the.gr8.playerstats.statistic; +import com.gmail.artemis.the.gr8.playerstats.enums.Query; import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -7,6 +8,7 @@ import org.bukkit.Statistic; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class StatRequest { @@ -14,9 +16,8 @@ public class StatRequest { private String statName; private String subStatEntry; private String playerName; + private Query selection; private boolean playerFlag; - private boolean topFlag; - private boolean serverFlag; private Statistic statEnum; private Statistic.Type statType; @@ -28,8 +29,6 @@ public class StatRequest { public StatRequest(@NotNull CommandSender s) { sender = s; playerFlag = false; - topFlag = false; - serverFlag = false; } //sets the statName, and automatically tries to set the correct statType and get the corresponding item/block/entity if there is a subStatEntry @@ -52,7 +51,6 @@ public class StatRequest { } } - //sets the subStatEntry, and automatically tries to get the corresponding item/block/entity if there is a valid statType present //if the subStatEntry is set to null, any present item/block/entity is set to null again public void setSubStatEntry(String subStatEntry) { @@ -103,12 +101,8 @@ public class StatRequest { this.playerFlag = playerFlag; } - public void setTopFlag(boolean topFlag) { - this.topFlag = topFlag; - } - - public void setServerFlag(boolean serverFlag) { - this.serverFlag = serverFlag; + public void setSelection(Query selection) { + this.selection = selection; } public CommandSender getCommandSender() { @@ -152,11 +146,7 @@ public class StatRequest { return playerFlag; } - public boolean topFlag() { - return topFlag; - } - - public boolean serverFlag() { - return serverFlag; + public @Nullable Query getSelection() { + return selection; } } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatThread.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatThread.java index 2fa61e4..9e4e856 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatThread.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/StatThread.java @@ -1,6 +1,7 @@ package com.gmail.artemis.the.gr8.playerstats.statistic; import com.gmail.artemis.the.gr8.playerstats.Main; +import com.gmail.artemis.the.gr8.playerstats.enums.Query; import com.gmail.artemis.the.gr8.playerstats.filehandlers.TestFileHandler; import com.gmail.artemis.the.gr8.playerstats.reload.ReloadThread; import com.gmail.artemis.the.gr8.playerstats.ThreadManager; @@ -69,19 +70,18 @@ public class StatThread extends Thread { String playerName = request.getPlayerName(); String statName = request.getStatName(); String subStatEntry = request.getSubStatEntry(); - boolean topFlag = request.topFlag(); - boolean serverFlag = request.serverFlag(); + Query selection = request.getSelection(); - if (topFlag || serverFlag) { - if (ThreadManager.getLastRecordedCalcTime() > 30000) { + if (selection == Query.TOP || selection == Query.SERVER) { + if (ThreadManager.getLastRecordedCalcTime() > 20000) { adventure.sender(sender).sendMessage(messageFactory.waitAMoment(true)); } - else if (ThreadManager.getLastRecordedCalcTime() > 2000) { + else if (ThreadManager.getLastRecordedCalcTime() > 1500) { adventure.sender(sender).sendMessage(messageFactory.waitAMoment(false)); } try { - if (topFlag) { + if (selection == Query.TOP) { adventure.sender(sender).sendMessage(messageFactory.formatTopStats( getTopStats(), statName, subStatEntry)); } @@ -98,7 +98,7 @@ public class StatThread extends Thread { } } - else if (playerName != null) { + else if (selection == Query.PLAYER) { try { long time = System.currentTimeMillis(); adventure.sender(sender).sendMessage( diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/TopStatAction.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/TopStatAction.java index f3e7a6d..694d55e 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/TopStatAction.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/statistic/TopStatAction.java @@ -54,15 +54,17 @@ public class TopStatAction extends RecursiveAction { do { String playerName = iterator.next(); OfflinePlayer player = OfflinePlayerHandler.getOfflinePlayer(playerName); - int statistic = 0; - switch (request.getStatType()) { - case UNTYPED -> statistic = player.getStatistic(request.getStatEnum()); - case ENTITY -> statistic = player.getStatistic(request.getStatEnum(), request.getEntity()); - case BLOCK -> statistic = player.getStatistic(request.getStatEnum(), request.getBlock()); - case ITEM -> statistic = player.getStatistic(request.getStatEnum(), request.getItem()); - } - if (statistic > 0) { - playerStats.put(playerName, statistic); + if (player != null) { + int statistic = 0; + switch (request.getStatType()) { + case UNTYPED -> statistic = player.getStatistic(request.getStatEnum()); + case ENTITY -> statistic = player.getStatistic(request.getStatEnum(), request.getEntity()); + case BLOCK -> statistic = player.getStatistic(request.getStatEnum(), request.getBlock()); + case ITEM -> statistic = player.getStatistic(request.getStatEnum(), request.getItem()); + } + if (statistic > 0) { + playerStats.put(playerName, statistic); + } } } while (iterator.hasNext()); } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/MessageFactory.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/MessageFactory.java index e73694e..960d8db 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/MessageFactory.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/utils/MessageFactory.java @@ -1,6 +1,6 @@ package com.gmail.artemis.the.gr8.playerstats.utils; -import com.gmail.artemis.the.gr8.playerstats.enums.CommandOption; +import com.gmail.artemis.the.gr8.playerstats.enums.Query; import com.gmail.artemis.the.gr8.playerstats.filehandlers.ConfigHandler; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -75,10 +75,6 @@ public class MessageFactory { .color(msgColor); } - public TextComponent missingTarget() { - return getPluginPrefix().append(text("Please add \"me\", \"player\" or \"top\"").color(msgColor)); - } - public TextComponent missingPlayerName() { return getPluginPrefix().append(text("Please specify a valid player-name!").color(msgColor)); } @@ -95,7 +91,9 @@ public class MessageFactory { } public TextComponent unknownError() { - return getPluginPrefix().append(text("Something went wrong with your request, please try again!").color(msgColor)); + return getPluginPrefix() + .append(text("Something went wrong with your request, please try again or see /statistic for a usage explanation!") + .color(msgColor)); } public TextComponent helpMsg() { @@ -160,10 +158,10 @@ public class MessageFactory { public TextComponent formatPlayerStat(String playerName, String statName, String subStatEntryName, int stat) { TextComponent.Builder singleStat = Component.text(); - singleStat.append(playerNameComponent(CommandOption.PLAYER, playerName + ": ")) - .append(statNumberComponent(CommandOption.PLAYER, stat)).append(space()) - .append(statNameComponent(CommandOption.PLAYER, statName)) - .append(subStatNameComponent(CommandOption.PLAYER, subStatEntryName)); + singleStat.append(playerNameComponent(Query.PLAYER, playerName + ": ")) + .append(statNumberComponent(Query.PLAYER, stat)).append(space()) + .append(statNameComponent(Query.PLAYER, statName)) + .append(subStatNameComponent(Query.PLAYER, subStatEntryName)); return singleStat.build(); } @@ -172,10 +170,10 @@ public class MessageFactory { TextComponent.Builder topList = Component.text(); topList.append(newline()).append(getPluginPrefix()) - .append(titleComponent(CommandOption.TOP, "Top")).append(space()) + .append(titleComponent(Query.TOP, "Top")).append(space()) .append(titleNumberComponent(topStats.size())).append(space()) - .append(statNameComponent(CommandOption.TOP, statName)).append(space()) - .append(subStatNameComponent(CommandOption.TOP, subStatEntryName)); + .append(statNameComponent(Query.TOP, statName)).append(space()) + .append(subStatNameComponent(Query.TOP, subStatEntryName)); boolean useDots = config.useDots(); Set playerNames = topStats.keySet(); @@ -187,7 +185,7 @@ public class MessageFactory { topList.append(newline()) .append(rankingNumberComponent(count + ". ")) - .append(playerNameComponent(CommandOption.TOP, playerName)); + .append(playerNameComponent(Query.TOP, playerName)); if (useDots) { topList.append(space()); @@ -201,24 +199,24 @@ public class MessageFactory { } } else { - topList.append(playerNameComponent(CommandOption.TOP, ":")); + topList.append(playerNameComponent(Query.TOP, ":")); } - topList.append(space()).append(statNumberComponent(CommandOption.TOP, topStats.get(playerName))); + topList.append(space()).append(statNumberComponent(Query.TOP, topStats.get(playerName))); } return topList.build(); } public TextComponent formatServerStat(String statName, String subStatEntry, int stat) { TextComponent.Builder serverStat = Component.text(); - serverStat.append(titleComponent(CommandOption.SERVER, "Total for")) + serverStat.append(titleComponent(Query.SERVER, "Total for")) .append(space()) .append(serverNameComponent()) .append(space()) - .append(statNumberComponent(CommandOption.SERVER, stat)) + .append(statNumberComponent(Query.SERVER, stat)) .append(space()) - .append(statNameComponent(CommandOption.SERVER, statName)) + .append(statNameComponent(Query.SERVER, statName)) .append(space()) - .append(subStatNameComponent(CommandOption.SERVER, subStatEntry)); + .append(subStatNameComponent(Query.SERVER, subStatEntry)); return serverStat.build(); } @@ -241,19 +239,19 @@ public class MessageFactory { return subStat; } - private TextComponent playerNameComponent(CommandOption selection, String playerName) { + private TextComponent playerNameComponent(Query selection, String playerName) { return getComponent(playerName, getColorFromString(config.getPlayerNameFormatting(selection, false)), getStyleFromString(config.getPlayerNameFormatting(selection, true))); } - private TextComponent statNameComponent(CommandOption selection, String statName) { + private TextComponent statNameComponent(Query selection, String statName) { return getComponent(statName.toLowerCase().replace("_", " "), getColorFromString(config.getStatNameFormatting(selection, false)), getStyleFromString(config.getStatNameFormatting(selection, true))); } - private TextComponent subStatNameComponent(CommandOption selection, String subStatName) { + private TextComponent subStatNameComponent(Query selection, String subStatName) { if (subStatName == null) { return empty(); } @@ -265,13 +263,13 @@ public class MessageFactory { } } - private TextComponent statNumberComponent(CommandOption selection, int number) { + private TextComponent statNumberComponent(Query selection, int number) { return getComponent(number + "", getColorFromString(config.getStatNumberFormatting(selection, false)), getStyleFromString(config.getStatNumberFormatting(selection, true))); } - private TextComponent titleComponent(CommandOption selection, String content) { + private TextComponent titleComponent(Query selection, String content) { return getComponent(content, getColorFromString(config.getTitleFormatting(selection, false)), getStyleFromString(config.getTitleFormatting(selection, true))); @@ -284,9 +282,11 @@ public class MessageFactory { } private TextComponent serverNameComponent() { - return getComponent(config.getServerName() + ":", + TextComponent colon = text(":").color(getColorFromString(config.getServerNameFormatting(false))); + return getComponent(config.getServerName(), getColorFromString(config.getServerNameFormatting(false)), - getStyleFromString(config.getServerNameFormatting(true))); + getStyleFromString(config.getServerNameFormatting(true))) + .append(colon); } private TextComponent rankingNumberComponent(String number) { 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 cac34f0..9de4347 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 @@ -2,7 +2,6 @@ package com.gmail.artemis.the.gr8.playerstats.utils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ebb2e28..db02e40 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -71,8 +71,8 @@ total-server: title: gold title-style: none - server-name: '#FFB80E' - server-name-style: none + server-name: gold + server-name-style: italic stat-names: yellow stat-names-style: none