diff --git a/Plan/.idea/libraries/Maven__com_djrapitops_abstract_plugin_framework_2_0_3.xml b/Plan/.idea/libraries/Maven__com_djrapitops_abstract_plugin_framework_2_0_3.xml index e45a58e08..bbaec2a3a 100644 --- a/Plan/.idea/libraries/Maven__com_djrapitops_abstract_plugin_framework_2_0_3.xml +++ b/Plan/.idea/libraries/Maven__com_djrapitops_abstract_plugin_framework_2_0_3.xml @@ -1,7 +1,7 @@ - + diff --git a/Plan/pom.xml b/Plan/pom.xml index 0ca473df0..1595f4805 100644 --- a/Plan/pom.xml +++ b/Plan/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.djrapitops Plan - 3.6.2 + 3.6.3 jar diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index f04272aac..533d35d0d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -259,6 +259,7 @@ public class Plan extends BukkitPlugin { scheduler.shutdown(); // Schedules the save to shutdown after it has ran the execute method. } + getPluginLogger().endAllDebugs(); Log.info(Locale.get(Msg.DISABLED).toString()); Locale.unload(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java index b71b3f1ba..e1876fa91 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/webuser/WebLevelCommand.java @@ -32,14 +32,17 @@ public class WebLevelCommand extends SubCommand { ColorScheme cs = plugin.getColorScheme(); String sCol = cs.getSecondaryColor(); String cmdBall = Locale.get(Msg.CMD_CONSTANT_LIST_BALL).parse(); + String cmdFooter = Locale.get(Msg.CMD_CONSTANT_FOOTER).parse(); + String[] messages = new String[]{ - Locale.get(Msg.CMD_CONSTANT_FOOTER).parse(), - cmdBall + sCol + "0: Access all pages", - cmdBall + sCol + "1: Access '/players' and all inspect pages", - cmdBall + sCol + "2: Access inspect page with the same username as the webuser", - cmdBall + sCol + "3+: No permissions", - Locale.get(Msg.CMD_CONSTANT_FOOTER).parse() + cmdFooter, + cmdBall + sCol + "0: Access all pages", + cmdBall + sCol + "1: Access '/players' and all inspect pages", + cmdBall + sCol + "2: Access inspect page with the same username as the webuser", + cmdBall + sCol + "3+: No permissions", + cmdFooter }; + sender.sendMessage(messages); return true; } 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 4a13c8b8d..3c3d8dda8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/UserData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/UserData.java @@ -484,14 +484,6 @@ public class UserData { return gmTimes; } - public void setGmTimes(Map times) { - if (Verify.notNull(times)) { - for (Map.Entry entry : times.entrySet()) { - gmTimes.setTime(entry.getKey(), entry.getValue()); - } - } - } - /** * Set the GM Times object containing playtime in each gamemode. * @@ -503,6 +495,14 @@ public class UserData { } } + public void setGmTimes(Map times) { + if (Verify.notNull(times)) { + for (Map.Entry entry : times.entrySet()) { + gmTimes.setTime(entry.getKey(), entry.getValue()); + } + } + } + /** * Is the user Operator? * diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java index f63db6aa1..be713b4e8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/AnalysisCacheHandler.java @@ -64,7 +64,7 @@ public class AnalysisCacheHandler { } /** - * @return + * @return if currently an analysis is being run */ public boolean isAnalysisBeingRun() { return analysis.isAnalysisBeingRun(); 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 25fbb76e1..32ef1d5ad 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 @@ -312,7 +312,6 @@ public class DataCacheHandler extends SessionCache { * @param uuid Player's UUID */ public void saveCachedData(UUID uuid) { - Log.debug(uuid + ": SaveCachedData"); DBCallableProcessor saveProcessor = data -> { data.access(); data.setClearAfterSave(true); @@ -517,28 +516,28 @@ public class DataCacheHandler extends SessionCache { } /** - * @return + * @return The SaveTask */ public DataCacheSaveQueue getSaveTask() { return saveTask; } /** - * @return + * @return The ClearTask */ public DataCacheClearQueue getClearTask() { return clearTask; } /** - * @return + * @return The ProcessTask */ public DataCacheProcessQueue getProcessTask() { return processTask; } /** - * @return + * @return The GetTask */ public DataCacheGetQueue getGetTask() { return getTask; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java index ce7fffce3..1a6116c54 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/queue/DataCacheProcessQueue.java @@ -88,7 +88,6 @@ class ProcessConsumer extends Consumer { return; } - Log.debug(info.getUuid() + ": Processing type: " + info.getType().name()); DBCallableProcessor p = data -> { if (!info.process(data)) { Log.error("Attempted to process data for wrong uuid: W:" + data.getUuid() + " | R:" + info.getUuid() + " Type:" + info.getType().name()); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/DBUtils.java b/Plan/src/main/java/com/djrapitops/plan/database/DBUtils.java index b34d39eed..61b7aef6d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/DBUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/DBUtils.java @@ -33,9 +33,8 @@ public class DBUtils { * BATCH_SIZE. * * @param Object type - * @param objects Collection of the objects. // * @return Lists with max - * size of BATCH_SIZE. - * @return + * @param objects Collection of the objects + * @return Lists with max size of BATCH_SIZE */ public static List> splitIntoBatches(Collection objects) { List> batches = new ArrayList<>(); @@ -57,9 +56,9 @@ public class DBUtils { } /** - * @param - * @param objects - * @return + * @param Object type + * @param objects Collection of the objects + * @return Lists with max size of BATCH_SIZE */ public static List>> splitIntoBatchesId(Map> objects) { List>> wrappedBatches = new ArrayList<>(); @@ -83,6 +82,11 @@ public class DBUtils { return wrappedBatches; } + /** + * @param Object type + * @param objects Collection of the objects + * @return Lists with max size of BATCH_SIZE + */ public static List>> splitIntoBatchesWithID(Map objects) { List>> wrappedBatches = new ArrayList<>(); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java index ec216ee91..669aea4b1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/databases/SQLDB.java @@ -306,7 +306,7 @@ public abstract class SQLDB extends Database { int userId = usersTable.getUserId(uuid); boolean success = userId != -1 && locationsTable.removeUserLocations(userId) - && ipsTable.removeUserIps(userId) + && ipsTable.removeUserIPs(userId) && nicknamesTable.removeUserNicknames(userId) && gmTimesTable.removeUserGMTimes(userId) && sessionsTable.removeUserSessions(userId) @@ -538,6 +538,7 @@ public abstract class SQLDB extends Database { return; } Log.debug("Database", "Save userdata: " + uuid); + Benchmark.start("Save Single UserData"); checkConnection(); data.access(); usersTable.saveUserDataInformation(data); @@ -551,6 +552,7 @@ public abstract class SQLDB extends Database { worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes()); data.stopAccessing(); commit(); + Benchmark.stop("Database", "Save Single UserData"); setAvailable(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java index 6766d7af7..e51d6773f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/IPsTable.java @@ -1,5 +1,6 @@ package main.java.com.djrapitops.plan.database.tables; +import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.utilities.Benchmark; @@ -20,8 +21,8 @@ public class IPsTable extends Table { private final String columnIP; /** - * @param db - * @param usingMySQL + * @param db The database + * @param usingMySQL if the server is using MySQL */ public IPsTable(SQLDB db, boolean usingMySQL) { super("plan_ips", db, usingMySQL); @@ -30,7 +31,7 @@ public class IPsTable extends Table { } /** - * @return + * @return if the table was created successfully */ @Override public boolean createTable() { @@ -50,10 +51,10 @@ public class IPsTable extends Table { } /** - * @param userId - * @return + * @param userId The User ID from which the IPs should be removed from + * @return if the IPs were removed successfully */ - public boolean removeUserIps(int userId) { + public boolean removeUserIPs(int userId) { PreparedStatement statement = null; try { statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnUserID + "=?)"); @@ -69,18 +70,19 @@ public class IPsTable extends Table { } /** - * @param userId - * @return - * @throws SQLException + * @param userId The User ID from which the IPs should be retrieved from + * @return The retrieved IPs + * @throws SQLException when an error at retrieval happens */ public List getIPAddresses(int userId) throws SQLException { PreparedStatement statement = null; ResultSet set = null; try { + List ips = new ArrayList<>(); + statement = prepareStatement("SELECT * FROM " + tableName + " WHERE UPPER(" + columnUserID + ") LIKE UPPER(?)"); statement.setInt(1, userId); set = statement.executeQuery(); - List ips = new ArrayList<>(); while (set.next()) { String ipAddressName = set.getString(columnIP); try { @@ -92,15 +94,14 @@ public class IPsTable extends Table { return ips; } finally { - close(set); - close(statement); + close(set, statement); } } /** - * @param userId - * @param ips - * @throws SQLException + * @param userId The User ID for which the IPs should be saved for + * @param ips The IPs + * @throws SQLException when an error at saving happens */ public void saveIPList(int userId, Set ips) throws SQLException { if (ips == null) { @@ -120,8 +121,8 @@ public class IPsTable extends Table { + columnIP + ") VALUES (?, ?)"); boolean commitRequired = false; - for (InetAddress ip : ips) { + for (InetAddress ip : ips) { if (ip == null) { continue; } @@ -142,12 +143,12 @@ public class IPsTable extends Table { } /** - * @param ids - * @return - * @throws SQLException + * @param ids The User IDs for which the IPs should be retrieved for + * @return The User IDs corresponding with their used IPs + * @throws SQLException when an error at retrieval happens */ public Map> getIPList(Collection ids) throws SQLException { - if (ids == null || ids.isEmpty()) { + if (Verify.isEmpty(ids)) { return new HashMap<>(); } @@ -182,22 +183,23 @@ public class IPsTable extends Table { return ips; } finally { - close(set); - close(statement); + close(set, statement); Benchmark.stop("Database", "Get Ips Multiple"); } } /** - * @param ips - * @throws SQLException + * @param ips The User IDs corresponding to their IPs used + * @throws SQLException when an error at saving happens */ public void saveIPList(Map> ips) throws SQLException { - if (ips == null || ips.isEmpty()) { + if (Verify.isEmpty(ips)) { return; } + Benchmark.start("Save Ips Multiple"); Map> saved = getIPList(ips.keySet()); + PreparedStatement statement = null; try { statement = prepareStatement("INSERT INTO " + tableName + " (" @@ -205,7 +207,7 @@ public class IPsTable extends Table { + columnIP + ") VALUES (?, ?)"); boolean commitRequired = false; - int batchSize = 0; + for (Map.Entry> entrySet : ips.entrySet()) { Integer id = entrySet.getKey(); Set ipAddresses = entrySet.getValue(); @@ -229,7 +231,6 @@ public class IPsTable extends Table { statement.setString(2, ip.getHostAddress()); statement.addBatch(); commitRequired = true; - batchSize++; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java index dc372f737..5df78ac7a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/NicknamesTable.java @@ -1,5 +1,6 @@ package main.java.com.djrapitops.plan.database.tables; +import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.database.databases.SQLDB; import main.java.com.djrapitops.plan.utilities.Benchmark; @@ -19,8 +20,8 @@ public class NicknamesTable extends Table { private final String columnCurrent; /** - * @param db - * @param usingMySQL + * @param db The database + * @param usingMySQL if the server is using MySQL */ public NicknamesTable(SQLDB db, boolean usingMySQL) { super("plan_nicknames", db, usingMySQL); @@ -30,7 +31,7 @@ public class NicknamesTable extends Table { } /** - * @return + * @return if the table was created successfully */ @Override public boolean createTable() { @@ -43,6 +44,7 @@ public class NicknamesTable extends Table { + "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")" + ")" ); + if (getVersion() < 3) { alterTablesV3(); } @@ -58,8 +60,8 @@ public class NicknamesTable extends Table { } /** - * @param userId - * @return + * @param userId The User ID from which the nicknames should be removed from + * @return if the removal was successful */ public boolean removeUserNicknames(int userId) { PreparedStatement statement = null; @@ -77,9 +79,9 @@ public class NicknamesTable extends Table { } /** - * @param userId - * @return - * @throws SQLException + * @param userId The User ID from which the nicknames should be retrieved from + * @return The nicknames of the User + * @throws SQLException when an error at retrieval happens */ public List getNicknames(int userId) throws SQLException { PreparedStatement statement = null; @@ -88,6 +90,7 @@ public class NicknamesTable extends Table { statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUserID + "=?)"); statement.setInt(1, userId); set = statement.executeQuery(); + List nicknames = new ArrayList<>(); String lastNick = ""; while (set.next()) { @@ -95,36 +98,39 @@ public class NicknamesTable extends Table { if (nickname.isEmpty()) { continue; } + nicknames.add(nickname); if (set.getBoolean(columnCurrent)) { lastNick = nickname; } } + if (!lastNick.isEmpty()) { - nicknames.remove(lastNick); - nicknames.add(lastNick); + nicknames.set(nicknames.size() - 1, lastNick); } + return nicknames; } finally { - close(set); - close(statement); + close(set, statement); } } /** - * @param userId - * @param names - * @param lastNick - * @throws SQLException + * @param userId The User ID for which the nicknames should be saved for + * @param names The nicknames + * @param lastNick The latest nickname + * @throws SQLException when an error at saving happens */ public void saveNickList(int userId, Set names, String lastNick) throws SQLException { - if (names == null || names.isEmpty()) { + if (Verify.isEmpty(names)) { return; } + names.removeAll(getNicknames(userId)); if (names.isEmpty()) { return; } + PreparedStatement statement = null; try { statement = prepareStatement("INSERT INTO " + tableName + " (" @@ -132,53 +138,55 @@ public class NicknamesTable extends Table { + columnCurrent + ", " + columnNick + ") VALUES (?, ?, ?)"); - boolean commitRequired = false; + for (String name : names) { statement.setInt(1, userId); - statement.setInt(2, (name.equals(lastNick)) ? 1 : 0); + statement.setInt(2, name.equals(lastNick) ? 1 : 0); statement.setString(3, name); statement.addBatch(); - commitRequired = true; } - if (commitRequired) { - statement.executeBatch(); - } + statement.executeBatch(); } finally { close(statement); } } /** - * @param ids - * @return - * @throws SQLException + * @param ids The User IDs for which the nicknames should be retrieved for + * @return The User ID corresponding with the nicknames + * @throws SQLException when an error at retrieval happens */ public Map> getNicknames(Collection ids) throws SQLException { - if (ids == null || ids.isEmpty()) { + if (Verify.isEmpty(ids)) { return new HashMap<>(); } + Benchmark.start("Get Nicknames Multiple"); + PreparedStatement statement = null; ResultSet set = null; try { Map> nicks = new HashMap<>(); Map lastNicks = new HashMap<>(); + for (Integer id : ids) { nicks.put(id, new ArrayList<>()); } + statement = prepareStatement("SELECT * FROM " + tableName); set = statement.executeQuery(); while (set.next()) { - Integer id = set.getInt(columnUserID); if (!ids.contains(id)) { continue; } + String nickname = set.getString(columnNick); if (nickname.isEmpty()) { continue; } + nicks.get(id).add(nickname); if (set.getBoolean(columnCurrent)) { lastNicks.put(id, nickname); @@ -199,19 +207,18 @@ public class NicknamesTable extends Table { return nicks; } finally { - close(set); - close(statement); + close(set, statement); Benchmark.stop("Database", "Get Nicknames Multiple"); } } /** - * @param nicknames - * @param lastNicks - * @throws SQLException + * @param nicknames The User ID corresponding to the nicknames + * @param lastNicks The User ID corresponding with the last nick they inherited + * @throws SQLException when an error at saving happens */ public void saveNickLists(Map> nicknames, Map lastNicks) throws SQLException { - if (nicknames == null || nicknames.isEmpty()) { + if (Verify.isEmpty(nicknames)) { return; } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java index 216613c9c..5f1f5a672 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/SessionsTable.java @@ -112,7 +112,7 @@ public class SessionsTable extends Table { return; } - Benchmark.start("Save Sessions"); + PreparedStatement statement = null; try { statement = prepareStatement("INSERT INTO " + tableName + " (" @@ -120,7 +120,6 @@ public class SessionsTable extends Table { + columnSessionStart + ", " + columnSessionEnd + ") VALUES (?, ?, ?)"); - for (SessionData session : sessions) { long end = session.getSessionEnd(); long start = session.getSessionStart(); @@ -137,7 +136,6 @@ public class SessionsTable extends Table { statement.executeBatch(); } finally { close(statement); - Benchmark.stop("Database", "Save Sessions"); } } 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..ec0f69f89 100644 --- a/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java +++ b/Plan/src/main/java/com/djrapitops/plan/locale/Locale.java @@ -39,11 +39,26 @@ 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<>(); } + public static void unload() { + Locale locale = LocaleHolder.getLocale(); + if (locale != null) { + locale.close(); + } + } + + public static Message get(Msg msg) { + Locale locale = LocaleHolder.getLocale(); + if (locale == null) { + throw new IllegalStateException("Locale has not been initialized."); + } + return locale.getMessage(msg); + } + public void loadLocale() { String locale = Settings.LOCALE.toString().toUpperCase(); Benchmark.start("Initializing locale"); @@ -62,9 +77,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,41 +331,25 @@ 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; - } - - public static void unload() { - Locale locale = LocaleHolder.getLOCALE(); - if (locale != null) { - locale.close(); - } - } - - public static Message get(Msg msg) { - Locale locale = LocaleHolder.getLOCALE(); - if (locale == null) { - throw new IllegalStateException("Locale has not been initialized."); - } - return locale.getMessage(msg); + LocaleHolder.locale = null; } private static class LocaleHolder { - private static Locale LOCALE; + private static Locale locale; - public static void setLOCALE(Locale LOCALE) { - LocaleHolder.LOCALE = LOCALE; + public static Locale getLocale() { + return locale; } - public static Locale getLOCALE() { - return LOCALE; + public static void setLocale(Locale locale) { + LocaleHolder.locale = locale; } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/locale/Msg.java b/Plan/src/main/java/com/djrapitops/plan/locale/Msg.java index a945950ac..21754c39e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/locale/Msg.java +++ b/Plan/src/main/java/com/djrapitops/plan/locale/Msg.java @@ -147,11 +147,11 @@ public enum Msg { this.identifier = identifier; } - public String getIdentifier() { - return identifier; - } - public static Map getIdentifiers() { return Arrays.stream(values()).collect(Collectors.toMap(Msg::getIdentifier, Function.identity())); } + + public String getIdentifier() { + return identifier; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/Html.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/Html.java index 241efa46e..4d0830ae7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/Html.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/Html.java @@ -1,13 +1,6 @@ package main.java.com.djrapitops.plan.ui.html; import com.djrapitops.plugin.utilities.Verify; -import main.java.com.djrapitops.plan.Log; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; /** * @author Rsl1122 @@ -60,8 +53,7 @@ public enum Html { TABLELINE_3_CUSTOMKEY("REPLACE1REPLACE3REPLACE5"), TABLELINE_3_CUSTOMKEY_1("REPLACE1REPLACE2REPLACE3"), ERROR_TABLE_2(TABLELINE_2.parse("No data", "No data")), - TABLE_END(""), // KILLDATA_NONE("No Kills"), - ; + TABLE_END(""); // KILLDATA_NONE("No Kills"), private String html; @@ -70,50 +62,15 @@ public enum Html { } /** - * @param localeFile - */ - public static void loadLocale(File localeFile) { - try (Scanner localeScanner = new Scanner(localeFile, "UTF-8")) { - List localeRows = new ArrayList<>(); - boolean html = false; - - while (localeScanner.hasNextLine()) { - String line = localeScanner.nextLine(); - if (line.equals("<<<<<>>>>>")) { - html = true; - continue; - } - - if (!html) { - continue; - } - - localeRows.add(line); - } - - for (String localeRow : localeRows) { - try { - String[] split = localeRow.split(" <> "); - Html.valueOf(split[0]).setHtml(split[1]); - } catch (IllegalArgumentException e) { - Log.error("There is a miswritten lines in locale on lines " + localeRows.indexOf(localeRow)); - } - } - } catch (IOException e) { - Log.error("Something went wrong at loading locale " + localeFile.getAbsoluteFile() + ": " + e.getCause()); - } - } - - /** - * @return + * @return The HTML String */ public String parse() { return html; } /** - * @param p - * @return + * @param p The replacement Strings + * @return The parsed HTML String */ public String parse(String... p) { Verify.nullCheck(p); @@ -125,7 +82,7 @@ public enum Html { } /** - * @param html + * @param html Sets the HTML String */ public void setHtml(String html) { this.html = html; diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java index 8dcf965ef..34f45cfac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/WorldMapCreator.java @@ -14,8 +14,8 @@ public class WorldMapCreator { /** * Creates a data series with iso-a3 specification of Country codes. * - * @param geoCodeCounts - * @return + * @param geoCodeCounts The country codes and the amount of players located in the country + * @return The created data series */ public static String createDataSeries(Map geoCodeCounts) { StringBuilder arrayBuilder = new StringBuilder("["); @@ -25,16 +25,17 @@ public class WorldMapCreator { for (Map.Entry entry : geoCodeCounts.entrySet()) { String geoCode = entry.getKey(); Integer players = entry.getValue(); + if (players != 0) { arrayBuilder.append("{'code':'").append(geoCode).append("','value':").append(players).append("}"); if (i < size - 1) { arrayBuilder.append(","); } } + i++; } - arrayBuilder.append("]"); return arrayBuilder.toString(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java index 5975375da..df4a2d7ff 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/CommandUseTableCreator.java @@ -21,11 +21,12 @@ public class CommandUseTableCreator { } /** - * @param commandUse - * @return + * @param commandUse The commands and the amount of times casted + * @return The created command use table */ public static String createSortedCommandUseTable(Map commandUse) { List sorted = MapComparator.sortByValue(commandUse); + StringBuilder html = new StringBuilder(); if (sorted.isEmpty()) { html.append(Html.ERROR_TABLE_2.parse()); @@ -47,6 +48,7 @@ public class CommandUseTableCreator { i++; } } + return html.toString(); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/KillsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/KillsTableCreator.java index 8b5b9d466..ac5035722 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/KillsTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/KillsTableCreator.java @@ -26,8 +26,8 @@ public class KillsTableCreator { } /** - * @param killData - * @return + * @param killData The list of the {@link KillData} Objects from which the kill table should be created + * @return The created kills table */ public static String createKillsTable(List killData) { StringBuilder html = new StringBuilder(Html.TABLE_KILLS_START.parse()); @@ -35,16 +35,17 @@ public class KillsTableCreator { if (killData.isEmpty()) { html.append(Html.TABLELINE_3.parse(Locale.get(Msg.HTML_TABLE_NO_KILLS).parse(), "", "")); } else { - int i = 0; - killData.sort(new KillDataComparator()); Collections.reverse(killData); + int i = 0; for (KillData kill : killData) { if (i >= 20) { break; } + long date = kill.getDate(); + IOfflinePlayer victim = Fetch.getIOfflinePlayer(kill.getVictim()); String name = victim.getName(); html.append(Html.TABLELINE_3_CUSTOMKEY_1.parse( @@ -52,9 +53,11 @@ public class KillsTableCreator { Html.LINK.parse(HtmlUtils.getInspectUrl(name), name), kill.getWeapon() )); + i++; } } + html.append(Html.TABLE_END.parse()); return html.toString(); diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/PlayersTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/PlayersTableCreator.java index e26bd5061..0f07d71a1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/PlayersTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/tables/PlayersTableCreator.java @@ -23,8 +23,8 @@ public class PlayersTableCreator { } /** - * @param data - * @return + * @param data The list of the {@link UserData} Objects from which the players table should be created + * @return The created players table */ public static String createSortablePlayersTable(List data) { StringBuilder html = new StringBuilder(); @@ -37,6 +37,7 @@ public class PlayersTableCreator { if (i >= 750) { break; } + try { boolean isBanned = uData.isBanned(); boolean isUnknown = uData.getLoginTimes() == 1; @@ -59,7 +60,9 @@ public class PlayersTableCreator { String.valueOf(uData.getGeolocation()) )); } catch (NullPointerException ignored) { + /* ignored */ } + i++; } 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..0551dd635 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 @@ -29,15 +29,17 @@ public class TextUI { } /** - * @param uuid - * @return + * @param uuid The UUID for which the inspect messages should be get for + * @return The inspect messages */ public static String[] getInspectMessages(UUID uuid) { InspectCacheHandler inspectCache = Plan.getInstance().getInspectCache(); + long now = MiscUtils.getTime(); if (!inspectCache.isCached(uuid)) { return new String[]{"Error has occurred, please retry."}; } + UserData d = inspectCache.getFromCache(uuid); ColorScheme cs = Plan.getInstance().getColorScheme(); @@ -49,6 +51,7 @@ public class TextUI { boolean banned = d.isBanned(); boolean online = d.isOnline(); String ball = sec + " " + DefaultMessages.BALL + main; + return new String[]{ sec + " " + DefaultMessages.BALL + (banned ? ChatColor.DARK_RED + " Banned" : ter + (active ? " Active" : " Inactive")) + (online ? ChatColor.GREEN + " Online" : ChatColor.RED + " Offline"), ball + " Registered: " + sec + FormatUtils.formatTimeStampYear(d.getRegistered()), @@ -62,26 +65,31 @@ public class TextUI { } /** - * @return + * Gets the analysis messages + * + * @return The analysis messages */ public static String[] getAnalysisMessages() { AnalysisCacheHandler analysisCache = Plan.getInstance().getAnalysisCache(); + if (!analysisCache.isCached()) { return new String[]{"Error has occurred, please retry."}; } + AnalysisData d = analysisCache.getData(); ColorScheme cs = Plan.getInstance().getColorScheme(); String main = cs.getMainColor(); String sec = cs.getSecondaryColor(); - String ball = sec + " " + DefaultMessages.BALL + main; + final ActivityPart activity = d.getActivityPart(); final JoinInfoPart join = d.getJoinInfoPart(); final KillPart kills = d.getKillPart(); final PlaytimePart playtime = d.getPlaytimePart(); final PlayerCountPart count = d.getPlayerCountPart(); final TPSPart tps = d.getTpsPart(); + return new String[]{ ball + " Total Players: " + sec + count.getPlayerCount(), // diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java index 2874327ed..4c4564a6c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/Request.java @@ -103,7 +103,8 @@ public class Request implements Closeable { if (reqLine.length >= 2) { request = reqLine[0]; target = reqLine[1].replace("%20", " ") - .replace("%2E", ".");; + .replace("%2E", "."); + ; } else { request = "GET"; target = "/"; diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java index b83870d5e..d3b1dad5a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/webserver/WebServer.java @@ -350,7 +350,7 @@ public class WebServer { } /** - * @return + * @return if the WebServer is enabled */ public boolean isEnabled() { return enabled; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java b/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java index f88981502..045cb71d0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java @@ -29,6 +29,7 @@ public class PassEncryptUtil { public static final int HASH_SIZE_INDEX = 2; public static final int SALT_INDEX = 3; public static final int PBKDF2_INDEX = 4; + /** * Constructor used to hide the public constructor */ diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java index 4d20728b3..08d22443f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/PlaceholderUtils.java @@ -45,7 +45,7 @@ public class PlaceholderUtils { replaceMap.put("%plugins%", data.replacePluginsTabLayout()); replaceMap.put("%refresh%", FormatUtils.formatTimeAmountDifference(data.getRefreshDate(), MiscUtils.getTime())); - replaceMap.put("%refreshlong%", data.getRefreshDate() + ""); + replaceMap.put("%refreshlong%", String.valueOf(data.getRefreshDate())); replaceMap.put("%servername%", Settings.SERVER_NAME.toString()); @@ -94,7 +94,7 @@ public class PlaceholderUtils { gmPart.analyse(); replaceMap.putAll(gmPart.getReplaceMap()); - replaceMap.put("%ips%", (showIPandUUID ? data.getIps().toString() : "Hidden (Config)")); + replaceMap.put("%ips%", showIPandUUID ? data.getIps().toString() : "Hidden (Config)"); replaceMap.put("%nicknames%", HtmlUtils.removeXSS(HtmlUtils.swapColorsToSpan(data.getNicknames().toString()))); replaceMap.put("%name%", data.getName()); replaceMap.put("%registered%", FormatUtils.formatTimeStampYear(data.getRegistered())); @@ -102,7 +102,7 @@ public class PlaceholderUtils { replaceMap.put("%playtime%", FormatUtils.formatTimeAmount(data.getPlayTime())); replaceMap.put("%banned%", data.isBanned() ? Locale.get(Msg.HTML_BANNED).parse() : ""); replaceMap.put("%op%", data.isOp() ? Locale.get(Msg.HTML_OP).parse() : ""); - replaceMap.put("%isonline%", (data.isOnline()) ? Locale.get(Msg.HTML_ONLINE).parse() : Locale.get(Msg.HTML_OFFLINE).parse()); + replaceMap.put("%isonline%", data.isOnline() ? Locale.get(Msg.HTML_ONLINE).parse() : Locale.get(Msg.HTML_OFFLINE).parse()); replaceMap.put("%deaths%", data.getDeaths()); replaceMap.put("%playerkills%", data.getPlayerKills().size()); replaceMap.put("%mobkills%", data.getMobKills()); 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..617606cca 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 @@ -267,7 +267,7 @@ public class Analysis { long now = MiscUtils.getTime(); Benchmark.start("Fill Dataset"); - List banSources = plugin.getHookHandler().getAdditionalDataSources() + List banSources = plugin.getHookHandler().getAdditionalDataSources() .stream().filter(PluginData::isBanData).collect(Collectors.toList()); rawData.forEach(uData -> { uData.access(); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java index 6f1070269..1f9ce278a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java @@ -13,6 +13,7 @@ public class MathUtils { private static final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.ENGLISH); private static final DecimalFormat decimalFormat = new DecimalFormat("#.##", decimalFormatSymbols); + /** * Constructor used to hide the public constructor */ diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/LocaleEntryComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/LocaleEntryComparator.java index 16befa9dd..a95ead3f6 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/LocaleEntryComparator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/LocaleEntryComparator.java @@ -10,8 +10,8 @@ import java.util.Map; /** * Compares Locale Map Entries and sorts them alphabetically according to the Enum Names. * - * @since 3.6.2 * @author Rsl1122 + * @since 3.6.2 */ public class LocaleEntryComparator implements Comparator> { diff --git a/Plan/src/main/resources/plugin.yml b/Plan/src/main/resources/plugin.yml index 3e0993c53..dd2f27d67 100644 --- a/Plan/src/main/resources/plugin.yml +++ b/Plan/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: main.java.com.djrapitops.plan.Plan -version: 3.6.2 +version: 3.6.3 softdepend: - OnTime - EssentialsX