mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-01-22 21:41:19 +01:00
Further messing with API
This commit is contained in:
parent
228f1f2d73
commit
3ff4458a3a
@ -11,6 +11,7 @@ import com.gmail.artemis.the.gr8.playerstats.listeners.JoinListener;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.InternalStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.StatManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.RequestManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
@ -87,12 +88,12 @@ public final class Main extends JavaPlugin {
|
||||
private void initializeMainClasses(ConfigHandler config, EnumHandler enumHandler, OfflinePlayerHandler offlinePlayerHandler) {
|
||||
adventure = BukkitAudiences.create(this);
|
||||
|
||||
shareManager = new ShareManager(config);
|
||||
StatManager statManager = new StatManager(offlinePlayerHandler, config.getTopListMaxSize());
|
||||
|
||||
shareManager = new ShareManager(config);
|
||||
outputManager = new OutputManager(getAdventure(), config, shareManager);
|
||||
internalStatFetcher = new InternalStatFetcher(enumHandler, offlinePlayerHandler, outputManager);
|
||||
threadManager = new ThreadManager(config, statManager, outputManager);
|
||||
|
||||
playerStatsAPI = new PlayerStatsAPI(internalStatFetcher, statManager, outputManager);
|
||||
playerStatsAPI = new PlayerStatsAPI(statManager, outputManager);
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package com.gmail.artemis.the.gr8.playerstats;
|
||||
|
||||
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.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.reload.ReloadThread;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.StatManager;
|
||||
@ -61,19 +61,19 @@ public final class ThreadManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void startStatThread(StatRequestCore statRequestCore) {
|
||||
public void startStatThread(StatRequest statRequest) {
|
||||
statThreadID += 1;
|
||||
String cmdSender = statRequestCore.getCommandSender().getName();
|
||||
String cmdSender = statRequest.getCommandSender().getName();
|
||||
|
||||
if (config.limitStatRequests() && statThreads.containsKey(cmdSender)) {
|
||||
Thread runningThread = statThreads.get(cmdSender);
|
||||
if (runningThread.isAlive()) {
|
||||
outputManager.sendFeedbackMsg(statRequestCore.getCommandSender(), StandardMessage.REQUEST_ALREADY_RUNNING);
|
||||
outputManager.sendFeedbackMsg(statRequest.getCommandSender(), StandardMessage.REQUEST_ALREADY_RUNNING);
|
||||
} else {
|
||||
startNewStatThread(statRequestCore);
|
||||
startNewStatThread(statRequest);
|
||||
}
|
||||
} else {
|
||||
startNewStatThread(statRequestCore);
|
||||
startNewStatThread(statRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,9 +89,9 @@ public final class ThreadManager {
|
||||
return lastRecordedCalcTime;
|
||||
}
|
||||
|
||||
private void startNewStatThread(StatRequestCore statRequestCore) {
|
||||
lastActiveStatThread = new StatThread(outputManager, statManager, statThreadID, statRequestCore, lastActiveReloadThread);
|
||||
statThreads.put(statRequestCore.getCommandSender().getName(), lastActiveStatThread);
|
||||
private void startNewStatThread(StatRequest statRequest) {
|
||||
lastActiveStatThread = new StatThread(outputManager, statManager, statThreadID, statRequest, lastActiveReloadThread);
|
||||
statThreads.put(statRequest.getCommandSender().getName(), lastActiveStatThread);
|
||||
lastActiveStatThread.start();
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.PlayerStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.ServerStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.TopStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.PlayerStatRequest;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -25,9 +23,9 @@ public interface PlayerStats {
|
||||
return Main.getPlayerStatsAPI();
|
||||
}
|
||||
|
||||
PlayerStatFetcher playerStat(String playerName);
|
||||
PlayerStatRequest playerStat(String playerName);
|
||||
|
||||
ServerStatFetcher serverStat();
|
||||
RequestGenerator serverStat();
|
||||
|
||||
TopStatFetcher topStat(int topListSize);
|
||||
RequestGenerator topStat(int topListSize);
|
||||
}
|
@ -1,40 +1,40 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.InternalStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.StatManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.PlayerStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.ServerStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.TopStatFetcher;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.PlayerStatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.RequestManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
|
||||
import static org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
/** The implementation of the API Interface */
|
||||
public final class PlayerStatsAPI implements PlayerStats {
|
||||
|
||||
private static InternalStatFetcher requestGenerator;
|
||||
private static StatCalculator statCalculator;
|
||||
private static StatFormatter statFormatter;
|
||||
|
||||
@Internal
|
||||
public PlayerStatsAPI(InternalStatFetcher request, StatManager stat, StatFormatter format) {
|
||||
PlayerStatsAPI.requestGenerator = request;
|
||||
public PlayerStatsAPI(StatManager stat, StatFormatter format) {
|
||||
statCalculator = stat;
|
||||
statFormatter = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerStatFetcher playerStat(String playerName) {
|
||||
return new PlayerStatFetcher(playerName);
|
||||
public PlayerStatRequest playerStat(String playerName) {
|
||||
StatRequest request = RequestManager.generateBasicPlayerRequest(playerName);
|
||||
return new PlayerStatRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStatFetcher serverStat() {
|
||||
return new ServerStatFetcher();
|
||||
public RequestGenerator serverStat() {
|
||||
StatRequest request = RequestManager.generateBasicServerRequest();
|
||||
return new RequestManager(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TopStatFetcher topStat(int topListSize) {
|
||||
return new TopStatFetcher(topListSize);
|
||||
public RequestGenerator topStat(int topListSize) {
|
||||
StatRequest request = RequestManager.generateBasicTopRequest(topListSize);
|
||||
return new RequestManager(request);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public interface RequestExecutor<T> {
|
||||
|
||||
StatResult<T> untyped(Statistic statistic);
|
||||
|
||||
StatResult<T> blockOrItemType(Statistic statistic, Material material);
|
||||
|
||||
StatResult<T> entityType(Statistic statistic, EntityType entityType);
|
||||
}
|
@ -1,37 +1,18 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
/** Turns user input into a valid {@link StatRequestCore}. This StatRequest should hold all
|
||||
/** Turns user input into a valid {@link StatRequest}. This StatRequest should hold all
|
||||
the information PlayerStats needs to work with, and is used by the {@link StatCalculator}
|
||||
to get the desired statistic data.*/
|
||||
@Internal
|
||||
public abstract class RequestGenerator {
|
||||
public interface RequestGenerator {
|
||||
|
||||
protected StatRequestCore statRequest;
|
||||
StatRequest untyped(Statistic statistic);
|
||||
|
||||
protected abstract StatRequestCore generateBaseRequest();
|
||||
StatRequest blockOrItemType(Statistic statistic, Material material);
|
||||
|
||||
StatRequestCore untyped(Statistic statistic) {
|
||||
statRequest.setStatistic(statistic);
|
||||
return statRequest;
|
||||
}
|
||||
|
||||
StatRequestCore blockOrItemType(Statistic statistic, Material material) {
|
||||
statRequest.setSubStatEntryName(material.toString());
|
||||
if (statistic.getType() == Statistic.Type.BLOCK) {
|
||||
statRequest.setBlock(material);
|
||||
} else {
|
||||
statRequest.setItem(material);
|
||||
}
|
||||
return statRequest;
|
||||
}
|
||||
|
||||
StatRequestCore entityType(Statistic statistic, EntityType entityType) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
StatRequest entityType(Statistic statistic, EntityType entityType);
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/** The {@link StatCalculator} is responsible for getting, calculating and/or ordering raw numbers.
|
||||
It represents the actual statistic-getting magic that happens once a valid
|
||||
{@link StatRequestCore} is passed to it.
|
||||
{@link StatRequest} is passed to it.
|
||||
<br>
|
||||
<br>The StatCalculator gets its data from the vanilla statistic files (stored by the server). It can return three kinds of data,
|
||||
depending on the chosen {@link Target}:
|
||||
@ -17,16 +17,16 @@ import java.util.LinkedHashMap;
|
||||
<br>- LinkedHashMap[String player-name, Integer number] (for {@link Target#TOP})
|
||||
<br>
|
||||
<br>For more information on how to create a valid StatRequest,
|
||||
see the class description for {@link StatRequestCore}.*/
|
||||
see the class description for {@link StatRequest}.*/
|
||||
@Internal
|
||||
public interface StatCalculator {
|
||||
|
||||
/** Returns the requested Statistic*/
|
||||
int getPlayerStat(StatRequestCore statRequestCore);
|
||||
int getPlayerStat(StatRequest statRequest);
|
||||
|
||||
/** Don't call from main Thread!*/
|
||||
long getServerStat(StatRequestCore statRequestCore);
|
||||
long getServerStat(StatRequest statRequest);
|
||||
|
||||
/** Don't call from main Thread!*/
|
||||
LinkedHashMap<String, Integer> getTopStats(StatRequestCore statRequestCore);
|
||||
LinkedHashMap<String, Integer> getTopStats(StatRequest statRequest);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.ComponentUtils;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.*;
|
||||
@ -9,7 +9,7 @@ import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/** The {@link StatFormatter} formats raw numbers into pretty messages.
|
||||
This Formatter takes a {@link StatRequestCore} and combines it with the raw number(s)
|
||||
This Formatter takes a {@link StatRequest} and combines it with the raw number(s)
|
||||
returned by the {@link StatCalculator}, and transforms those into a pretty message
|
||||
(by default a TextComponent) with all the relevant information in it.
|
||||
<br>
|
||||
@ -38,16 +38,16 @@ public interface StatFormatter {
|
||||
|
||||
/** @return a TextComponent with the following parts:
|
||||
<br>[player-name]: [number] [stat-name] {sub-stat-name}*/
|
||||
TextComponent formatPlayerStat(StatRequestCore statRequestCore, int playerStat);
|
||||
TextComponent formatPlayerStat(StatRequest statRequest, int playerStat);
|
||||
|
||||
/** @return a TextComponent with the following parts:
|
||||
<br>[Total on] [server-name]: [number] [stat-name] [sub-stat-name]*/
|
||||
TextComponent formatServerStat(StatRequestCore statRequestCore, long serverStat);
|
||||
TextComponent formatServerStat(StatRequest statRequest, long serverStat);
|
||||
|
||||
/** @return a TextComponent with the following parts:
|
||||
<br>[PlayerStats] [Top 10] [stat-name] [sub-stat-name]
|
||||
<br> [1.] [player-name] [number]
|
||||
<br> [2.] [player-name] [number]
|
||||
<br> [3.] etc...*/
|
||||
TextComponent formatTopStat(StatRequestCore statRequestCore, LinkedHashMap<String, Integer> topStats);
|
||||
TextComponent formatTopStat(StatRequest statRequest, LinkedHashMap<String, Integer> topStats);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.commands;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.InternalStatFetcher;
|
||||
import org.bukkit.command.Command;
|
||||
@ -32,9 +32,9 @@ public final class StatCommand implements CommandExecutor {
|
||||
outputManager.sendExamples(sender);
|
||||
}
|
||||
else {
|
||||
StatRequestCore statRequestCore = internalStatFetcher.generateRequest(sender, args);
|
||||
if (internalStatFetcher.validateRequest(statRequestCore)) {
|
||||
threadManager.startStatThread(statRequestCore);
|
||||
StatRequest statRequest = internalStatFetcher.generateRequest(sender, args);
|
||||
if (internalStatFetcher.validateRequest(statRequest)) {
|
||||
threadManager.startStatThread(statRequest);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.ComponentFactory;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.ExampleMessage;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.HelpMessage;
|
||||
@ -169,15 +169,15 @@ public final class MessageBuilder {
|
||||
<p>- Integer shareCode: if a shareCode is provided, a clickable "share" button will be added.
|
||||
<br>- CommandSender sender: if a sender is provided, a signature with "shared by sender-name" will be added.</br>
|
||||
<br>- If both parameters are null, the statResult will be returned as is.</br>*/
|
||||
public BiFunction<Integer, CommandSender, TextComponent> formattedPlayerStatFunction(int stat, @NotNull StatRequestCore statRequestCore) {
|
||||
public BiFunction<Integer, CommandSender, TextComponent> formattedPlayerStatFunction(int stat, @NotNull StatRequest statRequest) {
|
||||
TextComponent playerStat = Component.text()
|
||||
.append(componentFactory.playerName(statRequestCore.getPlayerName(), Target.PLAYER)
|
||||
.append(componentFactory.playerName(statRequest.getPlayerName(), Target.PLAYER)
|
||||
.append(text(":"))
|
||||
.append(space()))
|
||||
.append(getStatNumberComponent(statRequestCore.getStatistic(), stat, Target.PLAYER, statRequestCore.isConsoleSender()))
|
||||
.append(getStatNumberComponent(statRequest.getStatistic(), stat, Target.PLAYER, statRequest.isConsoleSender()))
|
||||
.append(space())
|
||||
.append(getStatNameComponent(statRequestCore))
|
||||
.append(getStatUnitComponent(statRequestCore.getStatistic(), statRequestCore.getTarget(), statRequestCore.isConsoleSender())) //space is provided by statUnitComponent
|
||||
.append(getStatNameComponent(statRequest))
|
||||
.append(getStatUnitComponent(statRequest.getStatistic(), statRequest.getTarget(), statRequest.isConsoleSender())) //space is provided by statUnitComponent
|
||||
.build();
|
||||
|
||||
return getFormattingFunction(playerStat, Target.PLAYER);
|
||||
@ -188,16 +188,16 @@ public final class MessageBuilder {
|
||||
<p>- Integer shareCode: if a shareCode is provided, a clickable "share" button will be added.
|
||||
<br>- CommandSender sender: if a sender is provided, a signature with "shared by sender-name" will be added.</br>
|
||||
<br>- If both parameters are null, the statResult will be returned as is.</br>*/
|
||||
public BiFunction<Integer, CommandSender, TextComponent> formattedServerStatFunction(long stat, @NotNull StatRequestCore statRequestCore) {
|
||||
public BiFunction<Integer, CommandSender, TextComponent> formattedServerStatFunction(long stat, @NotNull StatRequest statRequest) {
|
||||
TextComponent serverStat = text()
|
||||
.append(componentFactory.title(config.getServerTitle(), Target.SERVER))
|
||||
.append(space())
|
||||
.append(componentFactory.serverName(config.getServerName()))
|
||||
.append(space())
|
||||
.append(getStatNumberComponent(statRequestCore.getStatistic(), stat, Target.SERVER, statRequestCore.isConsoleSender()))
|
||||
.append(getStatNumberComponent(statRequest.getStatistic(), stat, Target.SERVER, statRequest.isConsoleSender()))
|
||||
.append(space())
|
||||
.append(getStatNameComponent(statRequestCore))
|
||||
.append(getStatUnitComponent(statRequestCore.getStatistic(), statRequestCore.getTarget(), statRequestCore.isConsoleSender())) //space is provided by statUnit
|
||||
.append(getStatNameComponent(statRequest))
|
||||
.append(getStatUnitComponent(statRequest.getStatistic(), statRequest.getTarget(), statRequest.isConsoleSender())) //space is provided by statUnit
|
||||
.build();
|
||||
|
||||
return getFormattingFunction(serverStat, Target.SERVER);
|
||||
@ -208,10 +208,10 @@ public final class MessageBuilder {
|
||||
<p>- Integer shareCode: if a shareCode is provided, a clickable "share" button will be added.
|
||||
<br>- CommandSender sender: if a sender is provided, a signature with "shared by sender-name" will be added.</br>
|
||||
<br>- If both parameters are null, the statResult will be returned as is.</br>*/
|
||||
public BiFunction<Integer, CommandSender, TextComponent> formattedTopStatFunction(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequestCore statRequestCore) {
|
||||
final TextComponent title = getTopStatsTitleComponent(statRequestCore, topStats.size());
|
||||
final TextComponent shortTitle = getTopStatsTitleShortComponent(statRequestCore, topStats.size());
|
||||
final TextComponent list = getTopStatListComponent(topStats, statRequestCore);
|
||||
public BiFunction<Integer, CommandSender, TextComponent> formattedTopStatFunction(@NotNull LinkedHashMap<String, Integer> topStats, @NotNull StatRequest statRequest) {
|
||||
final TextComponent title = getTopStatsTitleComponent(statRequest, topStats.size());
|
||||
final TextComponent shortTitle = getTopStatsTitleShortComponent(statRequest, topStats.size());
|
||||
final TextComponent list = getTopStatListComponent(topStats, statRequest);
|
||||
final boolean useEnters = config.useEnters(Target.TOP, false);
|
||||
final boolean useEntersForShared = config.useEnters(Target.TOP, true);
|
||||
|
||||
@ -302,25 +302,25 @@ public final class MessageBuilder {
|
||||
return componentFactory.sharerName(sender.getName());
|
||||
}
|
||||
|
||||
private TextComponent getTopStatsTitleComponent(StatRequestCore statRequestCore, int statListSize) {
|
||||
private TextComponent getTopStatsTitleComponent(StatRequest statRequest, int statListSize) {
|
||||
return Component.text()
|
||||
.append(componentFactory.pluginPrefix()).append(space())
|
||||
.append(componentFactory.title(config.getTopStatsTitle(), Target.TOP)).append(space())
|
||||
.append(componentFactory.titleNumber(statListSize)).append(space())
|
||||
.append(getStatNameComponent(statRequestCore)) //space is provided by statUnitComponent
|
||||
.append(getStatUnitComponent(statRequestCore.getStatistic(), statRequestCore.getTarget(), statRequestCore.isConsoleSender()))
|
||||
.append(getStatNameComponent(statRequest)) //space is provided by statUnitComponent
|
||||
.append(getStatUnitComponent(statRequest.getStatistic(), statRequest.getTarget(), statRequest.isConsoleSender()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private TextComponent getTopStatsTitleShortComponent(StatRequestCore statRequestCore, int statListSize) {
|
||||
private TextComponent getTopStatsTitleShortComponent(StatRequest statRequest, int statListSize) {
|
||||
return Component.text()
|
||||
.append(componentFactory.title(config.getTopStatsTitle(), Target.TOP)).append(space())
|
||||
.append(componentFactory.titleNumber(statListSize)).append(space())
|
||||
.append(getStatNameComponent(statRequestCore)) //space is provided by statUnitComponent
|
||||
.append(getStatNameComponent(statRequest)) //space is provided by statUnitComponent
|
||||
.build();
|
||||
}
|
||||
|
||||
private TextComponent getTopStatListComponent(LinkedHashMap<String, Integer> topStats, StatRequestCore statRequestCore) {
|
||||
private TextComponent getTopStatListComponent(LinkedHashMap<String, Integer> topStats, StatRequest statRequest) {
|
||||
TextComponent.Builder topList = Component.text();
|
||||
boolean useDots = config.useDots();
|
||||
boolean boldNames = config.playerNameIsBold();
|
||||
@ -335,7 +335,7 @@ public final class MessageBuilder {
|
||||
if (useDots) {
|
||||
topList.append(playerNameBuilder)
|
||||
.append(space());
|
||||
int dots = FontUtils.getNumberOfDotsToAlign(count + ". " + playerName, statRequestCore.isConsoleSender(), boldNames);
|
||||
int dots = FontUtils.getNumberOfDotsToAlign(count + ". " + playerName, statRequest.isConsoleSender(), boldNames);
|
||||
if (dots >= 1) {
|
||||
topList.append(componentFactory.dots().append(text((".".repeat(dots)))));
|
||||
}
|
||||
@ -343,33 +343,33 @@ public final class MessageBuilder {
|
||||
else {
|
||||
topList.append(playerNameBuilder.append(text(":")));
|
||||
}
|
||||
topList.append(space()).append(getStatNumberComponent(statRequestCore.getStatistic(), topStats.get(playerName), Target.TOP, statRequestCore.isConsoleSender()));
|
||||
topList.append(space()).append(getStatNumberComponent(statRequest.getStatistic(), topStats.get(playerName), Target.TOP, statRequest.isConsoleSender()));
|
||||
}
|
||||
return topList.build();
|
||||
}
|
||||
|
||||
/** 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(StatRequestCore statRequestCore) {
|
||||
private TextComponent getStatNameComponent(StatRequest statRequest) {
|
||||
if (config.useTranslatableComponents()) {
|
||||
String statKey = languageKeyHandler.getStatKey(statRequestCore.getStatistic());
|
||||
String subStatKey = statRequestCore.getSubStatEntryName();
|
||||
String statKey = languageKeyHandler.getStatKey(statRequest.getStatistic());
|
||||
String subStatKey = statRequest.getSubStatEntryName();
|
||||
if (subStatKey != null) {
|
||||
switch (statRequestCore.getStatistic().getType()) {
|
||||
case BLOCK -> subStatKey = languageKeyHandler.getBlockKey(statRequestCore.getBlock());
|
||||
case ENTITY -> subStatKey = languageKeyHandler.getEntityKey(statRequestCore.getEntity());
|
||||
case ITEM -> subStatKey = languageKeyHandler.getItemKey(statRequestCore.getItem());
|
||||
switch (statRequest.getStatistic().getType()) {
|
||||
case BLOCK -> subStatKey = languageKeyHandler.getBlockKey(statRequest.getBlock());
|
||||
case ENTITY -> subStatKey = languageKeyHandler.getEntityKey(statRequest.getEntity());
|
||||
case ITEM -> subStatKey = languageKeyHandler.getItemKey(statRequest.getItem());
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return componentFactory.statAndSubStatNameTranslatable(statKey, subStatKey, statRequestCore.getTarget());
|
||||
return componentFactory.statAndSubStatNameTranslatable(statKey, subStatKey, statRequest.getTarget());
|
||||
}
|
||||
else {
|
||||
return componentFactory.statAndSubStatName(
|
||||
StringUtils.prettify(statRequestCore.getStatistic().toString()),
|
||||
StringUtils.prettify(statRequestCore.getSubStatEntryName()),
|
||||
statRequestCore.getTarget());
|
||||
StringUtils.prettify(statRequest.getStatistic().toString()),
|
||||
StringUtils.prettify(statRequest.getSubStatEntryName()),
|
||||
statRequest.getTarget());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import com.gmail.artemis.the.gr8.playerstats.ShareManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.StatFormatter;
|
||||
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.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.BukkitConsoleComponentFactory;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.components.PrideComponentFactory;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
@ -50,27 +50,27 @@ public final class OutputManager implements StatFormatter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent formatPlayerStat(@NotNull StatRequestCore statRequestCore, int playerStat) {
|
||||
public TextComponent formatPlayerStat(@NotNull StatRequest statRequest, int playerStat) {
|
||||
BiFunction<Integer, CommandSender, TextComponent> playerStatFunction =
|
||||
getWriter(statRequestCore).formattedPlayerStatFunction(playerStat, statRequestCore);
|
||||
getWriter(statRequest).formattedPlayerStatFunction(playerStat, statRequest);
|
||||
|
||||
return processFunction(statRequestCore.getCommandSender(), playerStatFunction);
|
||||
return processFunction(statRequest.getCommandSender(), playerStatFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent formatServerStat(@NotNull StatRequestCore statRequestCore, long serverStat) {
|
||||
public TextComponent formatServerStat(@NotNull StatRequest statRequest, long serverStat) {
|
||||
BiFunction<Integer, CommandSender, TextComponent> serverStatFunction =
|
||||
getWriter(statRequestCore).formattedServerStatFunction(serverStat, statRequestCore);
|
||||
getWriter(statRequest).formattedServerStatFunction(serverStat, statRequest);
|
||||
|
||||
return processFunction(statRequestCore.getCommandSender(), serverStatFunction);
|
||||
return processFunction(statRequest.getCommandSender(), serverStatFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextComponent formatTopStat(@NotNull StatRequestCore statRequestCore, @NotNull LinkedHashMap<String, Integer> topStats) {
|
||||
public TextComponent formatTopStat(@NotNull StatRequest statRequest, @NotNull LinkedHashMap<String, Integer> topStats) {
|
||||
BiFunction<Integer, CommandSender, TextComponent> topStatFunction =
|
||||
getWriter(statRequestCore).formattedTopStatFunction(topStats, statRequestCore);
|
||||
getWriter(statRequest).formattedTopStatFunction(topStats, statRequest);
|
||||
|
||||
return processFunction(statRequestCore.getCommandSender(), topStatFunction);
|
||||
return processFunction(statRequest.getCommandSender(), topStatFunction);
|
||||
}
|
||||
|
||||
public void sendFeedbackMsg(@NotNull CommandSender sender, StandardMessage message) {
|
||||
@ -136,8 +136,8 @@ public final class OutputManager implements StatFormatter {
|
||||
return sender instanceof ConsoleCommandSender ? consoleWriter : writer;
|
||||
}
|
||||
|
||||
private MessageBuilder getWriter(StatRequestCore statRequestCore) {
|
||||
if (statRequestCore.isAPIRequest() || !statRequestCore.isConsoleSender()) {
|
||||
private MessageBuilder getWriter(StatRequest statRequest) {
|
||||
if (statRequest.isAPIRequest() || !statRequest.isConsoleSender()) {
|
||||
return writer;
|
||||
} else {
|
||||
return consoleWriter;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -18,7 +18,7 @@ final class StatAction extends RecursiveTask<ConcurrentHashMap<String, Integer>>
|
||||
|
||||
private final OfflinePlayerHandler offlinePlayerHandler;
|
||||
private final ImmutableList<String> playerNames;
|
||||
private final StatRequestCore statRequestCore;
|
||||
private final StatRequest statRequest;
|
||||
private final ConcurrentHashMap<String, Integer> allStats;
|
||||
|
||||
/**
|
||||
@ -26,15 +26,15 @@ final class StatAction extends RecursiveTask<ConcurrentHashMap<String, Integer>>
|
||||
* using the default ForkJoinPool, and returns the ConcurrentHashMap when everything is done
|
||||
* @param offlinePlayerHandler the OfflinePlayerHandler to convert playerNames into Players
|
||||
* @param playerNames ImmutableList of playerNames for players that should be included in stat calculations
|
||||
* @param statRequestCore a validated statRequest
|
||||
* @param statRequest a validated statRequest
|
||||
* @param allStats the ConcurrentHashMap to put the results on
|
||||
*/
|
||||
public StatAction(OfflinePlayerHandler offlinePlayerHandler, ImmutableList<String> playerNames, StatRequestCore statRequestCore, ConcurrentHashMap<String, Integer> allStats) {
|
||||
public StatAction(OfflinePlayerHandler offlinePlayerHandler, ImmutableList<String> playerNames, StatRequest statRequest, ConcurrentHashMap<String, Integer> allStats) {
|
||||
threshold = ThreadManager.getTaskThreshold();
|
||||
|
||||
this.offlinePlayerHandler = offlinePlayerHandler;
|
||||
this.playerNames = playerNames;
|
||||
this.statRequestCore = statRequestCore;
|
||||
this.statRequest = statRequest;
|
||||
this.allStats = allStats;
|
||||
|
||||
MyLogger.subActionCreated(Thread.currentThread().getName());
|
||||
@ -46,8 +46,8 @@ final class StatAction extends RecursiveTask<ConcurrentHashMap<String, Integer>>
|
||||
return getStatsDirectly();
|
||||
}
|
||||
else {
|
||||
final StatAction subTask1 = new StatAction(offlinePlayerHandler, playerNames.subList(0, playerNames.size()/2), statRequestCore, allStats);
|
||||
final StatAction subTask2 = new StatAction(offlinePlayerHandler, playerNames.subList(playerNames.size()/2, playerNames.size()), statRequestCore, allStats);
|
||||
final StatAction subTask1 = new StatAction(offlinePlayerHandler, playerNames.subList(0, playerNames.size()/2), statRequest, allStats);
|
||||
final StatAction subTask2 = new StatAction(offlinePlayerHandler, playerNames.subList(playerNames.size()/2, playerNames.size()), statRequest, allStats);
|
||||
|
||||
//queue and compute all subtasks in the right order
|
||||
subTask1.fork();
|
||||
@ -65,11 +65,11 @@ final class StatAction extends RecursiveTask<ConcurrentHashMap<String, Integer>>
|
||||
OfflinePlayer player = offlinePlayerHandler.getOfflinePlayer(playerName);
|
||||
if (player != null) {
|
||||
int statistic = 0;
|
||||
switch (statRequestCore.getStatistic().getType()) {
|
||||
case UNTYPED -> statistic = player.getStatistic(statRequestCore.getStatistic());
|
||||
case ENTITY -> statistic = player.getStatistic(statRequestCore.getStatistic(), statRequestCore.getEntity());
|
||||
case BLOCK -> statistic = player.getStatistic(statRequestCore.getStatistic(), statRequestCore.getBlock());
|
||||
case ITEM -> statistic = player.getStatistic(statRequestCore.getStatistic(), statRequestCore.getItem());
|
||||
switch (statRequest.getStatistic().getType()) {
|
||||
case UNTYPED -> statistic = player.getStatistic(statRequest.getStatistic());
|
||||
case ENTITY -> statistic = player.getStatistic(statRequest.getStatistic(), statRequest.getEntity());
|
||||
case BLOCK -> statistic = player.getStatistic(statRequest.getStatistic(), statRequest.getBlock());
|
||||
case ITEM -> statistic = player.getStatistic(statRequest.getStatistic(), statRequest.getItem());
|
||||
}
|
||||
if (statistic > 0) {
|
||||
allStats.put(playerName, statistic);
|
||||
|
@ -2,7 +2,7 @@ package com.gmail.artemis.the.gr8.playerstats.statistic;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.StatCalculator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@ -30,28 +30,28 @@ public final class StatManager implements StatCalculator {
|
||||
|
||||
/** Gets the statistic data for an individual player. If somehow the player
|
||||
cannot be found, this returns 0.*/
|
||||
public int getPlayerStat(StatRequestCore statRequestCore) {
|
||||
OfflinePlayer player = offlinePlayerHandler.getOfflinePlayer(statRequestCore.getPlayerName());
|
||||
public int getPlayerStat(StatRequest statRequest) {
|
||||
OfflinePlayer player = offlinePlayerHandler.getOfflinePlayer(statRequest.getPlayerName());
|
||||
if (player != null) {
|
||||
return switch (statRequestCore.getStatistic().getType()) {
|
||||
case UNTYPED -> player.getStatistic(statRequestCore.getStatistic());
|
||||
case ENTITY -> player.getStatistic(statRequestCore.getStatistic(), statRequestCore.getEntity());
|
||||
case BLOCK -> player.getStatistic(statRequestCore.getStatistic(), statRequestCore.getBlock());
|
||||
case ITEM -> player.getStatistic(statRequestCore.getStatistic(), statRequestCore.getItem());
|
||||
return switch (statRequest.getStatistic().getType()) {
|
||||
case UNTYPED -> player.getStatistic(statRequest.getStatistic());
|
||||
case ENTITY -> player.getStatistic(statRequest.getStatistic(), statRequest.getEntity());
|
||||
case BLOCK -> player.getStatistic(statRequest.getStatistic(), statRequest.getBlock());
|
||||
case ITEM -> player.getStatistic(statRequest.getStatistic(), statRequest.getItem());
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, Integer> getTopStats(StatRequestCore statRequestCore) {
|
||||
return getAllStatsAsync(statRequestCore).entrySet().stream()
|
||||
public LinkedHashMap<String, Integer> getTopStats(StatRequest statRequest) {
|
||||
return getAllStatsAsync(statRequest).entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
|
||||
.limit(topListMaxSize)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
public long getServerStat(StatRequestCore statRequestCore) {
|
||||
List<Integer> numbers = getAllStatsAsync(statRequestCore)
|
||||
public long getServerStat(StatRequest statRequest) {
|
||||
List<Integer> numbers = getAllStatsAsync(statRequest)
|
||||
.values()
|
||||
.parallelStream()
|
||||
.toList();
|
||||
@ -60,14 +60,14 @@ public final class StatManager implements StatCalculator {
|
||||
|
||||
/** Invokes a bunch of worker pool threads to divide and conquer (get the statistics for all players
|
||||
that are stored in the {@link OfflinePlayerHandler}) */
|
||||
private @NotNull ConcurrentHashMap<String, Integer> getAllStatsAsync(StatRequestCore statRequestCore) {
|
||||
private @NotNull ConcurrentHashMap<String, Integer> getAllStatsAsync(StatRequest statRequest) {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
ForkJoinPool commonPool = ForkJoinPool.commonPool();
|
||||
ConcurrentHashMap<String, Integer> allStats;
|
||||
|
||||
try {
|
||||
allStats = commonPool.invoke(getStatTask(statRequestCore));
|
||||
allStats = commonPool.invoke(getStatTask(statRequest));
|
||||
} catch (ConcurrentModificationException e) {
|
||||
MyLogger.logMsg("The statRequest could not be executed due to a ConcurrentModificationException. " +
|
||||
"This likely happened because Bukkit hasn't fully initialized all player-data yet. " +
|
||||
@ -82,12 +82,12 @@ public final class StatManager implements StatCalculator {
|
||||
return allStats;
|
||||
}
|
||||
|
||||
private StatAction getStatTask(StatRequestCore statRequestCore) {
|
||||
private StatAction getStatTask(StatRequest statRequest) {
|
||||
int size = offlinePlayerHandler.getOfflinePlayerCount() != 0 ? offlinePlayerHandler.getOfflinePlayerCount() : 16;
|
||||
ConcurrentHashMap<String, Integer> allStats = new ConcurrentHashMap<>(size);
|
||||
ImmutableList<String> playerNames = ImmutableList.copyOf(offlinePlayerHandler.getOfflinePlayerNames());
|
||||
|
||||
StatAction task = new StatAction(offlinePlayerHandler, playerNames, statRequestCore, allStats);
|
||||
StatAction task = new StatAction(offlinePlayerHandler, playerNames, statRequest, allStats);
|
||||
MyLogger.actionCreated(playerNames.size());
|
||||
|
||||
return task;
|
||||
|
@ -3,7 +3,7 @@ package com.gmail.artemis.the.gr8.playerstats.statistic;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.StatFormatter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.StandardMessage;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequestCore;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.request.StatRequest;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.reload.ReloadThread;
|
||||
import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
@ -20,16 +20,16 @@ public final class StatThread extends Thread {
|
||||
private static StatManager statManager;
|
||||
|
||||
private final ReloadThread reloadThread;
|
||||
private final StatRequestCore statRequestCore;
|
||||
private final StatRequest statRequest;
|
||||
|
||||
public StatThread(OutputManager m, StatManager t, int ID, StatRequestCore s, @Nullable ReloadThread r) {
|
||||
public StatThread(OutputManager m, StatManager t, int ID, StatRequest s, @Nullable ReloadThread r) {
|
||||
outputManager = m;
|
||||
statManager = t;
|
||||
|
||||
reloadThread = r;
|
||||
statRequestCore = s;
|
||||
statRequest = s;
|
||||
|
||||
this.setName("StatThread-" + statRequestCore.getCommandSender().getName() + "-" + ID);
|
||||
this.setName("StatThread-" + statRequest.getCommandSender().getName() + "-" + ID);
|
||||
MyLogger.threadCreated(this.getName());
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ public final class StatThread extends Thread {
|
||||
public void run() throws IllegalStateException, NullPointerException {
|
||||
MyLogger.threadStart(this.getName());
|
||||
|
||||
if (statRequestCore == null) {
|
||||
if (statRequest == null) {
|
||||
throw new NullPointerException("No statistic statRequest was found!");
|
||||
}
|
||||
if (reloadThread != null && reloadThread.isAlive()) {
|
||||
try {
|
||||
MyLogger.waitingForOtherThread(this.getName(), reloadThread.getName());
|
||||
outputManager.sendFeedbackMsg(statRequestCore.getCommandSender(), StandardMessage.STILL_RELOADING);
|
||||
outputManager.sendFeedbackMsg(statRequest.getCommandSender(), StandardMessage.STILL_RELOADING);
|
||||
reloadThread.join();
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
@ -54,27 +54,27 @@ public final class StatThread extends Thread {
|
||||
|
||||
long lastCalc = ThreadManager.getLastRecordedCalcTime();
|
||||
if (lastCalc > 2000) {
|
||||
outputManager.sendFeedbackMsgWaitAMoment(statRequestCore.getCommandSender(), lastCalc > 20000);
|
||||
outputManager.sendFeedbackMsgWaitAMoment(statRequest.getCommandSender(), lastCalc > 20000);
|
||||
}
|
||||
|
||||
Target selection = statRequestCore.getTarget();
|
||||
Target selection = statRequest.getTarget();
|
||||
try {
|
||||
TextComponent statResult = switch (selection) {
|
||||
case PLAYER -> outputManager.formatPlayerStat(statRequestCore, statManager.getPlayerStat(statRequestCore));
|
||||
case TOP -> outputManager.formatTopStat(statRequestCore, statManager.getTopStats(statRequestCore));
|
||||
case SERVER -> outputManager.formatServerStat(statRequestCore, statManager.getServerStat(statRequestCore));
|
||||
case PLAYER -> outputManager.formatPlayerStat(statRequest, statManager.getPlayerStat(statRequest));
|
||||
case TOP -> outputManager.formatTopStat(statRequest, statManager.getTopStats(statRequest));
|
||||
case SERVER -> outputManager.formatServerStat(statRequest, statManager.getServerStat(statRequest));
|
||||
};
|
||||
if (statRequestCore.isAPIRequest()) {
|
||||
if (statRequest.isAPIRequest()) {
|
||||
String msg = StatFormatter.statResultComponentToString(statResult);
|
||||
statRequestCore.getCommandSender().sendMessage(msg);
|
||||
statRequest.getCommandSender().sendMessage(msg);
|
||||
}
|
||||
else {
|
||||
outputManager.sendToCommandSender(statRequestCore.getCommandSender(), statResult);
|
||||
outputManager.sendToCommandSender(statRequest.getCommandSender(), statResult);
|
||||
}
|
||||
}
|
||||
catch (ConcurrentModificationException e) {
|
||||
if (!statRequestCore.isConsoleSender()) {
|
||||
outputManager.sendFeedbackMsg(statRequestCore.getCommandSender(), StandardMessage.UNKNOWN_ERROR);
|
||||
if (!statRequest.isConsoleSender()) {
|
||||
outputManager.sendFeedbackMsg(statRequest.getCommandSender(), StandardMessage.UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public final class InternalStatFetcher {
|
||||
InternalStatFetcher.outputManager = outputManager;
|
||||
}
|
||||
|
||||
/** This will create a {@link StatRequestCore} 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 such as a CommandSender would put in Minecraft chat:
|
||||
@ -36,51 +36,51 @@ public final class InternalStatFetcher {
|
||||
@param sender the CommandSender that requested this specific statistic
|
||||
@return the generated StatRequest
|
||||
*/
|
||||
public StatRequestCore generateRequest(CommandSender sender, String[] args) {
|
||||
StatRequestCore statRequestCore = new StatRequestCore(sender);
|
||||
public StatRequest generateRequest(CommandSender sender, String[] args) {
|
||||
StatRequest statRequest = new StatRequest(sender);
|
||||
for (String arg : args) {
|
||||
//check for statName
|
||||
if (enumHandler.isStatistic(arg) && statRequestCore.getStatistic() == null) {
|
||||
statRequestCore.setStatistic(EnumHandler.getStatEnum(arg));
|
||||
if (enumHandler.isStatistic(arg) && statRequest.getStatistic() == null) {
|
||||
statRequest.setStatistic(EnumHandler.getStatEnum(arg));
|
||||
}
|
||||
//check for subStatEntry and playerFlag
|
||||
else if (enumHandler.isSubStatEntry(arg)) {
|
||||
if (arg.equalsIgnoreCase("player") && !statRequestCore.getPlayerFlag()) {
|
||||
statRequestCore.setPlayerFlag(true);
|
||||
if (arg.equalsIgnoreCase("player") && !statRequest.getPlayerFlag()) {
|
||||
statRequest.setPlayerFlag(true);
|
||||
}
|
||||
else {
|
||||
if (statRequestCore.getSubStatEntryName() == null) statRequestCore.setSubStatEntryName(arg);
|
||||
if (statRequest.getSubStatEntryName() == null) statRequest.setSubStatEntryName(arg);
|
||||
}
|
||||
}
|
||||
//check for selection
|
||||
else if (arg.equalsIgnoreCase("top")) {
|
||||
statRequestCore.setTarget(Target.TOP);
|
||||
statRequest.setTarget(Target.TOP);
|
||||
}
|
||||
else if (arg.equalsIgnoreCase("server")) {
|
||||
statRequestCore.setTarget(Target.SERVER);
|
||||
statRequest.setTarget(Target.SERVER);
|
||||
}
|
||||
else if (arg.equalsIgnoreCase("me")) {
|
||||
if (sender instanceof Player) {
|
||||
statRequestCore.setPlayerName(sender.getName());
|
||||
statRequestCore.setTarget(Target.PLAYER);
|
||||
statRequest.setPlayerName(sender.getName());
|
||||
statRequest.setTarget(Target.PLAYER);
|
||||
}
|
||||
else if (sender instanceof ConsoleCommandSender) {
|
||||
statRequestCore.setTarget(Target.SERVER);
|
||||
statRequest.setTarget(Target.SERVER);
|
||||
}
|
||||
}
|
||||
else if (offlinePlayerHandler.isRelevantPlayer(arg) && statRequestCore.getPlayerName() == null) {
|
||||
statRequestCore.setPlayerName(arg);
|
||||
statRequestCore.setTarget(Target.PLAYER);
|
||||
else if (offlinePlayerHandler.isRelevantPlayer(arg) && statRequest.getPlayerName() == null) {
|
||||
statRequest.setPlayerName(arg);
|
||||
statRequest.setTarget(Target.PLAYER);
|
||||
}
|
||||
else if (arg.equalsIgnoreCase("api")) {
|
||||
statRequestCore.setAPIRequest();
|
||||
statRequest.setAPIRequest();
|
||||
}
|
||||
}
|
||||
patchRequest(statRequestCore);
|
||||
return statRequestCore;
|
||||
patchRequest(statRequest);
|
||||
return statRequest;
|
||||
}
|
||||
|
||||
/** Checks if a given {@link StatRequestCore} would result in a valid statistic look-up,
|
||||
/** Checks if a given {@link StatRequest} would result in a valid statistic look-up,
|
||||
and sends a feedback message to the CommandSender that prompted the statRequest if it is invalid.
|
||||
<br> The following is checked:
|
||||
<ul>
|
||||
@ -88,14 +88,14 @@ public final class InternalStatFetcher {
|
||||
<li>Is a <code>subStatEntry</code> needed, and if so, is a corresponding Material/EntityType present?
|
||||
<li>If the <code>target</code> is Player, is a valid <code>playerName</code> provided?
|
||||
</ul>
|
||||
@param statRequestCore the StatRequest to check
|
||||
@param statRequest the StatRequest to check
|
||||
@return true if the StatRequest is valid, and false otherwise.
|
||||
*/
|
||||
public boolean validateRequest(StatRequestCore statRequestCore) {
|
||||
return validateRequestAndSendMessage(statRequestCore, statRequestCore.getCommandSender());
|
||||
public boolean validateRequest(StatRequest statRequest) {
|
||||
return validateRequestAndSendMessage(statRequest, statRequest.getCommandSender());
|
||||
}
|
||||
|
||||
/** Checks if a given {@link StatRequestCore} would result in a valid statistic look-up,
|
||||
/** Checks if a given {@link StatRequest} would result in a valid statistic look-up,
|
||||
and sends a feedback message if it is invalid.
|
||||
<br> The following is checked:
|
||||
<ul>
|
||||
@ -103,24 +103,24 @@ public final class InternalStatFetcher {
|
||||
<li>Is a <code>subStatEntry</code> needed, and if so, is a corresponding Material/EntityType present?
|
||||
<li>If the <code>target</code> is Player, is a valid <code>playerName</code> provided?
|
||||
</ul>
|
||||
@param statRequestCore the StatRequest to check
|
||||
@param statRequest the StatRequest to check
|
||||
@return true if the StatRequest is valid, and false otherwise.
|
||||
*/
|
||||
private boolean validateRequestAndSendMessage(StatRequestCore statRequestCore, CommandSender sender) {
|
||||
if (statRequestCore.getStatistic() == null) {
|
||||
private boolean validateRequestAndSendMessage(StatRequest statRequest, CommandSender sender) {
|
||||
if (statRequest.getStatistic() == null) {
|
||||
outputManager.sendFeedbackMsg(sender, StandardMessage.MISSING_STAT_NAME);
|
||||
return false;
|
||||
}
|
||||
Statistic.Type type = statRequestCore.getStatistic().getType();
|
||||
if (statRequestCore.getSubStatEntryName() == null && type != Statistic.Type.UNTYPED) {
|
||||
Statistic.Type type = statRequest.getStatistic().getType();
|
||||
if (statRequest.getSubStatEntryName() == null && type != Statistic.Type.UNTYPED) {
|
||||
outputManager.sendFeedbackMsgMissingSubStat(sender, type);
|
||||
return false;
|
||||
}
|
||||
else if (!hasMatchingSubStat(statRequestCore)) {
|
||||
outputManager.sendFeedbackMsgWrongSubStat(sender, type, statRequestCore.getSubStatEntryName());
|
||||
else if (!hasMatchingSubStat(statRequest)) {
|
||||
outputManager.sendFeedbackMsgWrongSubStat(sender, type, statRequest.getSubStatEntryName());
|
||||
return false;
|
||||
}
|
||||
else if (statRequestCore.getTarget() == Target.PLAYER && statRequestCore.getPlayerName() == null) {
|
||||
else if (statRequest.getTarget() == Target.PLAYER && statRequest.getPlayerName() == null) {
|
||||
outputManager.sendFeedbackMsg(sender, StandardMessage.MISSING_PLAYER_NAME);
|
||||
return false;
|
||||
}
|
||||
@ -132,51 +132,51 @@ public final class InternalStatFetcher {
|
||||
/** Adjust the StatRequest object if needed: unpack the playerFlag into a subStatEntry,
|
||||
try to retrieve the corresponding Enum Constant for any relevant block/entity/item,
|
||||
and remove any unnecessary subStatEntries.*/
|
||||
private void patchRequest(StatRequestCore statRequestCore) {
|
||||
if (statRequestCore.getStatistic() != null) {
|
||||
Statistic.Type type = statRequestCore.getStatistic().getType();
|
||||
private void patchRequest(StatRequest statRequest) {
|
||||
if (statRequest.getStatistic() != null) {
|
||||
Statistic.Type type = statRequest.getStatistic().getType();
|
||||
|
||||
if (statRequestCore.getPlayerFlag()) { //unpack the playerFlag
|
||||
if (type == Statistic.Type.ENTITY && statRequestCore.getSubStatEntryName() == null) {
|
||||
statRequestCore.setSubStatEntryName("player");
|
||||
if (statRequest.getPlayerFlag()) { //unpack the playerFlag
|
||||
if (type == Statistic.Type.ENTITY && statRequest.getSubStatEntryName() == null) {
|
||||
statRequest.setSubStatEntryName("player");
|
||||
}
|
||||
else {
|
||||
statRequestCore.setTarget(Target.PLAYER);
|
||||
statRequest.setTarget(Target.PLAYER);
|
||||
}
|
||||
}
|
||||
|
||||
String subStatEntry = statRequestCore.getSubStatEntryName();
|
||||
String subStatEntry = statRequest.getSubStatEntryName();
|
||||
switch (type) { //attempt to convert relevant subStatEntries into their corresponding Enum Constant
|
||||
case BLOCK -> {
|
||||
Material block = EnumHandler.getBlockEnum(subStatEntry);
|
||||
if (block != null) statRequestCore.setBlock(block);
|
||||
if (block != null) statRequest.setBlock(block);
|
||||
}
|
||||
case ENTITY -> {
|
||||
EntityType entity = EnumHandler.getEntityEnum(subStatEntry);
|
||||
if (entity != null) statRequestCore.setEntity(entity);
|
||||
if (entity != null) statRequest.setEntity(entity);
|
||||
}
|
||||
case ITEM -> {
|
||||
Material item = EnumHandler.getItemEnum(subStatEntry);
|
||||
if (item != null) statRequestCore.setItem(item);
|
||||
if (item != null) statRequest.setItem(item);
|
||||
}
|
||||
case UNTYPED -> { //remove unnecessary subStatEntries
|
||||
if (subStatEntry != null) statRequestCore.setSubStatEntryName(null);
|
||||
if (subStatEntry != null) statRequest.setSubStatEntryName(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasMatchingSubStat(StatRequestCore statRequestCore) {
|
||||
Statistic.Type type = statRequestCore.getStatistic().getType();
|
||||
private boolean hasMatchingSubStat(StatRequest statRequest) {
|
||||
Statistic.Type type = statRequest.getStatistic().getType();
|
||||
switch (type) {
|
||||
case BLOCK -> {
|
||||
return statRequestCore.getBlock() != null;
|
||||
return statRequest.getBlock() != null;
|
||||
}
|
||||
case ENTITY -> {
|
||||
return statRequestCore.getEntity() != null;
|
||||
return statRequest.getEntity() != null;
|
||||
}
|
||||
case ITEM -> {
|
||||
return statRequestCore.getItem() != null;
|
||||
return statRequest.getItem() != null;
|
||||
}
|
||||
default -> {
|
||||
return true;
|
||||
|
@ -1,23 +0,0 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public final class PlayerStatFetcher extends RequestGenerator {
|
||||
|
||||
private final String playerName;
|
||||
|
||||
public PlayerStatFetcher(String playerName) {
|
||||
super.statRequest = generateBaseRequest();
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StatRequestCore generateBaseRequest() {
|
||||
StatRequestCore request = new StatRequestCore(Bukkit.getConsoleSender(), true);
|
||||
request.setTarget(Target.PLAYER);
|
||||
request.setPlayerName(playerName);
|
||||
return request;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.PlayerStats;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestExecutor;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class PlayerStatRequest implements RequestExecutor<Integer> {
|
||||
|
||||
private final StatRequest statRequest;
|
||||
|
||||
public PlayerStatRequest(StatRequest request) {
|
||||
statRequest = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatResult<Integer> untyped(Statistic statistic) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatResult<Integer> blockOrItemType(Statistic statistic, Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatResult<Integer> entityType(Statistic statistic, EntityType entityType) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.PlayerStats;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestExecutor;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class RequestManager implements RequestGenerator {
|
||||
|
||||
private final StatRequest statRequest;
|
||||
|
||||
public RequestManager(StatRequest request) {
|
||||
|
||||
this.statRequest = request;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public StatRequest untyped(Statistic statistic) {
|
||||
statRequest.setStatistic(statistic);
|
||||
return statRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatRequest blockOrItemType(Statistic statistic, Material material) {
|
||||
statRequest.setSubStatEntryName(material.toString());
|
||||
if (statistic.getType() == Statistic.Type.BLOCK) {
|
||||
statRequest.setBlock(material);
|
||||
} else {
|
||||
statRequest.setItem(material);
|
||||
}
|
||||
return statRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatRequest entityType(Statistic statistic, EntityType entityType) {
|
||||
statRequest.setSubStatEntryName(entityType.toString());
|
||||
statRequest.setEntity(entityType);
|
||||
return statRequest;
|
||||
}
|
||||
|
||||
public static StatRequest generateBasicPlayerRequest(String playerName) {
|
||||
StatRequest request = new StatRequest(Bukkit.getConsoleSender(), true);
|
||||
request.setTarget(Target.PLAYER);
|
||||
request.setPlayerName(playerName);
|
||||
return request;
|
||||
}
|
||||
|
||||
public static StatRequest generateBasicServerRequest() {
|
||||
StatRequest request = new StatRequest(Bukkit.getConsoleSender(), true);
|
||||
request.setTarget(Target.SERVER);
|
||||
return request;
|
||||
}
|
||||
|
||||
public static StatRequest generateBasicTopRequest(int topListSize) {
|
||||
StatRequest request = new StatRequest(Bukkit.getConsoleSender(), true);
|
||||
request.setTarget(Target.TOP);
|
||||
request.setTopListSize(topListSize != 0 ? topListSize : 10);
|
||||
return request;
|
||||
}
|
||||
|
||||
private <T> RequestExecutor<Integer> getExecutor() {
|
||||
return switch (statRequest.getTarget()) {
|
||||
case PLAYER -> new PlayerStatRequest(statRequest);
|
||||
case SERVER -> null;
|
||||
case TOP -> null;
|
||||
};
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public final class ServerStatFetcher extends RequestGenerator {
|
||||
|
||||
public ServerStatFetcher() {
|
||||
super.statRequest = generateBaseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StatRequestCore generateBaseRequest() {
|
||||
StatRequestCore request = new StatRequestCore(Bukkit.getConsoleSender(), true);
|
||||
request.setTarget(Target.SERVER);
|
||||
return request;
|
||||
}
|
||||
}
|
@ -1,16 +1,158 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.result.StatResult;
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record StatRequest(StatRequestCore requestCore) {
|
||||
/** A StatRequest is the object PlayerStats uses to calculate and format the requested statistic.
|
||||
This object can be generated from two different sources:
|
||||
<br>- Internally: by PlayerStats itself when /stat is called, using the args provided by the CommandSender.
|
||||
<br>- Externally: through the API methods provided by the {@link RequestGenerator} interface.
|
||||
<br>
|
||||
<br>For this StatRequest to be valid, it needs the following values:
|
||||
<ul>
|
||||
<li> a {@link Statistic} <code>statistic</code> </li>
|
||||
<li> if this Statistic is not of {@link Statistic.Type} Untyped, a <code>subStatEntryName</code> needs to be set,
|
||||
together with one of the following values:
|
||||
<br>- for Type.Block: a {@link Material} <code>blockMaterial</code>
|
||||
<br>- for Type.Item: a {@link Material} <code>itemMaterial</code>
|
||||
<br>- for Type.Entity: an {@link EntityType} <code>entityType</code>
|
||||
<li> a {@link Target} <code>target</code> (automatically set for all API-requests)
|
||||
<li> if the <code>target</code> is Target.Player, a <code>playerName</code> needs to be added
|
||||
</ul>*/
|
||||
public final class StatRequest {
|
||||
|
||||
public <T> StatResult<T> execute() {
|
||||
return null;
|
||||
private final CommandSender sender;
|
||||
private boolean isAPIRequest;
|
||||
private Statistic statistic;
|
||||
private String playerName;
|
||||
private Target target;
|
||||
private int topListSize;
|
||||
|
||||
private String subStatEntryName;
|
||||
private EntityType entity;
|
||||
private Material block;
|
||||
private Material item;
|
||||
private boolean playerFlag;
|
||||
|
||||
/** Create a new {@link StatRequest} with default values:
|
||||
<br>- CommandSender sender (provided)
|
||||
<br>- Target <code>target</code> = {@link Target#TOP}
|
||||
<br>- boolean <code>playerFlag</code> = false
|
||||
<br>- boolean <code>isAPIRequest</code> = false
|
||||
|
||||
@param sender the CommandSender who prompted this RequestGenerator
|
||||
*/
|
||||
public StatRequest(@NotNull CommandSender sender) {
|
||||
this(sender, false);
|
||||
}
|
||||
|
||||
public void eeeeeeh() {
|
||||
StatResult<StringBuffer> lod = execute();
|
||||
}
|
||||
}
|
||||
/** Create a new {@link StatRequest} with default values:
|
||||
<br>- CommandSender sender (provided)
|
||||
<br>- Target target = {@link Target#TOP}
|
||||
<br>- boolean playerFlag = false
|
||||
<br>- boolean isAPIRequest (provided)
|
||||
|
||||
//TODO fix >:(
|
||||
@param sender the CommandSender who prompted this RequestGenerator
|
||||
@param isAPIRequest whether this RequestGenerator is coming through the API or the onCommand
|
||||
*/
|
||||
public StatRequest(@NotNull CommandSender sender, boolean isAPIRequest) {
|
||||
this.sender = sender;
|
||||
this.isAPIRequest = isAPIRequest;
|
||||
target = Target.TOP;
|
||||
playerFlag = false;
|
||||
}
|
||||
|
||||
public void setAPIRequest() {
|
||||
this.isAPIRequest = true;
|
||||
}
|
||||
|
||||
public boolean isAPIRequest() {
|
||||
return isAPIRequest;
|
||||
}
|
||||
|
||||
public @NotNull CommandSender getCommandSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public boolean isConsoleSender() {
|
||||
return sender instanceof ConsoleCommandSender;
|
||||
}
|
||||
|
||||
public void setStatistic(Statistic statistic) {
|
||||
this.statistic = statistic;
|
||||
}
|
||||
|
||||
public Statistic getStatistic() {
|
||||
return statistic;
|
||||
}
|
||||
|
||||
public void setSubStatEntryName(String subStatEntry) {
|
||||
this.subStatEntryName = subStatEntry;
|
||||
}
|
||||
|
||||
public String getSubStatEntryName() {
|
||||
return subStatEntryName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerFlag(boolean playerFlag) {
|
||||
this.playerFlag = playerFlag;
|
||||
}
|
||||
|
||||
public boolean getPlayerFlag() {
|
||||
return playerFlag;
|
||||
}
|
||||
|
||||
public void setTarget(Target target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public @NotNull Target getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTopListSize(int topListSize) {
|
||||
this.topListSize = topListSize;
|
||||
}
|
||||
|
||||
public int getTopListSize() {
|
||||
return this.topListSize;
|
||||
}
|
||||
|
||||
public void setEntity(EntityType entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public EntityType getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setBlock(Material block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public Material getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public void setItem(Material item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public Material getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** A StatRequest is the object PlayerStats uses to calculate and format the requested statistic.
|
||||
This object can be generated from two different sources:
|
||||
<br>- Internally: by PlayerStats itself when /stat is called, using the args provided by the CommandSender.
|
||||
<br>- Externally: through the API methods provided by the {@link RequestGenerator} interface.
|
||||
<br>
|
||||
<br>For this StatRequest to be valid, it needs the following values:
|
||||
<ul>
|
||||
<li> a {@link Statistic} <code>statistic</code> </li>
|
||||
<li> if this Statistic is not of {@link Statistic.Type} Untyped, a <code>subStatEntryName</code> needs to be set,
|
||||
together with one of the following values:
|
||||
<br>- for Type.Block: a {@link Material} <code>blockMaterial</code>
|
||||
<br>- for Type.Item: a {@link Material} <code>itemMaterial</code>
|
||||
<br>- for Type.Entity: an {@link EntityType} <code>entityType</code>
|
||||
<li> a {@link Target} <code>target</code> (automatically set for all API-requests)
|
||||
<li> if the <code>target</code> is Target.Player, a <code>playerName</code> needs to be added
|
||||
</ul>*/
|
||||
public final class StatRequestCore {
|
||||
|
||||
private final CommandSender sender;
|
||||
private boolean isAPIRequest;
|
||||
private Statistic statistic;
|
||||
private String playerName;
|
||||
private Target target;
|
||||
|
||||
private String subStatEntryName;
|
||||
private EntityType entity;
|
||||
private Material block;
|
||||
private Material item;
|
||||
private boolean playerFlag;
|
||||
|
||||
/** Create a new {@link StatRequestCore} with default values:
|
||||
<br>- CommandSender sender (provided)
|
||||
<br>- Target <code>target</code> = {@link Target#TOP}
|
||||
<br>- boolean <code>playerFlag</code> = false
|
||||
<br>- boolean <code>isAPIRequest</code> = false
|
||||
|
||||
@param sender the CommandSender who prompted this RequestGenerator
|
||||
*/
|
||||
public StatRequestCore(@NotNull CommandSender sender) {
|
||||
this(sender, false);
|
||||
}
|
||||
|
||||
/** Create a new {@link StatRequestCore} with default values:
|
||||
<br>- CommandSender sender (provided)
|
||||
<br>- Target target = {@link Target#TOP}
|
||||
<br>- boolean playerFlag = false
|
||||
<br>- boolean isAPIRequest (provided)
|
||||
|
||||
@param sender the CommandSender who prompted this RequestGenerator
|
||||
@param isAPIRequest whether this RequestGenerator is coming through the API or the onCommand
|
||||
*/
|
||||
public StatRequestCore(@NotNull CommandSender sender, boolean isAPIRequest) {
|
||||
this.sender = sender;
|
||||
this.isAPIRequest = isAPIRequest;
|
||||
target = Target.TOP;
|
||||
playerFlag = false;
|
||||
}
|
||||
|
||||
public void setAPIRequest() {
|
||||
this.isAPIRequest = true;
|
||||
}
|
||||
|
||||
public boolean isAPIRequest() {
|
||||
return isAPIRequest;
|
||||
}
|
||||
|
||||
public @NotNull CommandSender getCommandSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public boolean isConsoleSender() {
|
||||
return sender instanceof ConsoleCommandSender;
|
||||
}
|
||||
|
||||
public void setStatistic(Statistic statistic) {
|
||||
this.statistic = statistic;
|
||||
}
|
||||
|
||||
public Statistic getStatistic() {
|
||||
return statistic;
|
||||
}
|
||||
|
||||
public void setSubStatEntryName(String subStatEntry) {
|
||||
this.subStatEntryName = subStatEntry;
|
||||
}
|
||||
|
||||
public @Nullable String getSubStatEntryName() {
|
||||
return subStatEntryName;
|
||||
}
|
||||
|
||||
public void setPlayerName(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerFlag(boolean playerFlag) {
|
||||
this.playerFlag = playerFlag;
|
||||
}
|
||||
|
||||
public boolean getPlayerFlag() {
|
||||
return playerFlag;
|
||||
}
|
||||
|
||||
public void setTarget(Target target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public @NotNull Target getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setEntity(EntityType entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public EntityType getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setBlock(Material block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public Material getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public void setItem(Material item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public Material getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.statistic.request;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.api.RequestGenerator;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class TopStatFetcher extends RequestGenerator {
|
||||
|
||||
private final int topListSize;
|
||||
|
||||
public TopStatFetcher(int topListSize) {
|
||||
this.topListSize = topListSize;
|
||||
super.statRequest = generateBaseRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StatRequestCore generateBaseRequest() {
|
||||
StatRequestCore request = new StatRequestCore(Bukkit.getConsoleSender(), true);
|
||||
request.setTarget(Target.TOP);
|
||||
return request;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user