From 549cefd098d25522d4a91ded02d6d9577ef722e7 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 1 Mar 2017 11:47:14 +0200 Subject: [PATCH] Bugfix attempts & Error message change - Changed "Plan has run into error..." to include error type - More attempts to fix #26 - Null checks for uuid - Now not saving userdata when uuid = null - If uuid = null, data will not be fetched. --- .../main/java/com/djrapitops/plan/Phrase.java | 2 +- .../main/java/com/djrapitops/plan/Plan.java | 16 ++--------- .../plan/data/cache/DataCacheGetQueue.java | 3 +++ .../plan/database/databases/SQLDB.java | 27 ++++++++++++++++--- .../SortableCommandUseTableCreator.java | 12 +++++++-- .../djrapitops/plan/utilities/Analysis.java | 2 +- .../plan/utilities/AnalysisUtils.java | 7 +++-- .../djrapitops/plan/utilities/HtmlUtils.java | 1 + 8 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/Phrase.java b/Plan/src/main/java/com/djrapitops/plan/Phrase.java index 96fa1c71d..1406fba2c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Phrase.java +++ b/Plan/src/main/java/com/djrapitops/plan/Phrase.java @@ -74,7 +74,7 @@ public enum Phrase { ERROR_NO_DATA_VIEW(ChatColor.YELLOW + "Webserver disabled but Alternative IP/PlanLite not used, no way to view data!"), ERROR_WEBSERVER_OFF_ANALYSIS(ChatColor.YELLOW + "" + PREFIX + "This command can be only used if the webserver is running on this server."), ERROR_WEBSERVER_OFF_INSPECT(ChatColor.YELLOW + "" + PREFIX + "This command can be only used if webserver/planlite is enabled on this server."), - ERROR_LOGGED("Ran into an error. It has been logged to the Errors.txt"), + ERROR_LOGGED("Caugth "+REPLACE0+". It has been logged to the Errors.txt"), ERROR_SESSIONDATA_INITIALIZATION("Player's session was initialized in a wrong way! (" + REPLACE0 + ")"), // CMD_FOOTER(COLOR_TER.color() + "" + ARROWS_RIGHT), diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index 14b55295e..0146a943a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -51,18 +51,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; -/* TODO -Placeholder API -Play session length -- Playtime month -- Playtime week -Location Analysis to view meaningful locations on Dynmap (Investigate dynmap api) -Text interface -Database Cleaning of useless data -Add -n argument for nickname search. -Fix any bugs that come up -Random security code generation - */ /** * * @author Rsl1122 @@ -189,7 +177,7 @@ public class Plan extends JavaPlugin { } public void toLog(String source, Exception e) { - logError(Phrase.ERROR_LOGGED + ""); + logError(Phrase.ERROR_LOGGED.parse(e.toString())); toLog(source + " Caught " + e); for (StackTraceElement x : e.getStackTrace()) { toLog(" " + x); @@ -220,7 +208,7 @@ public class Plan extends JavaPlugin { pw.flush(); } } catch (IOException e) { - getLogger().severe("Failed to create DBerrors.txt file"); + getLogger().severe("Failed to create Errors.txt file"); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheGetQueue.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheGetQueue.java index e45131102..ebec44f7d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheGetQueue.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheGetQueue.java @@ -66,6 +66,9 @@ class GetConsumer implements Runnable { void consume(HashMap> processors) { try { for (UUID uuid : processors.keySet()) { + if (uuid == null) { + continue; + } List processorsList = processors.get(uuid); if (processorsList != null) { try { 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 c52a883a2..84a273a8b 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 @@ -333,7 +333,7 @@ public abstract class SQLDB extends Database { } @Override - public void setVersion(int version) throws SQLException { + public void setVersion(int version) throws SQLException { connection.prepareStatement("DELETE FROM " + versionName).executeUpdate(); connection.prepareStatement("INSERT INTO " + versionName + " (version) VALUES (" + version + ")").executeUpdate(); @@ -390,7 +390,11 @@ public abstract class SQLDB extends Database { PreparedStatement statement = connection.prepareStatement("SELECT " + userColumnUUID + " FROM " + userName); ResultSet set = statement.executeQuery(); while (set.next()) { - uuids.add(UUID.fromString(set.getString(userColumnUUID))); + UUID uuid = UUID.fromString(set.getString(userColumnUUID)); + if (uuid == null) { + continue; + } + uuids.add(uuid); } set.close(); return uuids; @@ -413,6 +417,9 @@ public abstract class SQLDB extends Database { boolean commitRequired = false; if (!data.isEmpty()) { for (String key : data.keySet()) { + if (key.length() > 20) { + continue; + } statement.setString(1, key); statement.setInt(2, data.get(key)); statement.addBatch(); @@ -687,8 +694,13 @@ public abstract class SQLDB extends Database { if (uData == null) { continue; } + UUID uuid = uData.getUuid(); + if (uuid == null) { + continue; + } uData.access(); - int userId = getUserId(uData.getUuid().toString()); + + int userId = getUserId(uuid.toString()); if (userId == -1) { saveLast.add(uData); continue; @@ -749,8 +761,12 @@ public abstract class SQLDB extends Database { uData.stopAccessing(); } for (UserData userData : saveLast) { + UUID uuid = userData.getUuid(); + if (uuid == null) { + continue; + } try { - saveUserData(userData.getUuid(), userData); + saveUserData(uuid, userData); } catch (SQLException e) { exceptions.add(e); } catch (NullPointerException e) { @@ -764,6 +780,9 @@ public abstract class SQLDB extends Database { @Override public void saveUserData(UUID uuid, UserData data) throws SQLException { + if (uuid == null) { + return; + } checkConnection(); data.access(); int userId = getUserId(uuid.toString()); diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/tables/SortableCommandUseTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/tables/SortableCommandUseTableCreator.java index ff25b2924..d76e3b6f7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/tables/SortableCommandUseTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/tables/SortableCommandUseTableCreator.java @@ -3,8 +3,10 @@ package main.java.com.djrapitops.plan.ui.tables; import java.util.Collections; import java.util.HashMap; import java.util.List; +import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.ui.Html; import main.java.com.djrapitops.plan.utilities.comparators.MapComparator; +import static org.bukkit.plugin.java.JavaPlugin.getPlugin; /** * @@ -20,8 +22,14 @@ public class SortableCommandUseTableCreator { return html; } Collections.reverse(sorted); - for (String[] values : sorted) { - html += Html.TABLELINE_2.parse(values[1], values[0]); + for (String[] values : sorted) { + try { + html += Html.TABLELINE_2.parse(values[1], values[0]); + } catch (IllegalArgumentException e) { + Plan plugin = getPlugin(Plan.class); + plugin.toLog("SortableCommandUseTableCreator", e); + plugin.toLog("Cause: "+values[1]+" "+values[2]); + } } return html; } 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 2f0652c83..6136a03c0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java @@ -68,7 +68,7 @@ public class Analysis { BukkitTask asyncAnalysisTask = (new BukkitRunnable() { @Override public void run() { - uuids.stream().forEach((uuid) -> { + uuids.stream().filter(uuid -> uuid != null).forEach((uuid) -> { inspectCache.cache(uuid, 15); }); log(Phrase.ANALYSIS_FETCH_DATA + ""); 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 01cfe4ba2..7dcd0f502 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java @@ -64,10 +64,13 @@ public class AnalysisUtils { static int getNewPlayers(List registered, long scale, long now) { int newPlayers = 0; - // Filters out register dates before scale - newPlayers = registered.stream() + if (!registered.isEmpty()) { + newPlayers = registered.stream() .filter((reg) -> (reg > now - scale)) .map((_item) -> 1).reduce(newPlayers, Integer::sum); + } + // Filters out register dates before scale + return newPlayers; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java index 953eaf1d7..481d2d20c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/HtmlUtils.java @@ -2,6 +2,7 @@ package main.java.com.djrapitops.plan.utilities; import java.io.File; import java.io.FileNotFoundException; +import java.nio.file.Files; import java.util.HashMap; import java.util.Scanner; import main.java.com.djrapitops.plan.Plan;