mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-21 20:22:45 +02:00
[Debt] PlanAPI getInstance uses a static holder.
This is close to a Singleton pattern, but not quite. Testing required to know impact of using static here. - Is it possible to set null?
This commit is contained in:
parent
32044ed016
commit
e12f258a33
|
@ -23,9 +23,10 @@ public abstract class CommonAPI implements PlanAPI {
|
|||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public CommonAPI(UUIDUtility uuidUtility, ErrorHandler errorHandler) {
|
||||
CommonAPI(UUIDUtility uuidUtility, ErrorHandler errorHandler) {
|
||||
this.uuidUtility = uuidUtility;
|
||||
this.errorHandler = errorHandler;
|
||||
PlanAPIHolder.set(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
package com.djrapitops.plan.api;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.PluginData;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,16 @@ import java.util.UUID;
|
|||
public interface PlanAPI {
|
||||
|
||||
static PlanAPI getInstance() {
|
||||
return PlanSystem.getInstance().getPlanAPI();
|
||||
return Optional.ofNullable(PlanAPIHolder.API)
|
||||
.orElseThrow(() -> new IllegalStateException("PlanAPI has not been initialised yet."));
|
||||
}
|
||||
|
||||
class PlanAPIHolder {
|
||||
static PlanAPI API;
|
||||
|
||||
static void set(PlanAPI api) {
|
||||
PlanAPIHolder.API = api;
|
||||
}
|
||||
}
|
||||
|
||||
void addPluginDataSource(PluginData pluginData);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
package com.djrapitops.plan.system;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
|
@ -97,11 +96,6 @@ public class PlanSystem implements SubSystem {
|
|||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static PlanSystem getInstance() {
|
||||
return PlanPlugin.getInstance().getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() throws EnableException {
|
||||
enableSystems(
|
||||
|
|
Loading…
Reference in New Issue
Block a user