From d5bfae0d2fdd13e89d097186bc54e85e6ab0c2ce Mon Sep 17 00:00:00 2001 From: Shevchik Date: Thu, 6 Mar 2014 16:54:15 +0400 Subject: [PATCH] Teleport player to spawn if he logged in with nan location --- src/com/cnaude/chairs/core/Chairs.java | 8 ++++---- .../chairs/listeners/NANLoginListener.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/com/cnaude/chairs/listeners/NANLoginListener.java diff --git a/src/com/cnaude/chairs/core/Chairs.java b/src/com/cnaude/chairs/core/Chairs.java index 6db9705..0295ff7 100644 --- a/src/com/cnaude/chairs/core/Chairs.java +++ b/src/com/cnaude/chairs/core/Chairs.java @@ -21,6 +21,7 @@ import org.bukkit.util.Vector; import com.cnaude.chairs.commands.ChairsCommand; import com.cnaude.chairs.commands.ChairsIgnoreList; +import com.cnaude.chairs.listeners.NANLoginListener; import com.cnaude.chairs.listeners.TrySitEventListener; import com.cnaude.chairs.listeners.TryUnsitEventListener; import com.cnaude.chairs.sitaddons.ChairEffects; @@ -50,13 +51,11 @@ public class Chairs extends JavaPlugin { private PlayerSitData psitdata; - public PlayerSitData getPlayerSitData() - { + public PlayerSitData getPlayerSitData() { return psitdata; } private Class vehiclearrowclass; - protected Class getVehicleArrowClass() - { + protected Class getVehicleArrowClass() { return vehiclearrowclass; } @@ -96,6 +95,7 @@ public class Chairs extends JavaPlugin { if (sitPickupEnabled) { chairEffects.startPickup(); } + getServer().getPluginManager().registerEvents(new NANLoginListener(), this); getServer().getPluginManager().registerEvents(new TrySitEventListener(this, ignoreList), this); getServer().getPluginManager().registerEvents(new TryUnsitEventListener(this), this); getServer().getPluginManager().registerEvents(new CommandRestrict(this), this); diff --git a/src/com/cnaude/chairs/listeners/NANLoginListener.java b/src/com/cnaude/chairs/listeners/NANLoginListener.java new file mode 100644 index 0000000..24d82f9 --- /dev/null +++ b/src/com/cnaude/chairs/listeners/NANLoginListener.java @@ -0,0 +1,19 @@ +package com.cnaude.chairs.listeners; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class NANLoginListener implements Listener { + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (Double.isNaN(player.getLocation().getY())) { + player.teleport(player.getWorld().getSpawnLocation()); + } + } + +}