Added more documentation

This commit is contained in:
Artemis-the-gr8 2022-08-01 17:49:42 +02:00
parent 9ad0f1eeca
commit f988b96adf
6 changed files with 49 additions and 13 deletions

View File

@ -15,7 +15,6 @@ import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.Statistic;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

View File

@ -5,6 +5,7 @@ import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.ApiStatus.Internal;
import org.jetbrains.annotations.NotNull;
public interface RequestExecutor<T> {
@ -18,9 +19,13 @@ public interface RequestExecutor<T> {
return PlayerStatsAPI.statFormatter();
}
StatResult<T> untyped(Statistic statistic);
StatResult<T> untyped(@NotNull Statistic statistic);
StatResult<T> blockOrItemType(Statistic statistic, Material material);
/** @throws IllegalArgumentException if <code>statistic</code> is not of Type.Block
(with a block as <code>material</code>), or <code>statistic</code> is not of Type.Item
(with an item as <code>material</code>)
@return a {@link StatResult} */
StatResult<T> blockOrItemType(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException;
StatResult<T> entityType(Statistic statistic, EntityType entityType);
StatResult<T> entityType(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException;
}

View File

@ -7,6 +7,7 @@ import net.kyori.adventure.text.TextComponent;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
public final class PlayerStatRequest implements RequestExecutor<Integer> {
@ -17,19 +18,19 @@ public final class PlayerStatRequest implements RequestExecutor<Integer> {
}
@Override
public StatResult<Integer> untyped(Statistic statistic) {
public StatResult<Integer> untyped(@NotNull Statistic statistic) {
StatRequest completedRequest = statRequestHandler.untyped(statistic);
return getStatResult(completedRequest);
}
@Override
public StatResult<Integer> blockOrItemType(Statistic statistic, Material material) {
public StatResult<Integer> blockOrItemType(@NotNull Statistic statistic, @NotNull Material material) {
StatRequest completedRequest = statRequestHandler.blockOrItemType(statistic, material);
return getStatResult(completedRequest);
}
@Override
public StatResult<Integer> entityType(Statistic statistic, EntityType entityType) {
public StatResult<Integer> entityType(@NotNull Statistic statistic, @NotNull EntityType entityType) {
StatRequest completedRequest = statRequestHandler.entityType(statistic, entityType);
return getStatResult(completedRequest);
}

View File

@ -7,6 +7,7 @@ import net.kyori.adventure.text.TextComponent;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
public final class ServerStatRequest implements RequestExecutor<Long> {
@ -17,19 +18,19 @@ public final class ServerStatRequest implements RequestExecutor<Long> {
}
@Override
public StatResult<Long> untyped(Statistic statistic) {
public StatResult<Long> untyped(@NotNull Statistic statistic) {
StatRequest completedRequest = statRequestHandler.untyped(statistic);
return getStatResult(completedRequest);
}
@Override
public StatResult<Long> blockOrItemType(Statistic statistic, Material material) {
public StatResult<Long> blockOrItemType(@NotNull Statistic statistic, @NotNull Material material) {
StatRequest completedRequest = statRequestHandler.blockOrItemType(statistic, material);
return getStatResult(completedRequest);
}
@Override
public StatResult<Long> entityType(Statistic statistic, EntityType entityType) {
public StatResult<Long> entityType(@NotNull Statistic statistic, @NotNull EntityType entityType) {
StatRequest completedRequest = statRequestHandler.entityType(statistic, entityType);
return getStatResult(completedRequest);
}

View File

@ -7,6 +7,7 @@ import net.kyori.adventure.text.TextComponent;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedHashMap;
@ -19,19 +20,19 @@ public final class TopStatRequest implements RequestExecutor<LinkedHashMap<Strin
}
@Override
public StatResult<LinkedHashMap<String, Integer>> untyped(Statistic statistic) {
public StatResult<LinkedHashMap<String, Integer>> untyped(@NotNull Statistic statistic) {
StatRequest completedRequest = statRequestHandler.untyped(statistic);
return getStatResult(completedRequest);
}
@Override
public StatResult<LinkedHashMap<String, Integer>> blockOrItemType(Statistic statistic, Material material) {
public StatResult<LinkedHashMap<String, Integer>> blockOrItemType(@NotNull Statistic statistic, @NotNull Material material) {
StatRequest completedRequest = statRequestHandler.blockOrItemType(statistic, material);
return getStatResult(completedRequest);
}
@Override
public StatResult<LinkedHashMap<String, Integer>> entityType(Statistic statistic, EntityType entityType) {
public StatResult<LinkedHashMap<String, Integer>> entityType(@NotNull Statistic statistic, @NotNull EntityType entityType) {
StatRequest completedRequest = statRequestHandler.entityType(statistic, entityType);
return getStatResult(completedRequest);
}

View File

@ -1,7 +1,36 @@
package com.gmail.artemis.the.gr8.playerstats.statistic.result;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.TextComponent;
/** Holds the result of a completed stat-lookup. From the StatResult,
you can get the raw numbers:
<ul>
<li> <code>int</code> for playerStat
<li> <code>long</code> for serverStat
<li> <code>LinkedHashMap(String, Integer)</code> for topStat
</ul>
Besides raw numbers, you can also get a formatted message. This can either
be a String or a {@link TextComponent}, and contains the following information:
<ul>
<li> for playerStat:
<br> [player-name]: [formatted-number] [stat-name] [sub-stat-name]
<li> for serverStat:
<br> [Total on] [server-name]: [formatted-number] [stat-name] [sub-stat-name]
<li> for topStat:
<br> [PlayerStats] [Top x] [stat-name] [sub-stat-name]
<br> [1.] [player-name] [.....] [formatted-number]
<br> [2.] [player-name] [.....] [formatted-number]
<br> [3.] etc...
</ul>
If you get a TextComponent, you can send this directly to a Minecraft client or console
with the Adventure library. To send a Component, you need to get a {@link BukkitAudiences}
object, and use that to send the desired Component. Normally you would have to add Adventure
as a dependency to your project, 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>.
<br>
*/
public interface StatResult<T> {
T getNumericalValue();