The API is working!

This commit is contained in:
Artemis-the-gr8 2022-07-24 17:09:58 +02:00
parent f6dca79c57
commit 5368331441
4 changed files with 20 additions and 11 deletions

View File

@ -63,6 +63,12 @@
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-plain</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>

View File

@ -2,7 +2,7 @@ package com.gmail.artemis.the.gr8.playerstats.api;
import com.gmail.artemis.the.gr8.playerstats.Main;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
@ -19,7 +19,9 @@ import org.jetbrains.annotations.NotNull;
<p>The result of the methods in PlayerStats' API are returned in the form of a TextComponent,
which can be sent directly to a Minecraft client with the Adventure library,
or turned into a String with {@link #statResultComponentToString(TextComponent)}.</p>*/
or turned into a String with {@link #statResultComponentToString(TextComponent)}.
Don't use the Adventure method .content() on your result instead of the method specified in here -
because of the way the TextComponent is built by PlayerStats, you won't be able to get the full content that way. </p>*/
public interface PlayerStats {
/** Returns an instance of the {@link PlayerStatsAPI}.
@ -29,6 +31,13 @@ public interface PlayerStats {
return Main.getPlayerStatsAPI();
}
/** Turns a TextComponent into its String representation. If you don't want to work with
Adventure's TextComponents, you can call this method to turn any stat-result into a String.
It will lose all color and style, but it will keep line-breaks.*/
default String statResultComponentToString(TextComponent statResult) {
return PlainTextComponentSerializer.plainText().serialize(statResult);
}
/** Get a formatted player-statistic of Statistic.Type UNTYPED.*/
TextComponent getPlayerStat(@NotNull Statistic statistic, @NotNull String playerName) throws IllegalArgumentException;
@ -55,11 +64,4 @@ public interface PlayerStats {
/** Get a formatted top-statistic of Statistic.Type ENTITY. Not recommended to call this from the main Thread (see class description).*/
TextComponent getTopStats(@NotNull Statistic statistic, @NotNull EntityType entity) throws IllegalArgumentException;
/** Turns a TextComponent into its String representation. If you don't want to work with
Adventure's TextComponents, you can call this method to turn any stat-result into a String.
It will lose all color and style, but it will keep line-breaks.*/
default String statResultComponentToString(TextComponent statResult) {
return MiniMessage.miniMessage().serialize(statResult);
}
}

View File

@ -352,7 +352,7 @@ public class MessageBuilder {
/** Depending on the config settings, return either a TranslatableComponent representing
the statName (and potential subStatName), or a TextComponent with capitalized English names.*/
private TextComponent getStatNameComponent(StatRequest request) {
if (config.useTranslatableComponents()) {
if (config.useTranslatableComponents() && !request.isAPIRequest()) {
String statKey = languageKeyHandler.getStatKey(request.getStatistic());
String subStatKey = request.getSubStatEntry();
if (subStatKey != null) {

View File

@ -67,8 +67,9 @@ public class RequestManager implements RequestGenerator {
return request;
}
/** This method will generate a {@link StatRequest} for a stat-request arriving through the API.*/
public StatRequest generateRequest(@NotNull Target selection, @NotNull Statistic statistic, Material material, EntityType entity, String playerName) {
StatRequest request = new StatRequest(Bukkit.getConsoleSender());
StatRequest request = new StatRequest(Bukkit.getConsoleSender(), true);
request.setSelection(selection);
request.setStatistic(statistic);
switch (statistic.getType()) {