diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java index 3ca20ae3c..ae8421dd6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ManageCommand.java @@ -24,7 +24,7 @@ public class ManageCommand extends TreeCommand { * @param plugin Current instance of Plan */ public ManageCommand(Plan plugin) { - super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE) + "", "plan m"); + super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE).toString(), "plan m"); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java index 9d8ca7382..a51d4e801 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageDumpCommand.java @@ -50,8 +50,12 @@ public class ManageDumpCommand extends SubCommand { plugin.getRunnableFactory().createNew(new AbsRunnable("DumpTask") { @Override public void run() { - sender.sendLink("Link to the Dump", DumpUtils.dump(plugin)); - sender.sendLink("Report Issues here", "https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new"); + try { + sender.sendLink("Link to the Dump", DumpUtils.dump(plugin)); + sender.sendLink("Report Issues here", "https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new"); + } finally { + this.cancel(); + } } }).runTaskAsynchronously(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueue.java index 987888f71..6a2733742 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueue.java @@ -27,7 +27,7 @@ public class DataCacheClearQueue extends Queue { * @param handler current instance of DataCacheHandler. */ public DataCacheClearQueue(DataCacheHandler handler) { - super(new ArrayBlockingQueue(Settings.PROCESS_CLEAR_LIMIT.getNumber())); + super(new ArrayBlockingQueue<>(Settings.PROCESS_CLEAR_LIMIT.getNumber())); setup = new ClearSetup(queue, handler); setup.go(); } @@ -65,7 +65,7 @@ class ClearConsumer extends Consumer implements Runnable { private DataCacheHandler handler; - ClearConsumer(BlockingQueue q, DataCacheHandler handler) { + ClearConsumer(BlockingQueue q, DataCacheHandler handler) { super(q, "ClearQueueConsumer"); this.handler = handler; } @@ -97,7 +97,7 @@ class ClearConsumer extends Consumer implements Runnable { class ClearSetup extends Setup { - public ClearSetup(BlockingQueue q, DataCacheHandler handler) { + ClearSetup(BlockingQueue q, DataCacheHandler handler) { super(new ClearConsumer(q, handler)); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java index 395287619..7c311a3d9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheGetQueue.java @@ -27,7 +27,7 @@ public class DataCacheGetQueue extends Queue * @param plugin current instance of Plan */ public DataCacheGetQueue(Plan plugin) { - super(new ArrayBlockingQueue(Settings.PROCESS_GET_LIMIT.getNumber())); + super(new ArrayBlockingQueue<>(Settings.PROCESS_GET_LIMIT.getNumber())); setup = new GetSetup(queue, plugin.getDB()); setup.go(); } @@ -50,8 +50,12 @@ public class DataCacheGetQueue extends Queue } } - public boolean containsUUIDtoBeCached(UUID uuid) { - return uuid != null && new ArrayList<>(queue).stream().anyMatch(map -> (map.get(uuid) != null && map.get(uuid).size() >= 2)); + boolean containsUUIDtoBeCached(UUID uuid) { + return uuid != null + && queue.stream() + .map(map -> map.get(uuid)) + .filter(Objects::nonNull) + .anyMatch(list -> list.size() >= 2); } } @@ -59,7 +63,7 @@ class GetConsumer extends Consumer>> { private Database db; - GetConsumer(BlockingQueue q, Database db) { + GetConsumer(BlockingQueue>> q, Database db) { super(q, "GetQueueConsumer"); this.db = db; } diff --git a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java index 73b66d1aa..9aada9493 100644 --- a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java +++ b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java @@ -39,7 +39,7 @@ public class Locale implements Closeable { private final Map messages; public Locale(Plan plugin) { - LocaleHolder.setLOCALE(this); + LocaleHolder.setLocale(this); this.plugin = plugin; messages = new HashMap<>(); } @@ -62,9 +62,9 @@ public class Locale implements Closeable { } } catch (IOException e) { Log.toLog(this.getClass().getName(), e); - + } finally { + Benchmark.stop("Enable", "Initializing locale"); } - Benchmark.stop("Enable", "Initializing locale"); } private void writeNewDefaultLocale() throws IOException { @@ -316,25 +316,24 @@ public class Locale implements Closeable { } public Message getMessage(Msg msg) { - Message message = messages.get(msg); - return message != null ? message : new Message(""); + return messages.getOrDefault(msg, new Message("")); } @Override public void close() { messages.clear(); - LocaleHolder.LOCALE = null; + LocaleHolder.locale = null; } public static void unload() { - Locale locale = LocaleHolder.getLOCALE(); + Locale locale = LocaleHolder.getLocale(); if (locale != null) { locale.close(); } } public static Message get(Msg msg) { - Locale locale = LocaleHolder.getLOCALE(); + Locale locale = LocaleHolder.getLocale(); if (locale == null) { throw new IllegalStateException("Locale has not been initialized."); } @@ -343,14 +342,14 @@ public class Locale implements Closeable { private static class LocaleHolder { - private static Locale LOCALE; + private static Locale locale; - public static void setLOCALE(Locale LOCALE) { - LocaleHolder.LOCALE = LOCALE; + public static void setLocale(Locale locale) { + LocaleHolder.locale = locale; } - public static Locale getLOCALE() { - return LOCALE; + public static Locale getLocale() { + return locale; } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java b/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java index 6d768862f..08fafbe8c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java @@ -84,12 +84,12 @@ public class TextUI { final TPSPart tps = d.getTpsPart(); return new String[]{ ball + " Total Players: " + sec + count.getPlayerCount(), - // + ball + " Active: " + sec + activity.getActive().size() + main + " Inactive: " + sec + activity.getInactive().size() + main + " Single Join: " + sec + activity.getJoinedOnce().size() + main + " Banned: " + sec + activity.getBans().size(), - // + ball + " New Players 24h: " + sec + join.get("npday") + main + " 7d: " + sec + d.get("npweek") + main + " 30d: " + sec + d.get("npmonth"), "", ball + " Total Playtime: " + sec + playtime.get("totalplaytime") + main + " Player Avg: " + sec + playtime.get("avgplaytime"), diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index cb8cfb81b..aab2532e6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -167,7 +167,7 @@ public class Analysis { PageCacheHandler.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler())); PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin)); - ExportUtility.export(plugin, analysisData, rawData); + ExportUtility.export(analysisData, rawData); } catch (Exception e) { Log.toLog(this.getClass().getName(), e); plugin.processStatus().setStatus("Analysis", "Error: " + e); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java index 5561ca666..d2aee8737 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/ExportUtility.java @@ -54,27 +54,31 @@ public class ExportUtility { } /** - * @param plugin * @param analysisData * @param rawData */ - public static void export(Plan plugin, AnalysisData analysisData, List rawData) { + public static void export(AnalysisData analysisData, List rawData) { if (!Settings.ANALYSIS_EXPORT.isTrue()) { return; } + Benchmark.start("Exporting Html pages"); try { File folder = getFolder(); Log.debug("Export", "Folder: " + folder.getAbsolutePath()); + writePlayersPageHtml(rawData, new File(folder, "players")); writeAnalysisHtml(analysisData, new File(folder, "server")); + File playersFolder = getPlayersFolder(folder); Log.debug("Export", "Player html files."); Log.debug("Export", "Player Page Folder: " + playersFolder.getAbsolutePath()); + String playerHtml = HtmlUtils.getStringFromResource("player.html"); - rawData.forEach(userData -> { - writeInspectHtml(userData, playersFolder, playerHtml); - }); + + Benchmark.start("Exporting Player pages"); + rawData.forEach(userData -> writeInspectHtml(userData, playersFolder, playerHtml)); + Benchmark.stop("Exporting Player pages"); } catch (IOException ex) { Log.toLog("ExportUtils.export", ex); } finally { @@ -96,17 +100,18 @@ public class ExportUtility { /** * @param userData * @param playersFolder - * @throws FileNotFoundException - * @throws IOException */ - public static boolean writeInspectHtml(UserData userData, File playersFolder, String playerHtml) { + public static void writeInspectHtml(UserData userData, File playersFolder, String playerHtml) { if (!Settings.ANALYSIS_EXPORT.isTrue()) { - return false; + return; } + String name = userData.getName(); + if (name.endsWith(".")) { name = name.replace(".", "%2E"); } + if (name.endsWith(" ")) { name = name.replace(" ", "%20"); } @@ -114,16 +119,17 @@ public class ExportUtility { try { String inspectHtml = HtmlUtils.replacePlaceholders(playerHtml, PlaceholderUtils.getInspectReplaceRules(userData)); + File playerFolder = new File(playersFolder, name); playerFolder.mkdirs(); + File inspectHtmlFile = new File(playerFolder, "index.html"); inspectHtmlFile.createNewFile(); + Files.write(inspectHtmlFile.toPath(), Collections.singletonList(inspectHtml)); } catch (IOException e) { - Log.toLog("Export.inspectPage: " + name, e); - return false; + Log.toLog("Export.writeInspectHtml: " + name, e); } - return true; } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java index ec12ed12f..bdaa55a54 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpLog.java @@ -1,5 +1,7 @@ package main.java.com.djrapitops.plan.utilities.file.dump; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; import main.java.com.djrapitops.plan.Log; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -21,7 +23,7 @@ import java.util.List; */ public class DumpLog { - private List lines = new ArrayList<>(); + private final List lines = new ArrayList<>(); /** * Writes a header @@ -88,6 +90,11 @@ public class DumpLog { * @param line The content of the line */ private void addLine(CharSequence line) { + if (line == null) { + lines.add("\n"); + return; + } + lines.add(line.toString()); } @@ -97,7 +104,27 @@ public class DumpLog { * @return The link to the Dump Log */ String upload() { - String content = this.toString(); + List parts = ImmutableList.copyOf(split()).reverse(); + + String lastLink = null; + for (String part : parts) { + if (lastLink != null) { + part += "\n" + lastLink; + } + + lastLink = upload(part); + } + + return lastLink; + } + + /** + * Uploads the content to Hastebin using HTTPS and POST + * + * @param content The content + * @return The link to the content + */ + private String upload(String content) { HttpsURLConnection connection = null; try { URL url = new URL("https://hastebin.com/documents"); @@ -111,13 +138,16 @@ public class DumpLog { connection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); - wr.writeBytes(this.toString()); + wr.writeBytes(content); wr.flush(); wr.close(); - BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + + String response = reader.readLine(); + JSONParser parser = new JSONParser(); - JSONObject json = (JSONObject) parser.parse(rd.readLine()); + JSONObject json = (JSONObject) parser.parse(response); return "https://hastebin.com/" + json.get("key"); } catch (IOException | ParseException e) { @@ -130,6 +160,15 @@ public class DumpLog { } } + /** + * Splits the content of the DumpLog into parts + * + * @return The splitted content + */ + private Iterable split() { + return Splitter.fixedLength(390000).split(this.toString()); + } + @Override public String toString() { return String.join("\n", lines); diff --git a/Plan/src/main/resources/player.html b/Plan/src/main/resources/player.html index 0377f1beb..8c84c7d05 100644 --- a/Plan/src/main/resources/player.html +++ b/Plan/src/main/resources/player.html @@ -741,12 +741,12 @@ function openFunc(i) { return function() { - if (window.getComputedStyle(document.getElementById("navbutton")).getPropertyValue('display') == "inline") { + if (window.getComputedStyle(document.getElementById("navbutton")).getPropertyValue('display') === "inline") { closeNav(); } var max = navButtons.length; for (var j = 0; j < max; j++) { - if (j == i) { + if (j === i) { navButtons[j].classList.add('active'); continue; } @@ -770,9 +770,7 @@ var begin = new Date(%refreshlong%); var seconds = now.getTime() - begin.getTime(); - var out = formatTime(seconds); - - document.getElementById('divTime').innerHTML = out; + document.getElementById('divTime').innerHTML = formatTime(seconds); setTimeout('countUpTimer()', 1000); } diff --git a/Plan/src/test/java/utils/MockUtils.java b/Plan/src/test/java/utils/MockUtils.java index a53069cfb..70db22851 100644 --- a/Plan/src/test/java/utils/MockUtils.java +++ b/Plan/src/test/java/utils/MockUtils.java @@ -16,7 +16,6 @@ import org.bukkit.entity.Player; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; -import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.HashSet; @@ -154,7 +153,7 @@ public class MockUtils { return PowerMockito.mock(CommandSender.class); } - public static HttpServer mockHTTPServer() throws IOException { + public static HttpServer mockHTTPServer() { HttpServer httpServer = PowerMockito.mock(HttpServer.class); when(httpServer.getAddress()).thenReturn(new InetSocketAddress(80)); when(httpServer.getExecutor()).thenReturn(command -> System.out.println("HTTP Server command received"));