Add option to teleport to spawn if outside world border

This commit is contained in:
William Blake Galbreath
2025-01-07 16:57:11 -08:00
committed by granny
parent d2a0414806
commit bb8ed69b06
6 changed files with 48 additions and 75 deletions

View File

@@ -1,69 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Mon, 13 Jul 2020 11:40:00 -0500
Subject: [PATCH] Add option to teleport to spawn if outside world border
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 3ea226168519e07b10d015f4c9b2b369569daf11..5d4b0f8b621f62604f098da7bf0822d25b469547 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -3390,4 +3390,26 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
return (CraftPlayer) super.getBukkitEntity();
}
// CraftBukkit end
+
+ // Purpur start
+ public void teleport(Location to) {
+ this.ejectPassengers();
+ this.stopRiding(true);
+
+ if (this.isSleeping()) {
+ this.stopSleepInBed(true, false);
+ }
+
+ if (this.containerMenu != this.inventoryMenu) {
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT);
+ }
+
+ ServerLevel toLevel = ((CraftWorld) to.getWorld()).getHandle();
+ if (this.level() == toLevel) {
+ this.connection.teleport(to);
+ } else {
+ this.server.getPlayerList().respawn(this, true, RemovalReason.KILLED, org.bukkit.event.player.PlayerRespawnEvent.RespawnReason.DEATH, to);
+ }
+ }
+ // Purpur end
}
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index d711bef21fba8e32ae99a0a52992e609e4841734..c073786171306ba023f31d2f9ede037707253fa2 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -477,6 +477,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (d1 < 0.0D) {
d0 = this.level().getWorldBorder().getDamagePerBlock();
if (d0 > 0.0D) {
+ if (level().purpurConfig.teleportIfOutsideBorder && this instanceof ServerPlayer serverPlayer) { serverPlayer.teleport(io.papermc.paper.util.MCUtil.toLocation(level(), ((ServerLevel) level()).getSharedSpawnPos())); return; } // Purpur
this.hurtServer(worldserver1, this.damageSources().outOfBorder(), (float) Math.max(1, Mth.floor(-d1 * d0)));
}
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
index bfd03c3cdc2b80415730aa1a18fad5afe838df25..b5d714f137257810ced4b4457bd5bb01123d3452 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
@@ -237,6 +237,7 @@ public class PurpurWorldConfig {
public boolean idleTimeoutTargetPlayer = true;
public String playerDeathExpDropEquation = "expLevel * 7";
public int playerDeathExpDropMax = 100;
+ public boolean teleportIfOutsideBorder = false;
private void playerSettings() {
if (PurpurConfig.version < 19) {
boolean oldVal = getBoolean("gameplay-mechanics.player.idle-timeout.mods-target", idleTimeoutTargetPlayer);
@@ -250,6 +251,7 @@ public class PurpurWorldConfig {
idleTimeoutTargetPlayer = getBoolean("gameplay-mechanics.player.idle-timeout.mobs-target", idleTimeoutTargetPlayer);
playerDeathExpDropEquation = getString("gameplay-mechanics.player.exp-dropped-on-death.equation", playerDeathExpDropEquation);
playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax);
+ teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder);
}
public boolean silkTouchEnabled = false;

View File

@@ -42,7 +42,7 @@ index 8d8248a014d95f1fc0d75b2c14c010eef39bab62..f2cd492c8c66ffe2eca5bbd925469a76
public LevelChunk getChunkIfLoaded(int x, int z) {
return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper - Use getChunkIfLoadedImmediately
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 8be848d3aaa34be2fa9a9de8f9f2908f0903b60f..a1ebdd491e79fff8e224095ee6058cd550c009f4 100644
index f8a31e8b2f917e9d00827dc98bfb766be1f9f85a..041019ff63f7f437c140ea354f84e49bc5e3184d 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -838,6 +838,15 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -177,7 +177,7 @@ index efee812785240c1ab1fd47514cfb236a3548f9cf..666455fff2b391b637cf1c07091e8810
protected ParticleOptions getInkParticle() {
return ParticleTypes.GLOW_SQUID_INK;
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index fd518913a12651a6df719628dfedc88b70806567..3e85aa9f530bef69a678c9349f366d9c65c87311 100644
index 359bb2a1a2b39d212280f39c853d2ef53bb3bdf5..d165166b9cdf8be3e403fe595da7e58495072ef8 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -250,9 +250,9 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -210,7 +210,7 @@ index fd518913a12651a6df719628dfedc88b70806567..3e85aa9f530bef69a678c9349f366d9c
@Override
protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos) {
@@ -3479,8 +3480,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3485,8 +3486,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.pushEntities();
profilerFiller.pop();
// Paper start - Add EntityMoveEvent
@@ -223,7 +223,7 @@ index fd518913a12651a6df719628dfedc88b70806567..3e85aa9f530bef69a678c9349f366d9c
Location from = new Location(this.level().getWorld(), this.xo, this.yo, this.zo, this.yRotO, this.xRotO);
Location to = new Location(this.level().getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
io.papermc.paper.event.entity.EntityMoveEvent event = new io.papermc.paper.event.entity.EntityMoveEvent(this.getBukkitLivingEntity(), from, to.clone());
@@ -3490,6 +3493,21 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3496,6 +3499,21 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.absMoveTo(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ(), event.getTo().getYaw(), event.getTo().getPitch());
}
}

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Implement elytra settings
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index e0b348d8c9f030e745b84d88ad52f70e4214e098..b4add726d6e1c192ecb9524dd9ea6e6c8b6a345d 100644
index 5dc3152ab79df8c2dd62c4b207ffab71bc8c158a..1d432935fb0967a32a77cc882b5093d6e0781d15 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -3537,7 +3537,18 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3543,7 +3543,18 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (i1 % 2 == 0) {
List<EquipmentSlot> list = EquipmentSlot.VALUES.stream().filter(slot -> canGlideUsing(this.getItemBySlot(slot), slot)).toList();
EquipmentSlot equipmentSlot = Util.getRandom(list, this.random);

View File

@@ -125,3 +125,30 @@
public ServerStatsCounter getStats() {
return this.stats;
@@ -3077,4 +_,26 @@
return (org.bukkit.craftbukkit.entity.CraftPlayer) super.getBukkitEntity();
}
// CraftBukkit end
+
+ // Purpur start - Add option to teleport to spawn if outside world border
+ public void teleport(org.bukkit.Location to) {
+ this.ejectPassengers();
+ this.stopRiding(true);
+
+ if (this.isSleeping()) {
+ this.stopSleepInBed(true, false);
+ }
+
+ if (this.containerMenu != this.inventoryMenu) {
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT);
+ }
+
+ ServerLevel toLevel = ((org.bukkit.craftbukkit.CraftWorld) to.getWorld()).getHandle();
+ if (this.level() == toLevel) {
+ this.connection.teleport(to);
+ } else {
+ this.server.getPlayerList().respawn(this, true, RemovalReason.KILLED, org.bukkit.event.player.PlayerRespawnEvent.RespawnReason.DEATH, to);
+ }
+ }
+ // Purpur end - Add option to teleport to spawn if outside world border
}

View File

@@ -1,5 +1,18 @@
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -459,6 +_,12 @@
if (d < 0.0) {
double damagePerBlock = this.level().getWorldBorder().getDamagePerBlock();
if (damagePerBlock > 0.0) {
+ // Purpur start - Add option to teleport to spawn if outside world border
+ if (this.level().purpurConfig.teleportIfOutsideBorder && this instanceof ServerPlayer serverPlayer) {
+ serverPlayer.teleport(io.papermc.paper.util.MCUtil.toLocation(this.level(), this.level().getSharedSpawnPos()));
+ return;
+ }
+ // Purpur end - Add option to teleport to spawn if outside world border
this.hurtServer(serverLevel1, this.damageSources().outOfBorder(), Math.max(1, Mth.floor(-d * damagePerBlock)));
}
}
@@ -1788,6 +_,7 @@
boolean flag = this.lastHurtByPlayerTime > 0;
this.dropEquipment(level); // CraftBukkit - from below

View File

@@ -226,6 +226,7 @@ public class PurpurWorldConfig {
public boolean idleTimeoutTargetPlayer = true;
public String playerDeathExpDropEquation = "expLevel * 7";
public int playerDeathExpDropMax = 100;
public boolean teleportIfOutsideBorder = false;
private void playerSettings() {
if (PurpurConfig.version < 19) {
boolean oldVal = getBoolean("gameplay-mechanics.player.idle-timeout.mods-target", idleTimeoutTargetPlayer);
@@ -239,6 +240,7 @@ public class PurpurWorldConfig {
idleTimeoutTargetPlayer = getBoolean("gameplay-mechanics.player.idle-timeout.mobs-target", idleTimeoutTargetPlayer);
playerDeathExpDropEquation = getString("gameplay-mechanics.player.exp-dropped-on-death.equation", playerDeathExpDropEquation);
playerDeathExpDropMax = getInt("gameplay-mechanics.player.exp-dropped-on-death.maximum", playerDeathExpDropMax);
teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder);
}
public boolean silkTouchEnabled = false;