From f532fca42576d19dfbb3aa55c5f47b8383f8a7e5 Mon Sep 17 00:00:00 2001
From: Steve Anton <anxuiz.nx@gmail.com>
Date: Tue, 22 Dec 2015 22:06:19 -0600
Subject: [PATCH] Add PlayerInitialSpawnEvent

---
 .../Add-PlayerInitialSpawnEvent.patch         | 57 +++++++++++++++++++
 .../Add-PlayerInitialSpawnEvent.patch         | 35 ++++++++++++
 2 files changed, 92 insertions(+)
 create mode 100644 Spigot-API-Patches/Add-PlayerInitialSpawnEvent.patch
 create mode 100644 Spigot-Server-Patches/Add-PlayerInitialSpawnEvent.patch

diff --git a/Spigot-API-Patches/Add-PlayerInitialSpawnEvent.patch b/Spigot-API-Patches/Add-PlayerInitialSpawnEvent.patch
new file mode 100644
index 0000000000..94f9911b78
--- /dev/null
+++ b/Spigot-API-Patches/Add-PlayerInitialSpawnEvent.patch
@@ -0,0 +1,57 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Steve Anton <anxuiz.nx@gmail.com>
+Date: Tue, 22 Dec 2015 22:04:15 -0600
+Subject: [PATCH] Add PlayerInitialSpawnEvent
+
+For modifying a player's initial spawn location as they join the server
+
+diff --git a/src/main/java/org/bukkit/event/player/PlayerInitialSpawnEvent.java b/src/main/java/org/bukkit/event/player/PlayerInitialSpawnEvent.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
+--- /dev/null
++++ b/src/main/java/org/bukkit/event/player/PlayerInitialSpawnEvent.java
+@@ -0,0 +0,0 @@
++package org.bukkit.event.player;
++
++import org.bukkit.Location;
++import org.bukkit.entity.Player;
++import org.bukkit.event.HandlerList;
++
++public class PlayerInitialSpawnEvent extends PlayerEvent {
++    private static final HandlerList handlers = new HandlerList();
++    private Location spawnLocation;
++
++    public PlayerInitialSpawnEvent(final Player player, final Location spawnLocation) {
++        super(player);
++        this.spawnLocation = spawnLocation;
++    }
++
++    /**
++     * Gets the current spawn location
++     *
++     * @return Location current spawn location
++     */
++    public Location getSpawnLocation() {
++        return this.spawnLocation;
++    }
++
++    /**
++     * Sets the new spawn location
++     *
++     * @param spawnLocation new location for the spawn
++     */
++    public void setSpawnLocation(Location spawnLocation) {
++        this.spawnLocation = spawnLocation;
++    }
++
++    @Override
++    public HandlerList getHandlers() {
++        return handlers;
++    }
++
++    public static HandlerList getHandlerList() {
++        return handlers;
++    }
++}
+\ No newline at end of file
+--
\ No newline at end of file
diff --git a/Spigot-Server-Patches/Add-PlayerInitialSpawnEvent.patch b/Spigot-Server-Patches/Add-PlayerInitialSpawnEvent.patch
new file mode 100644
index 0000000000..2d630cf8e8
--- /dev/null
+++ b/Spigot-Server-Patches/Add-PlayerInitialSpawnEvent.patch
@@ -0,0 +1,35 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Steve Anton <anxuiz.nx@gmail.com>
+Date: Tue, 22 Dec 2015 22:04:15 -0600
+Subject: [PATCH] Add PlayerInitialSpawnEvent
+
+For modifying a player's initial spawn location as they join the server
+
+diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/server/PlayerList.java
++++ b/src/main/java/net/minecraft/server/PlayerList.java
+@@ -0,0 +0,0 @@ public abstract class PlayerList {
+         }
+         // CraftBukkit end
+ 
++        // PaperSpigot start - support PlayerInitialSpawnEvent
++        Location originalLoc = new Location(entityplayer.world.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
++        org.bukkit.event.player.PlayerInitialSpawnEvent event = new org.bukkit.event.player.PlayerInitialSpawnEvent(entityplayer.getBukkitEntity(), originalLoc);
++        this.server.server.getPluginManager().callEvent(event);
++
++        Location newLoc = event.getSpawnLocation();
++        entityplayer.world = ((CraftWorld) newLoc.getWorld()).getHandle();
++        entityplayer.locX = newLoc.getX();
++        entityplayer.locY = newLoc.getY();
++        entityplayer.locZ = newLoc.getZ();
++        entityplayer.yaw = newLoc.getYaw();
++        entityplayer.pitch = newLoc.getPitch();
++        entityplayer.dimension = ((CraftWorld) newLoc.getWorld()).getHandle().dimension;
++        entityplayer.spawnWorld = entityplayer.world.worldData.getName();
++        // PaperSpigot end
++
+         entityplayer.spawnIn(this.server.getWorldServer(entityplayer.dimension));
+         entityplayer.playerInteractManager.a((WorldServer) entityplayer.world);
+         String s1 = "local";
+--
\ No newline at end of file