From 8fe7de9bb63581c9cf43932cdf111687a191fc79 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 30 Jul 2017 21:44:55 +0300 Subject: [PATCH] Fix unwanted Filtering of sessions from inspect page punchcards Fix some code inspect issues --- .../java/com/djrapitops/plan/api/API.java | 14 ++--- .../plan/command/commands/ListCommand.java | 3 - .../commands/RegisterCommandFilter.java | 2 +- .../com/djrapitops/plan/data/SessionData.java | 2 +- .../plan/database/databases/SQLDB.java | 2 +- .../plan/database/tables/LocationsTable.java | 2 +- .../plan/database/tables/TPSTable.java | 2 +- .../plan/database/tables/Table.java | 2 +- .../plan/database/tables/UsersTable.java | 2 +- .../ui/html/graphs/PunchCardGraphCreator.java | 9 +-- ...SessionLengthDistributionGraphCreator.java | 2 +- .../ui/html/tables/PlayersTableCreator.java | 2 +- .../plan/utilities/FormatUtils.java | 2 +- .../plan/utilities/ManageUtils.java | 58 ------------------- .../djrapitops/plan/utilities/MiscUtils.java | 4 +- .../plan/utilities/PassEncryptUtil.java | 5 +- .../plan/utilities/uuid/UUIDUtility.java | 2 +- .../plan/data/cache/DataCacheHandlerTest.java | 3 +- .../cache/queue/DataCacheClearQueueTest.java | 7 +-- .../cache/queue/DataCacheSaveQueueTest.java | 6 +- 20 files changed, 30 insertions(+), 101 deletions(-) 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 f3405c5a1..195e9948f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/api/API.java +++ b/Plan/src/main/java/com/djrapitops/plan/api/API.java @@ -85,11 +85,11 @@ public class API { * This method is useful if you have a table and want to link to the inspect * page. *

- * Html.LINK.parse("Link", "Playername") can be used to get a link - * {@code Playername} + * Html.LINK.parse("Link", "PlayerName") can be used to get a link + * {@code PlayerName} * - * @param name Playername of the player - * @return ip:port/security/player/Playername + * @param name Name of the player + * @return ip:port/security/player/PlayerName */ public String getPlayerInspectPageLink(String name) { return HtmlUtils.getInspectUrlWithProtocol(name); @@ -229,10 +229,10 @@ public class API { } /** - * Used to get the playerName of a player who has played on the server. + * Used to get the PlayerName of a player who has played on the server. * * @param uuid UUID of the player. - * @return Playername, eg "Rsl1122" + * @return PlayerName, eg "Rsl1122" * @throws IllegalArgumentException If uuid is null. * @throws IllegalStateException If the player has not played on the server * before. @@ -253,7 +253,7 @@ public class API { * @return UUID of the Player * @throws Exception if player's name is not registered at Mojang */ - public UUID playerNameToUUID(String playerName) throws Exception { + public UUID PlayerNameToUUID(String playerName) throws Exception { return UUIDFetcher.getUUIDOf(playerName); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListCommand.java index 181ea37a5..7c805e4b2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/ListCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/ListCommand.java @@ -22,8 +22,6 @@ import main.java.com.djrapitops.plan.utilities.HtmlUtils; */ public class ListCommand extends SubCommand { - private final Plan plugin; - /** * Class Constructor. * @@ -32,7 +30,6 @@ public class ListCommand extends SubCommand { public ListCommand(Plan plugin) { super("list, pl", CommandType.CONSOLE, Permissions.INSPECT_OTHER.getPermission(), "List to all cached players", ""); - this.plugin = plugin; setHelp(plugin); } diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommandFilter.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommandFilter.java index 744803d3a..377c321bf 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommandFilter.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/RegisterCommandFilter.java @@ -18,7 +18,7 @@ import java.util.Set; */ public class RegisterCommandFilter extends AbstractFilter { - private Set censoredCommands = ImmutableSet.of("/plan web register", "/plan webuser register", "/plan register"); + private final Set censoredCommands = ImmutableSet.of("/plan web register", "/plan webuser register", "/plan register"); @Override public Result filter(LogEvent event) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/SessionData.java b/Plan/src/main/java/com/djrapitops/plan/data/SessionData.java index 9cbe8ef1e..253a10100 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/SessionData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/SessionData.java @@ -1,7 +1,7 @@ package main.java.com.djrapitops.plan.data; /** - * This class is used for storing start and end of a playsession inside UserData + * This class is used for storing start and end of a play session inside UserData * object. * * @author Rsl1122 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 b7d777365..f68622e8c 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 @@ -123,7 +123,7 @@ public abstract class SQLDB extends Database { try { getVersion(); newDatabase = false; - } catch (Exception e) { + } catch (Exception ignored) { } if (!versionTable.createTable()) { diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java index 705b6a787..d40f67454 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/LocationsTable.java @@ -38,7 +38,7 @@ public class LocationsTable extends Table { public boolean removeAllData() { try { execute("DELETE FROM " + tableName); - } catch (Exception e) { + } catch (Exception ignored) { } return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java index def40f0a1..7f178683b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java @@ -79,7 +79,7 @@ public class TPSTable extends Table { } else { execute("ALTER TABLE " + tableName + " ADD COLUMN " + columnCPUUsage + " double NOT NULL DEFAULT 0"); } - } catch (SQLException e) { + } catch (SQLException ignored) { } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java index a9a41f5ee..8172f63a1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/Table.java @@ -96,7 +96,7 @@ public abstract class Table { for (String statement : statements) { try { execute(statement); - } catch (SQLException e) { + } catch (SQLException ignored) { } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java index a70ae706d..b76da386c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/UsersTable.java @@ -123,7 +123,7 @@ public class UsersTable extends Table { execute("ALTER TABLE " + tableName + " DROP COLUMN " + columnDemAge + "," + " DROP COLUMN " + columnDemGender); - } catch (Exception e) { + } catch (Exception ignored) { } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java index 08d97015b..09333ca71 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java @@ -6,7 +6,6 @@ package main.java.com.djrapitops.plan.ui.html.graphs; import main.java.com.djrapitops.plan.data.SessionData; -import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import java.util.Collection; @@ -15,7 +14,7 @@ import java.util.Objects; import java.util.stream.Collectors; /** - * Utility class for creating Punch Card Data Array for the javascripts. + * Utility class for creating Punch Card Data Array for the JavaScripts. * * @author Rsl1122 * @since 3.6.0 @@ -30,9 +29,9 @@ public class PunchCardGraphCreator { } /** - * Creates a Punchcard series data Array for HighCharts + * Creates a PunchCard series data Array for HighCharts * - * @param sessions Sessions (Unique/Player) to be placed into the punchcard. + * @param sessions Sessions (Unique/Player) to be placed into the PunchCard. * @return Data array as a string. */ public static String createDataSeries(Collection sessions) { @@ -73,12 +72,10 @@ public class PunchCardGraphCreator { } private static List getSessionStarts(Collection data) { - long now = MiscUtils.getTime(); return data.stream() .filter(Objects::nonNull) .filter(SessionData::isValid) .map(SessionData::getSessionStart) - .filter(start -> now - start < (long) 2592000 * (long) 1000) .sorted() .collect(Collectors.toList()); } diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java index b5cda83a6..f3871dc0c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/SessionLengthDistributionGraphCreator.java @@ -26,7 +26,7 @@ public class SessionLengthDistributionGraphCreator { * Contains values from 0 up to 120 minutes * * @param lengths Lengths of all sessions in a list. - * @return Data for Highcharts series. + * @return Data for HighCharts series. */ public static String createDataSeries(List lengths) { Map bars = getValues(lengths); 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 78f003053..7bf09b02e 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 @@ -60,7 +60,7 @@ public class PlayersTableCreator { String.valueOf(uData.getLastPlayed()), FormatUtils.formatTimeStamp(uData.getLastPlayed()), String.valueOf(uData.getGeolocation()) )); - } catch (NullPointerException e) { + } catch (NullPointerException ignored) { } i++; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java index eb7f822f0..aeac55a84 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java @@ -12,7 +12,7 @@ import java.text.DecimalFormat; */ public class FormatUtils { - private static DecimalFormat df = new DecimalFormat(Settings.FORMAT_DECIMALS.toString()); + private static final DecimalFormat df = new DecimalFormat(Settings.FORMAT_DECIMALS.toString()); /** * Constructor used to hide the public constructor diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java index 3de2a4679..c3fed49b9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/ManageUtils.java @@ -3,15 +3,12 @@ package main.java.com.djrapitops.plan.utilities; import com.djrapitops.plugin.utilities.Verify; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; -import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.databases.SQLiteDB; -import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import java.sql.SQLException; import java.util.*; -import java.util.stream.Collectors; /** * @author Rsl1122 @@ -84,61 +81,6 @@ public class ManageUtils { return true; } - /** - * @param sessions - * @return - */ - public static boolean containsCombinable(List sessions) { - return containsCombinable(sessions, 5000); - } - - private static boolean containsCombinable(List sessions, int threshold) { - // Checks if there are starts & ends that are the same, or less than threshold ms away from each other. - return sessions.stream() - .anyMatch(s -> sessions.stream() - .filter(ses -> !ses.equals(s)) - .map(SessionData::getSessionStart) - .anyMatch(start -> Math.abs(s.getSessionEnd() - start) < threshold)); - } - - /** - * @param sessions - * @param loginTimes - * @return - */ - public static List combineSessions(List sessions, Integer loginTimes) { - return combineSessions(sessions, loginTimes, 5000); - } - - private static List combineSessions(List sessions, Integer loginTimes, int threshold) { - if (threshold >= 35000) { - return sessions; - } - List newSessions = new ArrayList<>(); - List removed = new ArrayList<>(); - for (SessionData session : sessions) { - if (removed.contains(session)) { - continue; - } - List close = sessions.stream().filter(ses -> Math.abs(session.getSessionEnd() - ses.getSessionStart()) < threshold).collect(Collectors.toList()); - if (!close.isEmpty()) { - long big = MathUtils.getBiggestLong(close.stream().map(SessionData::getSessionEnd).collect(Collectors.toList())); - session.endSession(big); - removed.addAll(close); - } - newSessions.add(session); - } - if (loginTimes == newSessions.size()) { - return newSessions; - } - boolean containsCombinable = containsCombinable(newSessions, threshold); - if (containsCombinable) { - return combineSessions(newSessions, threshold + 1000); - } else { - return newSessions; - } - } - public static Database getDB(Plan plugin, String dbName) { Database database = null; for (Database sqldb : plugin.getDatabases()) { 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 764ae2640..52e917aa1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/MiscUtils.java @@ -99,7 +99,7 @@ public class MiscUtils { if (c != null) { try { c.close(); - } catch (IOException ex) { + } catch (IOException ignored) { } } } @@ -110,7 +110,7 @@ public class MiscUtils { if (c != null) { try { c.close(); - } catch (Exception ex) { + } catch (Exception ignored) { } } } 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 c600b1d49..22dd15f51 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/PassEncryptUtil.java @@ -75,7 +75,6 @@ public class PassEncryptUtil { // Currently, Java only supports SHA1. if (!params[HASH_ALGORITHM_INDEX].equals("sha1")) { throw new CannotPerformOperationException( - "Unsupported hash type." ); } @@ -182,8 +181,8 @@ public class PassEncryptUtil { @SuppressWarnings("serial") public static class CannotPerformOperationException extends Exception { - CannotPerformOperationException(String message) { - super(message); + CannotPerformOperationException() { + super("Unsupported hash type."); } CannotPerformOperationException(String message, Throwable source) { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java b/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java index 8000fa78e..779e7e2ae 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/uuid/UUIDUtility.java @@ -53,7 +53,7 @@ public class UUIDUtility { if (uuid == null) { uuid = UUIDFetcher.getUUIDOf(playername); } - } catch (Exception e) { + } catch (Exception ignored) { } return uuid; } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java index 9c5355247..d3fb5bc36 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/DataCacheHandlerTest.java @@ -40,7 +40,6 @@ import static org.powermock.api.mockito.PowerMockito.when; @PrepareForTest(JavaPlugin.class) public class DataCacheHandlerTest { - private Plan plan; private Database db; private DataCacheHandler handler; private boolean calledSaveCommandUse; @@ -59,7 +58,7 @@ public class DataCacheHandlerTest { @Before public void setUp() throws Exception { TestInit t = TestInit.init(); - plan = t.getPlanMock(); + Plan plan = t.getPlanMock(); calledSaveCommandUse = false; calledSaveUserData = false; db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) { diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java index 0a0626370..b84013953 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheClearQueueTest.java @@ -24,9 +24,6 @@ import test.java.utils.TestInit; @PrepareForTest({JavaPlugin.class}) public class DataCacheClearQueueTest { - private Plan plan; - private DataCacheHandler handler; - /** * */ @@ -39,8 +36,8 @@ public class DataCacheClearQueueTest { @Before public void setUp() throws Exception { TestInit t = TestInit.init(); - plan = t.getPlanMock(); - handler = new DataCacheHandler(plan) { + Plan plan = t.getPlanMock(); + DataCacheHandler handler = new DataCacheHandler(plan) { @Override public boolean getCommandUseFromDb() { return true; diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java index 52440e1a2..3ead38450 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/cache/queue/DataCacheSaveQueueTest.java @@ -31,8 +31,6 @@ import static org.powermock.api.mockito.PowerMockito.when; @PrepareForTest({JavaPlugin.class}) public class DataCacheSaveQueueTest { - private Plan plan; - private Database db; private boolean calledSaveUserData; private boolean calledSaveUserData2; @@ -48,10 +46,10 @@ public class DataCacheSaveQueueTest { @Before public void setUp() throws Exception { TestInit t = TestInit.init(); - plan = t.getPlanMock(); + Plan plan = t.getPlanMock(); calledSaveUserData = false; calledSaveUserData2 = false; - db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) { + Database db = new SQLiteDB(plan, "debug" + MiscUtils.getTime()) { @Override public void startConnectionPingTask() {