From 2538e32e6d69dd10ff91be5f196bb2cd126cf410 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 15 Jan 2017 14:17:42 +0200 Subject: [PATCH] Changed permissions for PlanLite plan. > planlite. Begun working on PlanLite features Analysis and html creation untested for new planlite when planlite is enabled. --- .../com/djrapitops/planlite/PlanCommand.java | 2 - .../src/com/djrapitops/planlite/PlanLite.java | 8 +- .../planlite/command/SubCommand.java | 1 - .../command/commands/AnalyzeCommand.java | 4 +- .../command/commands/DebugCommand.java | 37 ----- .../command/commands/HelpCommand.java | 7 +- .../command/commands/InfoCommand.java | 2 +- .../command/commands/InspectCommand.java | 2 +- .../command/commands/ReloadCommand.java | 2 +- .../command/commands/SearchCommand.java | 2 +- .../command/hooks/SuperbVoteHook.java | 1 - .../planlite/command/hooks/TownyHook.java | 2 - .../planlite/command/hooks/VaultHook.java | 1 - .../planlite/command/utils/DataUtils.java | 2 +- Plan Lite/src/plugin.yml | 50 +++--- .../main/java/com/djrapitops/plan/Plan.java | 17 +- .../com/djrapitops/plan/PlanLiteHook.java | 101 +++--------- .../java/com/djrapitops/plan/api/API.java | 149 ------------------ .../djrapitops/plan/data/AnalysisData.java | 22 +++ .../plan/data/PlanLiteAnalyzedData.java | 54 +++++++ .../plan/data/PlanLitePlayerData.java | 137 ++++++++++++++++ .../com/djrapitops/plan/data/UserData.java | 23 ++- .../plan/data/cache/DataCacheHandler.java | 30 +++- .../plan/data/handlers/PlanLiteHandler.java | 69 +++++++- .../data/listeners/PlanPlayerListener.java | 4 +- .../djrapitops/plan/utilities/Analysis.java | 39 ++++- .../plan/utilities/AnalysisUtils.java | 48 ++++++ Plan/src/main/resources/analysis.html | 13 +- 28 files changed, 486 insertions(+), 343 deletions(-) delete mode 100644 Plan Lite/src/com/djrapitops/planlite/command/commands/DebugCommand.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/data/PlanLiteAnalyzedData.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/data/PlanLitePlayerData.java diff --git a/Plan Lite/src/com/djrapitops/planlite/PlanCommand.java b/Plan Lite/src/com/djrapitops/planlite/PlanCommand.java index 2f09d8bda..fb028a524 100644 --- a/Plan Lite/src/com/djrapitops/planlite/PlanCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/PlanCommand.java @@ -3,7 +3,6 @@ package com.djrapitops.planlite; import com.djrapitops.planlite.command.CommandType; import com.djrapitops.planlite.command.SubCommand; import com.djrapitops.planlite.command.commands.AnalyzeCommand; -import com.djrapitops.planlite.command.commands.DebugCommand; import com.djrapitops.planlite.command.commands.HelpCommand; import com.djrapitops.planlite.command.commands.InfoCommand; import com.djrapitops.planlite.command.commands.InspectCommand; @@ -33,7 +32,6 @@ public class PlanCommand implements CommandExecutor { commands.add(new SearchCommand(plugin)); commands.add(new InfoCommand(plugin)); commands.add(new ReloadCommand(plugin)); - commands.add(new DebugCommand(plugin)); } public List getCommands() { diff --git a/Plan Lite/src/com/djrapitops/planlite/PlanLite.java b/Plan Lite/src/com/djrapitops/planlite/PlanLite.java index e842c7c75..a3ec1edc3 100644 --- a/Plan Lite/src/com/djrapitops/planlite/PlanLite.java +++ b/Plan Lite/src/com/djrapitops/planlite/PlanLite.java @@ -32,6 +32,7 @@ public class PlanLite extends JavaPlugin { private final Map hooks; private API api; private final Map extraHooks; + private PlanCommand planCommand; public PlanLite() { this.hooks = new HashMap<>(); @@ -78,8 +79,9 @@ public class PlanLite extends JavaPlugin { if (!hookFail.isEmpty()) { Bukkit.getServer().getConsoleSender().sendMessage("[PlanLite] " + failedMsg); } + planCommand = new PlanCommand(this); - getCommand("plan").setExecutor(new PlanCommand(this)); + getCommand("planlite").setExecutor(planCommand); log("Player Analytics Enabled."); } @@ -170,4 +172,8 @@ public class PlanLite extends JavaPlugin { logToFile("Failed to hook " + name + "\n" + e); } } + + public PlanCommand getPlanCommand() { + return planCommand; + } } diff --git a/Plan Lite/src/com/djrapitops/planlite/command/SubCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/SubCommand.java index e3326ce8a..e3b9b912b 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/SubCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/SubCommand.java @@ -1,6 +1,5 @@ package com.djrapitops.planlite.command; -//import com.djrapitops.plan.Phrase; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/AnalyzeCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/AnalyzeCommand.java index 781549598..6aadfe0f5 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/AnalyzeCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/commands/AnalyzeCommand.java @@ -24,7 +24,7 @@ public class AnalyzeCommand extends SubCommand { private Date refreshDate; public AnalyzeCommand(PlanLite plugin) { - super("analyze", "plan.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE); + super("analyze", "planlite.analyze", "Analyze data of all players /plan analyze [-refresh]", CommandType.CONSOLE); this.plugin = plugin; } @@ -34,7 +34,7 @@ public class AnalyzeCommand extends SubCommand { ChatColor textColor = ChatColor.GRAY; for (String arg : args) { if (arg.toLowerCase().equals("-refresh")) { - if (sender.hasPermission("plan.analyze.refresh") || !(sender instanceof Player)) { + if (sender.hasPermission("planlite.analyze.refresh") || !(sender instanceof Player)) { refreshAnalysisData(sender); } } diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/DebugCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/DebugCommand.java deleted file mode 100644 index c6776a6ec..000000000 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/DebugCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.djrapitops.planlite.command.commands; - -import com.djrapitops.planlite.PlanLite; -import com.djrapitops.planlite.command.CommandType; -import com.djrapitops.planlite.command.SubCommand; -import com.djrapitops.planlite.command.utils.DataUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; - -public class DebugCommand extends SubCommand { - - private PlanLite plugin; - - public DebugCommand(PlanLite plugin) { - super("debug", "plan.debug", "Test plugin for possible errors (debug feature)", CommandType.PLAYER); - this.plugin = plugin; - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { - if (!plugin.getConfig().getBoolean("debug")) { - sender.sendMessage(ChatColor.RED+"[PlanLite] Debug disabled in config"); - return true; - } - String[] commands = {"plan", "plan info", "plan reload", "plan inspect", - "plan inspect "+sender.getName()+"-a", "plan inspect reinogiern", - "plan analyze", "plan search", "plan search "+sender.getName()+" -p"}; - for (String command : commands) { - Bukkit.dispatchCommand(sender, command); - } - sender.sendMessage(ChatColor.GREEN+"[PlanLite] Debug successful, possible errors written in file."); - return true; - } - -} diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/HelpCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/HelpCommand.java index 54f2b4d4e..9eaa3339b 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/HelpCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/commands/HelpCommand.java @@ -1,6 +1,5 @@ package com.djrapitops.planlite.command.commands; -//import com.djrapitops.plan.Phrase; import com.djrapitops.planlite.PlanLite; import com.djrapitops.planlite.PlanCommand; import com.djrapitops.planlite.command.CommandType; @@ -16,7 +15,7 @@ public class HelpCommand extends SubCommand { private final PlanCommand command; public HelpCommand(PlanLite plugin, PlanCommand command) { - super("help,?", "plan.?", "Show command list.", CommandType.CONSOLE); + super("help,?", "planlite.?", "Show command list.", CommandType.CONSOLE); this.plugin = plugin; this.command = command; @@ -29,7 +28,7 @@ public class HelpCommand extends SubCommand { ChatColor textColor = ChatColor.GRAY; - sender.sendMessage(textColor + "-- [" + operatorColor + "PLAN - Player Analytics" + textColor + "] --"); + sender.sendMessage(textColor + "-- [" + operatorColor + "Plan Lite - Player Analytics Lite" + textColor + "] --"); for (SubCommand command : this.command.getCommands()) { if (command.getName().equalsIgnoreCase(getName())) { @@ -44,7 +43,7 @@ public class HelpCommand extends SubCommand { continue; } - sender.sendMessage(operatorColor + "/plan " + command.getFirstName() + textColor + " - " + command.getUsage()); + sender.sendMessage(operatorColor + "/planlite " + command.getFirstName() + textColor + " - " + command.getUsage()); } return true; diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/InfoCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/InfoCommand.java index a54fac425..fe8cbde7a 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/InfoCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/commands/InfoCommand.java @@ -13,7 +13,7 @@ public class InfoCommand extends SubCommand { private PlanLite plugin; public InfoCommand(PlanLite plugin) { - super("info", "plan.info", "View version and enabled hooks", CommandType.CONSOLE); + super("info", "planlite.info", "View version and enabled hooks", CommandType.CONSOLE); this.plugin = plugin; } diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/InspectCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/InspectCommand.java index a27c3be06..bbd8b463e 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/InspectCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/commands/InspectCommand.java @@ -21,7 +21,7 @@ public class InspectCommand extends SubCommand { private PlanLite plugin; public InspectCommand(PlanLite plugin) { - super("inspect", "plan.inspect", "Inspect data /plan [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS); + super("inspect", "planlite.inspect", "Inspect data /plan [-a, -r].", CommandType.CONSOLE_WITH_ARGUMENTS); this.plugin = plugin; } diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/ReloadCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/ReloadCommand.java index 8faad1af0..540f6b1b2 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/ReloadCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/commands/ReloadCommand.java @@ -15,7 +15,7 @@ public class ReloadCommand extends SubCommand { private PlanLite plugin; public ReloadCommand(PlanLite plugin) { - super("reload", "plan.reload", "Reload plugin config & Hooks", CommandType.CONSOLE); + super("reload", "planlite.reload", "Reload plugin config & Hooks", CommandType.CONSOLE); this.plugin = plugin; } diff --git a/Plan Lite/src/com/djrapitops/planlite/command/commands/SearchCommand.java b/Plan Lite/src/com/djrapitops/planlite/command/commands/SearchCommand.java index c6ebead38..8dfd8c048 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/commands/SearchCommand.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/commands/SearchCommand.java @@ -25,7 +25,7 @@ public class SearchCommand extends SubCommand { private final PlanLite plugin; public SearchCommand(PlanLite plugin) { - super("search", "plan.search", "Inspect specific data /plan [-p]", CommandType.CONSOLE_WITH_ARGUMENTS); + super("search", "planlite.search", "Inspect specific data /plan [-p]", CommandType.CONSOLE_WITH_ARGUMENTS); this.plugin = plugin; } diff --git a/Plan Lite/src/com/djrapitops/planlite/command/hooks/SuperbVoteHook.java b/Plan Lite/src/com/djrapitops/planlite/command/hooks/SuperbVoteHook.java index f02804643..efec432ed 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/hooks/SuperbVoteHook.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/hooks/SuperbVoteHook.java @@ -8,7 +8,6 @@ import com.djrapitops.planlite.api.DataType; import io.minimum.minecraft.superbvote.SuperbVote; import java.util.HashMap; import java.util.UUID; -import static org.bukkit.Bukkit.getOfflinePlayer; import org.bukkit.OfflinePlayer; import static org.bukkit.Bukkit.getOfflinePlayer; diff --git a/Plan Lite/src/com/djrapitops/planlite/command/hooks/TownyHook.java b/Plan Lite/src/com/djrapitops/planlite/command/hooks/TownyHook.java index 31f0eb296..5900cfddb 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/hooks/TownyHook.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/hooks/TownyHook.java @@ -16,8 +16,6 @@ import com.palmergames.bukkit.util.BukkitTools; import java.util.HashMap; import java.util.List; import static org.bukkit.plugin.java.JavaPlugin.getPlugin; -import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents; -import static org.bukkit.Bukkit.getOfflinePlayer; import org.bukkit.OfflinePlayer; import static com.palmergames.bukkit.towny.TownyFormatter.getFormattedResidents; import static org.bukkit.Bukkit.getOfflinePlayer; diff --git a/Plan Lite/src/com/djrapitops/planlite/command/hooks/VaultHook.java b/Plan Lite/src/com/djrapitops/planlite/command/hooks/VaultHook.java index 91d0af03a..e2366e12a 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/hooks/VaultHook.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/hooks/VaultHook.java @@ -9,7 +9,6 @@ import java.util.HashMap; import java.util.UUID; import org.bukkit.OfflinePlayer; import net.milkbowl.vault.economy.Economy; -import static org.bukkit.Bukkit.getOfflinePlayer; import static org.bukkit.Bukkit.getServer; import static org.bukkit.Bukkit.getOfflinePlayer; diff --git a/Plan Lite/src/com/djrapitops/planlite/command/utils/DataUtils.java b/Plan Lite/src/com/djrapitops/planlite/command/utils/DataUtils.java index 5ea5a0cf8..924866113 100644 --- a/Plan Lite/src/com/djrapitops/planlite/command/utils/DataUtils.java +++ b/Plan Lite/src/com/djrapitops/planlite/command/utils/DataUtils.java @@ -75,7 +75,7 @@ public class DataUtils { plugin.logToFile("INSPECT-GETNAME\nNo username given, returned empty username.\n" + args[0]); - } else if (sender.hasPermission("plan.inspect.other") || !(sender instanceof Player)) { + } else if (sender.hasPermission("planlite.inspect.other") || !(sender instanceof Player)) { playerName = args[0]; } } else { diff --git a/Plan Lite/src/plugin.yml b/Plan Lite/src/plugin.yml index 025fa0d4e..b5f613c31 100644 --- a/Plan Lite/src/plugin.yml +++ b/Plan Lite/src/plugin.yml @@ -34,50 +34,50 @@ softdepend: - PlayerLogger permissions: - plan.?: + planlite.?: description: Help command default: true - plan.inspect: + planlite.inspect: description: Allows you to check your player data. default: true - plan.inspect.other: + planlite.inspect.other: description: Allows you to check other players' player data. default: true - plan.analyze: + planlite.analyze: description: Allows you to check analysed data about all players. default: true - plan.analyze.refresh: + planlite.analyze.refresh: description: Allows you to refresh the analyse result with -r argument default: op - plan.reload: + planlite.reload: description: Allows to reload plugin config default: true - plan.search: + planlite.search: description: Allows search default: true - plan.info: + planlite.info: description: Allows to view info default: true - plan.debug: + planlite.debug: description: Allows debug command default: op - plan.basic: + planlite.basic: children: - plan.?: true - plan.inspect: true - plan.info: true - plan.search: true - plan.advanced: + planlite.?: true + planlite.inspect: true + planlite.info: true + planlite.search: true + planlite.advanced: childer: - plan.basic: true - plan.analyze: true - plan.staff: + planlite.basic: true + planlite.analyze: true + planlite.staff: children: - plan.debug: true - plan.advanced: true - plan.inspect.other: true - plan.analyze.refresh: true - plan.reload: true - plan.*: + planlite.debug: true + planlite.advanced: true + planlite.inspect.other: true + planlite.analyze.refresh: true + planlite.reload: true + planlite.*: children: - plan.staff: true \ No newline at end of file + planlite.staff: true \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 2837c7efb..e03e1d592 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -108,19 +108,12 @@ public class Plan extends JavaPlugin { public void hookPlanLite() { try { - if (getConfig().getBoolean("Settings.PlanLite.Enabled")) { - planLiteHook = new PlanLiteHook(this); - } + planLiteHook = new PlanLiteHook(this); } catch (NoClassDefFoundError | Exception e) { } } - @Deprecated - public List hookInit() { - return new ArrayList<>(); - } - @Override public void onDisable() { uiServer.stop(); @@ -169,14 +162,6 @@ public class Plan extends JavaPlugin { return api; } - public void addExtraHook(String name, Hook hook) { - if (planLiteHook != null) { - planLiteHook.addExtraHook(name, hook); - } else { - logError(Phrase.ERROR_PLANLITE.toString()); - } - } - private void registerListeners() { getServer().getPluginManager().registerEvents(new PlanChatListener(this), this); getServer().getPluginManager().registerEvents(new PlanPlayerListener(this), this); diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java b/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java index a0f613460..5b8eaaef3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java @@ -3,8 +3,9 @@ package com.djrapitops.plan; import com.djrapitops.planlite.PlanLite; import com.djrapitops.planlite.api.API; import com.djrapitops.planlite.api.DataPoint; -import com.djrapitops.planlite.api.Hook; import java.util.HashMap; +import java.util.Set; +import org.bukkit.Bukkit; import static org.bukkit.plugin.java.JavaPlugin.getPlugin; /** @@ -17,105 +18,47 @@ public class PlanLiteHook { private Plan plugin; private API planLiteApi; + private boolean enabled; + /** * Class Constructor. * - * Attempts to hook to PlanLite, if not present logs error. + * Attempts to hook to PlanLite, if not present sets enabled to false * * @param plugin */ public PlanLiteHook(Plan plugin) { this.plugin = plugin; - try { - this.planLite = getPlugin(PlanLite.class); - if (planLite == null) { - throw new Exception(Phrase.ERROR_PLANLITE.toString()); + if (plugin.getConfig().getBoolean("Settings.PlanLite.Enabled")) { + if (Bukkit.getPluginManager().isPluginEnabled("PlanLite")) { + try { + this.planLite = getPlugin(PlanLite.class); + if (planLite == null) { + throw new Exception(Phrase.ERROR_PLANLITE.toString()); + } + enabled = true; + planLiteApi = planLite.getAPI(); + return; + } catch (Exception e) { + } } - planLiteApi = planLite.getAPI(); - } catch (Exception e) { - } + enabled = false; } - void addExtraHook(String name, Hook hook) { - try { - if (planLite == null) { - throw new Exception(Phrase.ERROR_PLANLITE.toString()); - } - planLite.addExtraHook(name, hook); - plugin.log(Phrase.PLANLITE_REG_HOOK.toString() + name); - } catch (Exception | NoClassDefFoundError e) { - plugin.logError("Failed to hook " + name + "\n " + e); - } + public Set getEnabledHooksNames() { + return planLite.getHooks().keySet(); } - @Deprecated - public boolean getDebug() { - return planLiteApi.getDebug(); - } - - @Deprecated - public boolean getVisibleEssentials() { - return planLiteApi.getVisibleEssentials(); - } - - @Deprecated - public boolean getVisibleOnTime() { - return planLiteApi.getVisibleOnTime(); - } - - @Deprecated - public boolean getVisibleFactions() { - return planLiteApi.getVisibleFactions(); - } - - @Deprecated - public boolean getVisibleSuperbVote() { - return planLiteApi.getVisibleSuperbVote(); - } - - @Deprecated - public boolean getVisibleTowny() { - return planLiteApi.getVisibleTowny(); - } - - @Deprecated - public boolean getVisibleVault() { - return planLiteApi.getVisibleVault(); - } - - @Deprecated - public boolean getVisibleAdvancedAchievements() { - return planLiteApi.getVisibleAdvancedAchievements(); - } - - @Deprecated - public boolean getVisiblePlaceholderAPI() { - return planLiteApi.getVisiblePlaceholderAPI(); - } - - @Deprecated public HashMap getData(String playerName, boolean dataPoint) { return planLiteApi.getData(playerName, dataPoint); } - @Deprecated - public HashMap getData(String playerName) { - return planLiteApi.getData(playerName); - } - - @Deprecated public HashMap getAllData(String playerName, boolean dataPoint) { return planLiteApi.getAllData(playerName, dataPoint); } - @Deprecated - public HashMap getAllData(String playerName) { - return planLiteApi.getAllData(playerName); - } - - @Deprecated - public HashMap transformOldDataFormat(HashMap oldData) { - return planLiteApi.transformOldDataFormat(oldData); + public boolean isEnabled() { + return enabled; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/api/API.java b/Plan/src/main/java/com/djrapitops/plan/api/API.java index 7912edbcd..735565631 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/API.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/API.java @@ -2,11 +2,8 @@ package com.djrapitops.plan.api; import com.djrapitops.plan.Plan; import com.djrapitops.plan.PlanLiteHook; -import com.djrapitops.planlite.api.DataPoint; -import com.djrapitops.planlite.api.Hook; import com.djrapitops.plan.utilities.FormatUtils; import java.util.Date; -import java.util.HashMap; /** * @@ -68,150 +65,4 @@ public class API { public static String formatTimeStamp(String timeInMs) { return FormatUtils.formatTimeStamp(timeInMs); } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getDebug() throws NullPointerException { - return hook.getDebug(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleEssentials() throws NullPointerException { - return hook.getVisibleEssentials(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleOnTime() throws NullPointerException { - return hook.getVisibleOnTime(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleFactions() throws NullPointerException { - return hook.getVisibleFactions(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleSuperbVote() throws NullPointerException { - return hook.getVisibleSuperbVote(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleTowny() throws NullPointerException { - return hook.getVisibleTowny(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleVault() throws NullPointerException { - return hook.getVisibleVault(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisibleAdvancedAchievements() throws NullPointerException { - return hook.getVisibleAdvancedAchievements(); - } - - /** - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public boolean getVisiblePlaceholderAPI() throws NullPointerException { - return hook.getVisiblePlaceholderAPI(); - } - - /** - * @param playerName - * @param dataPoint variable to differentiate between DataPoint and String - * return - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public HashMap getData(String playerName, boolean dataPoint) throws NullPointerException { - return hook.getData(playerName, dataPoint); - } - - /** - * @param playerName - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public HashMap getData(String playerName) throws NullPointerException { - return hook.getData(playerName); - } - - /** - * @param playerName - * @param dataPoint variable to differentiate between DataPoint and String - * return - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public HashMap getAllData(String playerName, boolean dataPoint) throws NullPointerException { - return hook.getAllData(playerName, dataPoint); - } - - /** - * @param playerName - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public HashMap getAllData(String playerName) throws NullPointerException { - return hook.getAllData(playerName); - } - - /** - * @param oldData - * @return @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public HashMap transformOldDataFormat(HashMap oldData) throws NullPointerException { - return hook.transformOldDataFormat(oldData); - } - - /** - * @param name name of the plugin registering the hook - * @param hook Hook that is registered - * @throws NullPointerException if PlanLite not installed - * @deprecated Moved to PlanLite - */ - @Deprecated - public void addExtraHook(String name, Hook hook) throws NullPointerException { - plugin.addExtraHook(name, hook); - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java b/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java index 655d2e78c..3da75c152 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/AnalysisData.java @@ -1,5 +1,7 @@ package com.djrapitops.plan.data; +import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData; + /** * * @author Rsl1122 @@ -31,11 +33,31 @@ public class AnalysisData { private int totalPlayers; private long totalLoginTimes; private int ops; + + private boolean planLiteEnabled; + private PlanLiteAnalyzedData planLiteData; public AnalysisData() { } // Getters and setters v---------------------------------v + + public boolean isPlanLiteEnabled() { + return planLiteEnabled; + } + + public void setPlanLiteEnabled(boolean planLiteEnabled) { + this.planLiteEnabled = planLiteEnabled; + } + + public PlanLiteAnalyzedData getPlanLiteData() { + return planLiteData; + } + + public void setPlanLiteData(PlanLiteAnalyzedData planLiteData) { + this.planLiteData = planLiteData; + } + public String getPlayersChartImgHtmlMonth() { return playersChartImgHtmlMonth; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlanLiteAnalyzedData.java b/Plan/src/main/java/com/djrapitops/plan/data/PlanLiteAnalyzedData.java new file mode 100644 index 000000000..bd99501f8 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlanLiteAnalyzedData.java @@ -0,0 +1,54 @@ + +package main.java.com.djrapitops.plan.data; + +import java.util.HashMap; + +/** + * + * @author Rsl1122 + */ +public class PlanLiteAnalyzedData { + + private HashMap townMap; + private HashMap factionMap; + private int totalVotes; + private int totalMoney; + + public PlanLiteAnalyzedData() { + } + + public HashMap getTownMap() { + return townMap; + } + + public void setTownMap(HashMap townMap) { + this.townMap = townMap; + } + + public HashMap getFactionMap() { + return factionMap; + } + + public void setFactionMap(HashMap factionMap) { + this.factionMap = factionMap; + } + + public int getTotalVotes() { + return totalVotes; + } + + public void setTotalVotes(int totalVotes) { + this.totalVotes = totalVotes; + } + + public int getTotalMoney() { + return totalMoney; + } + + public void setTotalMoney(int totalMoney) { + this.totalMoney = totalMoney; + } + + + +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlanLitePlayerData.java b/Plan/src/main/java/com/djrapitops/plan/data/PlanLitePlayerData.java new file mode 100644 index 000000000..c72fc2e6c --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlanLitePlayerData.java @@ -0,0 +1,137 @@ +package main.java.com.djrapitops.plan.data; + +/** + * + * @author Rsl1122 + */ +public class PlanLitePlayerData { + + private boolean towny; + private boolean factions; + private boolean superbVote; + private boolean vault; + + private String town; + private String friends; + private String plotPerms; + private String plotOptions; + + private String faction; + + private int votes; + + private double money; + + public PlanLitePlayerData() { + } + + public void setTowny(boolean towny) { + this.towny = towny; + } + + public void setFactions(boolean factions) { + this.factions = factions; + } + + public void setSuperbVote(boolean superbVote) { + this.superbVote = superbVote; + } + + public void setVault(boolean vault) { + this.vault = vault; + } + + public void setTown(String town) { + this.town = town; + } + + public void setFriends(String friends) { + this.friends = friends; + } + + public void setPlotPerms(String plotPerms) { + this.plotPerms = plotPerms; + } + + public void setPlotOptions(String plotOptions) { + this.plotOptions = plotOptions; + } + + public void setFaction(String faction) { + this.faction = faction; + } + + public void setVotes(int votes) { + this.votes = votes; + } + + public void setMoney(double money) { + this.money = money; + } + + public boolean hasTowny() { + return towny; + } + + public boolean hasFactions() { + return factions; + } + + public boolean hasSuperbVote() { + return superbVote; + } + + public boolean hasVault() { + return vault; + } + + public String getTown() { + if (towny) { + return town; + } + return ""; + } + + public String getFriends() { + if (towny) { + return friends; + } + return ""; + } + + public String getPlotPerms() { + if (towny) { + return plotPerms; + } + return ""; + } + + public String getPlotOptions() { + if (towny) { + return plotOptions; + } + return ""; + } + + public String getFaction() { + if (factions) { + return faction; + } + return ""; + } + + public int getVotes() { + if (superbVote) { + return votes; + } + return -1; + } + + public double getMoney() { + if (vault) { + return money; + } + return -1; + } + +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java index b67b2ef93..81e7e7ed5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.UUID; +import main.java.com.djrapitops.plan.data.PlanLitePlayerData; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -35,7 +36,10 @@ public class UserData { private boolean isOp; private boolean isBanned; private DemographicsData demData; - + + private boolean planLiteFound; + private PlanLitePlayerData planLiteData; + private String name; public UserData(Player player, DemographicsData demData, Database db) { @@ -144,6 +148,23 @@ public class UserData { } // Getters ------------------------------------------------------------- + + public boolean isPlanLiteFound() { + return planLiteFound; + } + + public void setPlanLiteFound(boolean planLiteFound) { + this.planLiteFound = planLiteFound; + } + + public PlanLitePlayerData getPlanLiteData() { + return planLiteData; + } + + public void setPlanLiteData(PlanLitePlayerData planLiteData) { + this.planLiteData = planLiteData; + } + public UUID getUuid() { return uuid; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java index 1f6c8237c..e219bf4f8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java @@ -100,7 +100,11 @@ public class DataCacheHandler { public UserData getCurrentData(UUID uuid, boolean cache) { if (cache) { if (dataCache.get(uuid) == null) { - dataCache.put(uuid, db.getUserData(uuid)); + UserData uData = db.getUserData(uuid); + if (uData.getPlanLiteData() == null) { + getPlanLiteHandler().handleEvents(uData.getName(), uData); + } + dataCache.put(uuid, uData); plugin.log("Added " + uuid.toString() + " to Cache."); } return dataCache.get(uuid); @@ -108,7 +112,11 @@ public class DataCacheHandler { if (dataCache.get(uuid) != null) { return dataCache.get(uuid); } - return db.getUserData(uuid); + UserData uData = db.getUserData(uuid); + if (uData.getPlanLiteData() == null) { + getPlanLiteHandler().handleEvents(uData.getName(), uData); + } + return uData; } } @@ -185,6 +193,12 @@ public class DataCacheHandler { }); } + /** + * Saves a single player's data to the cache from the handler if the player + * is online. + * + * @param uuid UUID of the Player to save + */ public void saveHandlerDataToCache(UUID uuid) { Player p = getPlayer(uuid); if (p != null) { @@ -294,6 +308,13 @@ public class DataCacheHandler { return gamemodeTimesHandler; } + /** + * @return Current instance of PlanLiteHandler + */ + public PlanLiteHandler getPlanLiteHandler() { + return planLiteHandler; + } + /** * Returns the same value as Plan#getDB(). * @@ -341,6 +362,11 @@ public class DataCacheHandler { } } + /** + * Used by Analysis for Player activity graphs. + * + * @return Maximum number of players defined in server.properties. + */ public int getMaxPlayers() { return maxPlayers; } 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 68bf9cd6f..7c22d511d 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 @@ -2,14 +2,81 @@ package com.djrapitops.plan.data.handlers; import com.djrapitops.plan.Plan; import com.djrapitops.plan.PlanLiteHook; +import com.djrapitops.plan.data.UserData; +import com.djrapitops.plan.data.cache.DataCacheHandler; +import com.djrapitops.plan.utilities.FormatUtils; +import com.djrapitops.planlite.api.DataPoint; +import java.util.HashMap; +import java.util.Set; +import main.java.com.djrapitops.plan.data.PlanLitePlayerData; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerJoinEvent; public class PlanLiteHandler { private Plan plugin; private PlanLiteHook hook; + private DataCacheHandler handler; + private boolean enabled; public PlanLiteHandler(Plan plugin) { this.plugin = plugin; - hook = plugin.getPlanLiteHook(); + PlanLiteHook planLiteHook = plugin.getPlanLiteHook(); + enabled = planLiteHook.isEnabled(); + if (enabled) { + hook = planLiteHook; + } + } + + public void handleLogin(PlayerJoinEvent event, UserData data) { + if (!enabled) { + data.setPlanLiteFound(false); + return; + } + Player p = event.getPlayer(); + String playerName = p.getName(); + + handleEvents(playerName, data); + } + + public void handleEvents(String playerName, UserData data) { + if (!enabled) { + return; + } + Set enabledHooks = hook.getEnabledHooksNames(); + HashMap liteData = hook.getAllData(playerName, true); + PlanLitePlayerData plData = new PlanLitePlayerData(); + + plData.setTowny(enabledHooks.contains("Towny")); + plData.setFactions(enabledHooks.contains("Factions")); + plData.setSuperbVote(enabledHooks.contains("SuperbVote")); + plData.setVault(enabledHooks.contains("Vault")); + if (plData.hasTowny()) { + DataPoint town = liteData.get("TOW-TOWN"); + plData.setTown((town != null) ? town.data() : "Not in a town"); + plData.setFriends(liteData.get("TOW-FRIENDS").data()); + plData.setPlotPerms(liteData.get("TOW-PLOT PERMS").data()); + plData.setPlotOptions(liteData.get("TOW-PLOT OPTIONS").data()); + } + if (plData.hasFactions()) { + DataPoint faction = liteData.get("FAC-FACTION"); + plData.setFaction((faction != null) ? faction.data() : "Not in a faction"); + } + if (plData.hasSuperbVote()) { + try { + plData.setVotes(Integer.parseInt(liteData.get("SVO-VOTES").data())); + } catch (Exception e) { + plData.setVotes(0); + } + } + if (plData.hasVault()) { + try { + plData.setMoney(Double.parseDouble(FormatUtils.removeLetters(liteData.get("ECO-BALANCE").data()))); + } catch (Exception e) { + plData.setMoney(0); + } + } + data.setPlanLiteFound(true); + data.setPlanLiteData(plData); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java index 17fdbd66d..ea4bbaeac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java @@ -12,7 +12,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; -import static org.bukkit.plugin.java.JavaPlugin.getPlugin; import org.bukkit.scheduler.BukkitRunnable; /** @@ -29,6 +28,7 @@ public class PlanPlayerListener implements Listener { private final LocationHandler locationH; private final DemographicsHandler demographicH; private final RuleBreakingHandler rulebreakH; + private final PlanLiteHandler planLiteH; private final ServerDataHandler serverHandler; /** @@ -48,6 +48,7 @@ public class PlanPlayerListener implements Listener { demographicH = handler.getDemographicsHandler(); locationH = handler.getLocationHandler(); rulebreakH = handler.getRuleBreakingHandler(); + planLiteH = handler.getPlanLiteHandler(); serverHandler = handler.getServerDataHandler(); } @@ -73,6 +74,7 @@ public class PlanPlayerListener implements Listener { basicInfoH.handleLogin(event, data); gmTimesH.handleLogin(event, data); demographicH.handleLogin(event, data); + planLiteH.handleLogin(event, data); (new BukkitRunnable() { @Override public void run() { 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 25c0365a4..aa39204cf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java @@ -11,7 +11,8 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.UUID; -import org.bukkit.Bukkit; +import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData; +import main.java.com.djrapitops.plan.data.PlanLitePlayerData; import org.bukkit.GameMode; import org.bukkit.OfflinePlayer; import org.bukkit.scheduler.BukkitRunnable; @@ -96,7 +97,30 @@ public class Analysis { int ops = 0; List ages = new ArrayList<>(); + boolean planLiteEnabled = plugin.getPlanLiteHook().isEnabled(); + + PlanLiteAnalyzedData plData = new PlanLiteAnalyzedData(); + HashMap townMap = new HashMap<>(); + HashMap factionMap = new HashMap<>(); + int totalVotes = 0; + int totalMoney = 0; + for (UserData uData : rawData) { + if (planLiteEnabled) { + PlanLitePlayerData litePlayerData = uData.getPlanLiteData(); + String town = litePlayerData.getTown(); + if (!townMap.containsKey(town)) { + townMap.put(town, 0); + } + townMap.replace(town, townMap.get(town) + 1); + String faction = litePlayerData.getFaction(); + if (!factionMap.containsKey(faction)) { + factionMap.put(faction, 0); + } + factionMap.replace(faction, factionMap.get(faction) + 1); + totalVotes += litePlayerData.getVotes(); + totalMoney += litePlayerData.getMoney(); + } HashMap gmTimes = uData.getGmTimes(); gmZero += gmTimes.get(GameMode.SURVIVAL); gmOne += gmTimes.get(GameMode.CREATIVE); @@ -119,7 +143,20 @@ public class Analysis { } else { inactive++; } + } + + if (planLiteEnabled) { + plData.setFactionMap(factionMap); + plData.setTownMap(townMap); + plData.setTotalVotes(totalVotes); + plData.setTotalMoney(totalMoney); + data.setPlanLiteEnabled(true); + data.setPlanLiteData(plData); + } else { + data.setPlanLiteEnabled(false); + } + data.setTotalLoginTimes(totalLoginTimes); String activityPieChartHtml = AnalysisUtils.createActivityPieChart(totalBanned, active, inactive); 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 9d2a84d2d..fe232eb90 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; +import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData; import main.java.com.djrapitops.plan.ui.graphs.ActivityPieChartCreator; import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator; import main.java.com.djrapitops.plan.utilities.comparators.MapComparator; @@ -93,6 +94,12 @@ public class AnalysisUtils { replaceMap.put("%ops%", "" + data.getOps()); replaceMap.put("%refresh%", FormatUtils.formatTimeAmountSinceString("" + data.getRefreshDate(), new Date())); replaceMap.put("%totallogins%", "" + data.getTotalLoginTimes()); + if (data.isPlanLiteEnabled()) { + replaceMap.put("%planlite%", getPlanLiteAnalysisHtml(data.getPlanLiteData())); + } else { + replaceMap.put("%planlite%", ""); + } + return replaceMap; } @@ -134,4 +141,45 @@ public class AnalysisUtils { html += ""; return html; } + + private static String getPlanLiteAnalysisHtml(PlanLiteAnalyzedData planLiteData) { + List sortedTowns = MapComparator.sortByValue(planLiteData.getTownMap()); + Collections.reverse(sortedTowns); + List sortedFactions = MapComparator.sortByValue(planLiteData.getFactionMap()); + Collections.reverse(sortedFactions); + String html = "" + + ""; + + html += ""; + + int i = 1; + for (String[] values : sortedTowns) { + if (i >= 20) { + break; + } + html += "\r\n"; + i++; + } + html += "
" + values[1] + "" + values[0] + "
"; + int j = 1; + for (String[] values : sortedFactions) { + if (j >= 20) { + break; + } + html += "\r\n"; + j++; + } + html += "
" + values[1] + "" + values[0] + "
" + "" + + " " + + "

Information

" + + "

Total Money on the server: " + planLiteData.getTotalMoney() + "
Players have voted the server " + + planLiteData.getTotalVotes() + " times.

" + + ""; + html += ""; + return html; + } } diff --git a/Plan/src/main/resources/analysis.html b/Plan/src/main/resources/analysis.html index 9086033b2..38f61087d 100644 --- a/Plan/src/main/resources/analysis.html +++ b/Plan/src/main/resources/analysis.html @@ -47,18 +47,7 @@ %top50commands% - - -

Empty wrapper

- - -

Empty wrapper

- - + %planlite%