141 lines
7.4 KiB
Diff
141 lines
7.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Cryptite <cryptite@gmail.com>
|
|
Date: Tue, 25 Apr 2023 08:15:23 -0500
|
|
Subject: [PATCH] PlayerLoadStatsEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 0913c1be8b4130ada71e7d4f473a709e55b7d2d5..4483bc16c81a5ca088320a28b4723a603b563f7e 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -1495,7 +1495,7 @@ public abstract class PlayerList {
|
|
}
|
|
}
|
|
|
|
- serverstatisticmanager = new ServerStatsCounter(this.server, file1);
|
|
+ serverstatisticmanager = new ServerStatsCounter(this.server, file1, uuid); // Slice
|
|
// this.stats.put(uuid, serverstatisticmanager); // CraftBukkit
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/stats/ServerStatsCounter.java b/src/main/java/net/minecraft/stats/ServerStatsCounter.java
|
|
index 0e02785ec35e635bef33cc89c54b146c8e7dac99..5f13740dbf354291bca33fe91ba581562531f6fe 100644
|
|
--- a/src/main/java/net/minecraft/stats/ServerStatsCounter.java
|
|
+++ b/src/main/java/net/minecraft/stats/ServerStatsCounter.java
|
|
@@ -45,10 +45,16 @@ public class ServerStatsCounter extends StatsCounter {
|
|
private final File file;
|
|
private final Set<Stat<?>> dirty = Sets.newHashSet();
|
|
|
|
- public ServerStatsCounter(MinecraftServer server, File file) {
|
|
+ public ServerStatsCounter(MinecraftServer server, File file, java.util.UUID uuid) { // Slice
|
|
this.server = server;
|
|
this.file = file;
|
|
- if (file.isFile()) {
|
|
+ // Slice start - If event supplies stats, use it. Otherwise just load from disk as usual
|
|
+ com.destroystokyo.paper.event.player.PlayerLoadStatsEvent event = new com.destroystokyo.paper.event.player.PlayerLoadStatsEvent(uuid);
|
|
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
|
|
+ JsonObject providedStats = event.getStatistics();
|
|
+ if (providedStats != null) {
|
|
+ readStats(server.getFixerUpper(), fromJson(providedStats));
|
|
+ } else if (file.isFile()) { // Slice end
|
|
try {
|
|
this.parseLocal(server.getFixerUpper(), FileUtils.readFileToString(file));
|
|
} catch (IOException ioexception) {
|
|
@@ -109,46 +115,8 @@ public class ServerStatsCounter extends StatsCounter {
|
|
|
|
if (!jsonelement.isJsonNull()) {
|
|
CompoundTag nbttagcompound = ServerStatsCounter.fromJson(jsonelement.getAsJsonObject());
|
|
-
|
|
- nbttagcompound = DataFixTypes.STATS.updateToCurrentVersion(dataFixer, nbttagcompound, NbtUtils.getDataVersion(nbttagcompound, 1343));
|
|
- if (!nbttagcompound.contains("stats", 10)) {
|
|
- break label48;
|
|
- }
|
|
-
|
|
- CompoundTag nbttagcompound1 = nbttagcompound.getCompound("stats");
|
|
- Iterator iterator = nbttagcompound1.getAllKeys().iterator();
|
|
-
|
|
- while (true) {
|
|
- if (!iterator.hasNext()) {
|
|
- break label48;
|
|
- }
|
|
-
|
|
- String s1 = (String) iterator.next();
|
|
-
|
|
- if (nbttagcompound1.contains(s1, 10)) {
|
|
- Util.ifElse(BuiltInRegistries.STAT_TYPE.getOptional(new ResourceLocation(s1)), (statisticwrapper) -> {
|
|
- CompoundTag nbttagcompound2 = nbttagcompound1.getCompound(s1);
|
|
- Iterator iterator1 = nbttagcompound2.getAllKeys().iterator();
|
|
-
|
|
- while (iterator1.hasNext()) {
|
|
- String s2 = (String) iterator1.next();
|
|
-
|
|
- if (nbttagcompound2.contains(s2, 99)) {
|
|
- Util.ifElse(this.getStat(statisticwrapper, s2), (statistic) -> {
|
|
- this.stats.put(statistic, nbttagcompound2.getInt(s2));
|
|
- }, () -> {
|
|
- ServerStatsCounter.LOGGER.warn("Invalid statistic in {}: Don't know what {} is", this.file, s2);
|
|
- });
|
|
- } else {
|
|
- ServerStatsCounter.LOGGER.warn("Invalid statistic value in {}: Don't know what {} is for key {}", new Object[]{this.file, nbttagcompound2.get(s2), s2});
|
|
- }
|
|
- }
|
|
-
|
|
- }, () -> {
|
|
- ServerStatsCounter.LOGGER.warn("Invalid statistic type in {}: Don't know what {} is", this.file, s1);
|
|
- });
|
|
- }
|
|
- }
|
|
+ readStats(dataFixer, nbttagcompound);
|
|
+ break label48;
|
|
}
|
|
|
|
ServerStatsCounter.LOGGER.error("Unable to parse Stat data from {}", this.file);
|
|
@@ -173,6 +141,48 @@ public class ServerStatsCounter extends StatsCounter {
|
|
|
|
}
|
|
|
|
+ private void readStats(DataFixer dataFixer, CompoundTag nbttagcompound) {
|
|
+ nbttagcompound = DataFixTypes.STATS.updateToCurrentVersion(dataFixer, nbttagcompound, NbtUtils.getDataVersion(nbttagcompound, 1343));
|
|
+ if (!nbttagcompound.contains("stats", 10)) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ CompoundTag nbttagcompound1 = nbttagcompound.getCompound("stats");
|
|
+ Iterator iterator = nbttagcompound1.getAllKeys().iterator();
|
|
+
|
|
+ while (true) {
|
|
+ if (!iterator.hasNext()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ String s1 = (String) iterator.next();
|
|
+
|
|
+ if (nbttagcompound1.contains(s1, 10)) {
|
|
+ Util.ifElse(BuiltInRegistries.STAT_TYPE.getOptional(new ResourceLocation(s1)), (statisticwrapper) -> {
|
|
+ CompoundTag nbttagcompound2 = nbttagcompound1.getCompound(s1);
|
|
+ Iterator iterator1 = nbttagcompound2.getAllKeys().iterator();
|
|
+
|
|
+ while (iterator1.hasNext()) {
|
|
+ String s2 = (String) iterator1.next();
|
|
+
|
|
+ if (nbttagcompound2.contains(s2, 99)) {
|
|
+ Util.ifElse(this.getStat(statisticwrapper, s2), (statistic) -> {
|
|
+ this.stats.put(statistic, nbttagcompound2.getInt(s2));
|
|
+ }, () -> {
|
|
+ ServerStatsCounter.LOGGER.warn("Invalid statistic in {}: Don't know what {} is", this.file, s2);
|
|
+ });
|
|
+ } else {
|
|
+ ServerStatsCounter.LOGGER.warn("Invalid statistic value in {}: Don't know what {} is for key {}", new Object[]{this.file, nbttagcompound2.get(s2), s2});
|
|
+ }
|
|
+ }
|
|
+
|
|
+ }, () -> {
|
|
+ ServerStatsCounter.LOGGER.warn("Invalid statistic type in {}: Don't know what {} is", this.file, s1);
|
|
+ });
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
private <T> Optional<Stat<T>> getStat(StatType<T> type, String id) {
|
|
// CraftBukkit - decompile error start
|
|
Optional<ResourceLocation> optional = Optional.ofNullable(ResourceLocation.tryParse(id));
|