mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 15:49:00 +01:00
Fix/scoreboard delegate (#11453)
This commit is contained in:
parent
cc10499354
commit
ef4609df02
2 changed files with 79 additions and 0 deletions
|
@ -0,0 +1,28 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Intybyte <vaan.testwork@gmail.com>
|
||||||
|
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) {
|
|
@ -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<E> extends ForwardingSet<E> {
|
||||||
|
+
|
||||||
|
+ private final Set<E> delegate;
|
||||||
|
+ private final int maxSize;
|
||||||
|
+
|
||||||
|
+ public SizeLimitedSet(final Set<E> 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<? extends @Nullable E> 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<E> 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
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||||
|
|
Loading…
Reference in a new issue