mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-02 16:59:42 +01:00
UUIDUtility & PlanAPI initialized by Dagger - needs singleton
This commit is contained in:
parent
6700d6918c
commit
81a6ed7365
@ -7,6 +7,7 @@ package com.djrapitops.plan;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.command.PlanBungeeCommand;
|
||||
import com.djrapitops.plan.modules.APFModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeAPIModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeConfigModule;
|
||||
import com.djrapitops.plan.modules.bungee.BungeeDatabaseModule;
|
||||
import com.djrapitops.plan.modules.common.*;
|
||||
@ -43,7 +44,8 @@ import java.io.InputStream;
|
||||
BungeeDatabaseModule.class,
|
||||
WebServerSystemModule.class,
|
||||
ServerInfoSystemModule.class,
|
||||
PluginHookModule.class
|
||||
PluginHookModule.class,
|
||||
BungeeAPIModule.class
|
||||
})
|
||||
interface PlanBungeeComponent {
|
||||
|
||||
@ -54,6 +56,7 @@ interface PlanBungeeComponent {
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
@Singleton
|
||||
@BindsInstance
|
||||
Builder plan(PlanBungee plan);
|
||||
|
||||
|
@ -4,10 +4,15 @@
|
||||
*/
|
||||
package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.BungeeSystem;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -17,24 +22,37 @@ import java.util.UUID;
|
||||
*/
|
||||
public class BungeeAPI extends CommonAPI {
|
||||
|
||||
private final BungeeSystem bungeeSystem;
|
||||
private final HookHandler hookHandler;
|
||||
private final Database database;
|
||||
private final DataCache dataCache;
|
||||
|
||||
public BungeeAPI(BungeeSystem bungeeSystem) {
|
||||
this.bungeeSystem = bungeeSystem;
|
||||
@Inject
|
||||
public BungeeAPI(
|
||||
UUIDUtility uuidUtility,
|
||||
Database database,
|
||||
DataCache dataCache,
|
||||
HookHandler hookHandler,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(uuidUtility, errorHandler);
|
||||
|
||||
this.database = database;
|
||||
this.dataCache = dataCache;
|
||||
this.hookHandler = hookHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPluginDataSource(PluginData pluginData) {
|
||||
bungeeSystem.getHookHandler().addPluginDataSource(pluginData);
|
||||
hookHandler.addPluginDataSource(pluginData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName(UUID uuid) {
|
||||
return bungeeSystem.getCacheSystem().getDataCache().getName(uuid);
|
||||
return dataCache.getName(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchOperations fetchFromPlanDB() {
|
||||
return bungeeSystem.getDatabaseSystem().getActiveDatabase().fetch();
|
||||
return database.fetch();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -19,6 +20,14 @@ import java.util.UUID;
|
||||
*/
|
||||
public abstract class CommonAPI implements PlanAPI {
|
||||
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public CommonAPI(UUIDUtility uuidUtility, ErrorHandler errorHandler) {
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerInspectPageLink(UUID uuid) {
|
||||
return getPlayerInspectPageLink(getPlayerName(uuid));
|
||||
@ -31,7 +40,7 @@ public abstract class CommonAPI implements PlanAPI {
|
||||
|
||||
@Override
|
||||
public UUID playerNameToUUID(String playerName) {
|
||||
return UUIDUtility.getUUIDOf(playerName);
|
||||
return uuidUtility.getUUIDOf(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,7 +48,7 @@ public abstract class CommonAPI implements PlanAPI {
|
||||
try {
|
||||
return fetchFromPlanDB().getPlayerNames();
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.UUID;
|
||||
@ -25,7 +27,14 @@ public class ServerAPI extends CommonAPI {
|
||||
private final DataCache dataCache;
|
||||
|
||||
@Inject
|
||||
public ServerAPI(HookHandler hookHandler, Database activeDatabase, DataCache dataCache) {
|
||||
public ServerAPI(
|
||||
UUIDUtility uuidUtility,
|
||||
HookHandler hookHandler,
|
||||
Database activeDatabase,
|
||||
DataCache dataCache,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(uuidUtility, errorHandler);
|
||||
this.hookHandler = hookHandler;
|
||||
this.activeDatabase = activeDatabase;
|
||||
this.dataCache = dataCache;
|
||||
|
@ -33,16 +33,24 @@ public class InspectCommand extends CommandNode {
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private final WebServer webServer;
|
||||
private UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public InspectCommand(Locale locale, Database database, WebServer webServer, ErrorHandler errorHandler) {
|
||||
public InspectCommand(
|
||||
Locale locale,
|
||||
Database database,
|
||||
WebServer webServer,
|
||||
UUIDUtility uuidUtility,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
setArguments("<player>");
|
||||
|
||||
this.locale = locale;
|
||||
this.database = database;
|
||||
this.webServer = webServer;
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.INSPECT));
|
||||
@ -63,7 +71,7 @@ public class InspectCommand extends CommandNode {
|
||||
private void runInspectTask(String playerName, ISender sender) {
|
||||
Processing.submitNonCritical(() -> {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
|
@ -42,15 +42,22 @@ public class QInspectCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public QInspectCommand(Locale locale, Database database, ErrorHandler errorHandler) {
|
||||
public QInspectCommand(
|
||||
Locale locale,
|
||||
Database database,
|
||||
UUIDUtility uuidUtility,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
setArguments("<player>");
|
||||
|
||||
this.locale = locale;
|
||||
this.database = database;
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.QINSPECT));
|
||||
@ -72,7 +79,7 @@ public class QInspectCommand extends CommandNode {
|
||||
private void runInspectTask(String playerName, ISender sender) {
|
||||
Processing.submitNonCritical(() -> {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
return;
|
||||
|
@ -32,14 +32,21 @@ public class ManageRemoveCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public ManageRemoveCommand(Locale locale, Database database, ErrorHandler errorHandler) {
|
||||
public ManageRemoveCommand(
|
||||
Locale locale,
|
||||
Database database,
|
||||
UUIDUtility uuidUtility,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("remove|delete", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
this.locale = locale;
|
||||
this.database = database;
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
|
||||
setArguments("<player>", "[-a]");
|
||||
@ -65,7 +72,7 @@ public class ManageRemoveCommand extends CommandNode {
|
||||
private void runRemoveTask(String playerName, ISender sender, String[] args) {
|
||||
Processing.submitCritical(() -> {
|
||||
try {
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
UUID uuid = uuidUtility.getUUIDOf(playerName);
|
||||
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(locale.getString(CommandLang.FAIL_USERNAME_NOT_VALID));
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.djrapitops.plan.modules.bungee;
|
||||
|
||||
import com.djrapitops.plan.api.BungeeAPI;
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
/**
|
||||
* Dagger module for Bungee PlanAPI.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Module
|
||||
public class BungeeAPIModule {
|
||||
|
||||
@Provides
|
||||
PlanAPI providePlanAPI(BungeeAPI bungeeAPI) {
|
||||
return bungeeAPI;
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,6 @@ package com.djrapitops.plan.modules.server;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.api.ServerAPI;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@ -17,8 +14,8 @@ import dagger.Provides;
|
||||
public class ServerAPIModule {
|
||||
|
||||
@Provides
|
||||
PlanAPI providePlanAPI(HookHandler hookHandler, DataCache dataCache, Database database) {
|
||||
return new ServerAPI(hookHandler, database, dataCache);
|
||||
PlanAPI providePlanAPI(ServerAPI serverAPI) {
|
||||
return serverAPI;
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@ import com.djrapitops.plan.ShutdownHook;
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.database.BukkitDBSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.export.ExportSystem;
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
@ -35,7 +35,7 @@ public class BukkitSystem extends PlanSystem implements ServerSystem {
|
||||
ConfigSystem serverConfigSystem,
|
||||
InfoSystem serverInfoSystem,
|
||||
BukkitServerInfo serverInfo,
|
||||
BukkitDBSystem bukkitDBSystem,
|
||||
DBSystem databaseSystem,
|
||||
BukkitListenerSystem bukkitListenerSystem,
|
||||
BukkitTaskSystem bukkitTaskSystem,
|
||||
ExportSystem exportSystem,
|
||||
@ -47,7 +47,7 @@ public class BukkitSystem extends PlanSystem implements ServerSystem {
|
||||
this.fileSystem = fileSystem;
|
||||
this.configSystem = serverConfigSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
this.databaseSystem = bukkitDBSystem;
|
||||
this.databaseSystem = databaseSystem;
|
||||
listenerSystem = bukkitListenerSystem;
|
||||
taskSystem = bukkitTaskSystem;
|
||||
|
||||
|
@ -5,11 +5,10 @@
|
||||
package com.djrapitops.plan.system;
|
||||
|
||||
import com.djrapitops.plan.PlanBungee;
|
||||
import com.djrapitops.plan.api.BungeeAPI;
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.cache.BungeeCacheSystem;
|
||||
import com.djrapitops.plan.system.database.BungeeDBSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.export.ExportSystem;
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
@ -36,9 +35,10 @@ public class BungeeSystem extends PlanSystem {
|
||||
FileSystem fileSystem,
|
||||
BungeeConfigSystem bungeeConfigSystem,
|
||||
BungeeCacheSystem bungeeCacheSystem,
|
||||
BungeeDBSystem bungeeDBSystem,
|
||||
DBSystem databaseSystem,
|
||||
HookHandler hookHandler,
|
||||
ExportSystem exportSystem
|
||||
ExportSystem exportSystem,
|
||||
PlanAPI planAPI
|
||||
) {
|
||||
setTestSystem(this);
|
||||
|
||||
@ -46,7 +46,7 @@ public class BungeeSystem extends PlanSystem {
|
||||
this.fileSystem = fileSystem;
|
||||
configSystem = bungeeConfigSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
databaseSystem = bungeeDBSystem;
|
||||
this.databaseSystem = databaseSystem;
|
||||
cacheSystem = bungeeCacheSystem;
|
||||
listenerSystem = new BungeeListenerSystem(plugin);
|
||||
taskSystem = new BungeeTaskSystem(plugin.getRunnableFactory());
|
||||
@ -55,7 +55,7 @@ public class BungeeSystem extends PlanSystem {
|
||||
serverInfo = new BungeeServerInfo(plugin);
|
||||
|
||||
this.hookHandler = hookHandler;
|
||||
planAPI = new BungeeAPI(this);
|
||||
this.planAPI = planAPI;
|
||||
}
|
||||
|
||||
public static BungeeSystem getInstance() {
|
||||
|
@ -69,6 +69,7 @@ public abstract class PlanSystem implements SubSystem {
|
||||
localeSystem = new LocaleSystem();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static PlanSystem getInstance() {
|
||||
boolean bukkitAvailable = Check.isBukkitAvailable();
|
||||
boolean bungeeAvailable = Check.isBungeeAvailable();
|
||||
|
@ -9,7 +9,7 @@ import com.djrapitops.plan.ShutdownHook;
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.system.database.SpongeDBSystem;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.export.ExportSystem;
|
||||
import com.djrapitops.plan.system.file.FileSystem;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
@ -38,7 +38,7 @@ public class SpongeSystem extends PlanSystem implements ServerSystem {
|
||||
SpongeServerInfo serverInfo,
|
||||
SpongeListenerSystem spongeListenerSystem,
|
||||
SpongeTaskSystem spongeTaskSystem,
|
||||
SpongeDBSystem spongeDBSystem,
|
||||
DBSystem databaseSystem,
|
||||
ExportSystem exportSystem,
|
||||
HookHandler hookHandler,
|
||||
PlanAPI planAPI,
|
||||
@ -50,7 +50,7 @@ public class SpongeSystem extends PlanSystem implements ServerSystem {
|
||||
this.fileSystem = fileSystem;
|
||||
this.configSystem = serverConfigSystem;
|
||||
this.exportSystem = exportSystem;
|
||||
this.databaseSystem = spongeDBSystem;
|
||||
this.databaseSystem = databaseSystem;
|
||||
listenerSystem = spongeListenerSystem;
|
||||
taskSystem = spongeTaskSystem;
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class PlayerPageHandler extends PageHandler {
|
||||
}
|
||||
|
||||
String playerName = target.get(0);
|
||||
UUID uuid = UUIDUtility.getUUIDOf(playerName);
|
||||
UUID uuid = UUIDUtility.getUUIDOf_Old(playerName);
|
||||
Locale locale = request.getLocale();
|
||||
|
||||
boolean raw = target.size() >= 2 && target.get(1).equalsIgnoreCase("raw");
|
||||
|
@ -8,10 +8,11 @@ package com.djrapitops.plan.utilities.uuid;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.UUIDFetcher;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -19,11 +20,15 @@ import java.util.UUID;
|
||||
*/
|
||||
public class UUIDUtility {
|
||||
|
||||
/**
|
||||
* Constructor used to hide the public constructor
|
||||
*/
|
||||
private UUIDUtility() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
private final DataCache dataCache;
|
||||
private final Database database;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
public UUIDUtility(DataCache dataCache, Database database, ErrorHandler errorHandler) {
|
||||
this.dataCache = dataCache;
|
||||
this.database = database;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,9 +38,9 @@ public class UUIDUtility {
|
||||
* @return UUID of the player.
|
||||
*/
|
||||
@Deprecated
|
||||
public static UUID getUUIDOf(String playerName) {
|
||||
public static UUID getUUIDOf_Old(String playerName) {
|
||||
try {
|
||||
return getUUIDOf(playerName, Database.getActive());
|
||||
return Database.getActive().fetch().getUuidOf(playerName);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
@ -45,21 +50,18 @@ public class UUIDUtility {
|
||||
* Get UUID of a player.
|
||||
*
|
||||
* @param playerName Player's name
|
||||
* @param db Database to check from.
|
||||
* @return UUID of the player
|
||||
*/
|
||||
private static UUID getUUIDOf(String playerName, Database db) {
|
||||
public UUID getUUIDOf(String playerName) {
|
||||
UUID uuid = null;
|
||||
if (Check.isBukkitAvailable()) {
|
||||
UUID uuidOf = DataCache.getInstance().getUUIDof(playerName);
|
||||
if (uuidOf != null) {
|
||||
return uuidOf;
|
||||
}
|
||||
UUID uuidOf = dataCache.getUUIDof(playerName);
|
||||
if (uuidOf != null) {
|
||||
return uuidOf;
|
||||
}
|
||||
try {
|
||||
uuid = db.fetch().getUuidOf(playerName);
|
||||
uuid = database.fetch().getUuidOf(playerName);
|
||||
} catch (DBOpException e) {
|
||||
Log.toLog(UUIDUtility.class, e);
|
||||
errorHandler.log(L.ERROR, UUIDUtility.class, e);
|
||||
}
|
||||
try {
|
||||
if (uuid == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user