mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-02-17 01:51:35 +01:00
Added more documentation (for future Javadoc-generating)
This commit is contained in:
parent
ca7a1d3e67
commit
54040c4e3d
@ -2,7 +2,6 @@ package com.gmail.artemis.the.gr8.playerstats;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.PlayerStats;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.PlayerStatsAPI;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.StatFormatter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.commands.ReloadCommand;
|
||||
import com.gmail.artemis.the.gr8.playerstats.commands.ShareCommand;
|
||||
import com.gmail.artemis.the.gr8.playerstats.commands.StatCommand;
|
||||
@ -23,14 +22,14 @@ public class Main extends JavaPlugin {
|
||||
private static BukkitAudiences adventure;
|
||||
private static PlayerStats playerStatsAPI;
|
||||
|
||||
public static @NotNull BukkitAudiences adventure() {
|
||||
public static @NotNull BukkitAudiences adventure() throws IllegalStateException {
|
||||
if (adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure without PlayerStats being enabled!");
|
||||
}
|
||||
return adventure;
|
||||
}
|
||||
|
||||
public static @NotNull PlayerStats getPlayerStatsAPI() {
|
||||
public static @NotNull PlayerStats getPlayerStatsAPI() throws IllegalStateException {
|
||||
if (playerStatsAPI == null) {
|
||||
throw new IllegalStateException("PlayerStats does not seem to be loaded!");
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
|
||||
/** The manager of all Player-prompted statistic-sharing. If sharing is enabled, this class will save the
|
||||
results of past stat-lookups, so the results can be retrieved and shared when a Player clicks the share-button.*/
|
||||
public final class ShareManager {
|
||||
|
||||
private static volatile ShareManager instance;
|
||||
|
@ -13,6 +13,11 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/** The ThreadManager is in charge of the Threads that PlayerStats can utilize.
|
||||
It keeps track of past and currently active Threads, to ensure a Player cannot
|
||||
start multiple Threads at the same time (thereby limiting them to one stat-lookup at a time).
|
||||
It also passes appropriate references along to the {@link StatThread} or {@link ReloadThread},
|
||||
to ensure those will never run at the same time. */
|
||||
public final class ThreadManager {
|
||||
|
||||
private static volatile ThreadManager instance;
|
||||
|
@ -1,15 +1,36 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/** This Interface is the outgoing API and represents the heart of PlayerStats.
|
||||
To work with it, you can call {@link #getAPI()} to get an instance of {@link PlayerStatsAPI}.*/
|
||||
public interface PlayerStats {
|
||||
|
||||
static PlayerStats getAPI() {
|
||||
/** Returns an instance of the {@link PlayerStatsAPI}.
|
||||
@throws IllegalStateException if PlayerStats is not loaded on the server while you're trying to access the API*/
|
||||
@Contract(pure = true)
|
||||
static @NotNull PlayerStats getAPI() throws IllegalStateException {
|
||||
return Main.getPlayerStatsAPI();
|
||||
}
|
||||
|
||||
TextComponent getFancyStat(Target selection, CommandSender sender, String[] args) throws IllegalArgumentException;
|
||||
/** Returns a stat-result as if the caller ran the /stat command in Minecraft chat. Since calculating the
|
||||
top or server statistics can take some time, it is recommended to call this method asynchronously
|
||||
(otherwise the main Thread will have to wait until the calculations are done).
|
||||
The result of this method is returned in the form of a TextComponent,
|
||||
which can be sent directly to a Minecraft client, or turned into a String with {@link #componentToString(TextComponent)}.
|
||||
@param args an Array of args very similar to the input a CommandSender would put in Minecraft chat:
|
||||
<p>- a stat-name (example: "mine_block")</p>
|
||||
<p>- if applicable, a sub-stat-name (example: diorite)(</p>
|
||||
<p>- a target for this lookup: can be "top", "server", "player" (or "me" to indicate the current CommandSender)</p>
|
||||
<p>- if "player" was chosen, include a player-name</p>
|
||||
@param sender the CommandSender that requested this specific statistic*/
|
||||
TextComponent getFancyStat(CommandSender sender, String[] args) throws IllegalArgumentException;
|
||||
|
||||
/** Turns a TextComponent into its String representation. It will lose all color and style,
|
||||
but it will keep line-breaks.*/
|
||||
String componentToString(TextComponent component);
|
||||
}
|
@ -2,7 +2,6 @@ package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.StatManager;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@ -12,7 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import static org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
/** This class implements the API*/
|
||||
/** This is the implementation of the API Interface */
|
||||
public final class PlayerStatsAPI extends JavaPlugin implements PlayerStats {
|
||||
|
||||
private final Main plugin;
|
||||
@ -34,10 +33,10 @@ public final class PlayerStatsAPI extends JavaPlugin implements PlayerStats {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent getFancyStat(Target selection, CommandSender sender, String[] args) throws IllegalArgumentException {
|
||||
public TextComponent getFancyStat(CommandSender sender, String[] args) throws IllegalArgumentException {
|
||||
StatRequest request = statManager.generateRequest(sender, args);
|
||||
if (statManager.requestIsValid(request)) {
|
||||
switch (selection) {
|
||||
switch (request.getSelection()) {
|
||||
case PLAYER -> {
|
||||
int stat = statManager.getPlayerStat(request);
|
||||
return statFormatter.formatPlayerStat(request, stat);
|
||||
@ -54,4 +53,8 @@ public final class PlayerStatsAPI extends JavaPlugin implements PlayerStats {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String componentToString(TextComponent component) {
|
||||
return statFormatter.toString(component);
|
||||
}
|
||||
}
|
@ -3,12 +3,12 @@ package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/** The RequestHandler will help you turn a String (such as "stat animals_bred") into a specific StatRequest
|
||||
with all the information PlayerStatsAPI needs to work with. You'll need this StatRequest Object to get the Statistic
|
||||
/** The {@link RequestHandler} will help you turn a String (such as "stat animals_bred") into a specific {@link StatRequest}
|
||||
with all the information {@link PlayerStatsAPI} needs to work with. You'll need this StatRequest Object to get the statistic
|
||||
data that you want, and to format this data into a fancy Component or String, so you can output it somewhere.*/
|
||||
public interface RequestHandler {
|
||||
|
||||
/** This will create a StatRequest from the provided args, with the requesting Player (or Console)
|
||||
/** This will create a {@link StatRequest} from the provided args, with the requesting Player (or Console)
|
||||
as CommandSender. This CommandSender will receive feedback messages if the StatRequest could not be created.
|
||||
@param args an Array of args corresponding to a Statistic, a potential Sub-Statistic, and a Target
|
||||
(exactly as they are typed in Minecraft chat when using PlayerStatsAPI' /stat command -
|
||||
@ -16,10 +16,10 @@ public interface RequestHandler {
|
||||
@param sender the CommandSender that requested this specific statistic*/
|
||||
StatRequest generateRequest(CommandSender sender, String[] args);
|
||||
|
||||
/** This method validates the StatRequest and returns feedback to the player if it returns false.
|
||||
/** This method validates the {@link StatRequest} and returns feedback to the player if it returns false.
|
||||
It checks the following:
|
||||
<p>1. Is a Statistic set?</p>
|
||||
<p>2. Is a subStat needed, and is a subStat Enum Constant present? (block/entity/item)</p>
|
||||
<p>2. Is a subStat needed, and is a subStat Enum constant present? (block/entity/item)</p>
|
||||
<p>3. If the target is PLAYER, is a valid PlayerName provided? </p>
|
||||
@return true if the StatRequest is valid, and false + an explanation message otherwise. */
|
||||
boolean requestIsValid(StatRequest request);
|
||||
|
@ -2,6 +2,7 @@ package com.gmail.artemis.the.gr8.playerstats.config;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -29,7 +30,7 @@ public class ConfigHandler {
|
||||
MyLogger.setDebugLevel(getDebugLevel());
|
||||
}
|
||||
|
||||
/** Checks the number that "config-version" returns to see if the config needs updating, and if so, send it to the Updater.
|
||||
/** Checks the number that "config-version" returns to see if the config needs updating, and if so, send it to the {@link ConfigUpdateHandler}.
|
||||
<p>PlayerStats 1.1: "config-version" doesn't exist.</p>
|
||||
<p>PlayerStats 1.2: "config-version" is 2.</p>
|
||||
<p>PlayerStats 1.3: "config-version" is 3. </P>
|
||||
@ -49,7 +50,7 @@ public class ConfigHandler {
|
||||
}
|
||||
|
||||
/** Reloads the config from file, or creates a new file with default values if there is none.
|
||||
Also reads the value for debug-level and passes it on to MyLogger. */
|
||||
Also reads the value for debug-level and passes it on to {@link MyLogger}. */
|
||||
public boolean reloadConfig() {
|
||||
if (!configFile.exists()) {
|
||||
saveDefaultConfig();
|
||||
@ -135,6 +136,9 @@ public class ConfigHandler {
|
||||
return config.getBoolean("rainbow-mode", false);
|
||||
}
|
||||
|
||||
/** Whether to use enters before the statistic output in chat.
|
||||
Enters create some separation between the previous things that have been said in chat and the stat-result.
|
||||
<p>Default: true for non-shared top statistics, false for everything else</p>*/
|
||||
public boolean useEnters(Target selection, boolean getSharedSetting) {
|
||||
ConfigurationSection section = config.getConfigurationSection("use-enters");
|
||||
boolean def = selection == Target.TOP && !getSharedSetting;
|
||||
@ -354,7 +358,7 @@ public class ConfigHandler {
|
||||
return getDecorationString(Target.TOP, getStyleSetting, "dark_gray", "dots");
|
||||
}
|
||||
|
||||
/** Returns a String representing the Unit that should be used for a certain Unit.Type.
|
||||
/** Returns a String representing the {@link Unit} that should be used for a certain {@link Unit.Type}.
|
||||
If no String can be retrieved from the config, the supplied defaultValue will be returned.
|
||||
If the defaultValue is different for hoverText, an optional String defaultHoverValue can be supplied.
|
||||
@param isHoverText if true, the unit for hovering text is returned, otherwise the unit for plain text
|
||||
|
@ -1,5 +1,9 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.enums;
|
||||
|
||||
/** Represents the debugging level that PlayerStats can use.
|
||||
<p>1 = low (only show unexpected errors)</p>
|
||||
<p>2 = medium (detail all encountered exceptions, log main tasks and show time taken)</p>
|
||||
<p>3 = high (log all tasks and time taken)</p>*/
|
||||
public enum DebugLevel {
|
||||
LOW, MEDIUM, HIGH
|
||||
}
|
@ -6,34 +6,61 @@ import net.kyori.adventure.text.format.TextColor;
|
||||
import java.util.Random;
|
||||
|
||||
/** This enum represents the colorscheme PlayerStats uses in its output messages.
|
||||
<p>GRAY: ChatColor Gray</p>
|
||||
<p>DARK_PURPLE: #6E3485 (used for default sub-titles, title-underscores and brackets)</p>
|
||||
<p>MEDIUM_BLUE: #55AAFF (used for all plain feedback and error messages)</p>
|
||||
<p>LIGHT_BLUE: #55C6FF (used for default hover-text)</p>
|
||||
<p>GOLD: ChatColor Gold (used for first parts of usage messages and for first parts of hover-text accent)</p>
|
||||
<p>MEDIUM_GOLD: #FFD52B (used for second parts of usage messages and for second parts of hover-text accent) </p>
|
||||
<p>LIGHT_GOLD: #FFEA40 (used for third parts of usage messages)</p>
|
||||
<p>LIGHT_YELLOW: #FFFF8E (used for last parts of explanation message)</p>
|
||||
*/
|
||||
The first set of colors is used throughout the plugin, while the set of NAME-colors
|
||||
represents the colors that player-names can be in the "shared by player-name" section of shared statistics.*/
|
||||
public enum PluginColor {
|
||||
GRAY (NamedTextColor.GRAY), //#AAAAAA
|
||||
/** ChatColor Gray (#AAAAAA) */
|
||||
GRAY (NamedTextColor.GRAY),
|
||||
|
||||
/** A Dark Purple that is mainly used for title-underscores (#6E3485).*/
|
||||
DARK_PURPLE (TextColor.fromHexString("#6E3485")),
|
||||
|
||||
/** A Light Purple that is meant to simulate the color of a clicked link.
|
||||
Used for the "Hover Here" part of shared statistics (#845EC2).*/
|
||||
LIGHT_PURPLE (TextColor.fromHexString("#845EC2")),
|
||||
|
||||
/** ChatColor Blue (#5555FF)*/
|
||||
BLUE (NamedTextColor.BLUE),
|
||||
|
||||
/** A Medium Blue that is used for default feedback and error messages (#55AAFF).*/
|
||||
MEDIUM_BLUE (TextColor.fromHexString("#55AAFF")),
|
||||
|
||||
/** A Light Blue that is used for hover-messages and the share-button (#55C6FF). */
|
||||
LIGHT_BLUE (TextColor.fromHexString("#55C6FF")),
|
||||
GOLD (NamedTextColor.GOLD), //#FFAA00
|
||||
|
||||
/** ChatColor Gold (#FFAA00)*/
|
||||
GOLD (NamedTextColor.GOLD),
|
||||
|
||||
/** A Medium Gold that is used for the example message and for hover-text accents (#FFD52B).*/
|
||||
MEDIUM_GOLD (TextColor.fromHexString("#FFD52B")),
|
||||
|
||||
/** A Light Gold that is used for the example message and for hover-text accents (#FFEA40).*/
|
||||
LIGHT_GOLD (TextColor.fromHexString("#FFEA40")),
|
||||
|
||||
/** A Light Yellow that is used for final accents in the example message (#FFFF8E).*/
|
||||
LIGHT_YELLOW (TextColor.fromHexString("#FFFF8E")),
|
||||
|
||||
|
||||
/** ChatColor Blue (#5555FF)*/
|
||||
NAME_1 (NamedTextColor.BLUE), //#5555FF - blue
|
||||
NAME_2 (TextColor.fromHexString("#4287F5")), //between blue and medium_blue
|
||||
NAME_3 (TextColor.fromHexString("#55AAFF")), //same as medium_blue
|
||||
NAME_4 (TextColor.fromHexString("#D65DB1")), //magenta-purple
|
||||
NAME_5 (TextColor.fromHexString("#EE8A19")), //dark orange
|
||||
NAME_6 (TextColor.fromHexString("#01C1A7")), //aqua-cyan-green-ish
|
||||
NAME_7 (TextColor.fromHexString("#46D858")); //light green
|
||||
|
||||
/** A shade of blue between Blue and Medium Blue (#4287F5)*/
|
||||
NAME_2 (TextColor.fromHexString("#4287F5")),
|
||||
|
||||
/** Medium Blue (#55AAFF)*/
|
||||
NAME_3 (TextColor.fromHexString("#55AAFF")),
|
||||
|
||||
/** A shade of magenta/purple (#D65DB1)*/
|
||||
NAME_4 (TextColor.fromHexString("#D65DB1")),
|
||||
|
||||
/** A dark shade of orange (#EE8A19)*/
|
||||
NAME_5 (TextColor.fromHexString("#EE8A19")),
|
||||
|
||||
/** A shade of green/aqua/cyan-ish (#01C1A7)*/
|
||||
NAME_6 (TextColor.fromHexString("#01C1A7")),
|
||||
|
||||
/** A light shade of green (#46D858)*/
|
||||
NAME_7 (TextColor.fromHexString("#46D858"));
|
||||
|
||||
|
||||
private final TextColor color;
|
||||
@ -42,18 +69,23 @@ public enum PluginColor {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/** Returns the TextColor value belonging to the corresponding enum constant.*/
|
||||
public TextColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/** Gets the nearest NamedTextColor for the corresponding enum constant.*/
|
||||
public TextColor getConsoleColor() {
|
||||
return NamedTextColor.nearestTo(color);
|
||||
}
|
||||
|
||||
/** Randomly selects one of the 7 different NAME-colors.*/
|
||||
public static TextColor getRandomNameColor() {
|
||||
return getRandomNameColor(false);
|
||||
}
|
||||
|
||||
/** Randomly selects one of the 7 different NAME-colors, and if isConsole is true,
|
||||
returns the closest NamedTextColor.*/
|
||||
public static TextColor getRandomNameColor(boolean isConsole) {
|
||||
Random randomizer = new Random();
|
||||
PluginColor color = switch (randomizer.nextInt(7)) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.enums;
|
||||
|
||||
/** All standard messages PlayerStats can send as feedback.
|
||||
These are all the messages that can be sent without needing additional parameters.*/
|
||||
public enum StandardMessage {
|
||||
RELOADED_CONFIG,
|
||||
STILL_RELOADING,
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.enums;
|
||||
|
||||
/** This enum represents the targets PlayerStats accepts for a stat-lookup.*/
|
||||
public enum Target {
|
||||
PLAYER, SERVER, TOP
|
||||
}
|
@ -3,6 +3,7 @@ package com.gmail.artemis.the.gr8.playerstats.enums;
|
||||
import org.bukkit.Statistic;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/** All the units PlayerStats can display statistics in, separated by Type.*/
|
||||
public enum Unit {
|
||||
NUMBER (Type.UNTYPED, "Times"),
|
||||
KM (Type.DISTANCE, "km"),
|
||||
@ -31,10 +32,15 @@ public enum Unit {
|
||||
return this.label;
|
||||
}
|
||||
|
||||
/** Returns the Type this enum constant belongs to.*/
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/** For Type Time, Damage and Distance, this will return a smaller Unit than the current one
|
||||
(if there is a smaller Unit, that is, otherwise it will return itself).
|
||||
So for DAY, for example, it can return HOUR, MINUTE or SECOND.
|
||||
@param stepsSmaller how many steps smaller the returned Unit should be*/
|
||||
public Unit getSmallerUnit(int stepsSmaller) {
|
||||
switch (this) {
|
||||
case DAY -> {
|
||||
@ -93,6 +99,7 @@ public enum Unit {
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts the current Unit into seconds (and returns -1 if the current Unit is not of Type TIME)*/
|
||||
public double getSeconds() {
|
||||
return switch (this) {
|
||||
case DAY -> 86400;
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
/** Listens for new Players that join, and reloads PlayerStats if someone joins that hasn't joined before.*/
|
||||
public class JoinListener implements Listener {
|
||||
|
||||
private static ThreadManager threadManager;
|
||||
|
@ -8,6 +8,10 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/** The Object PlayerStats uses to calculate the appropriate statistic.
|
||||
It is generated from the args provided by a CommandSender when /stat is called,
|
||||
and always contains this CommandSender. By default, {@link #getSelection()}
|
||||
will return {@link Target#TOP}, unless another selection is specified in the args.*/
|
||||
public final class StatRequest {
|
||||
|
||||
private final CommandSender sender;
|
||||
@ -105,24 +109,4 @@ public final class StatRequest {
|
||||
public Material getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
/** Returns true if this StatRequest has all the information needed for a Statistic lookup to succeed.*/
|
||||
public boolean isValid() {
|
||||
if (statistic == null) return false;
|
||||
switch (statistic.getType()) {
|
||||
case BLOCK -> {
|
||||
if (block == null) return false;
|
||||
}
|
||||
case ENTITY -> {
|
||||
if (entity == null) return false;
|
||||
}
|
||||
case ITEM -> {
|
||||
if (item == null) return false;
|
||||
}
|
||||
case UNTYPED -> {
|
||||
if (subStatEntry != null) return false;
|
||||
}
|
||||
} //if target = PLAYER and playerName = null, return false, otherwise return true
|
||||
return selection != Target.PLAYER || playerName != null;
|
||||
}
|
||||
}
|
@ -4,5 +4,6 @@ import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/** This Record is used to store stat-results internally, so Players can share them by clicking a share-button.*/
|
||||
public record StatResult(String playerName, TextComponent statResult, int ID, UUID uuid) {
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import static net.kyori.adventure.text.Component.*;
|
||||
|
||||
/** Composes messages to send to a Player or Console. This class is responsible
|
||||
for constructing a final Component with the text content of the desired message.
|
||||
The component parts (with appropriate formatting) are supplied by a ComponentFactory.
|
||||
The component parts (with appropriate formatting) are supplied by a {@link ComponentFactory}.
|
||||
By default, this class works with the default ComponentFactory, but you can
|
||||
give it a different ComponentFactory upon creation.*/
|
||||
public class MessageBuilder {
|
||||
|
@ -28,6 +28,9 @@ import java.util.function.Function;
|
||||
import static org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import static com.gmail.artemis.the.gr8.playerstats.enums.StandardMessage.*;
|
||||
|
||||
/** This class manages all PlayerStats output. It is the only place where messages are sent.
|
||||
It gets the messages from a {@link MessageBuilder}, which is different for a Console as for Players
|
||||
(mainly to deal with the lack of hover-text, and for Bukkit consoles to make up for the lack of hex-colors).*/
|
||||
public final class OutputManager implements StatFormatter {
|
||||
|
||||
private static volatile OutputManager instance;
|
||||
|
@ -11,6 +11,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
/** The {@link ComponentFactory} that is used to build messages for a Bukkit Console.
|
||||
Bukkit consoles don't support hex colors, unlike Paper consoles.*/
|
||||
public class BukkitConsoleComponentFactory extends ComponentFactory {
|
||||
|
||||
public BukkitConsoleComponentFactory(ConfigHandler config) {
|
||||
|
@ -4,6 +4,7 @@ import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.PluginColor;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.MessageBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
@ -24,9 +25,9 @@ import java.util.UUID;
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
/** Creates Components with the desired formatting. This class can put Strings
|
||||
into formatted Components with TextColor and TextDecoration, or return empty Components
|
||||
or ComponentBuilders with the desired formatting.*/
|
||||
/** Creates Components with the desired formatting for the {@link MessageBuilder} to build messages with.
|
||||
This class can put Strings into formatted Components with TextColor
|
||||
and TextDecoration, or return empty Components with the desired formatting.*/
|
||||
public class ComponentFactory {
|
||||
|
||||
private static ConfigHandler config;
|
||||
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
/** A fully constructed message with examples on how to use PlayerStats.*/
|
||||
public final class ExampleMessage implements TextComponent {
|
||||
|
||||
private final TextComponent exampleMessage;
|
||||
|
@ -13,6 +13,7 @@ import java.util.List;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
/** The help message that explains how to use PlayerStats.*/
|
||||
public final class HelpMessage implements TextComponent {
|
||||
|
||||
private final TextComponent helpMessage;
|
||||
|
@ -11,6 +11,7 @@ import java.util.Random;
|
||||
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
|
||||
/** A festive version of the {@link ComponentFactory}*/
|
||||
public class PrideComponentFactory extends ComponentFactory {
|
||||
|
||||
public PrideComponentFactory(ConfigHandler c) {
|
||||
|
@ -2,6 +2,7 @@ package com.gmail.artemis.the.gr8.playerstats.msg.msgutils;
|
||||
|
||||
import org.bukkit.map.MinecraftFont;
|
||||
|
||||
/** A small utility class that helps calculate how many dots to use to get the numbers of a top-statistic aligned. */
|
||||
public final class FontUtils {
|
||||
|
||||
private FontUtils() {
|
||||
|
@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
/** A utility class that provides language keys to be put in a TranslatableComponent.*/
|
||||
public final class LanguageKeyHandler {
|
||||
|
||||
private static HashMap<Statistic, String> statNameKeys;
|
||||
|
@ -4,6 +4,9 @@ import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
/** A utility class that formats statistic numbers into something more readable.
|
||||
It transforms {@link Unit} Type TIME, DAMAGE, and DISTANCE into a more Minecraft-appropriate Unit,
|
||||
and adds commas to break up large numbers.*/
|
||||
public final class NumberFormatter {
|
||||
|
||||
private final DecimalFormat format;
|
||||
|
@ -2,6 +2,7 @@ package com.gmail.artemis.the.gr8.playerstats.msg.msgutils;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
|
||||
/** A small utility class that helps make enum constant names prettier for output in stat-messages.*/
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {
|
||||
|
@ -9,6 +9,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
|
||||
/** The action that is executed when a reload-command is triggered. */
|
||||
public final class ReloadAction extends RecursiveAction {
|
||||
|
||||
private static int threshold;
|
||||
|
@ -20,10 +20,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/** The Thread that is in charge of reloading PlayerStats. */
|
||||
public class ReloadThread extends Thread {
|
||||
|
||||
private static ConfigHandler config;
|
||||
private static OutputManager messageSender;
|
||||
private static OutputManager outputManager;
|
||||
private final OfflinePlayerHandler offlinePlayerHandler;
|
||||
|
||||
private static ShareManager shareManager;
|
||||
@ -33,10 +34,9 @@ public class ReloadThread extends Thread {
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
|
||||
public ReloadThread(ConfigHandler c, OutputManager m, OfflinePlayerHandler o, int ID, @Nullable StatThread s, @Nullable CommandSender se) {
|
||||
config = c;
|
||||
messageSender = m;
|
||||
outputManager = m;
|
||||
offlinePlayerHandler = o;
|
||||
|
||||
shareManager = ShareManager.getInstance(c);
|
||||
@ -49,6 +49,10 @@ public class ReloadThread extends Thread {
|
||||
MyLogger.threadCreated(this.getName());
|
||||
}
|
||||
|
||||
/** This method will perform a series of tasks. If a {@link StatThread} is still running,
|
||||
it will join the statThread and wait for it to finish. Then, it will reload the config,
|
||||
update the offlinePlayerList in the {@link OfflinePlayerHandler}, update the {@link DebugLevel},
|
||||
update the share-settings in {@link ShareManager} and update the MessageBuilders in the {@link OutputManager}.*/
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis();
|
||||
@ -69,7 +73,7 @@ public class ReloadThread extends Thread {
|
||||
reloadEverything();
|
||||
|
||||
if (sender != null) {
|
||||
messageSender.sendFeedbackMsg(sender, StandardMessage.RELOADED_CONFIG);
|
||||
outputManager.sendFeedbackMsg(sender, StandardMessage.RELOADED_CONFIG);
|
||||
}
|
||||
}
|
||||
else { //during first start-up
|
||||
@ -81,7 +85,7 @@ public class ReloadThread extends Thread {
|
||||
|
||||
private void reloadEverything() {
|
||||
MyLogger.setDebugLevel(config.getDebugLevel());
|
||||
messageSender.updateMessageWriters(config);
|
||||
outputManager.updateMessageWriters(config);
|
||||
offlinePlayerHandler.updateOfflinePlayerList(loadOfflinePlayers());
|
||||
shareManager.updateSettings(config);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.RecursiveAction;
|
||||
|
||||
|
||||
/** The action that is executed when a stat-command is triggered. */
|
||||
public final class StatAction extends RecursiveAction {
|
||||
|
||||
private static int threshold;
|
||||
|
@ -11,7 +11,6 @@ import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -20,6 +19,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** The Thread that is in charge of getting and calculating statistics.*/
|
||||
public class StatThread extends Thread {
|
||||
|
||||
private static ConfigHandler config;
|
||||
|
@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/** The PlayerStats Logger*/
|
||||
public final class MyLogger {
|
||||
|
||||
private static final Logger logger;
|
||||
|
@ -7,6 +7,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/** A utility class that deals with OfflinePlayers. It stores a list of all OfflinePlayer-names
|
||||
that need to be included in statistic calculations, and can retrieve the corresponding OfflinePlayer
|
||||
object for a given player-name.*/
|
||||
public class OfflinePlayerHandler {
|
||||
|
||||
private static ConcurrentHashMap<String, UUID> offlinePlayerUUIDs;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.utils;
|
||||
|
||||
/** A small utility class that calculates with unix time.*/
|
||||
public final class UnixTimeHandler {
|
||||
|
||||
private UnixTimeHandler() {
|
||||
|
Loading…
Reference in New Issue
Block a user