Skip to content

Commit

Permalink
Add bStats metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chuushi committed Mar 30, 2019
1 parent 2eed3ca commit 71dcab4
Show file tree
Hide file tree
Showing 11 changed files with 726 additions and 7 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ dependencies {
processResources {
filter ReplaceTokens, tokens:["version": project.version]
}

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Aug 10 22:05:42 EDT 2018
#Sat Mar 30 02:49:06 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Better Phantom handling for SMP

# Configuration

There are two configuration options that you can set.
There are three core configuration options that you can set.

* `remove-targeting-rested`: *Default: true.* Remove phantoms that try to
target players who recently rested.
Expand Down Expand Up @@ -37,3 +37,4 @@ they will despawn immediately. The same happens when the player is given the

* [Spigot resource link](https://www.spigotmc.org/resources/phantomsmp.59721/)
* [BukkitDev resource link](https://dev.bukkit.org/projects/phantomsmp)
* [bStats Metrics](https://bstats.org/plugin/bukkit/PhantomSMP/)
10 changes: 10 additions & 0 deletions src/main/java/com/simonorj/mc/phantomsmp/ConfigTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ConfigTool {
static final String REMOVE_TARGETING_RESTED_NODE = "remove-targeting-rested";
static final String REMOVE_WHEN_SLEEPING_NODE = "remove-when-sleeping";
static final String DISALLOW_SPAWNING_FOR_NODE = "disallow-targeting-for";
static final String ENABLE_METRICS_NODE = "enable-metrics";
static final String CONFIG_VERSION_NODE = "config-version";
static final int version = 1;

Expand All @@ -32,13 +33,18 @@ class ConfigTool {
"# ignored for phantom spawning. It will only have an effect on already\n" +
"# spawned phantoms only.\n";

private static final String ENABLE_METRICS =
"# Enable metrics for this plugin? (If unsure, leave it as true)\n" +
"# Link to metrics: https://bstats.org/plugin/bukkit/PhantomSMP/\n";

private static final String CONFIG_VERSION =
"# Keeps track of configuration version -- do not change!\n";

static String saveToString(FileConfiguration config) {
boolean remove = config.getBoolean(REMOVE_TARGETING_RESTED_NODE, true);
boolean sleeping = config.getBoolean(REMOVE_WHEN_SLEEPING_NODE, true);
int disallow = config.getInt(DISALLOW_SPAWNING_FOR_NODE, 72000);
boolean metrics = config.getBoolean(ENABLE_METRICS_NODE, true);

return HEADER +
"\n" +
Expand All @@ -54,6 +60,10 @@ static String saveToString(FileConfiguration config) {
DISALLOW_SPAWNING_FOR_NODE +
": " + disallow +
"\n\n" +
ENABLE_METRICS +
ENABLE_METRICS_NODE +
": " + metrics +
"\n\n" +
CONFIG_VERSION +
CONFIG_VERSION_NODE +
": " + version +
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/simonorj/mc/phantomsmp/PhantomSMP.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.simonorj.mc.phantomsmp;

import com.google.common.base.Charsets;
import com.simonorj.mc.phantomsmp.shadow.bstats.bukkit.Metrics;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.*;
Expand All @@ -27,6 +28,15 @@ public void onEnable() {

this.listener = new PhantomListener();
getServer().getPluginManager().registerEvents(listener, this);

if (getConfig().getBoolean(ConfigTool.ENABLE_METRICS_NODE, true))
setupMetrics();
}

private void setupMetrics() {
Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SimplePie("remove-targeting-rested", () -> String.valueOf(removeTargetingRested)));
metrics.addCustomChart(new Metrics.SimplePie("remove-targeting-rested", () -> String.valueOf(removeWhenSleeping)));
}

@Override
Expand Down
Loading

0 comments on commit 71dcab4

Please sign in to comment.