mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-01-08 19:37:58 +01:00
Made ApiFormatter use the same settings for TranslatableComponents as the InternalFormatter
This commit is contained in:
parent
7c3b6d0ef0
commit
cc2e061ae3
@ -33,13 +33,6 @@ public interface ApiFormatter {
|
||||
return new NumberFormatter();
|
||||
}
|
||||
|
||||
/** Replace "_" with " " and capitalize each first letter of the input.
|
||||
@param rawEnumString String to prettify, case-insensitive
|
||||
@return the transformed String. For example: animals_bred becomes Animals Bred*/
|
||||
default String BukkitEnumToString(String rawEnumString) {
|
||||
return StringUtils.prettify(rawEnumString);
|
||||
}
|
||||
|
||||
/** Gets the default prefix PlayerStats uses.
|
||||
@return [PlayerStats]*/
|
||||
TextComponent getPluginPrefix();
|
||||
@ -62,6 +55,10 @@ public interface ApiFormatter {
|
||||
TextComponent getTopStatTitle(int topStatSize, Statistic statistic);
|
||||
|
||||
/** Gets the top-stat-title for a statistic that has a sub-statistic (block, item or entity).
|
||||
@param statistic the Statistic enum constant for this message
|
||||
@param subStatName the name of the Material or EntityType of this statistic-lookup,
|
||||
acquired by doing #toString() on the Material/EntityType in question
|
||||
@param topStatSize the size of the top-list this title is for
|
||||
@return Top [topStatSize] [stat-name] [sub-stat-name] */
|
||||
TextComponent getTopStatTitle(int topStatSize, Statistic statistic, String subStatName);
|
||||
|
||||
@ -96,6 +93,10 @@ public interface ApiFormatter {
|
||||
|
||||
/** Formats the input into a server statistic message for a statistic that has a
|
||||
sub-statistic (block, item or entity).
|
||||
@param statistic the Statistic enum constant for this message
|
||||
@param statNumber the result of the statistic-lookup
|
||||
@param subStatName the name of the Material or EntityType of this statistic-lookup,
|
||||
acquired by doing #toString() on the Material/EntityType in question
|
||||
@return [Total on this server]: [stat-number] [stat-name] [sub-stat-name]*/
|
||||
TextComponent getServerStat(long statNumber, Statistic statistic, String subStatName);
|
||||
|
||||
|
@ -6,8 +6,10 @@ import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.ComponentFactory;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.PrideComponentFactory;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.FontUtils;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.LanguageKeyHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.NumberFormatter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.StringUtils;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Statistic;
|
||||
@ -21,12 +23,14 @@ public class ApiOutputManager implements ApiFormatter {
|
||||
private final ComponentFactory componentFactory;
|
||||
private final PrideComponentFactory prideComponentFactory;
|
||||
private final NumberFormatter numberFormatter;
|
||||
private final LanguageKeyHandler languageKeyHandler;
|
||||
|
||||
public ApiOutputManager(ConfigHandler configHandler) {
|
||||
config = configHandler;
|
||||
componentFactory = new ComponentFactory(configHandler);
|
||||
prideComponentFactory = new PrideComponentFactory(configHandler);
|
||||
numberFormatter = new NumberFormatter();
|
||||
languageKeyHandler = new LanguageKeyHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,13 +69,12 @@ public class ApiOutputManager implements ApiFormatter {
|
||||
}
|
||||
|
||||
private TextComponent getTopStatTitle(int topListSize, Statistic statistic, @Nullable String subStatName, @Nullable Unit unit) {
|
||||
String prettyStatName = StringUtils.prettify(statistic.toString());
|
||||
TextComponent.Builder titleBuilder = Component.text()
|
||||
.append(componentFactory.title("Top", Target.TOP))
|
||||
.append(space())
|
||||
.append(componentFactory.titleNumber(topListSize))
|
||||
.append(space())
|
||||
.append(componentFactory.statAndSubStatName(prettyStatName, subStatName, Target.TOP));
|
||||
.append(getStatAndSubStatNameComponent(statistic, subStatName, Target.TOP));
|
||||
|
||||
if (unit != null && unit != Unit.NUMBER) {
|
||||
if (unit == Unit.HEART) {
|
||||
@ -143,7 +146,6 @@ public class ApiOutputManager implements ApiFormatter {
|
||||
private TextComponent getServerStat(long statNumber, Statistic statistic, @Nullable String subStatName, Unit unit) {
|
||||
String serverTitle = config.getServerTitle();
|
||||
String serverName = config.getServerName();
|
||||
String prettyStatName = StringUtils.prettify(statistic.toString());
|
||||
Unit.Type unitType = unit.getType();
|
||||
|
||||
TextComponent.Builder serverStatBuilder = Component.text()
|
||||
@ -153,7 +155,7 @@ public class ApiOutputManager implements ApiFormatter {
|
||||
.append(space())
|
||||
.append(getStatNumberComponent(statNumber, Target.SERVER, unit))
|
||||
.append(space())
|
||||
.append(componentFactory.statAndSubStatName(prettyStatName, subStatName, Target.SERVER));
|
||||
.append(getStatAndSubStatNameComponent(statistic, subStatName, Target.SERVER));
|
||||
|
||||
if (unitType== Unit.Type.DAMAGE || unitType == Unit.Type.DISTANCE) {
|
||||
if (unit == Unit.HEART) {
|
||||
@ -169,6 +171,23 @@ public class ApiOutputManager implements ApiFormatter {
|
||||
return serverStatBuilder.build();
|
||||
}
|
||||
|
||||
private TextComponent getStatAndSubStatNameComponent(Statistic statistic, @Nullable String subStatName, Target target) {
|
||||
if (config.useTranslatableComponents()) {
|
||||
String statKey = languageKeyHandler.getStatKey(statistic);
|
||||
String subStatKey = switch (statistic.getType()) {
|
||||
case UNTYPED -> null;
|
||||
case ENTITY -> languageKeyHandler.getEntityKey(EnumHandler.getEntityEnum(subStatName));
|
||||
case BLOCK -> languageKeyHandler.getBlockKey(EnumHandler.getBlockEnum(subStatName));
|
||||
case ITEM -> languageKeyHandler.getItemKey(EnumHandler.getItemEnum(subStatName));
|
||||
};
|
||||
return componentFactory.statAndSubStatNameTranslatable(statKey, subStatKey, target);
|
||||
}
|
||||
|
||||
String prettyStatName = StringUtils.prettify(statistic.toString());
|
||||
String prettySubStatName = StringUtils.prettify(subStatName);
|
||||
return componentFactory.statAndSubStatName(prettyStatName, prettySubStatName, target);
|
||||
}
|
||||
|
||||
private TextComponent getStatNumberComponent(long statNumber, Target target, Unit unit) {
|
||||
return switch (unit.getType()) {
|
||||
case TIME -> getTimeNumberComponent(statNumber, target, unit, null);
|
||||
|
@ -198,7 +198,7 @@ public class ComponentFactory {
|
||||
}
|
||||
|
||||
/** Returns a TextComponent with TranslatableComponent as a child.*/
|
||||
public TextComponent statAndSubStatNameTranslatable(String statKey, String subStatKey, Target target) {
|
||||
public TextComponent statAndSubStatNameTranslatable(String statKey, @Nullable String subStatKey, Target target) {
|
||||
TextComponent.Builder totalStatNameBuilder = getComponentBuilder(null,
|
||||
getColorFromString(config.getStatNameDecoration(target, false)),
|
||||
getStyleFromString(config.getStatNameDecoration(target, true)));
|
||||
@ -323,7 +323,7 @@ public class ComponentFactory {
|
||||
}
|
||||
|
||||
/** Returns a TranslatableComponent for the subStatName, or an empty component.*/
|
||||
private TextComponent subStatNameTranslatable(String subStatKey, Target target) {
|
||||
private TextComponent subStatNameTranslatable(@Nullable String subStatKey, Target target) {
|
||||
if (subStatKey != null) {
|
||||
return getComponentBuilder(null,
|
||||
getColorFromString(config.getSubStatNameDecoration(target, false)),
|
||||
|
Loading…
Reference in New Issue
Block a user