Moved implementation of the API interface to the Main class
This commit is contained in:
parent
abf85b3948
commit
eca25980e5
|
@ -1,7 +1,8 @@
|
||||||
package com.artemis.the.gr8.playerstats;
|
package com.artemis.the.gr8.playerstats;
|
||||||
|
|
||||||
import com.artemis.the.gr8.playerstats.api.PlayerStats;
|
import com.artemis.the.gr8.playerstats.api.PlayerStats;
|
||||||
import com.artemis.the.gr8.playerstats.api.PlayerStatsAPI;
|
import com.artemis.the.gr8.playerstats.api.StatFormatter;
|
||||||
|
import com.artemis.the.gr8.playerstats.api.StatManager;
|
||||||
import com.artemis.the.gr8.playerstats.statistic.RequestManager;
|
import com.artemis.the.gr8.playerstats.statistic.RequestManager;
|
||||||
import com.artemis.the.gr8.playerstats.msg.OutputManager;
|
import com.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||||
import com.artemis.the.gr8.playerstats.commands.ReloadCommand;
|
import com.artemis.the.gr8.playerstats.commands.ReloadCommand;
|
||||||
|
@ -27,13 +28,13 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerStats' Main class
|
* PlayerStats' Main class
|
||||||
*/
|
*/
|
||||||
public final class Main extends JavaPlugin {
|
public final class Main extends JavaPlugin implements PlayerStats {
|
||||||
|
|
||||||
private static JavaPlugin pluginInstance;
|
private static JavaPlugin pluginInstance;
|
||||||
|
private static PlayerStats playerStatsAPI;
|
||||||
private static BukkitAudiences adventure;
|
private static BukkitAudiences adventure;
|
||||||
|
|
||||||
private static ConfigHandler config;
|
private static ConfigHandler config;
|
||||||
|
@ -42,12 +43,10 @@ public final class Main extends JavaPlugin {
|
||||||
private static OfflinePlayerHandler offlinePlayerHandler;
|
private static OfflinePlayerHandler offlinePlayerHandler;
|
||||||
private static EnumHandler enumHandler;
|
private static EnumHandler enumHandler;
|
||||||
|
|
||||||
|
private static RequestManager statRequestManager;
|
||||||
private static OutputManager outputManager;
|
private static OutputManager outputManager;
|
||||||
private static ShareManager shareManager;
|
private static ShareManager shareManager;
|
||||||
|
|
||||||
private static PlayerStats playerStatsImpl;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
//initialize all the Managers, singletons, ConfigHandler and the API
|
//initialize all the Managers, singletons, ConfigHandler and the API
|
||||||
|
@ -103,14 +102,16 @@ public final class Main extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull PlayerStats getPlayerStatsAPI() throws IllegalStateException {
|
public static @NotNull PlayerStats getPlayerStatsAPI() throws IllegalStateException {
|
||||||
if (playerStatsImpl == null) {
|
if (playerStatsAPI == null) {
|
||||||
throw new IllegalStateException("PlayerStats does not seem to be loaded!");
|
throw new IllegalStateException("PlayerStats does not seem to be loaded!");
|
||||||
}
|
}
|
||||||
return playerStatsImpl;
|
return playerStatsAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeMainClasses() {
|
private void initializeMainClasses() {
|
||||||
pluginInstance = this;
|
pluginInstance = this;
|
||||||
|
playerStatsAPI = this;
|
||||||
|
|
||||||
adventure = BukkitAudiences.create(this);
|
adventure = BukkitAudiences.create(this);
|
||||||
enumHandler = new EnumHandler();
|
enumHandler = new EnumHandler();
|
||||||
languageKeyHandler = new LanguageKeyHandler();
|
languageKeyHandler = new LanguageKeyHandler();
|
||||||
|
@ -121,9 +122,8 @@ public final class Main extends JavaPlugin {
|
||||||
outputManager = new OutputManager(adventure, config, languageKeyHandler);
|
outputManager = new OutputManager(adventure, config, languageKeyHandler);
|
||||||
|
|
||||||
RequestProcessor requestProcessor = new RequestProcessor(offlinePlayerHandler, outputManager, shareManager);
|
RequestProcessor requestProcessor = new RequestProcessor(offlinePlayerHandler, outputManager, shareManager);
|
||||||
RequestManager statManager = new RequestManager(offlinePlayerHandler, requestProcessor);
|
statRequestManager = new RequestManager(offlinePlayerHandler, requestProcessor);
|
||||||
threadManager = new ThreadManager(this, config, outputManager, statManager);
|
threadManager = new ThreadManager(this, config, outputManager, statRequestManager);
|
||||||
playerStatsImpl = new PlayerStatsAPI(statManager, outputManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupMetrics() {
|
private void setupMetrics() {
|
||||||
|
@ -145,4 +145,19 @@ public final class Main extends JavaPlugin {
|
||||||
}
|
}
|
||||||
}.runTaskLaterAsynchronously(this, 200);
|
}.runTaskLaterAsynchronously(this, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return "1.8";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StatManager getStatManager() {
|
||||||
|
return statRequestManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StatFormatter getFormatter() {
|
||||||
|
return outputManager.getMainMessageBuilder();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -8,18 +8,21 @@ import org.jetbrains.annotations.NotNull;
|
||||||
/**
|
/**
|
||||||
* The outgoing API that represents the core functionality of PlayerStats!
|
* The outgoing API that represents the core functionality of PlayerStats!
|
||||||
*
|
*
|
||||||
* <p> To work with it, you'll need to call PlayerStats.{@link #getAPI()} and get an instance of
|
* <p> To work with it, you'll need to call PlayerStats.{@link #getAPI()}
|
||||||
* {@link PlayerStatsAPI}. You can then use this object to access any of the further methods.
|
* and get an instance of PlayerStats. You can then use this object to
|
||||||
|
* access any of the further methods.
|
||||||
*
|
*
|
||||||
* @see RequestManager
|
* @see RequestManager
|
||||||
* @see StatFormatter
|
* @see StatFormatter
|
||||||
*/
|
*/
|
||||||
public interface PlayerStats {
|
public interface PlayerStats {
|
||||||
|
|
||||||
/** Gets an instance of the {@link PlayerStatsAPI}.
|
/** Gets an instance of the PlayerStatsAPI.
|
||||||
|
|
||||||
* @return the PlayerStats API
|
* @return the PlayerStats API
|
||||||
* @throws IllegalStateException if PlayerStats is not loaded on the server when this method is called*/
|
* @throws IllegalStateException if PlayerStats is not loaded on
|
||||||
|
* the server when this method is called
|
||||||
|
*/
|
||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
static @NotNull PlayerStats getAPI() throws IllegalStateException {
|
static @NotNull PlayerStats getAPI() throws IllegalStateException {
|
||||||
return Main.getPlayerStatsAPI();
|
return Main.getPlayerStatsAPI();
|
||||||
|
@ -34,9 +37,7 @@ public interface PlayerStats {
|
||||||
*
|
*
|
||||||
* @return the version of PlayerStatsAPI present on the server
|
* @return the version of PlayerStatsAPI present on the server
|
||||||
*/
|
*/
|
||||||
default String getVersion() {
|
String getVersion();
|
||||||
return "1.8";
|
|
||||||
}
|
|
||||||
|
|
||||||
StatManager getStatManager();
|
StatManager getStatManager();
|
||||||
|
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.artemis.the.gr8.playerstats.api;
|
|
||||||
|
|
||||||
import com.artemis.the.gr8.playerstats.msg.OutputManager;
|
|
||||||
|
|
||||||
import static org.jetbrains.annotations.ApiStatus.Internal;
|
|
||||||
|
|
||||||
/** The implementation of the API Interface */
|
|
||||||
public final class PlayerStatsAPI implements PlayerStats {
|
|
||||||
|
|
||||||
private static OutputManager outputManager;
|
|
||||||
private final StatManager statManager;
|
|
||||||
|
|
||||||
@Internal
|
|
||||||
public PlayerStatsAPI(StatManager statManager, OutputManager outputManager) {
|
|
||||||
PlayerStatsAPI.outputManager = outputManager;
|
|
||||||
this.statManager = statManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StatFormatter getFormatter() {
|
|
||||||
return outputManager.getMainMessageBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StatManager getStatManager() {
|
|
||||||
return statManager;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.artemis.the.gr8.playerstats.commands;
|
package com.artemis.the.gr8.playerstats.commands;
|
||||||
|
|
||||||
import com.artemis.the.gr8.playerstats.api.PlayerStats;
|
|
||||||
import com.artemis.the.gr8.playerstats.statistic.StatRequest;
|
|
||||||
import com.artemis.the.gr8.playerstats.utils.EnumHandler;
|
import com.artemis.the.gr8.playerstats.utils.EnumHandler;
|
||||||
import com.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
import com.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -29,14 +27,12 @@ public final class TabCompleter implements org.bukkit.command.TabCompleter {
|
||||||
this.enumHandler = enumHandler;
|
this.enumHandler = enumHandler;
|
||||||
this.offlinePlayerHandler = offlinePlayerHandler;
|
this.offlinePlayerHandler = offlinePlayerHandler;
|
||||||
prepareLists();
|
prepareLists();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//args[0] = statistic (length = 1)
|
//args[0] = statistic (length = 1)
|
||||||
//args[1] = target (player/server/top) OR sub-stat (block/item/entity) (length = 2)
|
//args[1] = target (player/server/top) OR sub-stat (block/item/entity) (length = 2)
|
||||||
//args[2] = playerName OR target (player/server/top) (length = 3)
|
//args[2] = playerName OR target (player/server/top) (length = 3)
|
||||||
//args[3] = playerName (length = 4)
|
//args[3] = playerName (length = 4)
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
|
|
|
@ -131,15 +131,6 @@ public enum Unit {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Unit corresponding to the given String. This String
|
|
||||||
* does not need to match exactly (it can be "day" or "days",
|
|
||||||
* for example), and is case-insensitive.
|
|
||||||
*
|
|
||||||
* @param unitName the name belonging to the desired Unit,
|
|
||||||
* case-insensitive
|
|
||||||
* @return the Unit
|
|
||||||
*/
|
|
||||||
/** Converts the current Unit into a short label (and returns a '?' if the current Unit is not of Type TIME)*/
|
/** Converts the current Unit into a short label (and returns a '?' if the current Unit is not of Type TIME)*/
|
||||||
public char getShortLabel(){
|
public char getShortLabel(){
|
||||||
return switch (this) {
|
return switch (this) {
|
||||||
|
|
|
@ -83,9 +83,9 @@ public final class NumberFormatter {
|
||||||
|
|
||||||
while(currUnit != null){
|
while(currUnit != null){
|
||||||
//Define amount of units
|
//Define amount of units
|
||||||
int amount = 0;
|
int amount;
|
||||||
|
|
||||||
//Current unit is equal to smallest unit, in this case round the remainder
|
//Current unit is equal to the smallest unit, in this case round the remainder
|
||||||
if(currUnit == smallestUnit){
|
if(currUnit == smallestUnit){
|
||||||
amount = (int) Math.round(leftoverSeconds / currUnit.getSeconds());
|
amount = (int) Math.round(leftoverSeconds / currUnit.getSeconds());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue