use of net.dzikoysk.funnyguilds.util.Yamler in project FunnyGuilds by FunnyGuilds.
the class FlatRegion method deserialize.
public static Region deserialize(File file) {
Yamler pc = new Yamler(file);
String name = pc.getString("name");
String cs = pc.getString("center");
int size = pc.getInt("size");
int enlarge = pc.getInt("enlarge");
pc = null;
if (name == null || cs == null) {
FunnyLogger.error("Cannot deserialize region! Caused by: name/center is null");
return null;
}
Location center = Parser.parseLocation(cs);
if (center == null) {
FunnyLogger.error("Cannot deserialize region! Caused by: center is null");
return null;
}
if (size < 1) {
size = Settings.getConfig().regionSize;
}
Object[] values = new Object[4];
values[0] = name;
values[1] = center;
values[2] = size;
values[3] = enlarge;
return DeserializationUtils.deserializeRegion(values);
}
use of net.dzikoysk.funnyguilds.util.Yamler in project FunnyGuilds by FunnyGuilds.
the class FlatUser method deserialize.
public static User deserialize(File file) {
if (file.isDirectory()) {
return null;
}
Yamler pc = new Yamler(file);
String id = pc.getString("uuid");
String name = pc.getString("name");
int points = pc.getInt("points");
int kills = pc.getInt("kills");
int deaths = pc.getInt("deaths");
long ban = pc.getLong("ban");
String reason = pc.getString("reason");
if (id == null || name == null) {
return null;
}
Object[] values = new Object[7];
values[0] = id;
values[1] = name;
values[2] = points;
values[3] = kills;
values[4] = deaths;
values[5] = ban;
values[6] = reason;
return DeserializationUtils.deserializeUser(values);
}
use of net.dzikoysk.funnyguilds.util.Yamler in project FunnyGuilds by FunnyGuilds.
the class Data method invitations.
private void invitations(DO todo) {
File file = new File(folder, "invitations.yml");
if (todo == DO.SAVE) {
file.delete();
Yamler pc = new Yamler(file);
for (Guild guild : GuildUtils.getGuilds()) {
List<InvitationList.Invitation> invitationList = InvitationList.getInvitationsFrom(guild);
for (InvitationList.Invitation invitation : invitationList) {
List<String> allyInvitations = new ArrayList<>();
List<String> playerInvitations = new ArrayList<>();
if (invitation.isToGuild()) {
playerInvitations.add(invitation.getFor().toString());
} else if (invitation.isToAlly()) {
allyInvitations.add(invitation.getFor().toString());
}
pc.set(invitation.getFrom().toString() + ".guilds", allyInvitations);
pc.set(invitation.getFrom().toString() + ".players", playerInvitations);
}
}
pc.save();
} else if (todo == DO.LOAD) {
if (!file.exists()) {
return;
}
Yamler pc = new Yamler(file);
for (String key : pc.getKeys(false)) {
Guild guild = GuildUtils.getByUUID(UUID.fromString(key));
if (guild != null) {
List<String> allyInvitations = pc.getStringList(key + ".guilds");
List<String> playerInvitations = pc.getStringList(key + ".players");
for (String ally : allyInvitations) {
Guild allyGuild = GuildUtils.getByUUID(UUID.fromString(ally));
if (allyGuild != null) {
InvitationList.createInvitation(guild, allyGuild);
}
}
for (String player : playerInvitations) {
InvitationList.createInvitation(guild, UUID.fromString(player));
}
}
}
}
}
use of net.dzikoysk.funnyguilds.util.Yamler in project FunnyGuilds by FunnyGuilds.
the class FlatGuild method deserialize.
public static Guild deserialize(File file) {
PluginConfig config = Settings.getConfig();
Yamler pc = new Yamler(file);
String id = pc.getString("uuid");
String name = pc.getString("name");
String tag = pc.getString("tag");
String os = pc.getString("owner");
String dp = pc.getString("deputy");
String hs = pc.getString("home");
String region = pc.getString("region");
List<String> ms = pc.getStringList("members");
List<String> rgs = pc.getStringList("regions");
List<String> als = pc.getStringList("allies");
List<String> ens = pc.getStringList("enemies");
boolean pvp = pc.getBoolean("pvp");
long born = pc.getLong("born");
long validity = pc.getLong("validity");
long attacked = pc.getLong("attacked");
long ban = pc.getLong("ban");
int lives = pc.getInt("lives");
if (name == null) {
FunnyLogger.error("[Deserialize] Cannot deserialize guild! Caused by: name is null");
return null;
} else if (tag == null) {
FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: tag is null");
return null;
} else if (os == null) {
FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: owner is null");
return null;
} else if (region == null && config.regionsEnabled) {
FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: region is null");
return null;
}
Region rg = RegionUtils.get(region);
if (rg == null && config.regionsEnabled) {
FunnyLogger.error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: region (object) is null");
return null;
}
UUID uuid = UUID.randomUUID();
if (id != null) {
uuid = UUID.fromString(id);
}
User owner = User.get(os);
List<User> deputies = new ArrayList<>();
if (dp != null && !dp.isEmpty()) {
deputies = UserUtils.getUsers(StringUtils.fromString(dp));
}
Location home = null;
if (rg != null) {
home = rg.getCenter();
if (hs != null) {
home = Parser.parseLocation(hs);
}
}
if (ms == null || ms.isEmpty()) {
ms = new ArrayList<>();
ms.add(os);
}
List<User> members = UserUtils.getUsers(ms);
List<String> regions = new ArrayList<>();
if (rgs != null) {
for (String n : rgs) {
if (RegionUtils.get(n) != null) {
regions.add(n);
}
}
}
List<Guild> allies = new ArrayList<>();
if (als != null) {
for (String s : als) {
Guild guild = GuildUtils.getByName(s);
if (guild != null) {
allies.add(guild);
}
}
}
List<Guild> enemies = new ArrayList<>();
if (ens != null) {
for (String s : ens) {
Guild guild = GuildUtils.getByName(s);
if (guild != null) {
enemies.add(guild);
}
}
}
if (born == 0) {
born = System.currentTimeMillis();
}
if (validity == 0) {
validity = System.currentTimeMillis() + config.validityStart;
}
if (lives == 0) {
lives = config.warLives;
}
Object[] values = new Object[17];
values[0] = uuid;
values[1] = name;
values[2] = tag;
values[3] = owner;
values[4] = home;
values[5] = region;
values[6] = members;
values[7] = regions;
values[8] = allies;
values[9] = enemies;
values[10] = born;
values[11] = validity;
values[12] = attacked;
values[13] = lives;
values[14] = ban;
values[15] = deputies;
values[16] = pvp;
return DeserializationUtils.deserializeGuild(values);
}
use of net.dzikoysk.funnyguilds.util.Yamler in project FunnyGuilds by FunnyGuilds.
the class FlatGuild method serialize.
public boolean serialize() {
if (guild.getName() == null) {
FunnyLogger.error("[Serialize] Cannot serialize guild! Caused by: name is null");
return false;
} else if (guild.getTag() == null) {
FunnyLogger.error("[Serialize] Cannot serialize guild: " + guild.getName() + "! Caused by: tag is null");
return false;
} else if (guild.getOwner() == null) {
FunnyLogger.error("[Serialize] Cannot serialize guild: " + guild.getName() + "! Caused by: owner is null");
return false;
} else if (guild.getRegion() == null && Settings.getConfig().regionsEnabled) {
FunnyLogger.error("[Serialize] Cannot serialize guild: " + guild.getName() + "! Caused by: region is null");
return false;
} else if (guild.getUUID() == null) {
guild.setUUID(UUID.randomUUID());
}
File file = Flat.loadCustomFile(BasicType.GUILD, guild.getName());
Yamler pc = new Yamler(file);
pc.set("uuid", guild.getUUID().toString());
pc.set("name", guild.getName());
pc.set("tag", guild.getTag());
pc.set("owner", guild.getOwner().getName());
pc.set("home", LocationUtils.toString(guild.getHome()));
pc.set("members", UserUtils.getNames(guild.getMembers()));
pc.set("region", guild.getRegion());
pc.set("regions", guild.getRegions());
pc.set("allies", GuildUtils.getNames(guild.getAllies()));
pc.set("enemies", GuildUtils.getNames(guild.getEnemies()));
pc.set("born", guild.getBorn());
pc.set("validity", guild.getValidity());
pc.set("attacked", guild.getAttacked());
pc.set("lives", guild.getLives());
pc.set("ban", guild.getBan());
pc.set("pvp", guild.getPvP());
pc.set("deputy", StringUtils.toString(UserUtils.getNames(guild.getDeputies()), false));
pc.save();
return true;
}
Aggregations