Save player location if he quit sitting on chair and restore it on join
This commit is contained in:
parent
8da5322de5
commit
6eae9eb644
@ -1,6 +1,7 @@
|
|||||||
package com.cnaude.chairs;
|
package com.cnaude.chairs;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -12,7 +13,10 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
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.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -73,6 +77,7 @@ public class Chairs extends JavaPlugin {
|
|||||||
protocolManager.getAsynchronousManager().unregisterAsyncHandlers(this);
|
protocolManager.getAsynchronousManager().unregisterAsyncHandlers(this);
|
||||||
protocolManager = null;
|
protocolManager = null;
|
||||||
for (String pName : new HashSet<String>(sit.keySet())) {
|
for (String pName : new HashSet<String>(sit.keySet())) {
|
||||||
|
savePlayerSitstoploc(pName);
|
||||||
ejectPlayerOnDisable(Bukkit.getPlayerExact(pName));
|
ejectPlayerOnDisable(Bukkit.getPlayerExact(pName));
|
||||||
}
|
}
|
||||||
if (ignoreList != null) {
|
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() {
|
public void loadConfig() {
|
||||||
autoRotate = getConfig().getBoolean("auto-rotate");
|
autoRotate = getConfig().getBoolean("auto-rotate");
|
||||||
signCheck = getConfig().getBoolean("sign-check");
|
signCheck = getConfig().getBoolean("sign-check");
|
||||||
|
@ -36,34 +36,11 @@ public class EventListener implements Listener {
|
|||||||
@EventHandler(priority=EventPriority.LOWEST,ignoreCancelled=true)
|
@EventHandler(priority=EventPriority.LOWEST,ignoreCancelled=true)
|
||||||
public void onJoin(PlayerJoinEvent e)
|
public void onJoin(PlayerJoinEvent e)
|
||||||
{
|
{
|
||||||
if (!plugin.authmelogincorrection)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
Location loc = player.getLocation();
|
Location loc = plugin.getPlayerSitstoploc(player.getName());
|
||||||
if (Double.isNaN(loc.getY()))
|
if (loc != null)
|
||||||
{
|
{
|
||||||
Location teleportloc = null;
|
player.teleport(loc);
|
||||||
//corect y, there should be a valid chair somewhere up
|
|
||||||
Location temploc = loc.clone();
|
|
||||||
for (int i = 1 ; i<loc.getWorld().getMaxHeight(); i++)
|
|
||||||
{
|
|
||||||
temploc.setY(i);
|
|
||||||
if (sitAllowed(player, temploc.getBlock()))
|
|
||||||
{
|
|
||||||
//maybe this is a chair we are looking for
|
|
||||||
teleportloc = temploc.clone();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if we didn't find the chair just teleport player to world spawn
|
|
||||||
if (teleportloc == null)
|
|
||||||
{
|
|
||||||
teleportloc = player.getWorld().getSpawnLocation();
|
|
||||||
}
|
|
||||||
player.teleport(teleportloc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,6 +50,7 @@ public class EventListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (plugin.sit.containsKey(player.getName()))
|
if (plugin.sit.containsKey(player.getName()))
|
||||||
{
|
{
|
||||||
|
plugin.savePlayerSitstoploc(player.getName());
|
||||||
plugin.ejectPlayer(player);
|
plugin.ejectPlayer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user