mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-02-01 23:21:20 +01:00
Added in a pretty help-display for Bukkit and found out the md_5 package import cannot work how I'm doing it (#32)
This commit is contained in:
parent
0fb8fa0487
commit
bc0ec51f36
@ -5,7 +5,6 @@ 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.listeners.JoinListener;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OutputFormatter;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -15,18 +14,20 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
private static boolean enableHexColors;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
//check if Spigot ChatColors can be used, and prepare accordingly
|
||||
boolean enableHexColors = false;
|
||||
try {
|
||||
Class.forName("net.md_5.bungee.api.ChatColor");
|
||||
enableHexColors = true;
|
||||
this.getLogger().info("Hex Color support enabled!");
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
enableHexColors = false;
|
||||
this.getLogger().info("Hex Colors are not supported for this server type, proceeding with default Chat Colors...");
|
||||
}
|
||||
|
||||
@ -59,6 +60,10 @@ public class Main extends JavaPlugin {
|
||||
this.getLogger().info("Disabled PlayerStats!");
|
||||
}
|
||||
|
||||
public static boolean hexEnabled() {
|
||||
return enableHexColors;
|
||||
}
|
||||
|
||||
public long logTimeTaken(String className, String methodName, long previousTime) {
|
||||
getLogger().info(className + " " + methodName + ": " + (System.currentTimeMillis() - previousTime));
|
||||
return System.currentTimeMillis();
|
||||
|
@ -71,13 +71,23 @@ public class StatCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
sender.spigot().sendMessage(outputFormatter.formatHelp());
|
||||
if (Main.hexEnabled()) {
|
||||
sender.spigot().sendMessage(outputFormatter.formatHelpSpigot());
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(outputFormatter.formatHelpBukkit());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
sender.spigot().sendMessage(outputFormatter.formatHelp());
|
||||
if (Main.hexEnabled()) {
|
||||
sender.spigot().sendMessage(outputFormatter.formatHelpSpigot());
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(outputFormatter.formatHelpBukkit());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -205,5 +205,6 @@ public class ConfigHandler {
|
||||
config = plugin.getConfig();
|
||||
plugin.saveDefaultConfig();
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -41,49 +41,66 @@ public class OutputFormatter {
|
||||
return pluginPrefix + exception;
|
||||
}
|
||||
|
||||
public BaseComponent[] formatHelp() {
|
||||
public BaseComponent[] formatHelpSpigot() {
|
||||
String spaces = " ";
|
||||
String underscores = "____________";
|
||||
|
||||
if (useHex) {
|
||||
ComponentBuilder underscores = new ComponentBuilder("____________").color(net.md_5.bungee.api.ChatColor.of("#6E3485"));
|
||||
TextComponent arrow = new TextComponent("→ ");
|
||||
arrow.setColor(net.md_5.bungee.api.ChatColor.GOLD);
|
||||
ComponentBuilder underscore = new ComponentBuilder(underscores).color(net.md_5.bungee.api.ChatColor.of("#6E3485"));
|
||||
TextComponent arrow = new TextComponent("→ ");
|
||||
arrow.setColor(net.md_5.bungee.api.ChatColor.GOLD);
|
||||
|
||||
TextComponent statName = new TextComponent("name");
|
||||
statName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
statName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("The name of the statistic (example: \"mine_block\")")));
|
||||
TextComponent statName = new TextComponent("name");
|
||||
statName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
statName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("The name of the statistic (example: \"mine_block\")")));
|
||||
|
||||
TextComponent subStatName = new TextComponent("sub-statistic");
|
||||
subStatName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
subStatName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Some statistics require an item, block or entity as sub-statistic (example: \"mine_block diorite\")")));
|
||||
TextComponent subStatName = new TextComponent("sub-statistic");
|
||||
subStatName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
subStatName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Some statistics require an item, block or entity as sub-statistic (example: \"mine_block diorite\")")));
|
||||
|
||||
TextComponent target = new TextComponent("me | player | top");
|
||||
target.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
target.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Choose whether you want to see your own statistic, another player's, or the top " + config.getTopListMaxSize())));
|
||||
TextComponent target = new TextComponent("me | player | top");
|
||||
target.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
target.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Choose whether you want to see your own statistic, another player's, or the top " + config.getTopListMaxSize())));
|
||||
|
||||
TextComponent playerName = new TextComponent("player-name");
|
||||
playerName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
playerName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("In case you selected \"player\", specify the player's name here")));
|
||||
TextComponent playerName = new TextComponent("player-name");
|
||||
playerName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
playerName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("In case you selected \"player\", specify the player's name here")));
|
||||
|
||||
ComponentBuilder title = new ComponentBuilder()
|
||||
.append(underscores.create()).append("\n").append(spaces).append(pluginPrefix).append(spaces).append(underscores.create()).append("\n")
|
||||
.append("Hover over the arguments for more information!").color(net.md_5.bungee.api.ChatColor.GRAY).italic(true).append("\n")
|
||||
.append("Usage: ").color(net.md_5.bungee.api.ChatColor.GOLD).italic(false)
|
||||
.append("/statistic ").color(net.md_5.bungee.api.ChatColor.YELLOW).append("\n")
|
||||
.append(spaces).append(arrow).append(statName).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(subStatName).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(target).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(playerName);
|
||||
ComponentBuilder help = new ComponentBuilder()
|
||||
.append("\n").append(underscore.create()).append(spaces).append(pluginPrefix).append(spaces).append(underscore.create()).append("\n")
|
||||
.append("Hover over the arguments for more information!").color(net.md_5.bungee.api.ChatColor.GRAY).italic(true).append("\n")
|
||||
.append("Usage: ").color(net.md_5.bungee.api.ChatColor.GOLD).italic(false)
|
||||
.append("/statistic ").color(net.md_5.bungee.api.ChatColor.YELLOW).append("\n")
|
||||
.append(spaces).append(arrow).append(statName).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(subStatName).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(target).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(playerName);
|
||||
|
||||
return title.create();
|
||||
}
|
||||
else {
|
||||
return new BaseComponent[0];
|
||||
}
|
||||
return help.create();
|
||||
}
|
||||
|
||||
public String formatHelpBukkit() {
|
||||
String spaces = " ";
|
||||
String underscores = ChatColor.GRAY + "____________";
|
||||
String arrow = spaces + ChatColor.GOLD + "→ ";
|
||||
ChatColor argumentColor = ChatColor.YELLOW;
|
||||
ChatColor descriptionColor = ChatColor.WHITE;
|
||||
|
||||
return "\n" +
|
||||
underscores + spaces + pluginPrefix + spaces + underscores + "\n" +
|
||||
ChatColor.GRAY + ChatColor.ITALIC + "A list of all the required and optional arguments" + ChatColor.RESET + "\n" +
|
||||
ChatColor.GOLD + "Usage: " + argumentColor + "/statistic " + "\n" +
|
||||
arrow + argumentColor + "name: " +
|
||||
descriptionColor + "The name of the statistic (example: \"mine_block\")" + "\n" +
|
||||
arrow + argumentColor + "sub-statistic: " +
|
||||
descriptionColor + "Some statistics require an item, block or entity as sub-statistic (example: \"mine_block diorite\")" + "\n" +
|
||||
arrow + argumentColor + "me | player | top: " +
|
||||
descriptionColor + "Choose whether you want to see your own statistic, another player's, or the top " + config.getTopListMaxSize() + "\n" +
|
||||
arrow + argumentColor + "player-name: " +
|
||||
descriptionColor + "In case you selected \"player\", specify the player's name here";
|
||||
}
|
||||
|
||||
public String formatPlayerStat(String playerName, String statName, String subStatEntryName, int stat) {
|
||||
@ -92,10 +109,10 @@ public class OutputFormatter {
|
||||
" (" + subStatEntryName.toLowerCase().replace("_", " ") + ")" : "";
|
||||
|
||||
singleStat.append(getPlayerFormatting(false)).append(playerName).append(": ")
|
||||
.append(getStatNumberColor(false)).append(getStatNumberStyle(false)).append(stat).append(" ")
|
||||
.append(getStatNameColor(false)).append(getStatNameStyle(false))
|
||||
.append(getStatNumberFormatting(false)).append(stat).append(" ")
|
||||
.append(getStatNameFormatting(false))
|
||||
.append(statName.toLowerCase().replace("_", " "))
|
||||
.append(getSubStatNameColor(false)).append(getSubStatNameStyle(false)).append(subStat);
|
||||
.append(getSubStatNameFormatting(false)).append(subStat);
|
||||
|
||||
return singleStat.toString();
|
||||
}
|
||||
@ -106,30 +123,29 @@ public class OutputFormatter {
|
||||
" (" + subStatEntryName.toLowerCase().replace("_", " ") + ")" : "";
|
||||
|
||||
topList.append("\n").append(pluginPrefix)
|
||||
.append(getStatNameColor(true)).append(getStatNameStyle(true)).append("Top ")
|
||||
.append(getListNumberColor()).append(getListNumberStyle()).append(topStats.size())
|
||||
.append(getStatNameColor(true)).append(getStatNameStyle(true)).append(" ")
|
||||
.append(getStatNameFormatting(true)).append("Top ")
|
||||
.append(getListNumberFormatting()).append(topStats.size())
|
||||
.append(getStatNameFormatting(true)).append(" ")
|
||||
.append(statName.toLowerCase().replace("_", " "))
|
||||
.append(getSubStatNameColor(true)).append(getSubStatNameStyle(true)).append(subStat);
|
||||
.append(getSubStatNameFormatting(true)).append(subStat);
|
||||
|
||||
boolean useDots = config.useDots();
|
||||
Set<String> playerNames = topStats.keySet();
|
||||
MinecraftFont font = new MinecraftFont();
|
||||
|
||||
|
||||
int count = 0;
|
||||
for (String playerName : playerNames) {
|
||||
count = count+1;
|
||||
|
||||
topList.append("\n")
|
||||
.append(getListNumberColor()).append(getListNumberStyle()).append(count).append(". ")
|
||||
.append(getPlayerColor(true)).append(getPlayerStyle(true)).append(playerName);
|
||||
.append(getListNumberFormatting()).append(count).append(". ")
|
||||
.append(getPlayerFormatting(true)).append(playerName);
|
||||
|
||||
if (useDots) {
|
||||
topList.append(getDotColor()).append(" ");
|
||||
|
||||
int dots = (int) Math.round((130.0 - font.getWidth(count + ". " + playerName))/2);
|
||||
if (getPlayerStyle(true).equals(ChatColor.BOLD)) {
|
||||
if (topPlayerStyleIsBold()) {
|
||||
dots = (int) Math.round((130.0 - font.getWidth(count + ". ") - (font.getWidth(playerName) * 1.19))/2);
|
||||
}
|
||||
if (dots >= 1) {
|
||||
@ -139,45 +155,42 @@ public class OutputFormatter {
|
||||
else {
|
||||
topList.append(":");
|
||||
}
|
||||
topList.append(" ").append(getStatNumberColor(true)).append(getStatNumberStyle(true)).append(topStats.get(playerName).toString());
|
||||
topList.append(" ").append(getStatNumberFormatting(true)).append(topStats.get(playerName).toString());
|
||||
}
|
||||
return topList.toString();
|
||||
}
|
||||
|
||||
private String getPlayerFormatting(boolean isTopStat) {
|
||||
return getPlayerColor(isTopStat) + "" + getPlayerStyle(isTopStat);
|
||||
return getColor("player-names", false, isTopStat) + "" +
|
||||
getColor("player-names", true, isTopStat);
|
||||
}
|
||||
|
||||
private Object getPlayerColor(boolean isTopStat) {return getColor("player-names", false, isTopStat);}
|
||||
|
||||
private Object getPlayerStyle(boolean isTopStat) {return getColor("player-names", true, isTopStat);}
|
||||
|
||||
private Object getStatNameColor(boolean isTopStat) {
|
||||
return getColor("stat-names", false, isTopStat);
|
||||
private boolean topPlayerStyleIsBold() {
|
||||
return getColor("player-names", true, true).equals(ChatColor.BOLD);
|
||||
}
|
||||
|
||||
private Object getStatNameStyle(boolean isTopStat) {return getColor("stat-names", true, isTopStat);}
|
||||
|
||||
private Object getSubStatNameColor(boolean isTopStat) {
|
||||
return getColor("sub-stat-names", false, isTopStat);
|
||||
private String getStatNameFormatting(boolean isTopStat) {
|
||||
return getColor("stat-names", false, isTopStat) + "" +
|
||||
getColor("stat-names", true, isTopStat);
|
||||
}
|
||||
|
||||
private Object getSubStatNameStyle(boolean isTopStat) {return getColor("sub-stat-names", true, isTopStat);}
|
||||
|
||||
private Object getStatNumberColor(boolean isTopStat) {
|
||||
return getColor("stat-numbers", false, isTopStat);
|
||||
private String getSubStatNameFormatting(boolean isTopStat) {
|
||||
return getColor("sub-stat-names", false, isTopStat) + "" +
|
||||
getColor("sub-stat-names", true, isTopStat);
|
||||
}
|
||||
|
||||
private Object getStatNumberStyle(boolean isTopStat) {return getColor("stat-numbers", true, isTopStat);}
|
||||
|
||||
private Object getListNumberColor() {
|
||||
return getColor("list-numbers", false, true);
|
||||
private String getStatNumberFormatting(boolean isTopStat) {
|
||||
return getColor("stat-numbers", false, isTopStat) + "" +
|
||||
getColor("stat-numbers", true, isTopStat);
|
||||
}
|
||||
|
||||
private Object getListNumberStyle() {return getColor("list-numbers", true, true);}
|
||||
private String getListNumberFormatting() {
|
||||
return getColor("list-numbers", false, true) + "" +
|
||||
getColor("list-numbers", true, true);
|
||||
}
|
||||
|
||||
private Object getDotColor() {
|
||||
return getColor("dots", false,true);
|
||||
private String getDotColor() {
|
||||
return getColor("dots", false,true) + "";
|
||||
}
|
||||
|
||||
//gets the appropriate ChatColor object (or empty string), depending on whether the Spigot ChatColor is available or not
|
||||
@ -205,4 +218,6 @@ public class OutputFormatter {
|
||||
chatColors = config.getChatColors();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user