Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/scoreboard delegate #11453

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions patches/server/1065-Create-Limited-set-for-Entity.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Intybyte <[email protected]>
Date: Mon, 30 Sep 2024 17:16:36 +0200
Subject: [PATCH] Create Limited set for Entity


diff --git a/src/main/java/io/papermc/paper/entity/PaperLimitedSet.java b/src/main/java/io/papermc/paper/entity/PaperLimitedSet.java
new file mode 100644
index 0000000000000000000000000000000000000000..456c8cdb38d29a73a96dc44f7e8e4ce799cbab38
--- /dev/null
+++ b/src/main/java/io/papermc/paper/entity/PaperLimitedSet.java
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,40 @@
+package io.papermc.paper.entity;
+
+import org.jetbrains.annotations.NotNull;
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
+import java.util.Collection;
+import java.util.HashSet;
+
+public class PaperLimitedSet extends HashSet<String> {
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
+ private final int maxTags;
+
+ public PaperLimitedSet(int maxTags) {
+ this.maxTags = maxTags;
+ }
+
+ @Override
+ public boolean add(String tag) {
+ // Enforce the max tag limit
+ if (this.size() >= maxTags) {
+ return false;
+ }
+ return this.add(tag);
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
+ }
+
+ @Override
+ public boolean addAll(@NotNull Collection<? extends String> tags) {
+ int currentSize = this.size();
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
+ boolean edited = false;
+
+ for (String tag : tags) {
+ if (currentSize >= maxTags) {
+ break;
+ }
+
+ boolean added = this.add(tag);
+ if (added) currentSize++;
+
+ edited = added || edited;
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
+ }
+ return edited;
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 4b54d0ea31062972e68ee8fafe3cfaf68f65a5cd..5f45c130213c008778093b33f2fa61632087a894 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -566,7 +566,7 @@ 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.entity.PaperLimitedSet(1024); // Paper - Create Limited set for Entity
this.pistonDeltas = new double[]{0.0D, 0.0D, 0.0D};
this.mainSupportingBlockPos = Optional.empty();
this.onGroundNoBlocks = false;
@@ -654,7 +654,7 @@ 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 - Create Limited set for Entity
}

public boolean removeTag(String tag) {