diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java b/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java index 0562e1406..6ef2fc228 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java @@ -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 getData(String playername) throws Exception { - HashMap 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 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 getAllData(String playername) throws Exception { - return getData(playername); - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java index 47a718b5d..686a65a79 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java @@ -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,8 +38,11 @@ public class PlanCommand implements CommandExecutor { commands.add(new SearchCommand(plugin)); commands.add(new InfoCommand(plugin)); commands.add(new ReloadCommand(plugin)); - if (plugin.getPlanLiteHook().isEnabled()) { - commands.add(new LiteCommand(plugin)); + PlanLiteHook planLiteHook = plugin.getPlanLiteHook(); + if (planLiteHook != null) { + if (planLiteHook.isEnabled()) { + commands.add(new LiteCommand(plugin)); + } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteDataPushHook.java b/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteDataPushHook.java new file mode 100644 index 000000000..8131e1e2c --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteDataPushHook.java @@ -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 getData(String playername) throws Exception { + HashMap 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 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 getAllData(String playername) throws Exception { + return getData(playername); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteHandler.java index 92447d4ab..5e6cdfa72 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handlers/PlanLiteHandler.java @@ -31,7 +31,11 @@ public class PlanLiteHandler { public PlanLiteHandler(Plan plugin) { this.plugin = plugin; PlanLiteHook planLiteHook = plugin.getPlanLiteHook(); - enabled = planLiteHook.isEnabled(); + if (planLiteHook != null) { + enabled = planLiteHook.isEnabled(); + } else { + enabled = false; + } if (enabled) { hook = planLiteHook; } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java index 44dc2b895..fdcf79239 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java @@ -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; @@ -112,8 +113,14 @@ public class Analysis { int ops = 0; List 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 townMap = new HashMap<>(); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java index 68db4be69..09850a2a2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java @@ -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(); - replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLitePlayerHtml(data.getPlanLiteData()) : ""); + if (hook != null) { + replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLitePlayerHtml(data.getPlanLiteData()) : ""); + } else { + replaceMap.put("%planlite%", ""); + } replaceMap.put("%inaccuratedatawarning%", (new Date().getTime() - data.getRegistered() < 180000) ? "

Data might be inaccurate, player has just registered.

" : ""); 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(); - replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLiteAnalysisHtml(data.getPlanLiteData()) : ""); + if (hook != null) { + replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLiteAnalysisHtml(data.getPlanLiteData()) : ""); + } else { + replaceMap.put("%planlite%", ""); + } return replaceMap; } diff --git a/Plan/src/main/resources/plugin.yml b/Plan/src/main/resources/plugin.yml index 02fe49b5a..ff927b465 100644 --- a/Plan/src/main/resources/plugin.yml +++ b/Plan/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.Plan -version: 2.1.1 +version: 2.1.2 commands: plan: