mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-01-08 19:37:58 +01:00
Moved all space-creating to MessageWriter where possible and fixed duplicate/missing spaces, and some minor bug fixing
This commit is contained in:
parent
772d59941d
commit
3ad7e337aa
@ -35,13 +35,12 @@ public class ComponentFactory {
|
||||
format = new NumberFormatter();
|
||||
}
|
||||
|
||||
/** Returns [PlayerStats] followed by a single space. */
|
||||
/** Returns [PlayerStats]. */
|
||||
public TextComponent pluginPrefixComponent(boolean isBukkitConsole) {
|
||||
return text("[")
|
||||
.color(PluginColor.GRAY.getColor())
|
||||
.append(text("PlayerStats").color(PluginColor.GOLD.getColor()))
|
||||
.append(text("]"))
|
||||
.append(space());
|
||||
.append(text("]"));
|
||||
}
|
||||
|
||||
/** Returns [PlayerStats] surrounded by underscores on both sides. */
|
||||
@ -53,7 +52,7 @@ public class ComponentFactory {
|
||||
return text(underscores).color(underscoreColor)
|
||||
.append(text(" ")) //4 spaces
|
||||
.append(pluginPrefixComponent(isBukkitConsole))
|
||||
.append(text(" ")) //3 spaces (since prefix already has one)
|
||||
.append(text(" ")) //4 spaces
|
||||
.append(text(underscores));
|
||||
}
|
||||
|
||||
@ -87,9 +86,14 @@ public class ComponentFactory {
|
||||
if (prettySubStatName == null) {
|
||||
return Component.empty();
|
||||
} else {
|
||||
return getComponent(prettySubStatName,
|
||||
return Component.empty()
|
||||
.append(space().decorations(TextDecoration.NAMES.values(), false))
|
||||
.append(getComponentBuilder(null,
|
||||
getColorFromString(config.getSubStatNameFormatting(selection, false)),
|
||||
getStyleFromString(config.getSubStatNameFormatting(selection, true)));
|
||||
getStyleFromString(config.getSubStatNameFormatting(selection, true)))
|
||||
.append(text("("))
|
||||
.append(text(prettySubStatName))
|
||||
.append(text(")")));
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +114,6 @@ public class ComponentFactory {
|
||||
else {
|
||||
return totalStatNameBuilder.append(translatable()
|
||||
.key(statName))
|
||||
.append(space().decorations(TextDecoration.NAMES.values(), false))
|
||||
.append(subStat)
|
||||
.build();
|
||||
}
|
||||
@ -128,14 +131,15 @@ public class ComponentFactory {
|
||||
}
|
||||
}
|
||||
if (subStatName != null) {
|
||||
return getComponentBuilder(null,
|
||||
return Component.empty()
|
||||
.append(space().decorations(TextDecoration.NAMES.values(), false))
|
||||
.append(getComponentBuilder(null,
|
||||
getColorFromString(config.getSubStatNameFormatting(request.getSelection(), false)),
|
||||
getStyleFromString(config.getSubStatNameFormatting(request.getSelection(), true)))
|
||||
.append(text("("))
|
||||
.append(translatable()
|
||||
.key(subStatName))
|
||||
.append(text(")"))
|
||||
.build();
|
||||
.append(text(")"))); //apparently Builders within Components don't need to be built
|
||||
}
|
||||
}
|
||||
return Component.empty();
|
||||
|
@ -108,18 +108,20 @@ public class MessageWriter {
|
||||
.append(componentFactory.statNumberComponent(stat, request.getStatistic().toString(), Target.PLAYER))
|
||||
.append(space())
|
||||
.append(getStatNameComponent(request))
|
||||
.append(space())
|
||||
.append(componentFactory.statUnitComponent(request.getStatistic().toString(), Target.PLAYER))
|
||||
.build();
|
||||
}
|
||||
|
||||
public TextComponent formatTopStats(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequest request) {
|
||||
TextComponent.Builder topList = Component.text()
|
||||
.append(newline())
|
||||
.append(componentFactory.pluginPrefixComponent(request.isBukkitConsoleSender()))
|
||||
.append(componentFactory.titleComponent(config.getTopStatsTitle(), Target.TOP))
|
||||
.append(componentFactory.pluginPrefixComponent(request.isBukkitConsoleSender())).append(space())
|
||||
.append(componentFactory.titleComponent(config.getTopStatsTitle(), Target.TOP)).append(space())
|
||||
.append(componentFactory.titleNumberComponent(topStats.size())).append(space())
|
||||
.append(getStatNameComponent(request))
|
||||
.append(space())
|
||||
.append(componentFactory.titleNumberComponent(topStats.size()))
|
||||
.append(space())
|
||||
.append(getStatNameComponent(request));
|
||||
.append(componentFactory.statUnitComponent(request.getStatistic().toString(), Target.TOP));
|
||||
|
||||
boolean useDots = config.useDots();
|
||||
boolean boldNames = config.playerNameIsBold();
|
||||
@ -224,7 +226,7 @@ public class MessageWriter {
|
||||
|
||||
public TextComponent helpMsg(boolean isConsoleSender) {
|
||||
return new HelpMessage(componentFactory,
|
||||
config.useHoverText(),
|
||||
config.useHoverText() && !isConsoleSender,
|
||||
isConsoleSender && Bukkit.getName().equalsIgnoreCase("CraftBukkit"),
|
||||
config.getTopListMaxSize());
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.msg;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||
import org.bukkit.Statistic;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@ -15,7 +14,6 @@ public class NumberFormatter {
|
||||
format.setGroupingSize(3);
|
||||
}
|
||||
|
||||
//TODO deal with unit name after number (add "blocks", etc in appropriate places)
|
||||
public String format(String statName, long number) {
|
||||
if (EnumHandler.isDistanceStatistic(statName)) {
|
||||
return formatDistance(number); //language-key: "soundCategory.block": "Blocks",
|
||||
|
@ -53,7 +53,7 @@ public class PrideComponentFactory extends ComponentFactory {
|
||||
"<#01c1a7>a</#01c1a7>" +
|
||||
"<#0690d4>t</#0690d4>" +
|
||||
"<#205bf3>s</#205bf3>" +
|
||||
"<#6c15fa>] </#6c15fa>"))
|
||||
"<#6c15fa>]</#6c15fa>"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ public class HelpMessage implements TextComponent {
|
||||
private final ComponentFactory componentFactory;
|
||||
private final TextComponent helpMessage;
|
||||
boolean isBukkitConsole;
|
||||
TextColor GRAY;
|
||||
TextColor DARK_PURPLE;
|
||||
TextColor GOLD;
|
||||
TextColor MEDIUM_GOLD;
|
||||
@ -50,41 +51,39 @@ public class HelpMessage implements TextComponent {
|
||||
|
||||
return Component.newline()
|
||||
.append(componentFactory.prefixTitleComponent(isBukkitConsole))
|
||||
.append(Component.newline())
|
||||
.append(text("Type \"/statistic examples\" to see examples!").color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC))
|
||||
.append(Component.newline())
|
||||
.append(text("Usage: ").color(NamedTextColor.GOLD))
|
||||
.append(newline())
|
||||
.append(text("Type \"/statistic examples\" to see examples!").color(GRAY).decorate(TextDecoration.ITALIC))
|
||||
.append(newline())
|
||||
.append(text("Usage:").color(GOLD)).append(space())
|
||||
.append(text("/statistic").color(LIGHT_GOLD))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow)
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("name").color(LIGHT_GOLD))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow)
|
||||
.append(text("{sub-statistic}").color(LIGHT_GOLD))
|
||||
.append(Component.space())
|
||||
.append(text("(a block, item or entity)").color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow)
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("{sub-statistic}").color(LIGHT_GOLD)).append(space())
|
||||
.append(text("(a block, item or entity)").color(GRAY))
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("me | player | server | top").color(LIGHT_GOLD))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(spaces).append(bullet)
|
||||
.append(text("me:").color(MEDIUM_GOLD))
|
||||
.append(Component.space()).append(text("your own statistic").color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(spaces).append(bullet)
|
||||
.append(text("player:").color(MEDIUM_GOLD))
|
||||
.append(Component.space()).append(text("choose a player").color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(spaces).append(bullet)
|
||||
.append(text("server:").color(MEDIUM_GOLD))
|
||||
.append(Component.space()).append(text("everyone on the server combined").color(NamedTextColor.GRAY))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(spaces).append(bullet)
|
||||
.append(text("top:").color(MEDIUM_GOLD))
|
||||
.append(Component.space()).append(text("the top").color(NamedTextColor.GRAY)
|
||||
.append(Component.space()).append(text(listSize)))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow)
|
||||
.append(newline())
|
||||
.append(spaces).append(spaces).append(bullet).append(space())
|
||||
.append(text("me:").color(MEDIUM_GOLD)).append(space())
|
||||
.append(text("your own statistic").color(GRAY))
|
||||
.append(newline())
|
||||
.append(spaces).append(spaces).append(bullet).append(space())
|
||||
.append(text("player:").color(MEDIUM_GOLD)).append(space())
|
||||
.append(text("choose a player").color(GRAY))
|
||||
.append(newline())
|
||||
.append(spaces).append(spaces).append(bullet).append(space())
|
||||
.append(text("server:").color(MEDIUM_GOLD)).append(space())
|
||||
.append(text("everyone on the server combined").color(GRAY))
|
||||
.append(newline())
|
||||
.append(spaces).append(spaces).append(bullet).append(space())
|
||||
.append(text("top:").color(MEDIUM_GOLD)).append(space())
|
||||
.append(text("the top").color(GRAY).append(space()).append(text(listSize)))
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("{player-name}").color(LIGHT_GOLD));
|
||||
}
|
||||
|
||||
@ -94,32 +93,30 @@ public class HelpMessage implements TextComponent {
|
||||
|
||||
return Component.newline()
|
||||
.append(componentFactory.prefixTitleComponent(false))
|
||||
.append(Component.newline())
|
||||
.append(newline())
|
||||
.append(componentFactory.subTitleComponent("Hover over the arguments for more information!"))
|
||||
.append(Component.newline())
|
||||
.append(text("Usage:").color(GOLD))
|
||||
.append(Component.space())
|
||||
.append(newline())
|
||||
.append(text("Usage:").color(GOLD)).append(space())
|
||||
.append(text("/statistic").color(LIGHT_GOLD))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow).append(Component.space())
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("name").color(LIGHT_GOLD)
|
||||
.hoverEvent(HoverEvent.showText(text("The name that describes the statistic").color(LIGHT_BLUE)
|
||||
.append(Component.newline())
|
||||
.append(newline())
|
||||
.append(text("Example: ").color(GOLD))
|
||||
.append(text("\"animals_bred\"").color(LIGHT_GOLD)))))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow).append(Component.space())
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("sub-statistic").color(LIGHT_GOLD)
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
text("Some statistics need an item, block or entity as extra input").color(LIGHT_BLUE)
|
||||
.append(Component.newline())
|
||||
.append(newline())
|
||||
.append(text("Example: ").color(GOLD)
|
||||
.append(text("\"mine_block diorite\"").color(LIGHT_GOLD))))))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow)
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
text("Choose one").color(DARK_PURPLE)))
|
||||
.append(Component.space())
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
text("Choose one").color(DARK_PURPLE)))).append(space())
|
||||
.append(text("me").color(LIGHT_GOLD)
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
text("See your own statistic").color(LIGHT_BLUE))))
|
||||
@ -134,25 +131,27 @@ public class HelpMessage implements TextComponent {
|
||||
.append(text(" | ").color(LIGHT_GOLD))
|
||||
.append(text("top").color(LIGHT_GOLD)
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
text("See the top ").color(LIGHT_BLUE)
|
||||
.append(text(listSize).color(LIGHT_BLUE)))))
|
||||
.append(Component.newline())
|
||||
.append(spaces).append(arrow)
|
||||
text("See the top").color(LIGHT_BLUE).append(space())
|
||||
.append(text(listSize)))))
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow).append(space())
|
||||
.append(text("player-name").color(LIGHT_GOLD)
|
||||
.hoverEvent(HoverEvent.showText(
|
||||
text("In case you typed ").color(LIGHT_BLUE)
|
||||
.append(text("\"player\"").color(LIGHT_GOLD)
|
||||
.append(text(", add the player's name").color(LIGHT_BLUE))))));
|
||||
text("In case you typed").color(LIGHT_BLUE).append(space())
|
||||
.append(text("\"player\"").color(LIGHT_GOLD))
|
||||
.append(text(", add the player's name")))));
|
||||
}
|
||||
|
||||
private void getPluginColors(boolean isBukkitConsole) {
|
||||
if (isBukkitConsole) {
|
||||
GRAY = PluginColor.GRAY.getConsoleColor();
|
||||
DARK_PURPLE = PluginColor.DARK_PURPLE.getConsoleColor();
|
||||
GOLD = PluginColor.GOLD.getConsoleColor();
|
||||
MEDIUM_GOLD = PluginColor.MEDIUM_GOLD.getConsoleColor();
|
||||
LIGHT_GOLD = PluginColor.LIGHT_GOLD.getConsoleColor();
|
||||
LIGHT_BLUE = PluginColor.LIGHT_BLUE.getConsoleColor();
|
||||
} else {
|
||||
GRAY = PluginColor.GRAY.getColor();
|
||||
DARK_PURPLE = PluginColor.DARK_PURPLE.getColor();
|
||||
GOLD = PluginColor.GOLD.getColor();
|
||||
MEDIUM_GOLD = PluginColor.MEDIUM_GOLD.getColor();
|
||||
@ -195,4 +194,12 @@ public class HelpMessage implements TextComponent {
|
||||
public @NotNull TextComponent style(@NotNull Style style) {
|
||||
return helpMessage.style(style);
|
||||
}
|
||||
|
||||
private TextComponent space() {
|
||||
return Component.space();
|
||||
}
|
||||
|
||||
private TextComponent newline() {
|
||||
return Component.newline();
|
||||
}
|
||||
}
|
@ -111,9 +111,9 @@ public class ReloadThread extends Thread {
|
||||
MyLogger.actionCreated((offlinePlayers != null) ? offlinePlayers.length : 0);
|
||||
ForkJoinPool.commonPool().invoke(task);
|
||||
MyLogger.actionFinished(1);
|
||||
MyLogger.logTimeTaken("ReloadThread",
|
||||
("loaded " + OfflinePlayerHandler.getOfflinePlayerCount() + " offline players"), time);
|
||||
|
||||
OfflinePlayerHandler.updateOfflinePlayerList(playerMap);
|
||||
MyLogger.logTimeTaken("ReloadThread",
|
||||
("loaded " + OfflinePlayerHandler.getOfflinePlayerCount() + " offline players"), time);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user