diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index 6bf5d37..dcb0d40 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -1,6 +1,7 @@ package com.cnaude.chairs; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -12,7 +13,10 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -73,6 +77,7 @@ public class Chairs extends JavaPlugin { protocolManager.getAsynchronousManager().unregisterAsyncHandlers(this); protocolManager = null; for (String pName : new HashSet(sit.keySet())) { + savePlayerSitstoploc(pName); ejectPlayerOnDisable(Bukkit.getPlayerExact(pName)); } if (ignoreList != null) { @@ -167,6 +172,36 @@ public class Chairs extends JavaPlugin { } + protected void savePlayerSitstoploc(String player) + { + FileConfiguration plconfig = new YamlConfiguration(); + Location sitstop = sitstopteleportloc.get(player); + plconfig.set(player+".world", sitstop.getWorld().getName()); + plconfig.set(player+".xyz", sitstop.toVector()); + plconfig.set(player+".pitch", sitstop.getPitch()); + plconfig.set(player+".yaw", sitstop.getYaw()); + try { + plconfig.save(new File(getDataFolder(),"playersdata"+File.separator+player+".yml")); + } catch (IOException e) { + } + } + protected Location getPlayerSitstoploc(String player) + { + File plfile = new File(getDataFolder(),"playersdata"+File.separator+player+".yml"); + if (plfile.exists()) + { + FileConfiguration plconfig = YamlConfiguration.loadConfiguration(plfile); + World world = Bukkit.getWorld(plconfig.getString(player+".world")); + Vector xyz = plconfig.getVector(player+".xyz"); + Location sitstop = new Location(world,xyz.getX(),xyz.getY(),xyz.getZ()); + sitstop.setPitch((float) plconfig.getDouble(player+".pitch")); + sitstop.setYaw((float) plconfig.getDouble(player+".yaw")); + plfile.delete(); + return sitstop; + } + return null; + } + public void loadConfig() { autoRotate = getConfig().getBoolean("auto-rotate"); signCheck = getConfig().getBoolean("sign-check"); diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index 90311d4..38c5216 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -35,35 +35,12 @@ public class EventListener implements Listener { @EventHandler(priority=EventPriority.LOWEST,ignoreCancelled=true) public void onJoin(PlayerJoinEvent e) - { - if (!plugin.authmelogincorrection) - { - return; - } - + { Player player = e.getPlayer(); - Location loc = player.getLocation(); - if (Double.isNaN(loc.getY())) + Location loc = plugin.getPlayerSitstoploc(player.getName()); + if (loc != null) { - Location teleportloc = null; - //corect y, there should be a valid chair somewhere up - Location temploc = loc.clone(); - for (int i = 1 ; i