mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 22:40:21 +01:00
net/minecraft/stats/
This commit is contained in:
parent
97043e3e5b
commit
a0a4359af1
4 changed files with 41 additions and 69 deletions
|
@ -0,0 +1,29 @@
|
|||
--- a/net/minecraft/stats/ServerRecipeBook.java
|
||||
+++ b/net/minecraft/stats/ServerRecipeBook.java
|
||||
@@ -67,7 +_,7 @@
|
||||
|
||||
for (RecipeHolder<?> recipeHolder : recipes) {
|
||||
ResourceKey<Recipe<?>> resourceKey = recipeHolder.id();
|
||||
- if (!this.known.contains(resourceKey) && !recipeHolder.value().isSpecial()) {
|
||||
+ if (!this.known.contains(resourceKey) && !recipeHolder.value().isSpecial() && org.bukkit.craftbukkit.event.CraftEventFactory.handlePlayerRecipeListUpdateEvent(player, resourceKey.location())) { // CraftBukkit{
|
||||
this.add(resourceKey);
|
||||
this.addHighlight(resourceKey);
|
||||
this.displayResolver
|
||||
@@ -78,7 +_,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
+ if (!list.isEmpty() && player.connection != null) { // SPIGOT-4478 during PlayerLoginEvent
|
||||
player.connection.send(new ClientboundRecipeBookAddPacket(list, false));
|
||||
}
|
||||
|
||||
@@ -96,7 +_,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
+ if (!list.isEmpty() && player.connection != null) { // SPIGOT-4478 during PlayerLoginEvent
|
||||
player.connection.send(new ClientboundRecipeBookRemovePacket(list));
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
--- a/net/minecraft/stats/ServerStatsCounter.java
|
||||
+++ b/net/minecraft/stats/ServerStatsCounter.java
|
||||
@@ -1,3 +1,4 @@
|
||||
@@ -1,3 +_,4 @@
|
||||
+// mc-dev import
|
||||
package net.minecraft.stats;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -57,9 +58,22 @@
|
||||
@@ -51,9 +_,22 @@
|
||||
LOGGER.error("Couldn't parse statistics file {}", file, var5);
|
||||
}
|
||||
}
|
||||
|
||||
+ // Paper start - Moved after stat fetching for player state file
|
||||
+ // Moves the loading after vanilla loading, so it overrides the values.
|
||||
+ // Disables saving any forced stats, so it stays at the same value (without enabling disableStatSaving)
|
||||
|
@ -27,32 +27,13 @@
|
|||
+ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
|
||||
try {
|
||||
FileUtils.writeStringToFile(this.file, this.toJson());
|
||||
} catch (IOException ioexception) {
|
||||
@@ -70,6 +84,8 @@
|
||||
} catch (IOException var2) {
|
||||
@@ -63,6 +_,8 @@
|
||||
|
||||
@Override
|
||||
public void setValue(Player player, Stat<?> stat, int value) {
|
||||
public void setValue(Player player, Stat<?> stat, int i) {
|
||||
+ if ( org.spigotmc.SpigotConfig.disableStatSaving ) return; // Spigot
|
||||
+ if (stat.getType() == Stats.CUSTOM && stat.getValue() instanceof final ResourceLocation resourceLocation && org.spigotmc.SpigotConfig.forcedStats.get(resourceLocation) != null) return; // Paper - disable saving forced stats
|
||||
super.setValue(player, stat, value);
|
||||
super.setValue(player, stat, i);
|
||||
this.dirty.add(stat);
|
||||
}
|
||||
@@ -158,13 +174,12 @@
|
||||
}
|
||||
|
||||
private <T> Optional<Stat<T>> getStat(StatType<T> type, String id) {
|
||||
- Optional optional = Optional.ofNullable(ResourceLocation.tryParse(id));
|
||||
- Registry iregistry = type.getRegistry();
|
||||
+ // CraftBukkit - decompile error start
|
||||
+ Optional<ResourceLocation> optional = Optional.ofNullable(ResourceLocation.tryParse(id));
|
||||
+ Registry<T> iregistry = type.getRegistry();
|
||||
|
||||
- Objects.requireNonNull(iregistry);
|
||||
- optional = optional.flatMap(iregistry::getOptional);
|
||||
- Objects.requireNonNull(type);
|
||||
- return optional.map(type::get);
|
||||
+ return optional.flatMap(iregistry::getOptional).map(type::get);
|
||||
+ // CraftBukkit - decompile error end
|
||||
}
|
||||
|
||||
private static CompoundTag fromJson(JsonObject json) {
|
|
@ -1,15 +1,15 @@
|
|||
--- a/net/minecraft/stats/StatsCounter.java
|
||||
+++ b/net/minecraft/stats/StatsCounter.java
|
||||
@@ -16,6 +16,12 @@
|
||||
public void increment(Player player, Stat<?> stat, int value) {
|
||||
int j = (int) Math.min((long) this.getValue(stat) + (long) value, 2147483647L);
|
||||
@@ -18,6 +_,12 @@
|
||||
}
|
||||
|
||||
public void setValue(Player player, Stat<?> stat, int value) {
|
||||
+ // CraftBukkit start - fire Statistic events
|
||||
+ org.bukkit.event.Cancellable cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.handleStatisticsIncrease(player, stat, this.getValue(stat), j);
|
||||
+ org.bukkit.event.Cancellable cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.handleStatisticsIncrease(player, stat, this.getValue(stat), value);
|
||||
+ if (cancellable != null && cancellable.isCancelled()) {
|
||||
+ return;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.setValue(player, stat, j);
|
||||
this.stats.put(stat, value);
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
--- a/net/minecraft/stats/ServerRecipeBook.java
|
||||
+++ b/net/minecraft/stats/ServerRecipeBook.java
|
||||
@@ -29,6 +29,8 @@
|
||||
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
||||
+
|
||||
public class ServerRecipeBook extends RecipeBook {
|
||||
|
||||
public static final String RECIPE_BOOK_TAG = "recipeBook";
|
||||
@@ -72,7 +74,7 @@
|
||||
RecipeHolder<?> recipeholder = (RecipeHolder) iterator.next();
|
||||
ResourceKey<Recipe<?>> resourcekey = recipeholder.id();
|
||||
|
||||
- if (!this.known.contains(resourcekey) && !recipeholder.value().isSpecial()) {
|
||||
+ if (!this.known.contains(resourcekey) && !recipeholder.value().isSpecial() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(player, resourcekey.location())) { // CraftBukkit
|
||||
this.add(resourcekey);
|
||||
this.addHighlight(resourcekey);
|
||||
this.displayResolver.displaysForRecipe(resourcekey, (recipedisplayentry) -> {
|
||||
@@ -82,7 +84,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
+ if (!list.isEmpty() && player.connection != null) { // SPIGOT-4478 during PlayerLoginEvent
|
||||
player.connection.send(new ClientboundRecipeBookAddPacket(list, false));
|
||||
}
|
||||
|
||||
@@ -105,7 +107,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
+ if (!list.isEmpty() && player.connection != null) { // SPIGOT-4478 during PlayerLoginEvent
|
||||
player.connection.send(new ClientboundRecipeBookRemovePacket(list));
|
||||
}
|
||||
|
Loading…
Reference in a new issue