Add bStats metrics

This commit is contained in:
Norbi Peti 2021-03-03 16:48:43 +01:00
parent d70fb4f812
commit 8770debfef
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 48 additions and 5 deletions

28
pom.xml
View file

@ -23,6 +23,28 @@
</compilerArgs> </compilerArgs>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>buttondevteam.customdimensions.bstats</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
@ -50,6 +72,12 @@
<version>0.3.0</version> <version>0.3.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>

View file

@ -3,8 +3,11 @@ package buttondevteam.customdimensions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Callables;
import com.mojang.serialization.Lifecycle; import com.mojang.serialization.Lifecycle;
import net.minecraft.server.v1_16_R3.*; import net.minecraft.server.v1_16_R3.*;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer; import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
@ -18,8 +21,11 @@ import java.io.IOException;
import java.util.*; import java.util.*;
public class CustomDimensions extends JavaPlugin implements Listener { public class CustomDimensions extends JavaPlugin implements Listener {
private Metrics metrics;
@Override @Override
public void onEnable() { public void onEnable() {
metrics = new Metrics(this, 10545);
getLogger().info("Loading custom dimensions..."); getLogger().info("Loading custom dimensions...");
try { try {
load(); load();
@ -46,26 +52,33 @@ public class CustomDimensions extends JavaPlugin implements Listener {
saveConfig(); saveConfig();
} }
var ignored = getConfig().getStringList("ignored"); var ignored = getConfig().getStringList("ignored");
int allCount = -3, loadedCount = 0, ignoredCount = 0; //-3: overworld, nether, end
for (var dimEntry : dimensionRegistry.d()) { for (var dimEntry : dimensionRegistry.d()) {
allCount++;
if (ignored.contains(dimEntry.getKey().a().getKey())) { if (ignored.contains(dimEntry.getKey().a().getKey())) {
getLogger().info(dimEntry.getKey() + " is on the ignore list"); getLogger().info(dimEntry.getKey() + " is on the ignore list");
ignoredCount++;
continue; continue;
} }
try { try {
loadDimension(dimEntry.getKey(), dimEntry.getValue(), convertable, console, mainWorld); if (loadDimension(dimEntry.getKey(), dimEntry.getValue(), convertable, console, mainWorld))
loadedCount++;
} catch (Exception e) { } catch (Exception e) {
getLogger().warning("Failed to load dimension " + dimEntry.getKey()); getLogger().warning("Failed to load dimension " + dimEntry.getKey());
e.printStackTrace(); e.printStackTrace();
} }
} }
metrics.addCustomChart(new SimplePie("all_custom_dimensions", Callables.returning(allCount + "")));
metrics.addCustomChart(new SimplePie("loaded_custom_dimensions", Callables.returning(loadedCount + "")));
metrics.addCustomChart(new SimplePie("ignored_custom_dimensions", Callables.returning(ignoredCount + "")));
} }
private void loadDimension(ResourceKey<WorldDimension> dimKey, WorldDimension dimension, private boolean loadDimension(ResourceKey<WorldDimension> dimKey, WorldDimension dimension,
Convertable convertable, DedicatedServer console, org.bukkit.World mainWorld) throws IOException { Convertable convertable, DedicatedServer console, org.bukkit.World mainWorld) throws IOException {
if (dimKey == WorldDimension.OVERWORLD //The default dimensions are already loaded if (dimKey == WorldDimension.OVERWORLD //The default dimensions are already loaded
|| dimKey == WorldDimension.THE_NETHER || dimKey == WorldDimension.THE_NETHER
|| dimKey == WorldDimension.THE_END) || dimKey == WorldDimension.THE_END)
return; return false;
ResourceKey<World> worldKey = ResourceKey.a(IRegistry.L, dimKey.a()); ResourceKey<World> worldKey = ResourceKey.a(IRegistry.L, dimKey.a());
DimensionManager dimensionmanager = dimension.b(); DimensionManager dimensionmanager = dimension.b();
ChunkGenerator chunkgenerator = dimension.c(); ChunkGenerator chunkgenerator = dimension.c();
@ -74,7 +87,7 @@ public class CustomDimensions extends JavaPlugin implements Listener {
name = dimKey.a().getKey(); name = dimKey.a().getKey();
if (Bukkit.getWorld(name) != null) { if (Bukkit.getWorld(name) != null) {
getLogger().info(name + " already loaded"); getLogger().info(name + " already loaded");
return; return false;
} }
getLogger().info("Loading " + name); getLogger().info("Loading " + name);
var session = convertable.new ConversionSession(name, dimKey) { //The original session isn't prepared for custom dimensions var session = convertable.new ConversionSession(name, dimKey) { //The original session isn't prepared for custom dimensions
@ -135,6 +148,7 @@ public class CustomDimensions extends JavaPlugin implements Listener {
if (Bukkit.getWorld(name.toLowerCase(Locale.ENGLISH)) == null) { if (Bukkit.getWorld(name.toLowerCase(Locale.ENGLISH)) == null) {
getLogger().warning("Failed to load custom dimension " + name); getLogger().warning("Failed to load custom dimension " + name);
return false;
} else { } else {
console.initWorld(worldserver, worlddata, worlddata, worlddata.getGeneratorSettings()); console.initWorld(worldserver, worlddata, worlddata, worlddata.getGeneratorSettings());
worldserver.setSpawnFlags(true, true); worldserver.setSpawnFlags(true, true);
@ -142,6 +156,7 @@ public class CustomDimensions extends JavaPlugin implements Listener {
Bukkit.getPluginManager().callEvent(new WorldInitEvent(worldserver.getWorld())); Bukkit.getPluginManager().callEvent(new WorldInitEvent(worldserver.getWorld()));
console.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver); console.loadSpawn(worldserver.getChunkProvider().playerChunkMap.worldLoadListener, worldserver);
Bukkit.getPluginManager().callEvent(new WorldLoadEvent(worldserver.getWorld())); Bukkit.getPluginManager().callEvent(new WorldLoadEvent(worldserver.getWorld()));
return true;
} }
} }
} }