diff --git a/paper-server/patches/sources/net/minecraft/stats/ServerStatsCounter.java.patch b/paper-server/patches/sources/net/minecraft/stats/ServerStatsCounter.java.patch index 65bbb793d8..88534eabcc 100644 --- a/paper-server/patches/sources/net/minecraft/stats/ServerStatsCounter.java.patch +++ b/paper-server/patches/sources/net/minecraft/stats/ServerStatsCounter.java.patch @@ -5,7 +5,37 @@ package net.minecraft.stats; import com.google.common.collect.Maps; -@@ -158,13 +159,12 @@ +@@ -47,6 +48,13 @@ + public ServerStatsCounter(MinecraftServer server, File file) { + this.server = server; + this.file = file; ++ // Spigot start ++ for ( Map.Entry entry : org.spigotmc.SpigotConfig.forcedStats.entrySet() ) ++ { ++ Stat wrapper = Stats.CUSTOM.get( entry.getKey() ); ++ this.stats.put( wrapper, entry.getValue().intValue() ); ++ } ++ // Spigot end + if (file.isFile()) { + try { + this.parseLocal(server.getFixerUpper(), FileUtils.readFileToString(file)); +@@ -60,6 +68,7 @@ + } + + public void save() { ++ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot + try { + FileUtils.writeStringToFile(this.file, this.toJson()); + } catch (IOException ioexception) { +@@ -70,6 +79,7 @@ + + @Override + public void setValue(Player player, Stat stat, int value) { ++ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot + super.setValue(player, stat, value); + this.dirty.add(stat); + } +@@ -158,13 +168,12 @@ } private Optional> getStat(StatType type, String id) { diff --git a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java b/paper-server/src/main/java/org/spigotmc/SpigotConfig.java index 42c22e09de..95d81885f2 100644 --- a/paper-server/src/main/java/org/spigotmc/SpigotConfig.java +++ b/paper-server/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.ResourceLocation; 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 forcedStats = new HashMap<>(); + private static void stats() + { + SpigotConfig.disableStatSaving = SpigotConfig.getBoolean( "stats.disable-saving", false ); + + if ( !SpigotConfig.config.contains( "stats.forced-stats" ) ) { + SpigotConfig.config.createSection( "stats.forced-stats" ); + } + + ConfigurationSection section = SpigotConfig.config.getConfigurationSection( "stats.forced-stats" ); + for ( String name : section.getKeys( true ) ) + { + if ( section.isInt( name ) ) + { + try + { + ResourceLocation key = ResourceLocation.parse( name ); + if ( BuiltInRegistries.CUSTOM_STAT.get( key ) == null ) + { + Bukkit.getLogger().log(Level.WARNING, "Ignoring non existent stats.forced-stats " + name); + continue; + } + SpigotConfig.forcedStats.put( key, section.getInt( name ) ); + } catch (Exception ex) + { + Bukkit.getLogger().log(Level.WARNING, "Ignoring invalid stats.forced-stats " + name); + } + } + } + } }