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 82ef4c9c534f4a0840a61d33c7727bd4770c7511..bfbe9b82c14a525bffa96a8dfa071e8805ce6006 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -280,6 +280,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 e36bfda9be9874eaa5dfd6886d2bb8b9be5adbfa..036bf70c578b7bd1201405a8517695f627a5f079 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -2394,4 +2394,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 5a04f0e506293f76bc43540142ca3b26cf97c760..0b2a9a2d9f157dd9879c4429be6745859b4f28bf 100644 --- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java +++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java @@ -196,6 +196,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<>();