0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-21 22:06:13 +00:00
spigot/CraftBukkit-Patches/0029-Allow-statistics-to-be-disabled-forced.patch
2024-10-23 02:15:00 +11:00

99 lines
4.1 KiB
Diff

From 78171d3c3fa201db1dbe51033ce2a06d088573e5 Mon Sep 17 00:00:00 2001
From: Thinkofdeath <thethinkofdeath@gmail.com>
Date: Tue, 7 Jan 2014 15:56:26 +0000
Subject: [PATCH] Allow statistics to be disabled/forced
diff --git a/src/main/java/net/minecraft/stats/ServerStatisticManager.java b/src/main/java/net/minecraft/stats/ServerStatisticManager.java
index f9236cd8b9..71766d2e69 100644
--- a/src/main/java/net/minecraft/stats/ServerStatisticManager.java
+++ b/src/main/java/net/minecraft/stats/ServerStatisticManager.java
@@ -48,6 +48,13 @@ public class ServerStatisticManager extends StatisticManager {
public ServerStatisticManager(MinecraftServer minecraftserver, File file) {
this.server = minecraftserver;
this.file = file;
+ // Spigot start
+ for ( Map.Entry<MinecraftKey, Integer> entry : org.spigotmc.SpigotConfig.forcedStats.entrySet() )
+ {
+ Statistic<MinecraftKey> wrapper = StatisticList.CUSTOM.get( entry.getKey() );
+ this.stats.put( wrapper, entry.getValue().intValue() );
+ }
+ // Spigot end
if (file.isFile()) {
try {
this.parseLocal(minecraftserver.getFixerUpper(), FileUtils.readFileToString(file));
@@ -61,6 +68,7 @@ public class ServerStatisticManager extends StatisticManager {
}
public void save() {
+ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
try {
FileUtils.writeStringToFile(this.file, this.toJson());
} catch (IOException ioexception) {
@@ -71,6 +79,7 @@ public class ServerStatisticManager extends StatisticManager {
@Override
public void setValue(EntityHuman entityhuman, Statistic<?> statistic, int i) {
+ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
super.setValue(entityhuman, statistic, i);
this.dirty.add(statistic);
}
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 8091770655..db04e7418d 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -10,10 +10,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -231,4 +234,36 @@ public class SpigotConfig
System.setProperty( "io.netty.eventLoopThreads", Integer.toString( count ) );
Bukkit.getLogger().log( Level.INFO, "Using {0} threads for Netty based IO", count );
}
+
+ public static boolean disableStatSaving;
+ public static Map<MinecraftKey, Integer> forcedStats = new HashMap<>();
+ private static void stats()
+ {
+ disableStatSaving = getBoolean( "stats.disable-saving", false );
+
+ if ( !config.contains( "stats.forced-stats" ) ) {
+ config.createSection( "stats.forced-stats" );
+ }
+
+ ConfigurationSection section = config.getConfigurationSection( "stats.forced-stats" );
+ for ( String name : section.getKeys( true ) )
+ {
+ if ( section.isInt( name ) )
+ {
+ try
+ {
+ MinecraftKey key = MinecraftKey.parse( name );
+ if ( BuiltInRegistries.CUSTOM_STAT.get( key ) == null )
+ {
+ Bukkit.getLogger().log(Level.WARNING, "Ignoring non existent stats.forced-stats " + name);
+ continue;
+ }
+ forcedStats.put( key, section.getInt( name ) );
+ } catch (Exception ex)
+ {
+ Bukkit.getLogger().log(Level.WARNING, "Ignoring invalid stats.forced-stats " + name);
+ }
+ }
+ }
+ }
}
--
2.47.0