Files
Purpur/patches/server/0083-Add-option-to-teleport-to-spawn-if-outside-world-bor.patch
Ben Kerllenevich d9a75665da 9
2021-06-17 09:42:14 -04:00

73 lines
3.7 KiB
Diff

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/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 24fb9596b86f37bf47f1661e85660a73618bc0a5..6958d29382d270b8f4012a0a1ddf1229d5c43d48 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -2440,5 +2440,25 @@ public class ServerPlayer extends Player {
}
// 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().moveToWorld(this, toLevel, true, to, !toLevel.paperConfig.disableTeleportationSuffocationCheck);
+ }
+ }
+ // Purpur end
}
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 04a565e35deac75d03e9af4a47e3b28439e68694..36a1b330d5ad04da6aa231098998a17a7a0f6a74 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -45,6 +45,7 @@ import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MCUtil;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
@@ -407,6 +408,7 @@ public abstract class LivingEntity extends Entity {
double d1 = this.level.getWorldBorder().getDamagePerBlock();
if (d1 > 0.0D) {
+ if (level.purpurConfig.teleportIfOutsideBorder && this instanceof ServerPlayer) { ((ServerPlayer) this).teleport(MCUtil.toLocation(level, level.getSharedSpawnPos())); return; } // Purpur
this.hurt(DamageSource.IN_WALL, (float) Math.max(1, Mth.floor(-d0 * d1)));
}
}
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 1c9d361b078c5e731dfce11c1a2d23b2a84a44f5..f8e22d256c95030d5f685e389f6645d8344a38b9 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -242,6 +242,11 @@ public class PurpurWorldConfig {
playerInvulnerableWhileAcceptingResourcePack = getBoolean("gameplay-mechanics.player.invulnerable-while-accepting-resource-pack", playerInvulnerableWhileAcceptingResourcePack);
}
+ public boolean teleportIfOutsideBorder = false;
+ private void teleportIfOutsideBorder() {
+ teleportIfOutsideBorder = getBoolean("gameplay-mechanics.player.teleport-if-outside-border", teleportIfOutsideBorder);
+ }
+
public boolean silkTouchEnabled = false;
public String silkTouchSpawnerName = "Spawner";
public List<String> silkTouchSpawnerLore = new ArrayList<>();