public class Clan extends FileNBT {
public static final String TAG = "clan";
public Clan() {
super(getDir(), TAG);
}
//В главном классе
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event) {
loadData();
}
@Mod.EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
saveData();
}
//Не в главном классе
public static File getDir() {
return new File(MinecraftServer.getServer().worldServers[0].getSaveHandler().getWorldDirectory(), "clan");
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
if (nbt.hasKey("Groups", NBT.TAG_LIST)) {
groups.clear();
NBTTagList nbttaglist = nbt.getTagList("Groups", NBT.TAG_COMPOUND);
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
ClanGroup clan_group = new ClanGroup(nbttagcompound1.getString("ClanName"));
if (nbttagcompound1.hasKey("ClanDesk", NBT.TAG_STRING))
clan_group.setClanDescription(nbttagcompound1.getString("ClanDesk"));
if (nbttagcompound1.hasKey("Access", NBT.TAG_BYTE)) {
for (Access access : Access.values()) {
if (access.ordinal() == nbttagcompound1.getByte("Access")) {
clan_group.setAccess(access);
break;
}
}
}
if (nbttagcompound1.hasKey("Commander", NBT.TAG_COMPOUND)) {
GameProfile game_prodile = NBTUtil.func_152459_a(nbttagcompound1.getCompoundTag("Commander"));
clan_group.setCommander(game_prodile);
}
if (nbttagcompound1.hasKey("DeputyCommander", NBT.TAG_COMPOUND)) {
GameProfile game_prodile = NBTUtil.func_152459_a(nbttagcompound1.getCompoundTag("DeputyCommander"));
clan_group.setDeputyCommander(game_prodile);
}
if (nbttagcompound1.hasKey("Members", NBT.TAG_LIST)) {
NBTTagList nbttaglist2 = nbttagcompound1.getTagList("Members", NBT.TAG_COMPOUND);
for (int i2 = 0; i2 < nbttaglist2.tagCount(); ++i2) {
NBTTagCompound nbttagcompound2 = nbttaglist2.getCompoundTagAt(i);
GameProfile game_prodile = NBTUtil.func_152459_a(nbttagcompound2);
clan_group.getMembers().add(game_prodile);
}
}
if (nbttagcompound1.hasKey("Symbol", NBT.TAG_COMPOUND))
clan_group.setSymbol(ItemStack.loadItemStackFromNBT(nbttagcompound1.getCompoundTag("Symbol")));
clan_group.setPoints(nbttagcompound1.getInteger("Points"));
groups.add(clan_group);
//System.out.println(clan_group.getClanName());
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
NBTTagList nbttaglist = new NBTTagList();
if (groups != null && !groups.isEmpty())
for (ClanGroup clan_group : groups) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
if (StringUtils.isNullOrEmpty(clan_group.getClanName())) continue;
nbttagcompound1.setString("ClanName", clan_group.getClanName());
if (!StringUtils.isNullOrEmpty(clan_group.getClanDescription()))
nbttagcompound1.setString("ClanDesk", clan_group.getClanDescription());
nbttagcompound1.setByte("Access", (byte)clan_group.getAccess().ordinal());
if (clan_group.getCommander() != null) {
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
NBTUtil.func_152460_a(nbttagcompound3, clan_group.getCommander());
nbttagcompound1.setTag("Commander", nbttagcompound3);
}
if (clan_group.getDeputyCommander() != null) {
NBTTagCompound nbttagcompound4 = new NBTTagCompound();
NBTUtil.func_152460_a(nbttagcompound4, clan_group.getDeputyCommander());
nbttagcompound1.setTag("DeputyCommander", nbttagcompound4);
}
if (clan_group.getMembers() != null && !clan_group.getMembers().isEmpty()) {
NBTTagList nbttaglist2 = new NBTTagList();
for (GameProfile game_profile : clan_group.getMembers()) {
if (game_profile == null) continue;
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
NBTUtil.func_152460_a(nbttagcompound2, game_profile);
nbttaglist2.appendTag(nbttagcompound2);
}
nbttagcompound1.setTag("Members", nbttaglist2);
}
if (clan_group.getSymbol() != null) {
NBTTagCompound nbttagcompound5 = new NBTTagCompound();
clan_group.getSymbol().writeToNBT(nbttagcompound5);
nbttagcompound1.setTag("Symbol", nbttagcompound5);
}
nbttagcompound1.setInteger("Points", clan_group.getPoints());
nbttaglist.appendTag(nbttagcompound1);
}
nbt.setTag("Groups", nbttaglist);
}
}