Giter Site home page Giter Site logo

bastian / bstats-metrics Goto Github PK

View Code? Open in Web Editor NEW
93.0 93.0 111.0 343 KB

The different bStats Metrics classes

Home Page: https://bStats.org

License: MIT License

Java 85.36% Kotlin 14.64%
bstats bukkit bungeecord hacktoberfest metrics minecraft spigot sponge

bstats-metrics's Introduction

Hi, I'm Bastian ๐Ÿ‘‹

Professional full-stack developer & open source enthusiast

Bastian's GitHub stats

๐Ÿ“‹ My Projects

  • Javacord, a popular Java library for creating Discord bots.
  • bStats, the de facto standard for collecting statistics of Minecraft server plugins. Actively used by more than 6,000 plugins on over 200,000 servers worldwide, processing over 3,000,000,000 requests per month.

๐Ÿ“– Publications

bstats-metrics's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bstats-metrics's Issues

How to confirm it works?

I've integrated MetricsLite into ASkyBlock and AcidIsland, but I'm trying to confirm it works. I added some debug and it looks like the stats are sent to the server, but as of yet I don't see any report on my account for the plugin. I was hoping to see 1 Server listed. Should it show up immediately?

Hmm, the server response says:
{"error":"Connection throttled!"}

Maybe that's the problem. Will it reset at some point?

Scoreboard+bStats in plugins

A "SkyPlex" scoreboard appears on my server. I uninstalled each plugin one by one to see which one it was from, then I removed them all, but the scareboard always remains. In the plugins folder it still appears, always a folder named "bStats". I need help

Add option to check if Metrics is enabled

We need to be able to check if Metrics is enabled.

E.g I have a listener I want to enable if the server is using bstats. If they arent I dont need the listener running as they are not recording the stats anyway

I figured something simple
public boolean enabled;

enabled = config.get... etc

I can PR it if you want?

New versions of my plugin don't seem to be recognized

Hello there,

my plugin is https://bstats.org/plugin/bukkit/DungeonsXL/1039.

I'm a bit puzzled that my plugin has lost about 200 servers (nearly half of its users) since August. I suspected the end of some kind of bump caused by people staying at home during the Corona crisis, but the number kept on dwindling.

Now I noticed that none of the newest versions are included in the plugin version pie chart, so I believe something I did in the most recent builds made it stop working. Build 1003 was the last of the ones I uploaded to SpigotMC.org that is included and since then, 8 new builds published there don't appear.

I suspect that the issue has something to do with the way I shade my libraries. I handle bStats through my DRECommons library (https://github.com/DRE2N/DRECommons/blob/master/core/src/main/java/de/erethon/commons/javaplugin/DREPlugin.java#L70), which itself relocates Metrics to de.erethon.commons.bstats (https://github.com/DRE2N/DRECommons/blob/master/dist/pom.xml#L36).

DungeonsXL relocates the whole de.erethon.commons package to de.erethon.dungeonsxl.util.commons. As of some time ago, I stopped relocating de.erethon.commons because of some issues with my setup of the new API module of DungeonsXL. At the same time, I updated from bStats 1.5 to 1.7. As of the latest build (1059), it is relocated again because I suspected that caused the issues with bStats. However, despite being downloaded ~100 times, I still can't find build 1059 in my pie chart.

Debug shows that Metrics#getPluginData() returns data that makes sense and Metrics#isEnabled() is true after onEnable().

Could you please help me out by confirming if there's any data of builds as of 1026, or perhaps even give me a hint about what I'm doing wrong?

Standalone preset?

One of my add-ons are standalone (they don't run on any API listed). This wouldn't be a problem, since I can just port over the metrics class, but all the presets on the site look to require information that doesn't exist.

Option to disable initialization for unit tests?

I use Mockbukkit to test all of my Plugins and have a problem using bstats. Since it initializes everything in the constructor I am unable to mock it.

Is there a way to fix/disable the sending of data for unit tests?

Add fabric support

Fabric is a new mod framework for minecraft and many big plugins have already a fabric version. Maybe you can create one for bStats (a server-side mod).

Any updates on Velocity support?

I noticed the issue: #39 and #52 seem to be a bit outdated and was curious as to the progress of Velocity support. If any help is needed I am willing to contribute where possible, but would like to get a better understanding of where the team stands on adding Velocity support.

Sponge Server crash

When adding a plugin which uses bStats to a server that already has a different plugin using bStats the server crashes.

I believe this is due to the newly added plugin getting loaded first which is causing an error when loading the second plugin.

This can be replicated by setting the class in temp.txt to that of the plugin which gets loaded second.

Crash Log: https://pastebin.com/CxxTj5hQ
Crash Log (This paste won't expire): https://pastebin.com/HbzqsKq7

[Idea] Reset stats :)?

Hello,

I was wondering if you could add an option to reset the stats because I removed my config a couple times when I was testing my plugin and now I have the same server a couple times in my stats :P

Thank you in advance,

Regards,
Robpizza.

scatter/line chart representing integer distribution

Not sure what you mean by Map chart, but I'd like to see a scatter/line chart that represents the distribution of integer values. Unless this is actually possible with the existing line chart - the page on the charts seem to suggest it's a cumulative "over-time" sort of deal though.

E.g. something akin to a bell curve showing the distribution of grades of students for a particular test.

Don't hard-fail if not relocated. Allow a way of keeping it running for when the plugin is run from IDE.

I'm using Gradle shade to shade bStats and relocate. This works great for releases, but when running from an IDE it fails. This is because relocating is done at shade-time, and the IDE does not run the shade task.

Some solutions are:

  • System property to ignore the check
  • Check for IDE runtimes (IntelliJ/Eclipse)
  • Only output a massive warning into the console rather than hard fail.

Overall I'd prefer the last solution, but the first is workable.

Duplicate plugin names

I discovered the hard way that bStats does not allow duplicate plugin names. It appears the data sent includes the plugin name field, which is not unique.

I don't know how easy it would be change, but if the plugin main field can be used with plugin.getDescription().getMain() that would provide the fully qualified name of the plugin's main class. Plugin authors would then register on the bStats site with the full name, e.g., org.bstats.bukkit.Metrics. This would avoid plugin name conflicts.

Exact info about what DrilldownPie does

I was wondering, what a DrilldownPie chart actually does different compared to a simple or AdvancedPie chart.

Like what is the main "gimmic" of it?
And what I wonder even more is, what the different values in the HashMap<String, HashMap<String, Integer>> are actually used for.
Like which value is used for what in the chart?

What is even more frustrating is the fact, that the Custom Charts section talking about this Pie uses "Operating System" in the visual chart, but Java version within the code-snippet, which makes it harder to understand, which values are shown where in the pie chart.

Small fork with opt-out

So is there any chance you could provide an official release for Sponge which uses opt-out instead of opt-in? It is intended for plugins not distributed on Ore.

Bukkit Services vs. plugins

The submitted metrics do only contain information about plugins that have registered a service to the Bukkit ServiceManager (like Placeholder API). In addition, not all plugins that registered services are in the submitted plugin data - only the first plugin that has been loaded. I guess this is related to #4

SSLHandshakeException

22:10:11 [INFO]: Allow unsafe renegotiation: false
22:10:11 [INFO]: Allow legacy hello messages: true
22:10:11 [INFO]: Is initial handshake: true
22:10:11 [INFO]: Is secure renegotiation: false
22:10:11 [INFO]: Thread-34, setSoTimeout(0) called
22:10:11 [INFO]: Thread-34, the previous server name in SNI (type=host_name (0), value=bStats.org) was replaced with (type=host_name (0), value=bStats.org)
22:10:11 [INFO]: Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 for TLSv1.1
22:10:11 [INFO]: Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 for TLSv1.1
22:10:11 [INFO]: Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 for TLSv1.1
22:10:11 [INFO]: %% No cached client session
22:10:11 [INFO]: update handshake state: client_hello[1]
22:10:11 [INFO]: upcoming handshake states: server_hello[2]
22:10:11 [INFO]: *** ClientHello, TLSv1.2
22:10:11 [INFO]: RandomCookie:  GMT: 1581958675 bytes = { 29, 173, 209, 85, 78, 39, 30, 178, 57, 81, 183, 157, 198, 154, 57, 236, 177, 149, 56, 210, 137, 13, 12, 74, 220, 126, 49, 194 }
22:10:11 [INFO]: Session ID:  {}
22:10:11 [INFO]: Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
22:10:11 [INFO]: Compression Methods:  { 0 }
22:10:11 [INFO]: Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1}
22:10:11 [INFO]: Extension ec_point_formats, formats: [uncompressed]
22:10:11 [INFO]: Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA224withECDSA, SHA224withRSA, SHA224withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA, MD5withRSA
22:10:11 [INFO]: Extension extended_master_secret
22:10:11 [INFO]: ***
22:10:11 [INFO]: Thread-34, WRITE: TLSv1.2 Handshake, length = 201
22:10:11 [INFO]: Thread-34, WRITE: SSLv2 client hello message, length = 206
22:10:11 [INFO]: Thread-34, READ: TLSv1 Alert, length = 2
22:10:11 [INFO]: Thread-34, RECV TLSv1.2 ALERT:  fatal, handshake_failure
22:10:11 [INFO]: Thread-34, called closeSocket()
22:10:11 [INFO]: Thread-34, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
22:10:11 [INFO]: Thread-34, called close()
22:10:11 [INFO]: Thread-34, called closeInternal(true)
22:10:11 [WARN]: Could not submit plugin stats of WorldEdit
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[?:1.8.0_242]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1127) ~[?:1.8.0_242]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367) ~[?:1.8.0_242]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395) ~[?:1.8.0_242]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379) ~[?:1.8.0_242]
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) ~[?:1.8.0_242]
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) ~[?:1.8.0_242]
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1340) ~[?:1.8.0_242]
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1315) ~[?:1.8.0_242]
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:264) ~[?:1.8.0_242]
        at com.sk89q.worldedit.bukkit.bstats.bukkit.Metrics.sendData(Metrics.java:351) ~[?:?]
        at com.sk89q.worldedit.bukkit.bstats.bukkit.Metrics.access$300(Metrics.java:30) ~[?:?]
        at com.sk89q.worldedit.bukkit.bstats.bukkit.Metrics$2.run(Metrics.java:307) ~[?:?]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_242]

Filter Global Stats by MC Version

Can support be added to filter the Global Stats page by Minecraft version? IE choosing 1.15.2 only shows you the global stats of servers on 1.15.2.

maybe even multi select so can say "1.13+" too.

Sort Problems after Sorting with Mobile Version

I sort the charts from my Plugin with my Phone in the Webbrowser. That was very buggy and didn't worke. After this it didn't worke on my Pc too.

Informations:
Phone Browser: Samsung Internet Beta
Pc Browser: Opera Dev
Phone: Samsung Galaxy S7 edge
PluginName: EasyMaintenance
Version: Full Version(Not Lite) Bukkit Edition

[Idea] Counter chart

Hi,
Could you make a counter, it would be useful for my anticheat plugin for example a "player banned" counter, or things like that.
Thanks

Unknown user registered my plugin

Hello there, I recently decided to move my plugins from McStats over to bStats (huge kudos for making such an awesome service!). As the title suggests, I found out that somebody else has already registered my plugin under their own account.

The plugin can be found here on bStats and here on Bukkit. Although not a big deal, I was wondering whether there was a way to transfer the ownership back to me?

Thanks in advance!

License question

Hi,

I want to use your Metrics for my plugin. I added a simple isEnabled method:
private YamlConfiguration config; public boolean isEnabled() { return config.getBoolean("enabled"); }
How shall I state this change from your orginal?

And as you write in your License I have to include your copyright and license.
Where do I find your copyright?
Do I need to implement "your" GNU Lesser General Public License v3.0 too, if I use it on my own plugin?

Mistakes/errors

Problems:

  • My problem would be that when I add some charts I can not delete it afterwards because it will not let me.

  • The next issue is to indicate offline mode when the server is running properly.

  • The other problem is that when I encoded the charts and added I wait about. The page is refreshed for one and a half hours, and no number is shown in the charts. Here is the code I wrote very hard:

  	Metrics metrics = new Metrics(this);
  	Integer dela = getConfig().getInt("teleport-delay");
  	metrics.addCustomChart(new Metrics.SimplePie("teleport_delay", new Callable<String>() {
  		@Override
  		public String call() throws Exception {
  			return dela.toString();
  			}
  		}));

Here's an example of just running a server: https://bstats.org/plugin/bukkit/SetTheSpawn/#teleport_delay
https://bstats.org/plugin/bukkit/SetTheSpawn/#onlineMode

Allow a new type of data (kind of?)

Sorry for the title, I couldn't come up with a better one.

Anyway, we are having a discussion about whether ViaVersion should add bStat or not: ViaVersion/ViaVersion#1343

Some of us would love to see a graph that shows X% of the users are using Minecraft-1.8.8 and another Y% are using 1.12.2. But because multiple servers can have the same players this would need some action on the backend. So would it be possible to come up with a method that would allow creating such graphs? And of course, keeping the players anonymous?
I've never had the time to really work on the topic hashes but would cryptographic ones of the UUIDs be enough for such a thing?

Charts

I really want to delete all of the default charts and only use the ones i want.

Metrics#startup(GamePreInitializationEvent) is not called on Sponge for some reason

I am getting an error with bStats 2.1.0 and 2.2.1 on Sponge 7.3.0 when attempting to register a custom chart.

java.lang.NullPointerException: null
        at com.djrapitops.plan.utilities.metrics.sponge.Metrics.addCustomChart(Metrics.java:179) ~[Metrics.class:?]
        at com.djrapitops.plan.BStatsSponge.addStringSettingPie(BStatsSponge.java:56) ~[BStatsSponge.class:?]
        at com.djrapitops.plan.BStatsSponge.registerConfigSettingGraphs(BStatsSponge.java:51) ~[BStatsSponge.class:?]
        at com.djrapitops.plan.BStatsSponge.registerMetrics(BStatsSponge.java:43) ~[BStatsSponge.class:?]
        at com.djrapitops.plan.BStatsSponge.run(BStatsSponge.java:38) ~[BStatsSponge.class:?]
        at com.djrapitops.plugin.task.sponge.SpongeRunnableFactory$1.run(SpongeRunnableFactory.java:57) ~[SpongeRunnableFactory$1.class:?]
        at org.spongepowered.api.scheduler.Task$Builder.lambda$execute$0(Task.java:139) ~[Task$Builder.class:1.12.2-7.3.0]
        at org.spongepowered.common.scheduler.SchedulerBase.lambda$startTask$0(SchedulerBase.java:197) ~[SchedulerBase.class:1.12.2-7.3.0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_241]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_241]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_241]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_241]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]

Upon closer inspection metricsBase does not get initialized, so the startup listener method was not called for some reason. I attempted to sort out the issue by running a task 10 seconds after GameStartedServerEvent (when my plugin starts), but it did not have an effect.

Sponge version: latest recommended build https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/1.12.2-7.3.0/spongevanilla-1.12.2-7.3.0.jar

This server is running SpongeVanilla version 1.12.2-7.3.0

I have temporarily solved this issue by calling metrics.startup(null); before attempting to register the charts.


Code if needed
/*
 *  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.plugin.task.AbsRunnable;
import org.bstats.charts.SimplePie;
import org.bstats.sponge.Metrics;

import java.io.Serializable;

public class BStatsSponge extends AbsRunnable {

    private final Metrics metrics;
    private final Database database;

    public BStatsSponge(Metrics metrics, Database database) {
        this.metrics = metrics;
        this.database = database;
    }

    @Override
    public void run() {
        metrics.startup(null);
        registerMetrics();
    }

    public void registerMetrics() {
        if (metrics != null) {
            registerConfigSettingGraphs();
        }
    }

    private void registerConfigSettingGraphs() {
        String serverType = "Sponge";
        String databaseType = database.getType().getName();

        addStringSettingPie("server_type", serverType);
        addStringSettingPie("database_type", databaseType);
    }

    protected void addStringSettingPie(String id, Serializable setting) {
        metrics.addCustomChart(new SimplePie(id, setting::toString));
    }
}
/*
 *  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.commands.use.SpongeCommand;
import com.djrapitops.plan.commands.use.Subcommand;
import com.djrapitops.plan.exceptions.EnableException;
import com.djrapitops.plan.gathering.ServerShutdownSave;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.lang.PluginLang;
import com.djrapitops.plan.settings.theme.PlanColorScheme;
import com.djrapitops.plugin.SpongePlugin;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.logging.L;
import org.bstats.sponge.Metrics;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandManager;
import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.scheduler.Task;

import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

@Plugin(
        id = "plan",
        name = "Plan",
        version = "@version@",
        description = "Player Analytics Plugin by AuroraLS3",
        authors = {"AuroraLS3"},
        dependencies = {
                @Dependency(id = "griefprevention", optional = true),
                @Dependency(id = "luckperms", optional = true),
                @Dependency(id = "nucleus", optional = true),
                @Dependency(id = "redprotect", optional = true),
                @Dependency(id = "nuvotifier", optional = true)
        }
)
public class PlanSponge extends SpongePlugin implements PlanPlugin {

    @com.google.inject.Inject
    private Metrics.Factory metrics;

    @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;

    private final Map<String, CommandMapping> commands = new HashMap<>();

    @Listener
    public void onServerStart(GameStartedServerEvent event) {
        onEnable();
    }

    @Listener
    public void onServerStop(GameStoppingServerEvent event) {
        onDisable();
    }

    @Override
    public void onEnable() {
        PlanSpongeComponent component = DaggerPlanSpongeComponent.builder().plan(this).build();
        try {
            system = component.system();
            serverShutdownSave = component.serverShutdownSave();
            locale = system.getLocaleSystem().getLocale();
            system.enable();

            int pluginId = 3086;
            runnableFactory.create(null, new BStatsSponge(
                    metrics.make(pluginId),
                    system.getDatabaseSystem().getDatabase()
            )).runTaskLaterAsynchronously(TimeAmount.toTicks(10, TimeUnit.SECONDS));

            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.");
        } catch (EnableException e) {
            logger.error("----------------------------------------");
            logger.error("Error: " + e.getMessage());
            logger.error("----------------------------------------");
            logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
            onDisable();
        } catch (Exception e) {
            errorHandler.log(L.CRITICAL, this.getClass(), e);
            logger.error("Plugin Failed to Initialize Correctly. If this issue is caused by config settings you can use /plan reload");
            logger.error("This error should be reported at https://github.com/plan-player-analytics/Plan/issues");
            onDisable();
        }
        registerCommand(component.planCommand().build());
        if (system != null) {
            system.getProcessing().submitNonCritical(() -> system.getListenerSystem().callEnableEvent(this));
        }
    }

    @Override
    public void onDisable() {
        if (serverShutdownSave != null) serverShutdownSave.performSave();
        cancelAllTasks();
        if (system != null) system.disable();

        logger.info(locale.getString(PluginLang.DISABLED));
    }

    @Override
    public void cancelAllTasks() {
        runnableFactory.cancelAllKnownTasks();
        for (Task task : Sponge.getScheduler().getScheduledTasks(this)) {
            task.cancel();
        }
    }

    @Override
    public InputStream getResource(String resource) {
        return getClass().getResourceAsStream("/" + resource);
    }

    @Override
    public ColorScheme getColorScheme() {
        return PlanColorScheme.create(system.getConfigSystem().getConfig(), logger);
    }

    @Override
    public void onReload() {
        // Nothing to be done, systems are disabled
    }

    @Override
    public boolean isReloading() {
        return false;
    }

    @Override
    public void registerCommand(Subcommand command) {
        if (command == null) {
            logger.warn("Attempted to register a null command!");
            return;
        }
        for (String name : command.getAliases()) {
            CommandManager commandManager = Sponge.getCommandManager();

            CommandMapping registered = commands.get(name);
            if (registered != null) {
                commandManager.removeMapping(registered);
            }

            Optional<CommandMapping> register = commandManager.register(this, new SpongeCommand(runnableFactory, system.getErrorLogger(), command), name);
            register.ifPresent(commandMapping -> commands.put(name, commandMapping));
        }
    }

    @Override
    public Logger getLogger() {
        return slf4jLogger;
    }

    @Override
    public File getDataFolder() {
        return dataFolder;
    }

    @Override
    public String getVersion() {
        return getClass().getAnnotation(Plugin.class).version();
    }

    @Override
    public PlanSystem getSystem() {
        return system;
    }

    public Game getGame() {
        return Sponge.getGame();
    }
}

Multiple plugins using bStats-Metrics

We've discovered a strange behaviour when mutiple plugins use bStats-Metrics: Only one/the first loaded (?) plugin is sending it's metrics, others don't. So other plugins won't update on the metrics website (see https://bstats.org/plugin/bukkit/Bedrock for example).

Can you please fix that, so that all plugins will report their existence/data?

Firewall settings for bStats

I am using bStats for my plugins and figured out that on some of my servers i am testing that, bStats isn't reporting statistics.

I have some strict firewall settings for incoming traffic, are there some special ports to be whitelisted for making bStats working?

Hey thanks for the Sponge Port.

Could you make it so that when Metrics starts, it logs that it's started and the plugin that has embedded it (on Sponge) It would make it easier to know if we have correctly started the plugin and if stats are being collected.

Players' locales in the default statistics?

Hi,

I'm authoring some plugins and using bStats to grab some statistics on them. And it works great! Many thanks for the work you put in this :)

This being said, I think an additional piece of statistics could be useful for most plugins: the locale of the players. It's quite easy to retrieve the clients' locale (here on Bukkit implementations, but as the locale is in a field in the NMS Player, that would be pretty easy on other servers as well), and for translated plugins, that's a really useful piece of information, to know what are the players' tongue and where to put translations efforts.

Of course, we already have the servers' locations, but that's not the same: there's a lot of big servers hosted on a country other than its players, and you have the same bias if a provider in a close country is cheap (like some French servers providers).

If you don't think this is a good idea, I'll simply use a custom graph, easy; but I think such a feature could be useful for most plugins&mods :).

Thanks for reading and have a nice day!

Push stats on shutdown

Hey,

it would be nice if stats can also be pushed on shutdown. As it is only pushed every 30 minutes, there might be no data if the server run only 29 minutes. :/

Server Version not counting

Am I crazy or is something wrong with the server version pie chart?

I use the default Spigot metrics class, with only one change (plugin name, added + "-ReRelease")
Everything else on there seems accurate, but for the server version pie it shows spigot and only 2 servers, where as (at the time of me posting this) there are 86 servers connected.
GriefPreventionFlags-ReRelease

Heres a link to my REPO if anyone wants to see in the event something is wrong with my metrics class.

Thank you for reading!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.