Shaded bStats' Metrics

Also removed custom metrics for the moment.
This will later be used to allow addons to register their own metrics :)
This commit is contained in:
Florian CUNY 2018-08-16 13:49:44 +02:00
parent d04b286055
commit 4c319dd0e0
5 changed files with 64 additions and 1081 deletions

35
pom.xml
View File

@ -51,15 +51,27 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots</url>
</repository>
<repository>
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
</repository>
</repositories>
<dependencies>
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Metrics -->
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.2</version>
</dependency>
<!-- Mockito (Unit testing) -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
@ -78,6 +90,7 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<!-- Database -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
@ -166,6 +179,27 @@
<configuration>
<minimizeJar>false</minimizeJar>
</configuration>
<executions>
<execution>
<configuration>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<artifactSet>
<includes>
<include>org.bstats:bstats-bukkit</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>world.bentobox.bentobox.util.metrics</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -213,7 +247,6 @@
<properties>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.organization>tastybento-github</sonar.organization>
<sonar.exclusions>**/Metrics.java</sonar.exclusions>
</properties>
<build>
<plugins>

View File

@ -0,0 +1,22 @@
package world.bentobox.bentobox;
import org.bstats.bukkit.Metrics;
/**
* @author Poslovitch
*/
class BStats {
private final BentoBox plugin;
private Metrics metrics;
BStats(BentoBox plugin) {
this.plugin = plugin;
}
void registerMetrics() {
if (metrics == null) {
metrics = new Metrics(plugin);
}
}
}

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.PluginManager;
@ -40,8 +41,8 @@ public class BentoBox extends JavaPlugin {
private PlayersManager playersManager;
private IslandsManager islandsManager;
// Metrics
private Metrics metrics;
// bStats
private BStats bStats;
// Managers
private CommandsManager commandsManager;
@ -73,7 +74,7 @@ public class BentoBox extends JavaPlugin {
saveDefaultConfig();
setInstance(this);
// Load Flags
flagsManager = new FlagsManager(instance);
flagsManager = new FlagsManager(this);
// Load settings from config.yml. This will check if there are any issues with it too.
settings = new Config<>(this, Settings.class).loadConfigObject("");
@ -90,8 +91,7 @@ public class BentoBox extends JavaPlugin {
headGetter = new HeadGetter(this);
// Load metrics
metrics = new Metrics(instance);
registerCustomCharts();
bStats = new BStats(this);
// Load Notifier
notifier = new Notifier();
@ -138,6 +138,9 @@ public class BentoBox extends JavaPlugin {
instance.log("- Tastybento and Poslovitch, 2017-2018");
instance.log("#############################################");
// Register metrics
bStats.registerMetrics();
// Fire plugin ready event
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
});
@ -180,42 +183,6 @@ public class BentoBox extends JavaPlugin {
}
}
private void registerCustomCharts(){
metrics.addCustomChart(new Metrics.SingleLineChart("islands_count") {
@Override
public int getValue() {
return islandsManager.getCount();
}
});
metrics.addCustomChart(new Metrics.SingleLineChart("created_islands") {
@Override
public int getValue() {
int created = islandsManager.metricsGetCreatedCount();
islandsManager.metricsSetCreatedCount(0);
return created;
}
});
metrics.addCustomChart(new Metrics.SimplePie("default_locale") {
@Override
public String getValue() {
return getSettings().getDefaultLanguage();
}
});
metrics.addCustomChart(new Metrics.SimplePie("database") {
@Override
public String getValue() {
return DatabaseSetup.getDatabase().toString();
}
});
}
/**
* Returns the player database
* @return the player database

File diff suppressed because it is too large Load Diff

View File

@ -65,9 +65,6 @@ public class IslandsManager {
// Async database saving semaphore
private boolean midSave;
// Metrics data
private int metricsCreatedCount = 0;
/**
* Islands Manager
* @param plugin - plugin
@ -624,14 +621,6 @@ public class IslandsManager {
return getIslandAt(loc).filter(i -> i.onIsland(loc)).map(i -> i.getMemberSet().contains(player.getUniqueId())).orElse(false);
}
public int metricsGetCreatedCount(){
return metricsCreatedCount;
}
public void metricsSetCreatedCount(int count){
metricsCreatedCount = count;
}
/**
* Checks if an online player is in the protected area of their island, a team island or a
* coop island in the specific world in the arguments. Note that the user