diff options
author | Lulu13022002 <[email protected]> | 2024-08-25 23:32:32 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2024-08-25 14:32:32 -0700 |
commit | 789a267e93240f9e918014dd88bab89fe50a64d3 (patch) | |
tree | 5329e926874ef0d009a99403b5f38903e2118325 | |
parent | a7b8d9574e6901dddc25aafa27f91ca0b263516a (diff) | |
download | Paper-789a267e93240f9e918014dd88bab89fe50a64d3.tar.gz Paper-789a267e93240f9e918014dd88bab89fe50a64d3.zip |
Re-implement maxLeashDistance world conf and call missing event (#11301)
* Re-implement maxLeashDistance world config and call missing event
* migrate config setting to double or default
* fixes
---------
Co-authored-by: Jake Potrebic <[email protected]>
7 files changed, 77 insertions, 32 deletions
diff --git a/patches/server/0005-Paper-config-files.patch b/patches/server/0005-Paper-config-files.patch index 2290c0d83d..58b32ceedc 100644 --- a/patches/server/0005-Paper-config-files.patch +++ b/patches/server/0005-Paper-config-files.patch @@ -855,10 +855,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..d937adbe40687546686cddb27f2ae34f2795e9db +index 0000000000000000000000000000000000000000..1029b6de6f36b08bf634b4056ef5701383f6f258 --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java -@@ -0,0 +1,469 @@ +@@ -0,0 +1,467 @@ +package io.papermc.paper.configuration; + +import com.google.common.base.Suppliers; @@ -1031,6 +1031,14 @@ index 0000000000000000000000000000000000000000..d937adbe40687546686cddb27f2ae34f + .register(MapSerializer.TYPE, new MapSerializer(false)) + .register(new EnumValueSerializer()) + .register(new ComponentSerializer()) ++ .register(IntOr.Default.SERIALIZER) ++ .register(IntOr.Disabled.SERIALIZER) ++ .register(DoubleOr.Default.SERIALIZER) ++ .register(DoubleOr.Disabled.SERIALIZER) ++ .register(BooleanOrDefault.SERIALIZER) ++ .register(Duration.SERIALIZER) ++ .register(DurationOrDisabled.SERIALIZER) ++ .register(NbtPathSerializer.SERIALIZER) + ); + } + @@ -1054,9 +1062,6 @@ index 0000000000000000000000000000000000000000..d937adbe40687546686cddb27f2ae34f + .header(GLOBAL_HEADER) + .serializers(builder -> builder + .register(new PacketClassSerializer()) -+ .register(IntOr.Disabled.SERIALIZER) -+ .register(IntOr.Default.SERIALIZER) -+ .register(DoubleOr.Default.SERIALIZER) + ); + } + @@ -1100,14 +1105,7 @@ index 0000000000000000000000000000000000000000..d937adbe40687546686cddb27f2ae34f + .register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer()) + .register(DespawnRange.class, DespawnRange.SERIALIZER) + .register(StringRepresentableSerializer::isValidFor, new StringRepresentableSerializer()) -+ .register(IntOr.Default.SERIALIZER) -+ .register(IntOr.Disabled.SERIALIZER) -+ .register(DoubleOr.Default.SERIALIZER) -+ .register(BooleanOrDefault.SERIALIZER) -+ .register(Duration.SERIALIZER) -+ .register(DurationOrDisabled.SERIALIZER) + .register(EngineMode.SERIALIZER) -+ .register(NbtPathSerializer.SERIALIZER) + .register(FallbackValueSerializer.create(contextMap.require(SPIGOT_WORLD_CONFIG_CONTEXT_KEY).get(), MinecraftServer::getServer)) + .register(new RegistryValueSerializer<>(new TypeToken<EntityType<?>>() {}, access, Registries.ENTITY_TYPE, true)) + .register(new RegistryValueSerializer<>(Item.class, access, Registries.ITEM, true)) @@ -1418,7 +1416,7 @@ index 0000000000000000000000000000000000000000..990d1bb46e0f9719f4e9af928d80ac6f +} diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java new file mode 100644 -index 0000000000000000000000000000000000000000..2f2850d1bc1e27dea3c38ac26908cf130da2e051 +index 0000000000000000000000000000000000000000..aa3624fb8aaaf2720aaef7800f537dd4b906797f --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java @@ -0,0 +1,573 @@ @@ -1985,7 +1983,7 @@ index 0000000000000000000000000000000000000000..2f2850d1bc1e27dea3c38ac26908cf13 + public boolean showSignClickCommandFailureMsgsToPlayer = false; + public RedstoneImplementation redstoneImplementation = RedstoneImplementation.VANILLA; + public boolean disableEndCredits = false; -+ public double maxLeashDistance = Leashable.LEASH_TOO_FAR_DIST; ++ public DoubleOr.Default maxLeashDistance = DoubleOr.Default.USE_DEFAULT; + public boolean disableSprintInterruptionOnAttack = false; + public int shieldBlockingDelay = 5; + public boolean disableRelativeProjectileVelocity = false; @@ -4827,14 +4825,15 @@ index 0000000000000000000000000000000000000000..31068170086aeac51a2adb952b19672e +} diff --git a/src/main/java/io/papermc/paper/configuration/type/number/DoubleOr.java b/src/main/java/io/papermc/paper/configuration/type/number/DoubleOr.java new file mode 100644 -index 0000000000000000000000000000000000000000..5833c06b0707906ab7d10786ecd115f20e42e925 +index 0000000000000000000000000000000000000000..0e7205e6ba9b207082c8c530142f0b832dcd242d --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/type/number/DoubleOr.java -@@ -0,0 +1,59 @@ +@@ -0,0 +1,74 @@ +package io.papermc.paper.configuration.type.number; + +import com.google.common.base.Preconditions; +import java.util.OptionalDouble; ++import java.util.function.DoublePredicate; +import java.util.function.Function; +import java.util.function.Predicate; +import org.spongepowered.configurate.serialize.ScalarSerializer; @@ -4857,6 +4856,20 @@ index 0000000000000000000000000000000000000000..5833c06b0707906ab7d10786ecd115f2 + public static final ScalarSerializer<Default> SERIALIZER = new Serializer<>(Default.class, Default::new, DEFAULT_VALUE, USE_DEFAULT); + } + ++ record Disabled(OptionalDouble value) implements DoubleOr { ++ private static final String DISABLED_VALUE = "disabled"; ++ public static final Disabled DISABLED = new Disabled(OptionalDouble.empty()); ++ public static final ScalarSerializer<Disabled> SERIALIZER = new Serializer<>(Disabled.class, Disabled::new, DISABLED_VALUE, DISABLED); ++ ++ public boolean test(DoublePredicate predicate) { ++ return this.value.isPresent() && predicate.test(this.value.getAsDouble()); ++ } ++ ++ public boolean enabled() { ++ return this.value.isPresent(); ++ } ++ } ++ + final class Serializer<T extends DoubleOr> extends OptionalNumSerializer<T, OptionalDouble> { + Serializer(final Class<T> classOfT, final Function<OptionalDouble, T> factory, String emptySerializedValue, T emptyValue) { + super(classOfT, emptySerializedValue, emptyValue, OptionalDouble::empty, OptionalDouble::isEmpty, factory, double.class); diff --git a/patches/server/0349-Fix-item-duplication-and-teleport-issues.patch b/patches/server/0349-Fix-item-duplication-and-teleport-issues.patch index 9e5a58b90a..c577f08518 100644 --- a/patches/server/0349-Fix-item-duplication-and-teleport-issues.patch +++ b/patches/server/0349-Fix-item-duplication-and-teleport-issues.patch @@ -16,7 +16,7 @@ So even if something NEW comes up, it would be impossible to drop the same item twice because the source was destroyed. diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index d80fd4e2f41583f83c9527ccf4ce80afe851276a..bd5291ca4680572d2c5f3cec1231b1a3dcf72fa8 100644 +index d80fd4e2f41583f83c9527ccf4ce80afe851276a..10015beb7a2de890fe27bffde8f55c1dd78ce344 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -2515,11 +2515,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -52,8 +52,8 @@ index d80fd4e2f41583f83c9527ccf4ce80afe851276a..bd5291ca4680572d2c5f3cec1231b1a3 if (entity2 != null) { if (this != entity2) { + // Paper start - Fix item duplication and teleport issues -+ if (this instanceof Mob) { -+ ((Mob) this).dropLeash(true, true); // Paper drop lead ++ if (this instanceof Leashable leashable) { ++ leashable.dropLeash(true, true); // Paper drop lead + } + // Paper end - Fix item duplication and teleport issues entity2.restoreFrom(this); diff --git a/patches/server/0479-Configurable-max-leash-distance.patch b/patches/server/0479-Configurable-max-leash-distance.patch index 404169cae8..d2f544737b 100644 --- a/patches/server/0479-Configurable-max-leash-distance.patch +++ b/patches/server/0479-Configurable-max-leash-distance.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Configurable max leash distance diff --git a/src/main/java/net/minecraft/world/entity/Leashable.java b/src/main/java/net/minecraft/world/entity/Leashable.java -index 1f2d04a456c383815b0c5ef331471593556fd128..30d7dd9646ba9d6a9396dc140a61eb2cac07dfc6 100644 +index 1f2d04a456c383815b0c5ef331471593556fd128..5c51dd5229689cba459655d488aee59bd159a414 100644 --- a/src/main/java/net/minecraft/world/entity/Leashable.java +++ b/src/main/java/net/minecraft/world/entity/Leashable.java @@ -179,7 +179,7 @@ public interface Leashable { @@ -13,7 +13,20 @@ index 1f2d04a456c383815b0c5ef331471593556fd128..30d7dd9646ba9d6a9396dc140a61eb2c } - if ((double) f > 10.0D) { -+ if ((double) f > entity.level().paperConfig().misc.maxLeashDistance) { // Paper - Configurable max leash distance ++ if ((double) f > entity.level().paperConfig().misc.maxLeashDistance.or(LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance ((Leashable) entity).leashTooFarBehaviour(); } else if ((double) f > 6.0D) { ((Leashable) entity).elasticRangeLeashBehaviour(entity1, f); +diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java +index f2d311a5450eb684603580bbf7e9e7fc73fc2f5c..bf2c9134c7d9d5926add36b55e3cfea79e8c8243 100644 +--- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java ++++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java +@@ -97,7 +97,7 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { + @Override + public boolean handleLeashAtDistance(Entity leashHolder, float distance) { + if (this.isInSittingPose()) { +- if (distance > 10.0F) { ++ if (distance > (float) this.level().paperConfig().misc.maxLeashDistance.or(Leashable.LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance + this.dropLeash(true, true); + } + diff --git a/patches/server/0484-Expand-EntityUnleashEvent.patch b/patches/server/0484-Expand-EntityUnleashEvent.patch index 21185f3515..8d0a37b004 100644 --- a/patches/server/0484-Expand-EntityUnleashEvent.patch +++ b/patches/server/0484-Expand-EntityUnleashEvent.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Expand EntityUnleashEvent diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 44efb857aa839bbc0eca608661f22750bb059f4f..1ca18b0c4af08c998636bb3938a3dfdfb1d80cf0 100644 +index 7d131f3b3f5739468aa3115e97ed28b6bfeca33d..da184893d617311a43f9ce176a965f8417a2876d 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -2574,12 +2574,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess @@ -26,12 +26,14 @@ index 44efb857aa839bbc0eca608661f22750bb059f4f..1ca18b0c4af08c998636bb3938a3dfdf this.gameEvent(GameEvent.ENTITY_INTERACT, player); } -@@ -3450,8 +3453,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess +@@ -3449,9 +3452,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess + protected void removeAfterChangingDimensions() { this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause - if (this instanceof Leashable leashable) { +- if (this instanceof Leashable leashable) { - this.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN)); // CraftBukkit - leashable.dropLeash(true, false); ++ if (this instanceof Leashable leashable && leashable.isLeashed()) { // Paper - only call if it is leashed + // Paper start - Expand EntityUnleashEvent + final EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), UnleashReason.UNKNOWN, false); // CraftBukkit + event.callEvent(); @@ -41,7 +43,7 @@ index 44efb857aa839bbc0eca608661f22750bb059f4f..1ca18b0c4af08c998636bb3938a3dfdf } diff --git a/src/main/java/net/minecraft/world/entity/Leashable.java b/src/main/java/net/minecraft/world/entity/Leashable.java -index 30d7dd9646ba9d6a9396dc140a61eb2cac07dfc6..bc03f1fe2a311bf61449879751360c6775dde6ac 100644 +index 5c51dd5229689cba459655d488aee59bd159a414..e7535f15be3cc1537aafee53779ccfb4f21d1f38 100644 --- a/src/main/java/net/minecraft/world/entity/Leashable.java +++ b/src/main/java/net/minecraft/world/entity/Leashable.java @@ -166,8 +166,11 @@ public interface Leashable { @@ -95,6 +97,23 @@ index b46572f6e3b52f498b395d3b8c5def2aa799ff03..e87360e21e6eb7b0161c34a3ac6cb83d } return flag1; +diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java +index bf2c9134c7d9d5926add36b55e3cfea79e8c8243..7b7bc1a205dfacbe5709011b6b6799e75af9e4cc 100644 +--- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java ++++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java +@@ -98,7 +98,11 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { + public boolean handleLeashAtDistance(Entity leashHolder, float distance) { + if (this.isInSittingPose()) { + if (distance > (float) this.level().paperConfig().misc.maxLeashDistance.or(Leashable.LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance +- this.dropLeash(true, true); ++ // Paper start - Expand EntityUnleashEvent ++ org.bukkit.event.entity.EntityUnleashEvent event = new org.bukkit.event.entity.EntityUnleashEvent(this.getBukkitEntity(), org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.DISTANCE, true); ++ if (!event.callEvent()) return false; ++ this.dropLeash(true, event.isDropLeash()); ++ // Paper end - Expand EntityUnleashEvent + } + + return false; diff --git a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java b/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java index 3c0af74ed65610b1d5e3b72fdcf28c5a3423f0da..01173fc7177d78588978e087e63efda0b0527c2f 100644 --- a/src/main/java/net/minecraft/world/entity/decoration/LeashFenceKnotEntity.java diff --git a/patches/server/0685-Add-TameableDeathMessageEvent.patch b/patches/server/0685-Add-TameableDeathMessageEvent.patch index e683289da1..b2ed688a59 100644 --- a/patches/server/0685-Add-TameableDeathMessageEvent.patch +++ b/patches/server/0685-Add-TameableDeathMessageEvent.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Add TameableDeathMessageEvent diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java -index f2d311a5450eb684603580bbf7e9e7fc73fc2f5c..07ec4837d17a9cb7db2fa310a42fc87e052b3f9b 100644 +index 0eebf7ce352e7d811bd5798bf19c399e61affb09..5405792eea1d90492183faa23367f13b88cd1721 100644 --- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java +++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java -@@ -237,7 +237,12 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { +@@ -241,7 +241,12 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { @Override public void die(DamageSource damageSource) { if (!this.level().isClientSide && this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES) && this.getOwner() instanceof ServerPlayer) { diff --git a/patches/server/0760-Add-EntityToggleSitEvent.patch b/patches/server/0760-Add-EntityToggleSitEvent.patch index c9aef59416..28d2cdd4b0 100644 --- a/patches/server/0760-Add-EntityToggleSitEvent.patch +++ b/patches/server/0760-Add-EntityToggleSitEvent.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Add EntityToggleSitEvent diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java -index 07ec4837d17a9cb7db2fa310a42fc87e052b3f9b..39adc89b35213d5d5fb71bb4b7e0c641f77e4a06 100644 +index 5405792eea1d90492183faa23367f13b88cd1721..8a4f15964449a40ae4fffc5d16b7789d61c4c594 100644 --- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java +++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java @@ -86,7 +86,7 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { @@ -17,7 +17,7 @@ index 07ec4837d17a9cb7db2fa310a42fc87e052b3f9b..39adc89b35213d5d5fb71bb4b7e0c641 } @Override -@@ -162,6 +162,12 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { +@@ -166,6 +166,12 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { } public void setInSittingPose(boolean inSittingPose) { diff --git a/patches/server/0919-Fix-NPE-on-null-loc-for-EntityTeleportEvent.patch b/patches/server/0919-Fix-NPE-on-null-loc-for-EntityTeleportEvent.patch index 72b2cc189a..75efe1d68f 100644 --- a/patches/server/0919-Fix-NPE-on-null-loc-for-EntityTeleportEvent.patch +++ b/patches/server/0919-Fix-NPE-on-null-loc-for-EntityTeleportEvent.patch @@ -26,7 +26,7 @@ index a306b30af19277386a2f3e560b4902a8b5796f2a..54851f6cc0d5fddb32a9a1e84a4f5ae4 x = to.getX(); y = to.getY(); diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index 3def6b7919484c330bc1c4aea1a8e2c6ad21f999..ff16c7196b146388c526e3100e561be771ca8a91 100644 +index 306b55276189099bbbc8f2c86ad7428381fcf58c..278e22985ecda6653ce01a29209eb51506c48438 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -4229,7 +4229,7 @@ public abstract class LivingEntity extends Entity implements Attackable { @@ -39,10 +39,10 @@ index 3def6b7919484c330bc1c4aea1a8e2c6ad21f999..ff16c7196b146388c526e3100e561be7 this.teleportTo(to.getX(), to.getY(), to.getZ()); } else { diff --git a/src/main/java/net/minecraft/world/entity/TamableAnimal.java b/src/main/java/net/minecraft/world/entity/TamableAnimal.java -index 39adc89b35213d5d5fb71bb4b7e0c641f77e4a06..45224dc3867892b298b006c17f7f85741fcc96d6 100644 +index 8a4f15964449a40ae4fffc5d16b7789d61c4c594..06f74d3aeb35844cbb540a5fcd0da2644556da55 100644 --- a/src/main/java/net/minecraft/world/entity/TamableAnimal.java +++ b/src/main/java/net/minecraft/world/entity/TamableAnimal.java -@@ -299,7 +299,7 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { +@@ -303,7 +303,7 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity { } else { // CraftBukkit start EntityTeleportEvent event = CraftEventFactory.callEntityTeleportEvent(this, (double) x + 0.5D, (double) y, (double) z + 0.5D); |