Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
54 changes: 40 additions & 14 deletions patches/server/0005-Paper-config-files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,10 @@ index 0000000000000000000000000000000000000000..69add4a7f1147015806bc9b63a8340d1
+}
diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
new file mode 100644
index 0000000000000000000000000000000000000000..1029b6de6f36b08bf634b4056ef5701383f6f258
index 0000000000000000000000000000000000000000..1c562f384a66258b1a33c4ab33370b0a1cdeeeb1
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
@@ -0,0 +1,467 @@
@@ -0,0 +1,470 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.base.Suppliers;
Expand Down Expand Up @@ -903,6 +903,8 @@ index 0000000000000000000000000000000000000000..1029b6de6f36b08bf634b4056ef57013
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Reference2LongMap;
+import it.unimi.dsi.fastutil.objects.Reference2LongOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Type;
Expand Down Expand Up @@ -1108,6 +1110,7 @@ index 0000000000000000000000000000000000000000..1029b6de6f36b08bf634b4056ef57013
+ .serializers(serializers -> serializers
+ .register(new TypeToken<Reference2IntMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2IntMap<?>>(Reference2IntOpenHashMap::new, Integer.TYPE))
+ .register(new TypeToken<Reference2LongMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2LongMap<?>>(Reference2LongOpenHashMap::new, Long.TYPE))
+ .register(new TypeToken<Reference2ObjectMap<?, ?>>() {}, new FastutilMapSerializer.SomethingToSomething<Reference2ObjectMap<?, ?>>(Reference2ObjectOpenHashMap::new))
+ .register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer())
+ .register(DespawnRange.class, DespawnRange.SERIALIZER)
+ .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer())
Expand Down Expand Up @@ -1426,7 +1429,7 @@ new file mode 100644
index 0000000000000000000000000000000000000000..dad3fcc689ec806f985122a7cbd501a7d0fd0d36
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -0,0 +1,581 @@
@@ -0,0 +1,588 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.collect.HashBasedTable;
Expand All @@ -1451,6 +1454,8 @@ index 0000000000000000000000000000000000000000..dad3fcc689ec806f985122a7cbd501a7
+import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Reference2LongMap;
+import it.unimi.dsi.fastutil.objects.Reference2LongOpenHashMap;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
+import java.util.Arrays;
+import java.util.IdentityHashMap;
+import java.util.List;
Expand Down Expand Up @@ -1628,6 +1633,11 @@ index 0000000000000000000000000000000000000000..dad3fcc689ec806f985122a7cbd501a7
+ }
+ }
+
+ public Reference2ObjectMap<EntityType<?>, IntOr.Disabled> despawnTime = Util.make(new Reference2ObjectOpenHashMap<>(), map -> {
+ map.put(EntityType.SNOWBALL, IntOr.Disabled.DISABLED);
+ map.put(EntityType.LLAMA_SPIT, IntOr.Disabled.DISABLED);
+ });
+
+ @PostProcess
+ public void precomputeDespawnDistances() throws SerializationException {
+ for (Map.Entry<MobCategory, DespawnRangePair> entry : this.despawnRanges.entrySet()) {
Expand Down Expand Up @@ -2802,41 +2812,43 @@ index 0000000000000000000000000000000000000000..7fc0905fc6b8f5df762b4cea573f935d
+}
diff --git a/src/main/java/io/papermc/paper/configuration/serializer/collections/FastutilMapSerializer.java b/src/main/java/io/papermc/paper/configuration/serializer/collections/FastutilMapSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..4af710e144b70933d750c22edfe484c18e4a3540
index 0000000000000000000000000000000000000000..5a0ecd5423be7fd84e02808a3de4cf3d75d96ecd
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/serializer/collections/FastutilMapSerializer.java
@@ -0,0 +1,69 @@
@@ -0,0 +1,85 @@
+package io.papermc.paper.configuration.serializer.collections;
+
+import io.leangen.geantyref.GenericTypeReflector;
+import io.leangen.geantyref.TypeFactory;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.spongepowered.configurate.ConfigurationNode;
+import org.spongepowered.configurate.serialize.SerializationException;
+import org.spongepowered.configurate.serialize.TypeSerializer;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Map;
+import java.util.function.Function;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+import org.spongepowered.configurate.ConfigurationNode;
+import org.spongepowered.configurate.serialize.SerializationException;
+import org.spongepowered.configurate.serialize.TypeSerializer;
+
+@SuppressWarnings("rawtypes")
+@NullMarked
+public abstract class FastutilMapSerializer<M extends Map<?, ?>> implements TypeSerializer<M> {
+ private final Function<Map, ? extends M> factory;
+
+ protected FastutilMapSerializer(final Function<Map, ? extends M> factory) {
+ private final Function<? super Map, ? extends M> factory;
+
+ protected FastutilMapSerializer(final Function<? super Map, ? extends M> factory) {
+ this.factory = factory;
+ }
+
+ @Override
+ public M deserialize(final Type type, final ConfigurationNode node) throws SerializationException {
+ @Nullable final Map map = (Map) node.get(this.createBaseMapType((ParameterizedType) type));
+ final Map map = (Map) node.get(this.createBaseMapType((ParameterizedType) type));
+ return this.factory.apply(map == null ? Collections.emptyMap() : map);
+ }
+
+ @Override
+ public void serialize(final Type type, @Nullable final M obj, final ConfigurationNode node) throws SerializationException {
+ public void serialize(final Type type, final @Nullable M obj, final ConfigurationNode node) throws SerializationException {
+ if (obj == null || obj.isEmpty()) {
+ node.raw(null);
+ } else {
Expand All @@ -2848,6 +2860,7 @@ index 0000000000000000000000000000000000000000..4af710e144b70933d750c22edfe484c1
+ protected abstract Type createBaseMapType(final ParameterizedType type);
+
+ public static final class SomethingToPrimitive<M extends Map<?, ?>> extends FastutilMapSerializer<M> {
+
+ private final Type primitiveType;
+
+ public SomethingToPrimitive(final Function<Map, ? extends M> factory, final Type primitiveType) {
Expand All @@ -2862,6 +2875,7 @@ index 0000000000000000000000000000000000000000..4af710e144b70933d750c22edfe484c1
+ }
+
+ public static final class PrimitiveToSomething<M extends Map<?, ?>> extends FastutilMapSerializer<M> {
+
+ private final Type primitiveType;
+
+ public PrimitiveToSomething(final Function<Map, ? extends M> factory, final Type primitiveType) {
Expand All @@ -2874,6 +2888,18 @@ index 0000000000000000000000000000000000000000..4af710e144b70933d750c22edfe484c1
+ return TypeFactory.parameterizedClass(Map.class, GenericTypeReflector.box(this.primitiveType), type.getActualTypeArguments()[0]);
+ }
+ }
+
+ public static final class SomethingToSomething<M extends Map<?, ?>> extends FastutilMapSerializer<M> {
+
+ public SomethingToSomething(final Function<? super Map, ? extends M> factory) {
+ super(factory);
+ }
+
+ @Override
+ protected Type createBaseMapType(final ParameterizedType type) {
+ return TypeFactory.parameterizedClass(Map.class, type.getActualTypeArguments()[0], type.getActualTypeArguments()[1]);
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/configuration/serializer/collections/MapSerializer.java b/src/main/java/io/papermc/paper/configuration/serializer/collections/MapSerializer.java
new file mode 100644
Expand Down
39 changes: 39 additions & 0 deletions patches/server/1070-Configurable-Entity-Despawn-Time.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kevin Raneri <[email protected]>
Date: Mon, 30 Sep 2024 09:50:55 -0700
Subject: [PATCH] Configurable Entity Despawn Time


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 8be1b051543cda2b2e9e3d337834757e53f442de..ed5b00620527c1776722d25b1b45f1544802a341 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -432,6 +432,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
private UUID originWorld;
public boolean freezeLocked = false; // Paper - Freeze Tick Lock API
public boolean fixedPose = false; // Paper - Expand Pose API
+ private final int despawnTime; // Paper - entity despawn time limit

public void setOrigin(@javax.annotation.Nonnull Location location) {
this.origin = location.toVector();
@@ -614,6 +615,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
+ this.despawnTime = type == EntityType.PLAYER ? -1 : world.paperConfig().entities.spawning.despawnTime.getOrDefault(type, io.papermc.paper.configuration.type.number.IntOr.Disabled.DISABLED).or(-1); // Paper - entity despawn time limit
this.passengers = ImmutableList.of();
this.deltaMovement = Vec3.ZERO;
this.bb = Entity.INITIAL_AABB;
@@ -912,6 +914,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}

public void tick() {
+ // Paper start - entity despawn time limit
+ if (this.despawnTime >= 0 && this.tickCount >= this.despawnTime) {
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN);
+ return;
+ }
+ // Paper end - entity despawn time limit
this.baseTick();
}