From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath 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/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 4e1796c06b35c8d262f67900f5079ecd42fa03df..e6b390709d7e3d8596a7814422e4d41fba0c11c2 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -277,6 +277,7 @@ public abstract class EntityLiving extends Entity { double d1 = this.world.getWorldBorder().getDamageAmount(); if (d1 > 0.0D) { + if (world.purpurConfig.teleportIfOutsideBorder && this instanceof EntityPlayer) { ((EntityPlayer) this).teleport(MCUtil.toLocation(world, world.getSpawn())); return; } // Purpur this.damageEntity(DamageSource.STUCK, (float) Math.max(1, MathHelper.floor(-d0 * d1))); } } diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 4caca2cb5ce981aa555ceb7464fedc9e32779d88..0d4ab4e8eda4059fbafe7645c9627ab5566edd85 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -2378,4 +2378,26 @@ public class EntityPlayer extends EntityHuman implements ICrafting { return (CraftPlayer) super.getBukkitEntity(); } // CraftBukkit end + + // Purpur start + public void teleport(Location to) { + this.ejectPassengers(); + this.stopRiding(true); + + if (this.isSleeping()) { + this.wakeup(true, false); + } + + if (this.activeContainer != this.defaultContainer) { + this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT); + } + + WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle(); + if (this.world == toWorld) { + this.playerConnection.teleport(to); + } else { + this.server.getPlayerList().moveToWorld(this, toWorld, true, to, !toWorld.paperConfig.disableTeleportationSuffocationCheck); + } + } + // Purpur end } diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java index 2f326f88257f5a45deee872865211d15fc67fac6..73027d6eed7b93fa8b9f580235259a262d50b96d 100644 --- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java +++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java @@ -178,6 +178,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 silkTouchSpawnerLore = new ArrayList<>();