2011-04-07 07:03:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
2011-06-29 02:58:34 +00:00
|
|
|
|
using Substrate.Core;
|
|
|
|
|
using Substrate.NBT;
|
2011-04-07 07:03:54 +00:00
|
|
|
|
|
|
|
|
|
namespace Substrate
|
|
|
|
|
{
|
|
|
|
|
public class PlayerManager
|
|
|
|
|
{
|
|
|
|
|
protected string _playerPath;
|
|
|
|
|
|
|
|
|
|
public PlayerManager (string playerDir)
|
|
|
|
|
{
|
|
|
|
|
_playerPath = playerDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected PlayerFile GetPlayerFile (string name)
|
|
|
|
|
{
|
|
|
|
|
return new PlayerFile(_playerPath, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected NBT_Tree GetPlayerTree (string name)
|
|
|
|
|
{
|
|
|
|
|
PlayerFile pf = GetPlayerFile(name);
|
2011-04-07 08:04:53 +00:00
|
|
|
|
Stream nbtstr = pf.GetDataInputStream();
|
2011-04-07 07:03:54 +00:00
|
|
|
|
if (nbtstr == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new NBT_Tree(nbtstr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected bool SavePlayerTree (string name, NBT_Tree tree)
|
|
|
|
|
{
|
|
|
|
|
PlayerFile pf = GetPlayerFile(name);
|
2011-04-07 08:04:53 +00:00
|
|
|
|
Stream zipstr = pf.GetDataOutputStream();
|
2011-04-07 07:03:54 +00:00
|
|
|
|
if (zipstr == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree.WriteTo(zipstr);
|
|
|
|
|
zipstr.Close();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Player GetPlayer (string name)
|
|
|
|
|
{
|
|
|
|
|
if (!PlayerExists(name)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Player().LoadTreeSafe(GetPlayerTree(name).Root);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SetPlayer (string name, Player player)
|
|
|
|
|
{
|
2011-06-20 03:51:40 +00:00
|
|
|
|
return SavePlayerTree(name, new NBT_Tree(player.BuildTree() as TagNodeCompound));
|
2011-04-07 07:03:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool PlayerExists (string name)
|
|
|
|
|
{
|
|
|
|
|
return new PlayerFile(_playerPath, name).Exists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool DeletePlayer (string name)
|
|
|
|
|
{
|
|
|
|
|
new PlayerFile(_playerPath, name).Delete();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|