From 66268752396f851f3ac5d7d77aa18d026a9dff80 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 30 Aug 2017 18:59:23 +0300 Subject: [PATCH] MiscUtils.getIPlan --- .../main/java/com/djrapitops/plan/Log.java | 8 +-- .../plan/command/commands/InspectCommand.java | 12 +---- .../command/commands/RegisterCommand.java | 9 ++-- .../plan/systems/info/InformationManager.java | 3 +- .../info/InspectCacheRequestProcessor.java | 54 +++++++++++++++++++ .../djrapitops/plan/utilities/Benchmark.java | 9 +--- .../djrapitops/plan/utilities/MiscUtils.java | 9 ++++ 7 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/systems/processing/info/InspectCacheRequestProcessor.java diff --git a/Plan/src/main/java/com/djrapitops/plan/Log.java b/Plan/src/main/java/com/djrapitops/plan/Log.java index 0a9737598..b83eb7552 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Log.java +++ b/Plan/src/main/java/com/djrapitops/plan/Log.java @@ -1,9 +1,7 @@ package main.java.com.djrapitops.plan; -import com.djrapitops.plugin.utilities.Compatibility; import com.djrapitops.plugin.utilities.log.DebugInfo; import com.djrapitops.plugin.utilities.log.PluginLog; -import main.java.com.djrapitops.plan.bungee.PlanBungee; import main.java.com.djrapitops.plan.utilities.MiscUtils; import java.util.Collection; @@ -139,11 +137,7 @@ public class Log { } private static PluginLog getPluginLogger() { - if (Compatibility.isBukkitAvailable()) { - return Plan.getInstance().getPluginLogger(); - } else { - return PlanBungee.getInstance().getPluginLogger(); - } + return MiscUtils.getIPlan().getPluginLogger(); } public static void logStackTrace(Throwable e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java index 12a1aef8b..89f5cacfb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/InspectCommand.java @@ -12,9 +12,7 @@ import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.command.ConditionUtils; import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Msg; -import main.java.com.djrapitops.plan.systems.processing.Processor; -import main.java.com.djrapitops.plan.systems.webserver.PageCache; -import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; +import main.java.com.djrapitops.plan.systems.processing.info.InspectCacheRequestProcessor; import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; @@ -90,13 +88,7 @@ public class InspectCommand extends SubCommand { } } - plugin.addToProcessQueue(new Processor(uuid) { - @Override - public void process() { - PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(plugin.getInfoManager(), uuid)); - sendInspectMsg(sender, playerName); - } - }); + plugin.addToProcessQueue(new InspectCacheRequestProcessor(uuid, sender, playerName)); } catch (SQLException ex) { Log.toLog(this.getClass().getName(), ex); } finally { diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java index 058c63c4f..d20d12f0d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommand.java @@ -14,7 +14,6 @@ import main.java.com.djrapitops.plan.locale.Locale; import main.java.com.djrapitops.plan.locale.Msg; import main.java.com.djrapitops.plan.utilities.Check; import main.java.com.djrapitops.plan.utilities.PassEncryptUtil; -import org.bukkit.ChatColor; /** * Command for registering web users. @@ -50,8 +49,8 @@ public class RegisterCommand extends SubCommand { @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { String notEnoughArgsMsg = Locale.get(Msg.CMD_FAIL_REQ_ARGS).parse("(3) " + super.getArguments()); - String hashErrorMsg = ChatColor.RED + "Password hash error."; - String permLvlErrorMsg = ChatColor.RED + "Incorrect perm level, not a number: "; + String hashErrorMsg = "§cPassword hash error."; + String permLvlErrorMsg = "§cIncorrect perm level, not a number: "; try { if (CommandUtils.isPlayer(sender)) { Log.info(sender.getName() + " issued WebUser register command."); @@ -114,9 +113,9 @@ public class RegisterCommand extends SubCommand { plugin.getRunnableFactory().createNew(new AbsRunnable("Register WebUser Task") { @Override public void run() { - final String existsMsg = ChatColor.RED + "User Already Exists!"; + final String existsMsg = "§cUser Already Exists!"; final String userName = webUser.getName(); - final String successMsg = ChatColor.GREEN + "Added a new user (" + userName + ") successfully!"; + final String successMsg = "§aAdded a new user (" + userName + ") successfully!"; try { SecurityTable securityTable = plugin.getDB().getSecurityTable(); boolean userExists = securityTable.userExists(userName); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java index 8be0f9cfc..b94062fdc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/InformationManager.java @@ -18,6 +18,7 @@ import main.java.com.djrapitops.plan.systems.info.parsing.AnalysisPageParser; import main.java.com.djrapitops.plan.systems.info.parsing.InspectPageParser; import main.java.com.djrapitops.plan.systems.info.parsing.UrlParser; import main.java.com.djrapitops.plan.systems.webserver.PageCache; +import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.Analysis; @@ -72,7 +73,7 @@ public class InformationManager { } public void cachePlayer(UUID uuid) { - plugin.addToProcessQueue(); // TODO Player page information parser + PageCache.loadPage("inspectPage: "+uuid, () -> new InspectPageResponse(this, uuid)); // TODO Player page plugin tab request } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/processing/info/InspectCacheRequestProcessor.java b/Plan/src/main/java/com/djrapitops/plan/systems/processing/info/InspectCacheRequestProcessor.java new file mode 100644 index 000000000..8f88575fd --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/systems/processing/info/InspectCacheRequestProcessor.java @@ -0,0 +1,54 @@ +/* + * Licence is provided in the jar as license.yml also here: + * https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml + */ +package main.java.com.djrapitops.plan.systems.processing.info; + +import com.djrapitops.plugin.command.CommandUtils; +import com.djrapitops.plugin.command.ISender; +import main.java.com.djrapitops.plan.locale.Locale; +import main.java.com.djrapitops.plan.locale.Msg; +import main.java.com.djrapitops.plan.systems.processing.player.PlayerProcessor; +import main.java.com.djrapitops.plan.utilities.MiscUtils; +import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; + +import java.util.UUID; + +/** + * //TODO Class Javadoc Comment + * + * @author Rsl1122 + */ +public class InspectCacheRequestProcessor extends PlayerProcessor { + + private final ISender sender; + private final String playerName; + + public InspectCacheRequestProcessor(UUID uuid, ISender sender, String playerName) { + super(uuid); + this.playerName = playerName; + this.sender = sender; + } + + @Override + public void process() { + MiscUtils.getIPlan().getInfoManager().cachePlayer(getUUID()); + sendInspectMsg(sender, playerName); + } + + private void sendInspectMsg(ISender sender, String playerName) { + sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT) + " " + playerName); + // Link + String url = HtmlUtils.getInspectUrlWithProtocol(playerName); + String message = Locale.get(Msg.CMD_INFO_LINK).toString(); + boolean console = !CommandUtils.isPlayer(sender); + if (console) { + sender.sendMessage(message + url); + } else { + sender.sendMessage(message); + sender.sendLink(" ", Locale.get(Msg.CMD_INFO_CLICK_ME).toString(), url); + } + + sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString()); + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/Benchmark.java b/Plan/src/main/java/com/djrapitops/plan/utilities/Benchmark.java index 731398986..173f89e10 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/Benchmark.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/Benchmark.java @@ -1,10 +1,7 @@ package main.java.com.djrapitops.plan.utilities; import com.djrapitops.plugin.utilities.BenchUtil; -import com.djrapitops.plugin.utilities.Compatibility; import main.java.com.djrapitops.plan.Log; -import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.bungee.PlanBungee; /** * @author Rsl1122 @@ -49,10 +46,6 @@ public class Benchmark { } private static BenchUtil getBenchUtil() { - if (Compatibility.isBukkitAvailable()) { - return Plan.getInstance().benchmark(); - } else { - return PlanBungee.getInstance().benchmark(); - } + return MiscUtils.getIPlan().benchmark(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java index b084a7544..647ef67c4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java @@ -6,6 +6,7 @@ import com.djrapitops.plugin.command.ISender; import com.djrapitops.plugin.utilities.Compatibility; import main.java.com.djrapitops.plan.Permissions; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.bungee.PlanBungee; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.locale.Locale; @@ -134,4 +135,12 @@ public class MiscUtils { return PlanBungee.getInstance().getDescription().getVersion(); } } + + public static IPlan getIPlan() { + if (Compatibility.isBukkitAvailable()) { + return Plan.getInstance(); + } else { + return PlanBungee.getInstance(); + } + } }