Skip to content

Commit c17ef64

Browse files
authored
Fix/scoreboard delegate (PaperMC#11453)
1 parent 15b2aa1 commit c17ef64

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

patches/server/0009-MC-Utils.patch

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,6 +4805,57 @@ index 0000000000000000000000000000000000000000..a4ac34ebb58a404f4fca7e763e61d4ab
48054805
+ }
48064806
+ }
48074807
+}
4808+
diff --git a/src/main/java/io/papermc/paper/util/SizeLimitedSet.java b/src/main/java/io/papermc/paper/util/SizeLimitedSet.java
4809+
new file mode 100644
4810+
index 0000000000000000000000000000000000000000..1eee077b1e2c6d41bdaa4f1a477c715b13981c6d
4811+
--- /dev/null
4812+
+++ b/src/main/java/io/papermc/paper/util/SizeLimitedSet.java
4813+
@@ -0,0 +1,45 @@
4814+
+package io.papermc.paper.util;
4815+
+
4816+
+import com.google.common.collect.ForwardingSet;
4817+
+import java.util.Collection;
4818+
+import java.util.Set;
4819+
+import org.jspecify.annotations.NullMarked;
4820+
+import org.jspecify.annotations.Nullable;
4821+
+
4822+
+@NullMarked
4823+
+public class SizeLimitedSet<E> extends ForwardingSet<E> {
4824+
+
4825+
+ private final Set<E> delegate;
4826+
+ private final int maxSize;
4827+
+
4828+
+ public SizeLimitedSet(final Set<E> delegate, final int maxSize) {
4829+
+ this.delegate = delegate;
4830+
+ this.maxSize = maxSize;
4831+
+ }
4832+
+
4833+
+ @Override
4834+
+ public boolean add(final E element) {
4835+
+ if (this.size() >= this.maxSize) {
4836+
+ return false;
4837+
+ }
4838+
+ return super.add(element);
4839+
+ }
4840+
+
4841+
+ @Override
4842+
+ public boolean addAll(final Collection<? extends @Nullable E> collection) {
4843+
+ if ((collection.size() + this.size()) >= this.maxSize) {
4844+
+ return false;
4845+
+ }
4846+
+ boolean edited = false;
4847+
+
4848+
+ for (final E element : collection) {
4849+
+ edited |= super.add(element);
4850+
+ }
4851+
+ return edited;
4852+
+ }
4853+
+
4854+
+ @Override
4855+
+ protected Set<E> delegate() {
4856+
+ return this.delegate;
4857+
+ }
4858+
+}
48084859
diff --git a/src/main/java/io/papermc/paper/util/StackWalkerUtil.java b/src/main/java/io/papermc/paper/util/StackWalkerUtil.java
48094860
new file mode 100644
48104861
index 0000000000000000000000000000000000000000..f7114d5b8f2f93f62883e24da29afaf9f74ee1a6
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Intybyte <vaan.testwork@gmail.com>
3+
Date: Mon, 21 Oct 2024 01:41:04 +0200
4+
Subject: [PATCH] Expand scoreboard tag count validation to API set
5+
6+
7+
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
8+
index 1b547be0fe97119edf4f29666cfe0037e0c778e0..7ac7d0729705cb02f22277be3c467aed4f69ec0e 100644
9+
--- a/src/main/java/net/minecraft/world/entity/Entity.java
10+
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
11+
@@ -586,7 +586,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
12+
this.packetPositionCodec = new VecDeltaCodec();
13+
this.uuid = Mth.createInsecureUUID(this.random);
14+
this.stringUUID = this.uuid.toString();
15+
- this.tags = Sets.newHashSet();
16+
+ 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
17+
this.pistonDeltas = new double[]{0.0D, 0.0D, 0.0D};
18+
this.mainSupportingBlockPos = Optional.empty();
19+
this.onGroundNoBlocks = false;
20+
@@ -677,7 +677,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
21+
}
22+
23+
public boolean addTag(String tag) {
24+
- return this.tags.size() >= 1024 ? false : this.tags.add(tag);
25+
+ return this.tags.add(tag); // Paper - fully limit tag size - replace set impl
26+
}
27+
28+
public boolean removeTag(String tag) {

0 commit comments

Comments
 (0)