Added more documentation (#100)

This commit is contained in:
Artemis-the-gr8 2022-08-15 23:20:25 +02:00
parent 20fa697eab
commit 5eb4a1705c
5 changed files with 39 additions and 11 deletions

13
pom.xml
View File

@ -206,6 +206,19 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -3,18 +3,13 @@ package com.github.artemis.the.gr8.playerstats.api;
import com.github.artemis.the.gr8.playerstats.enums.Unit; import com.github.artemis.the.gr8.playerstats.enums.Unit;
import com.github.artemis.the.gr8.playerstats.msg.components.ComponentUtils; import com.github.artemis.the.gr8.playerstats.msg.components.ComponentUtils;
import com.github.artemis.the.gr8.playerstats.msg.msgutils.NumberFormatter; import com.github.artemis.the.gr8.playerstats.msg.msgutils.NumberFormatter;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import com.github.artemis.the.gr8.playerstats.statistic.result.StatResult;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** Formats messages meant for usage outside PlayerStats. /** Formats messages meant for usage outside PlayerStats. For more information about
the default formatting PlayerStats uses, see the class description of {@link StatResult}.*/
The output is ready to be sent to a Minecraft client or console with the Adventure library.
To send a Component, you need to get a {@link BukkitAudiences} object. Normally you would
have to add the library as a dependency, but since the library is included in PlayerStats, you can
access it directly. Information on how to get and use the BukkitAudiences object can be found on
<a href="https://docs.adventure.kyori.net/platform/bukkit.html">Adventure's website</a>.*/
public interface ApiFormatter { public interface ApiFormatter {
/** Turns a TextComponent into its String representation. This method is equipped /** Turns a TextComponent into its String representation. This method is equipped

View File

@ -28,9 +28,11 @@ public interface StatManager {
RequestGenerator<LinkedHashMap<String, Integer>> topStatRequest(int topListSize); RequestGenerator<LinkedHashMap<String, Integer>> topStatRequest(int topListSize);
/** Gets a RequestGenerator that can be used to create a TopStatRequest /** Gets a RequestGenerator that can be used to create a TopStatRequest
for all offline players on the server. This RequestGenerator will make sure for all offline players on the server (those that are included by
PlayerStats' settings). This RequestGenerator will make sure
all default settings for a top-statistic-lookup are configured. all default settings for a top-statistic-lookup are configured.
@return the RequestGenerator*/ @return the RequestGenerator*/
RequestGenerator<LinkedHashMap<String, Integer>> totalTopStatRequest(); RequestGenerator<LinkedHashMap<String, Integer>> totalTopStatRequest();
} }

View File

@ -54,7 +54,8 @@ public final class NumberFormatter {
} }
} }
/** The unit of time-based statistics is ticks by default.*/ /** The unit of time-based statistics is ticks by default.
@return a String with the form "1D 2H 3M 4S" (depending on the Unit range selected)*/
public String formatTimeNumber(long number, Unit bigUnit, Unit smallUnit) { //5 statistics public String formatTimeNumber(long number, Unit bigUnit, Unit smallUnit) { //5 statistics
if (number == 0) { if (number == 0) {
return "-"; return "-";

View File

@ -7,6 +7,10 @@ import org.bukkit.Statistic;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** Holds all the information PlayerStats needs to perform a lookup, and can be executed
to get the results. Calling {@link #execute()} on a Top- or ServerRequest can take some
time (especially if there is a substantial amount of OfflinePlayers on this particular server),
so I strongly advice you to call this asynchronously! */
public abstract class StatRequest<T> { public abstract class StatRequest<T> {
protected final RequestSettings requestSettings; protected final RequestSettings requestSettings;
@ -15,25 +19,38 @@ public abstract class StatRequest<T> {
requestSettings = request; requestSettings = request;
} }
/** Don't call this from the Main Thread!*/ /** Executes this StatRequest. Don't call this from the Main Thread!
@return a StatResult containing the value of this lookup, both as numerical value
and as formatted message*/
public abstract StatResult<T> execute(); public abstract StatResult<T> execute();
/** @return the Statistic this StatRequest will get the data of */
public Statistic getStatisticSetting() { public Statistic getStatisticSetting() {
return requestSettings.getStatistic(); return requestSettings.getStatistic();
} }
/** If the Statistic setting for this StatRequest is of Type.Block,
this will get the Material that was set
@return a Material for which #isBlock is true, or null if no Material was set*/
public @Nullable Material getBlockSetting() { public @Nullable Material getBlockSetting() {
return requestSettings.getBlock(); return requestSettings.getBlock();
} }
/** If the Statistic setting for this StatRequest is of Type.Item,
this will get the Material that was set
@return a Material for which #isItem is true, or null if no Material was set*/
public @Nullable Material getItemSetting() { public @Nullable Material getItemSetting() {
return requestSettings.getItem(); return requestSettings.getItem();
} }
/** If the Statistic setting for this StatRequest is of Type.Entity,
this will get the EntityType that was set
@return an EntityType, or null if no EntityType was set*/
public @Nullable EntityType getEntitySetting() { public @Nullable EntityType getEntitySetting() {
return requestSettings.getEntity(); return requestSettings.getEntity();
} }
/** @return the Target for this lookup (either Player, Server or Top)*/
public Target getTargetSetting() { public Target getTargetSetting() {
return requestSettings.getTarget(); return requestSettings.getTarget();
} }