From ef4609df02077d25c463510ae16c63e2da7c7e86 Mon Sep 17 00:00:00 2001 From: Vaan1310 <61906290+Intybyte@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:37:39 +0100 Subject: [PATCH] Fix/scoreboard delegate (#11453) --- ...oard-tag-count-validation-to-API-set.patch | 28 ++++++++++ patches/server/MC-Utils.patch | 51 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 patches/server/Expand-scoreboard-tag-count-validation-to-API-set.patch diff --git a/patches/server/Expand-scoreboard-tag-count-validation-to-API-set.patch b/patches/server/Expand-scoreboard-tag-count-validation-to-API-set.patch new file mode 100644 index 0000000000..c31a2ca7d2 --- /dev/null +++ b/patches/server/Expand-scoreboard-tag-count-validation-to-API-set.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Intybyte +Date: Mon, 21 Oct 2024 01:41:04 +0200 +Subject: [PATCH] Expand scoreboard tag count validation to API set + + +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess + this.packetPositionCodec = new VecDeltaCodec(); + this.uuid = Mth.createInsecureUUID(this.random); + this.stringUUID = this.uuid.toString(); +- this.tags = Sets.newHashSet(); ++ this.tags = new io.papermc.paper.util.SizeLimitedSet<>(new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(), MAX_ENTITY_TAG_COUNT); // Paper - fully limit tag size - replace set impl + this.pistonDeltas = new double[]{0.0D, 0.0D, 0.0D}; + this.mainSupportingBlockPos = Optional.empty(); + this.onGroundNoBlocks = false; +@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess + } + + public boolean addTag(String tag) { +- return this.tags.size() >= 1024 ? false : this.tags.add(tag); ++ return this.tags.add(tag); // Paper - fully limit tag size - replace set impl + } + + public boolean removeTag(String tag) { diff --git a/patches/server/MC-Utils.patch b/patches/server/MC-Utils.patch index 2266b4affa..0d1401a25b 100644 --- a/patches/server/MC-Utils.patch +++ b/patches/server/MC-Utils.patch @@ -4805,6 +4805,57 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + } +} +diff --git a/src/main/java/io/papermc/paper/util/SizeLimitedSet.java b/src/main/java/io/papermc/paper/util/SizeLimitedSet.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/util/SizeLimitedSet.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.util; ++ ++import com.google.common.collect.ForwardingSet; ++import java.util.Collection; ++import java.util.Set; ++import org.jspecify.annotations.NullMarked; ++import org.jspecify.annotations.Nullable; ++ ++@NullMarked ++public class SizeLimitedSet extends ForwardingSet { ++ ++ private final Set delegate; ++ private final int maxSize; ++ ++ public SizeLimitedSet(final Set delegate, final int maxSize) { ++ this.delegate = delegate; ++ this.maxSize = maxSize; ++ } ++ ++ @Override ++ public boolean add(final E element) { ++ if (this.size() >= this.maxSize) { ++ return false; ++ } ++ return super.add(element); ++ } ++ ++ @Override ++ public boolean addAll(final Collection collection) { ++ if ((collection.size() + this.size()) >= this.maxSize) { ++ return false; ++ } ++ boolean edited = false; ++ ++ for (final E element : collection) { ++ edited |= super.add(element); ++ } ++ return edited; ++ } ++ ++ @Override ++ protected Set delegate() { ++ return this.delegate; ++ } ++} diff --git a/src/main/java/io/papermc/paper/util/StackWalkerUtil.java b/src/main/java/io/papermc/paper/util/StackWalkerUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000