Sorted out bStats shenanigans

- Added bStats support for Velocity
- Fixed Sponge bStats issues
- Added bStats link for Velocity to html
This commit is contained in:
Risto Lahtela 2021-02-14 15:56:19 +02:00
parent 94c9dd3f95
commit 3ee0d2e455
12 changed files with 111 additions and 14 deletions

View File

@ -90,7 +90,7 @@ subprojects {
ext.geoIpVersion = "2.15.0"
ext.gsonVersion = "2.8.6"
ext.guavaVersion = "28.0-jre"
ext.bstatsVersion = "2.1.0"
ext.bstatsVersion = "2.2.1"
ext.placeholderapiVersion = "2.10.9"
ext.nkPlaceholderapiVersion = "1.3-SNAPSHOT"

View File

@ -202,6 +202,9 @@
BungeeCord</a>
<a class="btn col-plan" href="https://bstats.org/plugin/sponge/plan" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Sponge</a>
<a class="btn col-plan" href="https://bstats.org/plugin/velocity/Plan/10326"
rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Velocity</a>
</div>
<div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>

View File

@ -793,6 +793,9 @@
rel="noopener noreferrer" target="_blank"><i class="fa fa-fw fa-chart-area"></i> BungeeCord</a>
<a class="btn col-plan" href="https://bstats.org/plugin/sponge/plan" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Sponge</a>
<a class="btn col-plan" href="https://bstats.org/plugin/velocity/Plan/10326"
rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Velocity</a>
</div>
<div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>

View File

@ -662,6 +662,9 @@
BungeeCord</a>
<a class="btn col-plan" href="https://bstats.org/plugin/sponge/plan" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Sponge</a>
<a class="btn col-plan" href="https://bstats.org/plugin/velocity/Plan/10326"
rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Velocity</a>
</div>
<div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>

View File

@ -232,6 +232,9 @@
BungeeCord</a>
<a class="btn col-plan" href="https://bstats.org/plugin/sponge/plan" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Sponge</a>
<a class="btn col-plan" href="https://bstats.org/plugin/velocity/Plan/10326"
rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Velocity</a>
</div>
<div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>

View File

@ -284,6 +284,8 @@
BungeeCord</a>
<a class="btn col-plan" href="https://bstats.org/plugin/sponge/plan" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Sponge</a>
<a class="btn col-plan" href="https://bstats.org/plugin/velocity/Plan/10326" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Velocity</a>
</div>
<div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>

View File

@ -1283,6 +1283,9 @@
BungeeCord</a>
<a class="btn col-plan" href="https://bstats.org/plugin/sponge/plan" rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Sponge</a>
<a class="btn col-plan" href="https://bstats.org/plugin/velocity/Plan/10326"
rel="noopener noreferrer"
target="_blank"><i class="fa fa-fw fa-chart-area"></i> Velocity</a>
</div>
<div class="modal-footer">
<button class="btn bg-plan" data-dismiss="modal" type="button">OK</button>

View File

@ -17,12 +17,13 @@
package com.djrapitops.plan;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plugin.task.AbsRunnable;
import org.bstats.charts.SimplePie;
import org.bstats.sponge.Metrics;
import java.io.Serializable;
public class BStatsSponge {
public class BStatsSponge extends AbsRunnable {
private final Metrics metrics;
private final Database database;
@ -32,6 +33,11 @@ public class BStatsSponge {
this.database = database;
}
@Override
public void run() {
registerMetrics();
}
public void registerMetrics() {
if (metrics != null) {
registerConfigSettingGraphs();

View File

@ -62,19 +62,27 @@ import java.util.Optional;
)
public class PlanSponge extends SpongePlugin implements PlanPlugin {
@com.google.inject.Inject
private Metrics.Factory metrics;
private final Metrics metrics;
private final Logger slf4jLogger;
private final File dataFolder;
@com.google.inject.Inject
private Logger slf4jLogger;
@com.google.inject.Inject
@ConfigDir(sharedRoot = false)
private File dataFolder;
private PlanSystem system;
private Locale locale;
private ServerShutdownSave serverShutdownSave;
@com.google.inject.Inject
public PlanSponge(
Logger slf4jLogger,
@ConfigDir(sharedRoot = false) File dataFolder,
Metrics.Factory metrics
) {
this.slf4jLogger = slf4jLogger;
this.dataFolder = dataFolder;
int pluginId = 3086;
this.metrics = metrics.make(pluginId);
}
private final Map<String, CommandMapping> commands = new HashMap<>();
@Listener
@ -96,10 +104,8 @@ public class PlanSponge extends SpongePlugin implements PlanPlugin {
locale = system.getLocaleSystem().getLocale();
system.enable();
int pluginId = 3086;
new BStatsSponge(
metrics.make(pluginId),
system.getDatabaseSystem().getDatabase()
metrics, system.getDatabaseSystem().getDatabase()
).registerMetrics();
logger.info(locale.getString(PluginLang.ENABLED));

View File

@ -13,6 +13,7 @@ dependencies {
compileOnly project(":api")
compile "com.djrapitops:AbstractPluginFramework-velocity:$abstractPluginFrameworkVersion"
compile "org.bstats:bstats-velocity:$bstatsVersion"
compileOnly "com.velocitypowered:velocity-api:$velocityVersion"
testCompile "com.velocitypowered:velocity-api:$velocityVersion"
@ -24,6 +25,7 @@ dependencies {
shadowJar {
dependsOn blossomSourceReplacementJava
relocate 'org.bstats', 'com.djrapitops.plan.utilities.metrics'
configurations = [project.configurations.compile]
}

View File

@ -0,0 +1,51 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan;
import com.djrapitops.plan.storage.database.Database;
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics;
import java.util.function.Supplier;
public class BStatsVelocity {
private final PlanVelocity plugin;
private final Database database;
private final Metrics metrics;
public BStatsVelocity(PlanVelocity plugin, Database database, Metrics metrics) {
this.plugin = plugin;
this.database = database;
this.metrics = metrics;
}
public void registerMetrics() {
registerConfigSettingGraphs();
}
private void registerConfigSettingGraphs() {
addStringSettingPie("database_type", () -> database.getType().getName());
addStringSettingPie("network_servers", () -> String.valueOf(database.query(ServerQueries.fetchPlanServerInformationCollection()).size()));
}
protected void addStringSettingPie(String id, Supplier<String> setting) {
metrics.addCustomChart(new SimplePie(id, setting::get));
}
}

View File

@ -31,6 +31,7 @@ import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
import java.io.InputStream;
@ -52,12 +53,19 @@ import java.nio.file.Path;
)
public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
private final Metrics.Factory metricsFactory;
private PlanSystem system;
private Locale locale;
@com.google.inject.Inject
public PlanVelocity(ProxyServer proxy, Logger slf4jLogger, @DataDirectory Path dataFolderPath) {
public PlanVelocity(
ProxyServer proxy,
Logger slf4jLogger,
@DataDirectory Path dataFolderPath,
Metrics.Factory metricsFactory
) {
super(proxy, slf4jLogger, dataFolderPath);
this.metricsFactory = metricsFactory;
}
@Subscribe
@ -78,6 +86,13 @@ public class PlanVelocity extends VelocityPlugin implements PlanPlugin {
locale = system.getLocaleSystem().getLocale();
system.enable();
int pluginId = 10326;
new BStatsVelocity(
this,
system.getDatabaseSystem().getDatabase(),
metricsFactory.make(this, pluginId)
).registerMetrics();
logger.info(locale.getString(PluginLang.ENABLED));
} catch (AbstractMethodError e) {
logger.error("Plugin ran into AbstractMethodError - Server restart is required. Likely cause is updating the jar without a restart.");