mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
[Debt] Removed HookHandler.getInstance() method.
This method was in use for generating different PluginData related things: Bans, Analysis page & Inspect page plugins tabs. - Bans: Removed BanData related analysis objects as it is deprecated. Plugins will not be asked if a player is banned in the future, and will rely on server OfflinePlayer#isBanned instead. - Analysis Page: Generation tool is still static, on the TODO list. - Inspect Page: Added HookHandler as injected dependency
This commit is contained in:
parent
2b4e6fe9cb
commit
aff935bfc1
|
@ -2,13 +2,11 @@ package com.djrapitops.plan.data.plugin;
|
|||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.element.InspectContainer;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plugin.StaticHolder;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.djrapitops.pluginbridge.plan.Bridge;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -40,13 +38,6 @@ public class HookHandler implements SubSystem {
|
|||
additionalDataSources = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static HookHandler getInstance() {
|
||||
HookHandler hookHandler = PlanSystem.getInstance().getHookHandler();
|
||||
Verify.nullCheck(hookHandler, () -> new IllegalStateException("Plugin Hooks were not initialized."));
|
||||
return hookHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
try {
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
|||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.*;
|
||||
import com.djrapitops.plan.data.store.mutators.combiners.MultiBanCombiner;
|
||||
import com.djrapitops.plan.data.store.mutators.health.HealthInformation;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
@ -16,7 +15,6 @@ import com.djrapitops.plan.system.settings.Settings;
|
|||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.analysis.ServerBanDataReader;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||
|
@ -82,12 +80,6 @@ public class AnalysisContainer extends DataContainer {
|
|||
addCommandSuppliers();
|
||||
addServerHealth();
|
||||
addPluginSuppliers();
|
||||
|
||||
runCombiners();
|
||||
}
|
||||
|
||||
private void runCombiners() {
|
||||
new MultiBanCombiner(this.serverContainer).combine(getUnsafe(AnalysisKeys.BAN_DATA));
|
||||
}
|
||||
|
||||
private void addConstants() {
|
||||
|
@ -442,7 +434,6 @@ public class AnalysisContainer extends DataContainer {
|
|||
this
|
||||
)
|
||||
);
|
||||
putSupplier(AnalysisKeys.BAN_DATA, () -> new ServerBanDataReader().readBanDataForContainer(this));
|
||||
putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]);
|
||||
putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]);
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ public class AnalysisKeys {
|
|||
public static final Key<Long> ANALYSIS_TIME_MONTH_AGO = new Key<>(Long.class, "ANALYSIS_TIME_MONTH_AGO");
|
||||
public static final Key<Map<UUID, String>> PLAYER_NAMES = new Key<>(new Type<Map<UUID, String>>() {}, "PLAYER_NAMES");
|
||||
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
||||
@Deprecated
|
||||
public static final Key<Set<UUID>> BAN_DATA = new Key<>(new Type<Set<UUID>>() {}, "BAN_DATA");
|
||||
public static final Key<TreeMap<Long, Integer>> UNIQUE_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "UNIQUE_PLAYERS_PER_DAY");
|
||||
public static final Key<TreeMap<Long, Integer>> NEW_PLAYERS_PER_DAY = new Key<>(new Type<TreeMap<Long, Integer>>() {}, "NEW_PLAYERS_PER_DAY");
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
package com.djrapitops.plan.data.store.mutators.combiners;
|
||||
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class MultiBanCombiner {
|
||||
|
||||
private final DataContainer container;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param container DataContainer that supports {@link com.djrapitops.plan.data.store.keys.ServerKeys}.PLAYERS
|
||||
*/
|
||||
public MultiBanCombiner(DataContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public void combine(Set<UUID> banned) {
|
||||
combine(Collections.singletonMap(ServerInfo.getServerUUID_Old(), banned));
|
||||
}
|
||||
|
||||
public void combine(Map<UUID, Set<UUID>> perServerBanned) {
|
||||
List<PlayerContainer> playerContainers = container.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>());
|
||||
|
||||
for (Map.Entry<UUID, Set<UUID>> entry : perServerBanned.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
Set<UUID> banned = entry.getValue();
|
||||
for (PlayerContainer player : playerContainers) {
|
||||
if (player.getValue(PlayerKeys.UUID).map(banned::contains).orElse(false)) {
|
||||
PerServerContainer perServer = player.getValue(PlayerKeys.PER_SERVER)
|
||||
.orElse(new PerServerContainer());
|
||||
DataContainer perServerContainer = perServer.getOrDefault(serverUUID, new DataContainer());
|
||||
|
||||
perServerContainer.putRawData(PerServerKeys.BANNED, true);
|
||||
|
||||
perServer.put(serverUUID, perServerContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import com.djrapitops.plan.api.exceptions.connection.WebException;
|
|||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
|
||||
import com.djrapitops.plan.system.webserver.response.Response;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
|
||||
import com.djrapitops.plan.utilities.html.pages.PageFactory;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -24,24 +24,27 @@ public class GenerateInspectPluginsTabRequest extends InfoRequestWithVariables i
|
|||
|
||||
private final InfoSystem infoSystem;
|
||||
private final InfoRequestFactory infoRequestFactory;
|
||||
private final PageFactory pageFactory;
|
||||
|
||||
private UUID playerUUID;
|
||||
|
||||
GenerateInspectPluginsTabRequest(
|
||||
InfoSystem infoSystem,
|
||||
InfoRequestFactory infoRequestFactory
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
PageFactory pageFactory
|
||||
) {
|
||||
this.infoSystem = infoSystem;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this.pageFactory = pageFactory;
|
||||
}
|
||||
|
||||
public GenerateInspectPluginsTabRequest(
|
||||
GenerateInspectPluginsTabRequest(
|
||||
UUID uuid,
|
||||
InfoSystem infoSystem,
|
||||
InfoRequestFactory infoRequestFactory
|
||||
InfoRequestFactory infoRequestFactory,
|
||||
PageFactory pageFactory
|
||||
) {
|
||||
this.infoSystem = infoSystem;
|
||||
this.infoRequestFactory = infoRequestFactory;
|
||||
this(infoSystem, infoRequestFactory, pageFactory);
|
||||
Verify.nullCheck(uuid);
|
||||
playerUUID = uuid;
|
||||
variables.put("player", uuid.toString());
|
||||
|
@ -62,7 +65,7 @@ public class GenerateInspectPluginsTabRequest extends InfoRequestWithVariables i
|
|||
}
|
||||
|
||||
private void generateAndCache(UUID uuid) throws WebException {
|
||||
String[] navAndHtml = InspectPagePluginsContent.generateForThisServer(uuid).getContents();
|
||||
String[] navAndHtml = pageFactory.inspectPagePluginsContent(uuid).getContents();
|
||||
infoSystem.sendRequest(infoRequestFactory.cacheInspectPluginsTabRequest(uuid, navAndHtml[0], navAndHtml[1]));
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public class InfoRequestFactory {
|
|||
}
|
||||
|
||||
public GenerateInspectPluginsTabRequest generateInspectPluginsTabRequest(UUID uuid) {
|
||||
return new GenerateInspectPluginsTabRequest(uuid, infoSystem.get(), this);
|
||||
return new GenerateInspectPluginsTabRequest(uuid, infoSystem.get(), this, pageFactory);
|
||||
}
|
||||
|
||||
public GenerateNetworkPageContentRequest generateNetworkPageContentRequest() {
|
||||
|
|
|
@ -91,7 +91,7 @@ public class InfoRequestHandlerFactory {
|
|||
}
|
||||
|
||||
GenerateRequest generateInspectPluginsTabRequest() {
|
||||
return new GenerateInspectPluginsTabRequest(infoSystem.get(), infoRequestFactory.get());
|
||||
return new GenerateInspectPluginsTabRequest(infoSystem.get(), infoRequestFactory.get(), pageFactory.get());
|
||||
}
|
||||
|
||||
GenerateRequest generateNetworkPageContentRequest() {
|
||||
|
|
|
@ -37,11 +37,11 @@ public class InspectPagePluginsContent extends Response {
|
|||
addTab(serverUUID, nav, html);
|
||||
}
|
||||
|
||||
public static InspectPagePluginsContent generateForThisServer(UUID playerUUID) {
|
||||
HookHandler hookHandler = HookHandler.getInstance();
|
||||
public static InspectPagePluginsContent generateForThisServer(UUID playerUUID, ServerInfo serverInfo, HookHandler hookHandler) {
|
||||
String serverName = serverInfo.getServer().getName();
|
||||
String actualServerName = serverName.equals("Plan") ? "Server " + serverInfo.getServer().getId() : serverName;
|
||||
|
||||
Map<PluginData, InspectContainer> containers = hookHandler.getInspectContainersFor(playerUUID);
|
||||
String serverName = ServerInfo.getServerName_Old();
|
||||
String actualServerName = serverName.equals("Plan") ? "Server " + ServerInfo.getServerID_Old() : serverName;
|
||||
if (containers.isEmpty()) {
|
||||
return new InspectPagePluginsContent(playerUUID, "<li><a>" + actualServerName + " (No Data)</a></li>",
|
||||
"<div class=\"tab\"><div class=\"row clearfix\">" +
|
||||
|
@ -50,7 +50,12 @@ public class InspectPagePluginsContent extends Response {
|
|||
}
|
||||
|
||||
String nav = "<li><a class=\"nav-button\" href=\"javascript:void(0)\">" + actualServerName + "</a></li>";
|
||||
String tab = createTab(containers);
|
||||
|
||||
return new InspectPagePluginsContent(serverInfo.getServerUUID(), nav, tab);
|
||||
}
|
||||
|
||||
private static String createTab(Map<PluginData, InspectContainer> containers) {
|
||||
StringBuilder tab = new StringBuilder();
|
||||
tab.append("<div class=\"tab\"><div class=\"row clearfix\">");
|
||||
|
||||
|
@ -63,8 +68,7 @@ public class InspectPagePluginsContent extends Response {
|
|||
}
|
||||
|
||||
tab.append("</div></div>");
|
||||
|
||||
return new InspectPagePluginsContent(ServerInfo.getServerUUID_Old(), nav, tab.toString());
|
||||
return tab.toString();
|
||||
}
|
||||
|
||||
public void addTab(UUID serverUUID, String nav, String html) {
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package com.djrapitops.plan.utilities.analysis;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.BanData;
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ServerBanDataReader {
|
||||
|
||||
public ServerBanDataReader() {
|
||||
}
|
||||
|
||||
public Set<UUID> readBanDataForContainer(DataContainer container) {
|
||||
return readBanData(
|
||||
container.getValue(AnalysisKeys.PLAYERS_MUTATOR)
|
||||
.map(PlayersMutator::uuids)
|
||||
.orElse(new ArrayList<>())
|
||||
);
|
||||
}
|
||||
|
||||
public Set<UUID> readBanData(Collection<UUID> uuids) {
|
||||
List<BanData> banPlugins = HookHandler.getInstance().getBanDataSources();
|
||||
|
||||
Set<UUID> banned = new HashSet<>();
|
||||
for (BanData banPlugin : banPlugins) {
|
||||
try {
|
||||
banned.addAll(banPlugin.filterBanned(uuids));
|
||||
} catch (Exception | NoSuchMethodError | NoClassDefFoundError | NoSuchFieldError e) {
|
||||
Log.toLog("PluginData caused exception: " + banPlugin.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
return banned;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.djrapitops.plan.utilities.html.pages;
|
||||
|
||||
import com.djrapitops.plan.data.plugin.HookHandler;
|
||||
import com.djrapitops.plan.data.store.containers.AnalysisContainer;
|
||||
import com.djrapitops.plan.data.store.containers.NetworkContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
|
@ -8,6 +9,7 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
|||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
|
@ -39,6 +41,7 @@ public class PageFactory {
|
|||
private final Lazy<Graphs> graphs;
|
||||
private final Lazy<HtmlTables> tables;
|
||||
private final Lazy<Formatters> formatters;
|
||||
private final Lazy<HookHandler> hookHandler;
|
||||
private final Lazy<DebugLogger> debugLogger;
|
||||
private final Lazy<Timings> timings;
|
||||
private final Lazy<ErrorHandler> errorHandler;
|
||||
|
@ -54,6 +57,7 @@ public class PageFactory {
|
|||
Lazy<Graphs> graphs,
|
||||
Lazy<HtmlTables> tables,
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<HookHandler> hookHandler,
|
||||
Lazy<DebugLogger> debugLogger,
|
||||
Lazy<Timings> timings,
|
||||
Lazy<ErrorHandler> errorHandler
|
||||
|
@ -67,6 +71,7 @@ public class PageFactory {
|
|||
this.graphs = graphs;
|
||||
this.tables = tables;
|
||||
this.formatters = formatters;
|
||||
this.hookHandler = hookHandler;
|
||||
this.debugLogger = debugLogger;
|
||||
this.timings = timings;
|
||||
this.errorHandler = errorHandler;
|
||||
|
@ -100,6 +105,10 @@ public class PageFactory {
|
|||
);
|
||||
}
|
||||
|
||||
public InspectPagePluginsContent inspectPagePluginsContent(UUID playerUUID) {
|
||||
return InspectPagePluginsContent.generateForThisServer(playerUUID, serverInfo.get(), hookHandler.get());
|
||||
}
|
||||
|
||||
public NetworkPage networkPage() {
|
||||
NetworkContainer networkContainer = database.get().fetch().getNetworkContainer(); // Not cached, big.
|
||||
return new NetworkPage(networkContainer, serverInfo.get().getServerProperties());
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.*;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
// TODO Turn non static
|
||||
public class AnalysisPluginsTabContentCreator {
|
||||
|
||||
public static String[] createContent(
|
||||
|
@ -101,7 +102,8 @@ public class AnalysisPluginsTabContentCreator {
|
|||
) {
|
||||
Map<PluginData, AnalysisContainer> containers = new HashMap<>();
|
||||
|
||||
List<PluginData> sources = HookHandler.getInstance().getAdditionalDataSources();
|
||||
HookHandler hookHandler = null; // TODO
|
||||
List<PluginData> sources = hookHandler.getAdditionalDataSources();
|
||||
|
||||
sources.parallelStream().forEach(source -> {
|
||||
PlanPlugin plugin = PlanPlugin.getInstance();
|
||||
|
|
Loading…
Reference in New Issue
Block a user