mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-01-23 21:51:19 +01:00
Added formatter to API
This commit is contained in:
parent
f960bbd5a2
commit
992344b210
@ -1,7 +1,7 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Statistic;
|
||||
|
||||
public interface Formatter extends StatFormatter {
|
||||
|
||||
@ -15,5 +15,7 @@ public interface Formatter extends StatFormatter {
|
||||
|
||||
TextComponent getRainbowPluginPrefixAsTitle();
|
||||
|
||||
TextComponent formatSingleTopStatLine(int positionInTopList, String playerName, long statNumber, Unit statNumberUnit);
|
||||
/** @return a single line from a top-x statistic:
|
||||
* <br> x. Player-name ......... number */
|
||||
TextComponent formatSingleTopStatLine(int positionInTopList, String playerName, long statNumber, Statistic statistic);
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
@ -268,7 +268,7 @@ public final class MessageBuilder {
|
||||
};
|
||||
}
|
||||
|
||||
public TextComponent singleTopStatLine(int positionInTopList, String playerName, long statNumber, Unit statNumberUnit) {
|
||||
public TextComponent singleTopStatLine(int positionInTopList, String playerName, long statNumber, Statistic statistic) {
|
||||
TextComponent.Builder topStatLineBuilder = Component.text()
|
||||
.append(space())
|
||||
.append(componentFactory.rankNumber(positionInTopList))
|
||||
@ -279,7 +279,11 @@ public final class MessageBuilder {
|
||||
} else {
|
||||
topStatLineBuilder.append(componentFactory.playerName(playerName + ":", Target.TOP));
|
||||
}
|
||||
//TODO add formatted number here
|
||||
|
||||
return topStatLineBuilder
|
||||
.append(space())
|
||||
.append(getStatNumberComponent(statistic, Target.TOP, statNumber))
|
||||
.build();
|
||||
}
|
||||
|
||||
private Component getSharerNameComponent(CommandSender sender) {
|
||||
@ -370,8 +374,11 @@ public final class MessageBuilder {
|
||||
}
|
||||
|
||||
private TextComponent getStatNumberComponent(StatRequest request, long statNumber) {
|
||||
Unit.Type statUnitType = Unit.getTypeFromStatistic(request.getStatistic());
|
||||
Target target = request.getTarget();
|
||||
return getStatNumberComponent(request.getStatistic(), request.getTarget(), statNumber);
|
||||
}
|
||||
|
||||
private TextComponent getStatNumberComponent(Statistic statistic, Target target, long statNumber) {
|
||||
Unit.Type statUnitType = Unit.getTypeFromStatistic(statistic);
|
||||
return switch (statUnitType) {
|
||||
case DISTANCE -> getDistanceNumberComponent(statNumber, target);
|
||||
case DAMAGE -> getDamageNumberComponent(statNumber, target);
|
||||
@ -380,12 +387,6 @@ public final class MessageBuilder {
|
||||
};
|
||||
}
|
||||
|
||||
private TextComponent getStatNumberComponent(Unit unit, Target target, long statNumber) {
|
||||
return switch (unit.getType()) {
|
||||
case DISTANCE ->
|
||||
}
|
||||
}
|
||||
|
||||
private TextComponent getDistanceNumberComponent(long statNumber, Target target) {
|
||||
Unit statUnit = Unit.fromString(config.getDistanceUnit(false));
|
||||
String prettyNumber = formatter.formatDistanceNumber(statNumber, statUnit);
|
||||
|
@ -4,7 +4,6 @@ import com.gmail.artemis.the.gr8.playerstats.ShareManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.Formatter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.StandardMessage;
|
||||
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.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.BukkitConsoleComponentFactory;
|
||||
@ -78,8 +77,8 @@ public final class OutputManager implements Formatter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent formatSingleTopStatLine(int positionInTopList, String playerName, long statNumber, Unit statNumberUnit) {
|
||||
return null;
|
||||
public TextComponent formatSingleTopStatLine(int positionInTopList, String playerName, long statNumber, Statistic statistic) {
|
||||
return messageBuilder.singleTopStatLine(positionInTopList, playerName, statNumber, statistic);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -139,7 +138,7 @@ public final class OutputManager implements Formatter {
|
||||
|
||||
public void sendHelp(@NotNull CommandSender sender) {
|
||||
adventure.sender(sender).sendMessage(getMessageBuilder(sender)
|
||||
.helpMsg();
|
||||
.helpMsg());
|
||||
}
|
||||
|
||||
public void sendToAllPlayers(@NotNull TextComponent component) {
|
||||
|
Loading…
Reference in New Issue
Block a user