From e8da0085380993cc4c2b58648e8c5b48801f2d7a Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 20 Mar 2019 13:37:56 +0200 Subject: [PATCH] Added 'extensions' module: - Module is in charge of registering built in DataExtensions - This is done via ExtensionRegister --- Plan/api/build.gradle | 32 ++++++++++++++++++- Plan/bukkit/build.gradle | 12 +++---- .../listeners/bukkit/CommandListener.java | 2 +- .../tasks/bukkit/PaperTPSCountTimer.java | 1 + .../tasks/bukkit/PingCountTimerBukkit.java | 1 + Plan/common/build.gradle | 3 +- .../ExtensionServiceImplementation.java | 8 +++++ .../djrapitops/plan/system/PlanSystem.java | 5 +++ Plan/extensions/build.gradle | 12 +++++++ .../implementation/ExtensionRegister.java | 30 +++++++++++++++++ Plan/settings.gradle | 3 +- 11 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 Plan/extensions/build.gradle create mode 100644 Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java diff --git a/Plan/api/build.gradle b/Plan/api/build.gradle index 209482f70..f4373e6f6 100644 --- a/Plan/api/build.gradle +++ b/Plan/api/build.gradle @@ -1,9 +1,39 @@ +plugins { + id "com.jfrog.bintray" version "1.8.1" +} + +ext.apiVersion = '0.0.1' + +bintray { + user = System.getenv('BINTRAY_USER') + key = System.getenv('BINTRAY_KEY') + pkg { + repo = 'Plan-repository' + name = 'Plan-API' + licenses = ['LGPL-v3.0'] + vcsUrl = 'https://github.com/plan-player-analytics/Plan' + issueTrackerUrl = 'https://github.com/plan-player-analytics/Plan/issues' + version { + name = "$apiVersion" + desc = 'Plan APIv5 version 0.0.1' + } + publications = ['BintrayPublication'] + } +} + publishing { publications { + BintrayPublication(MavenPublication) { + groupId = 'com.djrapitops' + artifactId = 'Plan-api' + version = "$apiVersion" + + artifact jar + } mavenJava(MavenPublication) { groupId = 'com.djrapitops' artifactId = 'Plan-api' - version = project.version + version = "$apiVersion" artifact jar } diff --git a/Plan/bukkit/build.gradle b/Plan/bukkit/build.gradle index cb36eb1f4..fe6752325 100644 --- a/Plan/bukkit/build.gradle +++ b/Plan/bukkit/build.gradle @@ -4,13 +4,13 @@ dependencies { compile "com.djrapitops:AbstractPluginFramework-bukkit:$abstractPluginFrameworkVersion" compile "org.bstats:bstats-bukkit:$bstatsVersion" - compileOnly "com.destroystokyo.paper:paper-api:$paperVersion" - compileOnly "org.spigotmc:spigot-api:$spigotVersion" - compileOnly "org.bukkit:bukkit:$bukkitVersion" +// compileOnly "org.spigotmc:spigot-api:$spigotVersion" +// compileOnly "org.bukkit:bukkit:$bukkitVersion" + compileOnly "com.destroystokyo.paper:paper-api:$paperVersion" - testCompile "com.destroystokyo.paper:paper-api:$paperVersion" - testCompile "org.spigotmc:spigot-api:$spigotVersion" - testCompile "org.bukkit:bukkit:$bukkitVersion" +// testCompile "org.spigotmc:spigot-api:$spigotVersion" +// testCompile "org.bukkit:bukkit:$bukkitVersion" + testCompile "com.destroystokyo.paper:paper-api:$paperVersion" testCompile project(path: ":common", configuration: 'testArtifacts') } diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java index a8342dc1a..fe0931511 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/listeners/bukkit/CommandListener.java @@ -100,7 +100,7 @@ public class CommandListener implements Listener { try { command = plugin.getServer().getCommandMap().getCommand(commandName); } catch (NoSuchMethodError ignored) { - /* Ignored, Bukkit 1.8 has no such method */ + /* Ignored, Bukkit 1.8 has no such method. This method is from Paper */ } } return command; diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PaperTPSCountTimer.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PaperTPSCountTimer.java index 198921b76..d0092fa3a 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PaperTPSCountTimer.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PaperTPSCountTimer.java @@ -46,6 +46,7 @@ public class PaperTPSCountTimer extends BukkitTPSCountTimer { try { tps = plugin.getServer().getTPS()[0]; } catch (NoSuchMethodError e) { + // This method is from Paper return super.getTPS(diff, now, cpuUsage, usedMemory, entityCount, chunksLoaded, playersOnline, freeDiskSpace); } diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java index 1ef094ce2..40390b164 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/system/tasks/bukkit/PingCountTimerBukkit.java @@ -175,6 +175,7 @@ public class PingCountTimerBukkit extends AbsRunnable implements Listener { private int getPing(Player player) { if (PING_METHOD_AVAILABLE) { + // This method is from Paper return player.spigot().getPing(); } diff --git a/Plan/common/build.gradle b/Plan/common/build.gradle index d5ebebb63..0c1bc9a8b 100644 --- a/Plan/common/build.gradle +++ b/Plan/common/build.gradle @@ -1,6 +1,7 @@ dependencies { compile "com.djrapitops:AbstractPluginFramework-api:$abstractPluginFrameworkVersion" - compile project(path: ":api", configuration: 'shadow') + compile project(path: ":api") + compile project(path: ":extensions", configuration: 'shadow') compile "com.djrapitops:PlanPluginBridge:$planPluginBridgeVersion" compile "org.apache.httpcomponents:httpclient:$httpClientVersion" compile "org.apache.commons:commons-text:$commonsTextVersion" diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java index f19b1dca3..3a8a7658a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionServiceImplementation.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.extension; import com.djrapitops.plan.extension.implementation.DataProviderExtractor; +import com.djrapitops.plan.extension.implementation.ExtensionRegister; import com.djrapitops.plan.extension.implementation.providers.gathering.ProviderValueGatherer; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.info.server.ServerInfo; @@ -40,6 +41,7 @@ public class ExtensionServiceImplementation implements ExtensionService { private final DBSystem dbSystem; private final ServerInfo serverInfo; + private final ExtensionRegister extensionRegister; private final PluginLogger logger; private final ErrorHandler errorHandler; @@ -49,11 +51,13 @@ public class ExtensionServiceImplementation implements ExtensionService { public ExtensionServiceImplementation( DBSystem dbSystem, ServerInfo serverInfo, + ExtensionRegister extensionRegister, PluginLogger logger, ErrorHandler errorHandler ) { this.dbSystem = dbSystem; this.serverInfo = serverInfo; + this.extensionRegister = extensionRegister; this.logger = logger; this.errorHandler = errorHandler; @@ -62,6 +66,10 @@ public class ExtensionServiceImplementation implements ExtensionService { ExtensionService.ExtensionServiceHolder.set(this); } + public void enable() { + extensionRegister.registerBuiltInExtensions(); + } + @Override public void register(DataExtension extension) { DataProviderExtractor extractor = new DataProviderExtractor(extension); 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 fd8da3b44..68c9d3667 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 @@ -19,6 +19,7 @@ package com.djrapitops.plan.system; import com.djrapitops.plan.api.PlanAPI; import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.data.plugin.HookHandler; +import com.djrapitops.plan.extension.ExtensionServiceImplementation; import com.djrapitops.plan.system.cache.CacheSystem; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.export.ExportSystem; @@ -69,6 +70,7 @@ public class PlanSystem implements SubSystem { private final ExportSystem exportSystem; private final HtmlUtilities htmlUtilities; private final HookHandler hookHandler; + private final ExtensionServiceImplementation extensionService; private final PlanAPI planAPI; private final ErrorHandler errorHandler; @@ -90,6 +92,7 @@ public class PlanSystem implements SubSystem { ExportSystem exportSystem, HtmlUtilities htmlUtilities, HookHandler hookHandler, + ExtensionServiceImplementation extensionService, PlanAPI planAPI, ErrorHandler errorHandler ) { @@ -109,6 +112,7 @@ public class PlanSystem implements SubSystem { this.exportSystem = exportSystem; this.htmlUtilities = htmlUtilities; this.hookHandler = hookHandler; + this.extensionService = extensionService; this.planAPI = planAPI; this.errorHandler = errorHandler; } @@ -132,6 +136,7 @@ public class PlanSystem implements SubSystem { taskSystem, hookHandler ); + extensionService.enable(); enabled = true; } diff --git a/Plan/extensions/build.gradle b/Plan/extensions/build.gradle new file mode 100644 index 000000000..cea5a18ae --- /dev/null +++ b/Plan/extensions/build.gradle @@ -0,0 +1,12 @@ +dependencies { + compile project(path: ":api") + compile "com.djrapitops:Extension-AdvancedAchievements:1.1-R0.1" +} + +shadowJar { + configurations = [project.configurations.compile] + + dependencies { + exclude(project(':api')) + } +} \ No newline at end of file diff --git a/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java new file mode 100644 index 000000000..8bfee07f1 --- /dev/null +++ b/Plan/extensions/src/main/java/com/djrapitops/plan/extension/implementation/ExtensionRegister.java @@ -0,0 +1,30 @@ +package com.djrapitops.plan.extension.implementation; + +import com.djrapitops.extension.AdvancedAchievementsExtensionFactory; +import com.djrapitops.plan.extension.ExtensionService; + +import javax.inject.Inject; +import javax.inject.Singleton; + +/** + * In charge of registering built in {@link com.djrapitops.plan.extension.DataExtension} implementations. + * + * @author Rsl1122 + */ +@Singleton +public class ExtensionRegister { + + @Inject + public ExtensionRegister() { + /* Required for dagger injection */ + } + + public void registerBuiltInExtensions() { + // No need to catch exceptions here, + // this method will not be called unless Plan has enabled properly + ExtensionService extensionService = ExtensionService.getInstance(); + + new AdvancedAchievementsExtensionFactory().createExtension().ifPresent(extensionService::register); + } + +} \ No newline at end of file diff --git a/Plan/settings.gradle b/Plan/settings.gradle index 42f00dd45..b9f5a3f68 100644 --- a/Plan/settings.gradle +++ b/Plan/settings.gradle @@ -6,4 +6,5 @@ include 'bukkit' include 'sponge' include 'bungeecord' include 'velocity' -include 'plugin' \ No newline at end of file +include 'plugin' +include 'extensions' \ No newline at end of file