From 9718ffe5acb05378b02c00801d13c091397922ad Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 28 May 2019 20:19:21 +0300 Subject: [PATCH 1/3] [#1041] Fixed CapabilityService initialization --- .../plan/capability/CapabilityServiceImplementation.java | 4 ++++ .../src/main/java/com/djrapitops/plan/system/PlanSystem.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilityServiceImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilityServiceImplementation.java index 38696be98..a4ea36896 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilityServiceImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/capability/CapabilityServiceImplementation.java @@ -44,6 +44,10 @@ public class CapabilityServiceImplementation implements CapabilityService { return (CapabilityServiceImplementation) CapabilityServiceHolder.service; } + public static void initialize() { + get(); + } + public static void notifyAboutEnable(boolean isEnabled) { for (Consumer enableListener : get().enableListeners) { enableListener.accept(isEnabled); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/PlanSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/system/PlanSystem.java index a1610fc04..9f44547df 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/PlanSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/PlanSystem.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.system; import com.djrapitops.plan.api.PlanAPI; import com.djrapitops.plan.api.exceptions.EnableException; +import com.djrapitops.plan.capability.CapabilityServiceImplementation; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.extension.ExtensionService; import com.djrapitops.plan.extension.ExtensionServiceImplementation; @@ -120,6 +121,8 @@ public class PlanSystem implements SubSystem { @Override public void enable() throws EnableException { + CapabilityServiceImplementation.initialize(); + enableSystems( files, configSystem, From 2dc89789404a26793f6a69c807706212a8b9bf4e Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 28 May 2019 20:20:56 +0300 Subject: [PATCH 2/3] Removed broken test --- .../tables/PlayersTableJSONParserTest.java | 184 ------------------ 1 file changed, 184 deletions(-) delete mode 100644 Plan/common/src/test/java/com/djrapitops/plan/utilities/html/tables/PlayersTableJSONParserTest.java diff --git a/Plan/common/src/test/java/com/djrapitops/plan/utilities/html/tables/PlayersTableJSONParserTest.java b/Plan/common/src/test/java/com/djrapitops/plan/utilities/html/tables/PlayersTableJSONParserTest.java deleted file mode 100644 index 850901e65..000000000 --- a/Plan/common/src/test/java/com/djrapitops/plan/utilities/html/tables/PlayersTableJSONParserTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package com.djrapitops.plan.utilities.html.tables; - -import com.djrapitops.plan.data.container.Session; -import com.djrapitops.plan.db.Database; -import com.djrapitops.plan.db.access.queries.containers.ServerPlayersTableContainersQuery; -import com.djrapitops.plan.db.access.transactions.Transaction; -import com.djrapitops.plan.db.access.transactions.events.PlayerRegisterTransaction; -import com.djrapitops.plan.db.access.transactions.events.PlayerServerRegisterTransaction; -import com.djrapitops.plan.db.access.transactions.events.SessionEndTransaction; -import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransaction; -import com.djrapitops.plan.extension.CallEvents; -import com.djrapitops.plan.extension.DataExtension; -import com.djrapitops.plan.extension.ExtensionService; -import com.djrapitops.plan.extension.ExtensionServiceImplementation; -import com.djrapitops.plan.extension.annotation.*; -import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerPlayerDataTableQuery; -import com.djrapitops.plan.system.PlanSystem; -import com.djrapitops.plan.system.locale.Locale; -import com.djrapitops.plan.system.settings.config.PlanConfig; -import com.djrapitops.plan.system.settings.paths.WebserverSettings; -import com.djrapitops.plan.utilities.formatting.Formatters; -import com.google.gson.Gson; -import org.junit.Assume; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.io.TempDir; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; -import utilities.RandomData; -import utilities.TestConstants; -import utilities.mocks.PluginMockComponent; - -import java.nio.file.Path; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -/** - * Test against PlayersTableJSONParser JSON issues as well as other issues. - * - * @author Rsl1122 - */ -@RunWith(JUnitPlatform.class) -class PlayersTableJSONParserTest { - - private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500); - - private Database db; - private PlanSystem system; - - private UUID serverUUID; - private UUID playerUUID = TestConstants.PLAYER_ONE_UUID; - private UUID player2UUID = TestConstants.PLAYER_TWO_UUID; - - @BeforeEach - void setUp(@TempDir Path tempDir) throws Exception { - Assume.assumeTrue(false); // TODO Skipped due to problems with Gson, parsed 'columns' is null even though it's not. - - PluginMockComponent component = new PluginMockComponent(tempDir); - system = component.getPlanSystem(); - PlanConfig config = system.getConfigSystem().getConfig(); - config.set(WebserverSettings.PORT, TEST_PORT_NUMBER); - - system.enable(); - db = system.getDatabaseSystem().getDatabase(); - serverUUID = system.getServerInfo().getServerUUID(); - storePlayerData(); - } - - private void storePlayerData() throws Exception { - db.executeTransaction(new WorldNameStoreTransaction(serverUUID, "World")); - - db.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> 1000L, TestConstants.PLAYER_ONE_NAME, serverUUID)); - db.executeTransaction(new PlayerRegisterTransaction(player2UUID, () -> 123456789L, TestConstants.PLAYER_TWO_NAME)); - - Session session = new Session(playerUUID, serverUUID, 12345L, "World", "SURVIVAL"); - session.endSession(22345L); - db.executeTransaction(new SessionEndTransaction(session)); - Session session2 = new Session(player2UUID, serverUUID, 12345L, "World", "SURVIVAL"); - session2.endSession(22345L); - db.executeTransaction(new SessionEndTransaction(session2)); - - ExtensionService extensionService = ExtensionService.getInstance(); - extensionService.register(new PlayerExtension()); - ((ExtensionServiceImplementation) extensionService).updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL); - ((ExtensionServiceImplementation) extensionService).updatePlayerValues(player2UUID, TestConstants.PLAYER_TWO_NAME, CallEvents.MANUAL); - - db.executeTransaction(new Transaction() { - @Override - protected void performOperations() { - - } - }).get(); // Wait for transactions to finish - } - - @Test - void playersTableJSONDoesNotContainDuplicateColumns() { - PlayersTableJSONParser parser = createParser(); - class Column { - String title; - } - - class Table { - Column[] columns; - } - - String json = parser.toJSONString(); - System.out.println("Parsed: " + json); - Table table = new Gson().fromJson(json, Table.class); - - Set foundColumnNames = new HashSet<>(); - for (Column column : table.columns) { - assertFalse(foundColumnNames.contains(column.title), () -> "Duplicate column title: '" + column.title + "'"); - foundColumnNames.add(column.title); - } - } - - private PlayersTableJSONParser createParser() { - int xMostRecentPlayers = 5; - int loginThreshold = 5; - long playtimeThreshold = TimeUnit.DAYS.toMillis(1L); - boolean openPlayerLinksInNewTab = false; - - return new PlayersTableJSONParser( - db.query(new ServerPlayersTableContainersQuery(serverUUID)), - db.query(new ExtensionServerPlayerDataTableQuery(serverUUID, xMostRecentPlayers)), - xMostRecentPlayers, playtimeThreshold, loginThreshold, openPlayerLinksInNewTab, - new Formatters(system.getConfigSystem().getConfig(), new Locale()) - ); - } - - @AfterEach - void tearDown() { - system.disable(); - } - - @PluginInfo(name = "PlayerExtension") - public class PlayerExtension implements DataExtension { - @NumberProvider(text = "a number", showInPlayerTable = true) - public long value(UUID playerUUD) { - return 5L; - } - - @BooleanProvider(text = "a boolean", showInPlayerTable = true) - public boolean boolVal(UUID playerUUID) { - return false; - } - - @DoubleProvider(text = "a double", showInPlayerTable = true) - public double doubleVal(UUID playerUUID) { - return 0.5; - } - - @PercentageProvider(text = "a percentage", showInPlayerTable = true) - public double percentageVal(UUID playerUUID) { - return 0.5; - } - - @StringProvider(text = "a string", showInPlayerTable = true) - public String stringVal(UUID playerUUID) { - return "Something"; - } - } -} \ No newline at end of file From 70b9c4d8e66bb28c1726b4f5def1f5e226b5e936 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 28 May 2019 20:22:12 +0300 Subject: [PATCH 3/3] Bump version to 4.8.5 --- Plan/build.gradle | 2 +- Plan/common/src/main/resources/bungee.yml | 2 +- Plan/common/src/main/resources/plugin.yml | 2 +- Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java | 2 +- .../src/main/java/com/djrapitops/plan/PlanVelocity.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Plan/build.gradle b/Plan/build.gradle index cf6cc2748..6bc5f20ad 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -12,7 +12,7 @@ allprojects { wrapper.gradleVersion = "5.0" group "com.djrapitops" - version "4.8.4" + version "4.8.5" test { useJUnitPlatform() diff --git a/Plan/common/src/main/resources/bungee.yml b/Plan/common/src/main/resources/bungee.yml index 484cb4ca7..18c5ffe33 100644 --- a/Plan/common/src/main/resources/bungee.yml +++ b/Plan/common/src/main/resources/bungee.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.PlanBungee -version: 4.8.4 +version: 4.8.5 softdepend: - AdvancedBan - LiteBans diff --git a/Plan/common/src/main/resources/plugin.yml b/Plan/common/src/main/resources/plugin.yml index 5886f2767..4d3755ab1 100644 --- a/Plan/common/src/main/resources/plugin.yml +++ b/Plan/common/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: Plan author: Rsl1122 main: com.djrapitops.plan.Plan -version: 4.8.4 +version: 4.8.5 softdepend: - ASkyBlock - AdvancedAchievements diff --git a/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java b/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java index eb4ac3dd6..b40dafcc3 100644 --- a/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java +++ b/Plan/sponge/src/main/java/com/djrapitops/plan/PlanSponge.java @@ -42,7 +42,7 @@ import java.io.InputStream; @Plugin( id = "plan", name = "Plan", - version = "4.8.4", + version = "4.8.5", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"}, dependencies = { diff --git a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java index 74d94c208..00596df29 100644 --- a/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java +++ b/Plan/velocity/src/main/java/com/djrapitops/plan/PlanVelocity.java @@ -46,7 +46,7 @@ import java.nio.file.Path; @Plugin( id = "plan", name = "Plan", - version = "4.8.4", + version = "4.8.5", description = "Player Analytics Plugin by Rsl1122", authors = {"Rsl1122"} )