mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Bugfix for NoClassDefFoundError when PlanLite not installed
* Added new DataPushHook to prevent Hook from not being found. * Added null checks for PlanLiteHook, because it was causeing NPEs
This commit is contained in:
parent
af85c38024
commit
048c201bd6
@ -1,17 +1,11 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import com.djrapitops.plan.utilities.AnalysisUtils;
|
||||
import com.djrapitops.planlite.PlanLite;
|
||||
import com.djrapitops.planlite.UUIDFetcher;
|
||||
import com.djrapitops.planlite.api.API;
|
||||
import com.djrapitops.planlite.api.DataPoint;
|
||||
import com.djrapitops.planlite.api.DataType;
|
||||
import com.djrapitops.planlite.api.Hook;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.data.handlers.PlanLiteDataPushHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -22,7 +16,7 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlanLiteHook implements Hook {
|
||||
public class PlanLiteHook {
|
||||
|
||||
private PlanLite planLite;
|
||||
private Plan plugin;
|
||||
@ -50,7 +44,7 @@ public class PlanLiteHook implements Hook {
|
||||
enabled = true;
|
||||
planLiteApi = planLite.getAPI();
|
||||
if (config.getBoolean("Settings.PlanLite.UseAsAlternativeUI")) {
|
||||
planLite.addExtraHook("Plan", this);
|
||||
planLite.addExtraHook("Plan", new PlanLiteDataPushHook(plugin));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
@ -139,45 +133,4 @@ public class PlanLiteHook implements Hook {
|
||||
public boolean hasVault() {
|
||||
return getEnabledHooksNames().contains("Vault");
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to send data to PlanLite if it's use as UI is enabled.
|
||||
*
|
||||
* @param playername
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String playername) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
try {
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(playername);
|
||||
if (uuid != null) {
|
||||
InspectCacheHandler inspectCache = plugin.getInspectCache();
|
||||
inspectCache.cache(uuid);
|
||||
UserData uData = inspectCache.getFromCache(uuid);
|
||||
HashMap<String, String> userData = AnalysisUtils.getInspectReplaceRules(uData);
|
||||
for (String key : userData.keySet()) {
|
||||
if (key.equals("%planlite%") || key.equals("%gmpiechart%")) {
|
||||
continue;
|
||||
}
|
||||
data.put("PLA-" + key.toUpperCase().substring(1, key.length() - 1), new DataPoint(userData.get(key), DataType.OTHER));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to send data to PlanLite if it's use as UI is enabled.
|
||||
*
|
||||
* @param playername
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getAllData(String playername) throws Exception {
|
||||
return getData(playername);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.command;
|
||||
|
||||
import com.djrapitops.plan.Phrase;
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanLiteHook;
|
||||
import com.djrapitops.plan.command.commands.*;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
@ -37,10 +38,13 @@ public class PlanCommand implements CommandExecutor {
|
||||
commands.add(new SearchCommand(plugin));
|
||||
commands.add(new InfoCommand(plugin));
|
||||
commands.add(new ReloadCommand(plugin));
|
||||
if (plugin.getPlanLiteHook().isEnabled()) {
|
||||
PlanLiteHook planLiteHook = plugin.getPlanLiteHook();
|
||||
if (planLiteHook != null) {
|
||||
if (planLiteHook.isEnabled()) {
|
||||
commands.add(new LiteCommand(plugin));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Initialized SubCommands
|
||||
|
@ -0,0 +1,66 @@
|
||||
package main.java.com.djrapitops.plan.data.handlers;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
import com.djrapitops.plan.data.cache.InspectCacheHandler;
|
||||
import com.djrapitops.plan.utilities.AnalysisUtils;
|
||||
import com.djrapitops.planlite.UUIDFetcher;
|
||||
import com.djrapitops.planlite.api.DataPoint;
|
||||
import com.djrapitops.planlite.api.DataType;
|
||||
import com.djrapitops.planlite.api.Hook;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlanLiteDataPushHook implements Hook {
|
||||
|
||||
private final Plan plugin;
|
||||
|
||||
public PlanLiteDataPushHook(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to send data to PlanLite if it's use as UI is enabled.
|
||||
*
|
||||
* @param playername
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getData(String playername) throws Exception {
|
||||
HashMap<String, DataPoint> data = new HashMap<>();
|
||||
try {
|
||||
UUID uuid = UUIDFetcher.getUUIDOf(playername);
|
||||
if (uuid != null) {
|
||||
InspectCacheHandler inspectCache = plugin.getInspectCache();
|
||||
inspectCache.cache(uuid);
|
||||
UserData uData = inspectCache.getFromCache(uuid);
|
||||
HashMap<String, String> userData = AnalysisUtils.getInspectReplaceRules(uData);
|
||||
for (String key : userData.keySet()) {
|
||||
if (key.equals("%planlite%") || key.equals("%gmpiechart%")) {
|
||||
continue;
|
||||
}
|
||||
data.put("PLA-" + key.toUpperCase().substring(1, key.length() - 1), new DataPoint(userData.get(key), DataType.OTHER));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to send data to PlanLite if it's use as UI is enabled.
|
||||
*
|
||||
* @param playername
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public HashMap<String, DataPoint> getAllData(String playername) throws Exception {
|
||||
return getData(playername);
|
||||
}
|
||||
}
|
@ -31,7 +31,11 @@ public class PlanLiteHandler {
|
||||
public PlanLiteHandler(Plan plugin) {
|
||||
this.plugin = plugin;
|
||||
PlanLiteHook planLiteHook = plugin.getPlanLiteHook();
|
||||
if (planLiteHook != null) {
|
||||
enabled = planLiteHook.isEnabled();
|
||||
} else {
|
||||
enabled = false;
|
||||
}
|
||||
if (enabled) {
|
||||
hook = planLiteHook;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.djrapitops.plan.utilities;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.PlanLiteHook;
|
||||
import com.djrapitops.plan.data.AnalysisData;
|
||||
import com.djrapitops.plan.data.ServerData;
|
||||
import com.djrapitops.plan.data.UserData;
|
||||
@ -113,7 +114,13 @@ public class Analysis {
|
||||
int ops = 0;
|
||||
List<Integer> ages = new ArrayList<>();
|
||||
|
||||
boolean planLiteEnabled = plugin.getPlanLiteHook().isEnabled();
|
||||
boolean planLiteEnabled;
|
||||
PlanLiteHook planLiteHook = plugin.getPlanLiteHook();
|
||||
if (planLiteHook != null) {
|
||||
planLiteEnabled = planLiteHook.isEnabled();
|
||||
} else {
|
||||
planLiteEnabled = false;
|
||||
}
|
||||
|
||||
PlanLiteAnalyzedData plData = new PlanLiteAnalyzedData();
|
||||
HashMap<String, Integer> townMap = new HashMap<>();
|
||||
|
@ -52,6 +52,7 @@ public class AnalysisUtils {
|
||||
|
||||
/**
|
||||
* Gets the HashMap that is used to replace placeholders.
|
||||
*
|
||||
* @param data UserData used to replace the placeholders with
|
||||
* @return HashMap that contains string for each placeholder.
|
||||
*/
|
||||
@ -89,7 +90,11 @@ public class AnalysisUtils {
|
||||
replaceMap.put("%op%", data.isOp() ? ", Operator (Op)" : "");
|
||||
replaceMap.put("%isonline%", (data.isOnline()) ? "| Online" : "| Offline");
|
||||
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
|
||||
if (hook != null) {
|
||||
replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLitePlayerHtml(data.getPlanLiteData()) : "");
|
||||
} else {
|
||||
replaceMap.put("%planlite%", "");
|
||||
}
|
||||
replaceMap.put("%inaccuratedatawarning%", (new Date().getTime() - data.getRegistered() < 180000)
|
||||
? "<h3>Data might be inaccurate, player has just registered.</h3>" : "");
|
||||
return replaceMap;
|
||||
@ -102,6 +107,7 @@ public class AnalysisUtils {
|
||||
|
||||
/**
|
||||
* Gets the HashMap that is used to replace placeholders in Analysis.
|
||||
*
|
||||
* @param data AnalysisData used to replace the placeholders with
|
||||
* @return HashMap that contains string for each placeholder.
|
||||
*/
|
||||
@ -129,7 +135,11 @@ public class AnalysisUtils {
|
||||
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountSinceString("" + data.getRefreshDate(), new Date()));
|
||||
replaceMap.put("%totallogins%", "" + data.getTotalLoginTimes());
|
||||
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
|
||||
if (hook != null) {
|
||||
replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLiteAnalysisHtml(data.getPlanLiteData()) : "");
|
||||
} else {
|
||||
replaceMap.put("%planlite%", "");
|
||||
}
|
||||
return replaceMap;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Plan
|
||||
author: Rsl1122
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 2.1.1
|
||||
version: 2.1.2
|
||||
|
||||
commands:
|
||||
plan:
|
||||
|
Loading…
Reference in New Issue
Block a user