Add PlayerSpawnLocationEvent - API & implementation.
This commit is contained in:
parent
2031db9986
commit
124d44473c
65
Bukkit-Patches/0028-Add-PlayerSpawnLocationEvent.patch
Normal file
65
Bukkit-Patches/0028-Add-PlayerSpawnLocationEvent.patch
Normal file
|
@ -0,0 +1,65 @@
|
|||
From 0257e758e92240022e5ca1559204ab058942c368 Mon Sep 17 00:00:00 2001
|
||||
From: ninja <xninja@openmailbox.org>
|
||||
Date: Tue, 8 Apr 2014 14:01:32 +0200
|
||||
Subject: [PATCH] Add PlayerSpawnLocationEvent.
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/spigotmc/event/player/PlayerSpawnLocationEvent.java b/src/main/java/org/spigotmc/event/player/PlayerSpawnLocationEvent.java
|
||||
new file mode 100644
|
||||
index 0000000..dd3f58c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/spigotmc/event/player/PlayerSpawnLocationEvent.java
|
||||
@@ -0,0 +1,50 @@
|
||||
+package org.spigotmc.event.player;
|
||||
+
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.entity.Entity;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.player.PlayerEvent;
|
||||
+
|
||||
+/**
|
||||
+ * Called when player is about to spawn in a world after joining the server.
|
||||
+ */
|
||||
+public class PlayerSpawnLocationEvent extends PlayerEvent {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private Location spawnLocation;
|
||||
+
|
||||
+ public PlayerSpawnLocationEvent(final Player who, Location spawnLocation) {
|
||||
+ super(who);
|
||||
+ this.spawnLocation = spawnLocation;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ /**
|
||||
+ * Gets player's spawn location.
|
||||
+ * If the player {@link Player#hasPlayedBefore()}, it's going to default to the location inside player.dat file.
|
||||
+ * For new players, the default spawn location is spawn of the main Bukkit world.
|
||||
+ *
|
||||
+ * @return the spawn location
|
||||
+ */
|
||||
+ public Location getSpawnLocation() {
|
||||
+ return spawnLocation;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets player's spawn location.
|
||||
+ *
|
||||
+ * @param location the spawn location
|
||||
+ */
|
||||
+ public void setSpawnLocation(Location location) {
|
||||
+ this.spawnLocation = location;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
1.9.1
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
From 936a1c01475e1e77f038183c27e882e7bb47a912 Mon Sep 17 00:00:00 2001
|
||||
From: ninja <xninja@openmailbox.org>
|
||||
Date: Tue, 8 Apr 2014 14:05:19 +0200
|
||||
Subject: [PATCH] Implement PlayerSpawnLocationEvent.
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
||||
index 49837b4..bbef888 100644
|
||||
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
||||
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
||||
@@ -36,6 +36,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.util.Vector;
|
||||
+import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
public abstract class PlayerList {
|
||||
@@ -99,6 +100,19 @@ public abstract class PlayerList {
|
||||
s1 = networkmanager.getSocketAddress().toString();
|
||||
}
|
||||
|
||||
+ // Spigot start - spawn location event
|
||||
+ Player bukkitPlayer = entityplayer.getBukkitEntity();
|
||||
+ PlayerSpawnLocationEvent ev = new PlayerSpawnLocationEvent(bukkitPlayer, bukkitPlayer.getLocation());
|
||||
+ Bukkit.getPluginManager().callEvent(ev);
|
||||
+
|
||||
+ Location loc = ev.getSpawnLocation();
|
||||
+ WorldServer world = ((CraftWorld) loc.getWorld()).getHandle();
|
||||
+
|
||||
+ entityplayer.spawnIn(world);
|
||||
+ entityplayer.setPosition(loc.getX(), loc.getY(), loc.getZ());
|
||||
+ entityplayer.b(loc.getYaw(), loc.getPitch()); // should be setYawAndPitch
|
||||
+ // Spigot end
|
||||
+
|
||||
// CraftBukkit - Moved message to after join
|
||||
// g.info(entityplayer.getName() + "[" + s1 + "] logged in with entity id " + entityplayer.getId() + " at (" + entityplayer.locX + ", " + entityplayer.locY + ", " + entityplayer.locZ + ")");
|
||||
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
|
||||
--
|
||||
1.9.1
|
||||
|
Loading…
Reference in a new issue