Allow statistics to be disabled/forced
This commit is contained in:
parent
1e8cb6d468
commit
4ed5d54dde
@ -1,4 +1,4 @@
|
|||||||
From 40f35de3f974c832544ea0f1dfa24c8281688606 Mon Sep 17 00:00:00 2001
|
From 023df056c334c6f5e41eea9b32c722dc85d7622c Mon Sep 17 00:00:00 2001
|
||||||
From: md_5 <md_5@live.com.au>
|
From: md_5 <md_5@live.com.au>
|
||||||
Date: Sun, 1 Dec 2013 15:10:48 +1100
|
Date: Sun, 1 Dec 2013 15:10:48 +1100
|
||||||
Subject: [PATCH] mc-dev imports
|
Subject: [PATCH] mc-dev imports
|
||||||
@ -1609,6 +1609,213 @@ index 0000000..900ed68
|
|||||||
+ return regionfile.b(i & 31, j & 31);
|
+ return regionfile.b(i & 31, j & 31);
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/ServerStatisticManager.java b/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..2f980cb
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
||||||
|
@@ -0,0 +1,201 @@
|
||||||
|
+package net.minecraft.server;
|
||||||
|
+
|
||||||
|
+import java.io.File;
|
||||||
|
+import java.io.IOException;
|
||||||
|
+import java.lang.reflect.Constructor;
|
||||||
|
+import java.util.HashMap;
|
||||||
|
+import java.util.HashSet;
|
||||||
|
+import java.util.Iterator;
|
||||||
|
+import java.util.Map;
|
||||||
|
+import java.util.Set;
|
||||||
|
+import java.util.Map.Entry;
|
||||||
|
+
|
||||||
|
+import net.minecraft.util.com.google.common.collect.Maps;
|
||||||
|
+import net.minecraft.util.com.google.common.collect.Sets;
|
||||||
|
+import net.minecraft.util.com.google.gson.JsonElement;
|
||||||
|
+import net.minecraft.util.com.google.gson.JsonObject;
|
||||||
|
+import net.minecraft.util.com.google.gson.JsonParseException;
|
||||||
|
+import net.minecraft.util.com.google.gson.JsonParser;
|
||||||
|
+import net.minecraft.util.org.apache.commons.io.FileUtils;
|
||||||
|
+import org.apache.logging.log4j.LogManager;
|
||||||
|
+import org.apache.logging.log4j.Logger;
|
||||||
|
+
|
||||||
|
+public class ServerStatisticManager extends StatisticManager {
|
||||||
|
+
|
||||||
|
+ private static final Logger b = LogManager.getLogger();
|
||||||
|
+ private final MinecraftServer c;
|
||||||
|
+ private final File d;
|
||||||
|
+ private final Set e = Sets.newHashSet();
|
||||||
|
+ private int f = -300;
|
||||||
|
+ private boolean g = false;
|
||||||
|
+
|
||||||
|
+ public ServerStatisticManager(MinecraftServer minecraftserver, File file1) {
|
||||||
|
+ this.c = minecraftserver;
|
||||||
|
+ this.d = file1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void a() {
|
||||||
|
+ if (this.d.isFile()) {
|
||||||
|
+ try {
|
||||||
|
+ this.a.clear();
|
||||||
|
+ this.a.putAll(this.a(FileUtils.readFileToString(this.d)));
|
||||||
|
+ } catch (IOException ioexception) {
|
||||||
|
+ b.error("Couldn\'t read statistics file " + this.d, ioexception);
|
||||||
|
+ } catch (JsonParseException jsonparseexception) {
|
||||||
|
+ b.error("Couldn\'t parse statistics file " + this.d, jsonparseexception);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void b() {
|
||||||
|
+ try {
|
||||||
|
+ FileUtils.writeStringToFile(this.d, a(this.a));
|
||||||
|
+ } catch (IOException ioexception) {
|
||||||
|
+ b.error("Couldn\'t save stats", ioexception);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void a(EntityHuman entityhuman, Statistic statistic, int i) {
|
||||||
|
+ int j = statistic.d() ? this.a(statistic) : 0;
|
||||||
|
+
|
||||||
|
+ super.a(entityhuman, statistic, i);
|
||||||
|
+ this.e.add(statistic);
|
||||||
|
+ if (statistic.d() && j == 0 && i > 0) {
|
||||||
|
+ this.g = true;
|
||||||
|
+ if (this.c.ar()) {
|
||||||
|
+ this.c.getPlayerList().sendMessage(new ChatMessage("chat.type.achievement", new Object[] { entityhuman.getScoreboardDisplayName(), statistic.j()}));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public Set c() {
|
||||||
|
+ HashSet hashset = Sets.newHashSet(this.e);
|
||||||
|
+
|
||||||
|
+ this.e.clear();
|
||||||
|
+ this.g = false;
|
||||||
|
+ return hashset;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public Map a(String s) {
|
||||||
|
+ JsonElement jsonelement = (new JsonParser()).parse(s);
|
||||||
|
+
|
||||||
|
+ if (!jsonelement.isJsonObject()) {
|
||||||
|
+ return Maps.newHashMap();
|
||||||
|
+ } else {
|
||||||
|
+ JsonObject jsonobject = jsonelement.getAsJsonObject();
|
||||||
|
+ HashMap hashmap = Maps.newHashMap();
|
||||||
|
+ Iterator iterator = jsonobject.entrySet().iterator();
|
||||||
|
+
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ Entry entry = (Entry) iterator.next();
|
||||||
|
+ Statistic statistic = StatisticList.a((String) entry.getKey());
|
||||||
|
+
|
||||||
|
+ if (statistic != null) {
|
||||||
|
+ StatisticWrapper statisticwrapper = new StatisticWrapper();
|
||||||
|
+
|
||||||
|
+ if (((JsonElement) entry.getValue()).isJsonPrimitive() && ((JsonElement) entry.getValue()).getAsJsonPrimitive().isNumber()) {
|
||||||
|
+ statisticwrapper.a(((JsonElement) entry.getValue()).getAsInt());
|
||||||
|
+ } else if (((JsonElement) entry.getValue()).isJsonObject()) {
|
||||||
|
+ JsonObject jsonobject1 = ((JsonElement) entry.getValue()).getAsJsonObject();
|
||||||
|
+
|
||||||
|
+ if (jsonobject1.has("value") && jsonobject1.get("value").isJsonPrimitive() && jsonobject1.get("value").getAsJsonPrimitive().isNumber()) {
|
||||||
|
+ statisticwrapper.a(jsonobject1.getAsJsonPrimitive("value").getAsInt());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (jsonobject1.has("progress") && statistic.l() != null) {
|
||||||
|
+ try {
|
||||||
|
+ Constructor constructor = statistic.l().getConstructor(new Class[0]);
|
||||||
|
+ IJsonStatistic ijsonstatistic = (IJsonStatistic) constructor.newInstance(new Object[0]);
|
||||||
|
+
|
||||||
|
+ statisticwrapper.a(ijsonstatistic);
|
||||||
|
+ } catch (Throwable throwable) {
|
||||||
|
+ b.warn("Invalid statistic progress in " + this.d, throwable);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ hashmap.put(statistic, statisticwrapper);
|
||||||
|
+ } else {
|
||||||
|
+ b.warn("Invalid statistic in " + this.d + ": Don\'t know what " + (String) entry.getKey() + " is");
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return hashmap;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public static String a(Map map) {
|
||||||
|
+ JsonObject jsonobject = new JsonObject();
|
||||||
|
+ Iterator iterator = map.entrySet().iterator();
|
||||||
|
+
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ Entry entry = (Entry) iterator.next();
|
||||||
|
+
|
||||||
|
+ if (((StatisticWrapper) entry.getValue()).b() != null) {
|
||||||
|
+ JsonObject jsonobject1 = new JsonObject();
|
||||||
|
+
|
||||||
|
+ jsonobject1.addProperty("value", Integer.valueOf(((StatisticWrapper) entry.getValue()).a()));
|
||||||
|
+
|
||||||
|
+ try {
|
||||||
|
+ jsonobject1.add("progress", ((StatisticWrapper) entry.getValue()).b().a());
|
||||||
|
+ } catch (Throwable throwable) {
|
||||||
|
+ b.warn("Couldn\'t save statistic " + ((Statistic) entry.getKey()).e() + ": error serializing progress", throwable);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ jsonobject.add(((Statistic) entry.getKey()).e, jsonobject1);
|
||||||
|
+ } else {
|
||||||
|
+ jsonobject.addProperty(((Statistic) entry.getKey()).e, Integer.valueOf(((StatisticWrapper) entry.getValue()).a()));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return jsonobject.toString();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void d() {
|
||||||
|
+ Iterator iterator = this.a.keySet().iterator();
|
||||||
|
+
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ Statistic statistic = (Statistic) iterator.next();
|
||||||
|
+
|
||||||
|
+ this.e.add(statistic);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void a(EntityPlayer entityplayer) {
|
||||||
|
+ int i = this.c.aj();
|
||||||
|
+ HashMap hashmap = Maps.newHashMap();
|
||||||
|
+
|
||||||
|
+ if (this.g || i - this.f > 300) {
|
||||||
|
+ this.f = i;
|
||||||
|
+ Iterator iterator = this.c().iterator();
|
||||||
|
+
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ Statistic statistic = (Statistic) iterator.next();
|
||||||
|
+
|
||||||
|
+ hashmap.put(statistic, Integer.valueOf(this.a(statistic)));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutStatistic(hashmap));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void b(EntityPlayer entityplayer) {
|
||||||
|
+ HashMap hashmap = Maps.newHashMap();
|
||||||
|
+ Iterator iterator = AchievementList.e.iterator();
|
||||||
|
+
|
||||||
|
+ while (iterator.hasNext()) {
|
||||||
|
+ Achievement achievement = (Achievement) iterator.next();
|
||||||
|
+
|
||||||
|
+ if (this.a(achievement)) {
|
||||||
|
+ hashmap.put(achievement, Integer.valueOf(this.a((Statistic) achievement)));
|
||||||
|
+ this.e.remove(achievement);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutStatistic(hashmap));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public boolean e() {
|
||||||
|
+ return this.g;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
diff --git a/src/main/java/net/minecraft/server/StructureGenerator.java b/src/main/java/net/minecraft/server/StructureGenerator.java
|
diff --git a/src/main/java/net/minecraft/server/StructureGenerator.java b/src/main/java/net/minecraft/server/StructureGenerator.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..1eb87ae
|
index 0000000..1eb87ae
|
||||||
@ -1990,5 +2197,5 @@ index 0000000..c0db754
|
|||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
--
|
--
|
||||||
1.8.3.2
|
1.8.4.msysgit.0
|
||||||
|
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
From c73eb8c8476907817b0690014e5003e79f43dc1e 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/server/ServerStatisticManager.java b/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
||||||
|
index 2f980cb..3f78728 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/ServerStatisticManager.java
|
||||||
|
@@ -32,6 +32,14 @@ public class ServerStatisticManager extends StatisticManager {
|
||||||
|
public ServerStatisticManager(MinecraftServer minecraftserver, File file1) {
|
||||||
|
this.c = minecraftserver;
|
||||||
|
this.d = file1;
|
||||||
|
+ // Spigot start
|
||||||
|
+ for ( String name : org.spigotmc.SpigotConfig.forcedStats.keySet() )
|
||||||
|
+ {
|
||||||
|
+ StatisticWrapper wrapper = new StatisticWrapper();
|
||||||
|
+ wrapper.a( org.spigotmc.SpigotConfig.forcedStats.get( name ) );
|
||||||
|
+ a.put( StatisticList.a( name ), wrapper );
|
||||||
|
+ }
|
||||||
|
+ // Spigot end
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a() {
|
||||||
|
@@ -48,6 +56,7 @@ public class ServerStatisticManager extends StatisticManager {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void b() {
|
||||||
|
+ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
|
||||||
|
try {
|
||||||
|
FileUtils.writeStringToFile(this.d, a(this.a));
|
||||||
|
} catch (IOException ioexception) {
|
||||||
|
@@ -56,6 +65,7 @@ public class ServerStatisticManager extends StatisticManager {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(EntityHuman entityhuman, Statistic statistic, int i) {
|
||||||
|
+ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
|
||||||
|
int j = statistic.d() ? this.a(statistic) : 0;
|
||||||
|
|
||||||
|
super.a(entityhuman, statistic, i);
|
||||||
|
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
|
||||||
|
index cb5002f..17e1d21 100755
|
||||||
|
--- a/src/main/java/org/spigotmc/SpigotConfig.java
|
||||||
|
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
|
||||||
|
@@ -11,11 +11,14 @@ import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
+
|
||||||
|
+import gnu.trove.map.hash.TObjectIntHashMap;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
+import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.craftbukkit.command.TicksPerSecondCommand;
|
||||||
|
|
||||||
|
@@ -220,4 +223,31 @@ public class SpigotConfig
|
||||||
|
private static void lateBind() {
|
||||||
|
lateBind = getBoolean( "settings.late-bind", false );
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ public static boolean disableStatSaving;
|
||||||
|
+ public static TObjectIntHashMap<String> forcedStats = new TObjectIntHashMap<String>();
|
||||||
|
+ 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 ) )
|
||||||
|
+ {
|
||||||
|
+ forcedStats.put( name, section.getInt( name ) );
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if ( disableStatSaving && section.getInt( "achievement.openInventory", 0 ) < 1 )
|
||||||
|
+ {
|
||||||
|
+ Bukkit.getLogger().warning( "*** WARNING *** stats.disable-saving is true but stats.forced-stats.achievement.openInventory" +
|
||||||
|
+ " isn't set to 1. Disabling stat saving without forcing the achievement may cause it to get stuck on the player's " +
|
||||||
|
+ "screen." );
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
--
|
||||||
|
1.8.4.msysgit.0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user