Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Add bStats metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Dec 13, 2023
1 parent 88c0787 commit ba2be7a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 70 deletions.
65 changes: 14 additions & 51 deletions patches/minecraft/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
--- ../src-base/minecraft/net/minecraft/server/MinecraftServer.java
+++ ../src-work/minecraft/net/minecraft/server/MinecraftServer.java
@@ -1,7 +1,11 @@
@@ -1,7 +1,10 @@
package net.minecraft.server;

+import co.aikar.timings.MinecraftTimings;
+import co.aikar.timings.Timing;
+import co.aikar.timings.TimingsManager;
+import com.destroystokyo.paper.utils.CachedSizeConcurrentLinkedQueue;
import com.google.common.collect.Lists;
Expand All @@ -13,7 +12,7 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListenableFutureTask;
@@ -15,97 +19,119 @@
@@ -15,27 +18,20 @@
import io.netty.handler.codec.base64.Base64;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -44,25 +43,8 @@
+import joptsimple.OptionSet;
import net.minecraft.advancements.AdvancementManager;
import net.minecraft.advancements.FunctionManager;
+import net.minecraft.block.Block;
+import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandManager;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.ICrashReportDetail;
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Bootstrap;
+import net.minecraft.item.Item;
import net.minecraft.network.NetworkSystem;
import net.minecraft.network.ServerStatusResponse;
import net.minecraft.network.play.server.SPacketTimeUpdate;
+import net.minecraft.potion.Potion;
import net.minecraft.profiler.ISnooperInfo;
@@ -55,57 +51,62 @@
import net.minecraft.profiler.Profiler;
import net.minecraft.profiler.Snooper;
import net.minecraft.server.dedicated.DedicatedServer;
Expand All @@ -74,7 +56,6 @@
-import net.minecraft.util.ITickable;
-import net.minecraft.util.ReportedException;
-import net.minecraft.util.Util;
+import net.minecraft.tileentity.BannerPattern;
+import net.minecraft.util.*;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.DataFixesManager;
Expand All @@ -100,42 +81,24 @@
import net.minecraft.world.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
+import net.minecraftforge.common.DimensionManager;
+import net.minecraftforge.common.util.EnumHelper;
+import net.minecraftforge.fml.common.FMLCommonHandler;
+import net.minecraftforge.fml.common.registry.EntityRegistry;
+import net.minecraftforge.fml.common.registry.ForgeRegistries;
+import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+import net.minecraftforge.registries.GameData;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.World.Environment;
+import org.bukkit.block.banner.PatternType;
+import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
+import org.bukkit.craftbukkit.v1_12_R1.Main;
+import org.bukkit.craftbukkit.v1_12_R1.chunkio.ChunkIOExecutor;
+import org.bukkit.craftbukkit.v1_12_R1.enchantments.CraftEnchantment;
+import org.bukkit.craftbukkit.v1_12_R1.potion.CraftPotionEffectType;
+import org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboardManager;
+import org.bukkit.craftbukkit.v1_12_R1.util.ServerShutdownThread;
+import org.bukkit.entity.EntityType;
+import org.bukkit.potion.PotionEffectType;
+import org.lwjgl.Sys;
+import org.magmafoundation.magma.Magma;
+import org.magmafoundation.magma.Metrics;
+import org.magmafoundation.magma.Metrics.SimplePie;
+import org.magmafoundation.magma.api.ServerAPI;
+import org.magmafoundation.magma.configuration.MagmaConfig;
+import org.magmafoundation.magma.configuration.value.values.BooleanValue;
+import org.magmafoundation.magma.entity.CraftCustomEntity;
+import org.magmafoundation.magma.forge.ForgeInject;
+import org.magmafoundation.magma.metrics.Metrics;
+import org.magmafoundation.magma.patcher.PatcherManager;
+import org.spigotmc.CustomTimingsHandler;
+import org.spigotmc.SlackActivityAccountant;

-public abstract class MinecraftServer implements ICommandSender, Runnable, IThreadListener, ISnooperInfo
Expand Down Expand Up @@ -168,7 +131,7 @@
private PlayerList field_71318_t;
private boolean field_71317_u = true;
private boolean field_71316_v;
@@ -123,11 +149,11 @@
@@ -123,11 +124,11 @@
private int field_71280_D;
private int field_143008_E;
public final long[] field_71311_j = new long[100];
Expand All @@ -182,7 +145,7 @@
private String field_71287_L;
private boolean field_71288_M;
private boolean field_71289_N;
@@ -143,164 +169,233 @@
@@ -143,164 +144,233 @@
private final GameProfileRepository field_152365_W;
private final PlayerProfileCache field_152366_X;
private long field_147142_T;
Expand Down Expand Up @@ -510,7 +473,7 @@
int i = 16;
int j = 4;
int k = 192;
@@ -308,45 +403,43 @@
@@ -308,45 +378,43 @@
int i1 = 0;
this.func_71192_d("menu.generatingTerrain");
int j1 = 0;
Expand Down Expand Up @@ -580,7 +543,7 @@
}
}

@@ -364,264 +457,340 @@
@@ -364,264 +432,340 @@

public abstract boolean func_183002_r();

Expand Down Expand Up @@ -1034,7 +997,7 @@
this.field_71295_T = false;
this.field_71304_b.field_76327_a = true;
this.field_71304_b.func_76317_a();
@@ -630,23 +799,23 @@
@@ -630,23 +774,23 @@
this.field_71304_b.func_76320_a("root");
this.func_71190_q();

Expand Down Expand Up @@ -1065,7 +1028,7 @@
{
this.field_71304_b.func_76320_a("save");
this.field_71318_t.func_72389_g();
@@ -655,187 +824,231 @@
@@ -655,187 +799,231 @@
}

this.field_71304_b.func_76320_a("tallying");
Expand Down Expand Up @@ -1396,7 +1359,7 @@
}
});
}
@@ -843,145 +1056,115 @@
@@ -843,145 +1031,115 @@
return p_71230_1_;
}

Expand Down Expand Up @@ -1586,7 +1549,7 @@
worldserver1.func_72912_H().func_176144_a(p_147139_1_);
worldserver1.func_72891_a(this.func_71193_K(), this.field_71324_y);
}
@@ -989,80 +1172,75 @@
@@ -989,80 +1147,75 @@
}
}

Expand Down Expand Up @@ -1696,7 +1659,7 @@
++l;
}
}
@@ -1071,228 +1249,193 @@
@@ -1071,228 +1224,193 @@
p_70000_1_.func_152768_a("worlds", Integer.valueOf(l));
}

Expand Down Expand Up @@ -1979,7 +1942,7 @@
return entity;
}
}
@@ -1301,301 +1444,254 @@
@@ -1301,301 +1419,254 @@
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.magmafoundation.magma;
package org.magmafoundation.magma.metrics;

import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.magmafoundation.magma.Magma;
import org.magmafoundation.magma.api.ServerAPI;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.magmafoundation.magma.api.ServerAPI;

/**
* bStats collects some data for plugin authors.
Expand All @@ -55,7 +58,7 @@ public class Metrics {
private static String serverUUID;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
private final String pluginName = "Magma";
private final String pluginName = "Magma Maintained";
private final String pluginVersion = Magma.getVersion();
// Is bStats enabled on this server?
private boolean enabled;
Expand All @@ -82,10 +85,10 @@ public Metrics() {

// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
"To honor their work, you should not disable it.\n" +
"This has nearly no effect on the server performance!\n" +
"Check out https://bStats.org/ to learn more :)"
).copyDefaults(true);
try {
config.save(configFile);
Expand All @@ -100,16 +103,39 @@ public Metrics() {
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);

addCustomChart(new Metrics.SimplePie("minecraft_version", () -> {
addCustomChart(new SimplePie("minecraft_version", () -> {
String version = Bukkit.getVersion();
version = version.substring(version.indexOf("MC: ") + 4, version.length() - 1);
return version;
}));
addCustomChart(new Metrics.SimplePie("number_of_mods", () -> String.valueOf(ServerAPI.getModSize()))); // Report how many mods are running // MAGMA TODO: Add Server API
addCustomChart(new Metrics.SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size()));
addCustomChart(new Metrics.SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online": "offline"));
addCustomChart(new Metrics.SimplePie("server_version", Magma::getVersion));
addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
addCustomChart(new DrilldownPie("mods_vs_plugins", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();

Map<String, Integer> modslist = new HashMap<>();
String[] mods = ServerAPI.getModList().replace("[", "").replace("]", "").split(", ");
for (String x : mods) {
if (x.equals("minecraft") || x.equals("forge")) {
continue;
}
modslist.put(x, 1);
}

Map<String, Integer> pluginlist = new HashMap<>();
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin.isEnabled()) {
pluginlist.put(plugin.getDescription().getName(), 1);
}
}

map.put("mods", modslist);
map.put("plugins", pluginlist);

return map;
}));
addCustomChart(new SingleLineChart("players", () -> Bukkit.getOnlinePlayers().size()));
addCustomChart(new SimplePie("online_mode", () -> Bukkit.getOnlineMode() ? "online": "offline"));
addCustomChart(new SimplePie("server_version", Magma::getVersion));
addCustomChart(new DrilldownPie("java_version", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
Map<String, Integer> entry = new HashMap<>();
entry.put(System.getProperty("java.version"), 1);
Expand Down

0 comments on commit ba2be7a

Please sign in to comment.