use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class Flat method saveRegions.
private void saveRegions(boolean b) {
if (!Settings.getConfig().regionsEnabled) {
return;
}
int i = 0;
for (Region region : RegionUtils.getRegions()) {
if (!b) {
if (!region.changed()) {
continue;
}
}
if (!new FlatRegion(region).serialize()) {
RegionUtils.delete(region);
i++;
}
}
if (i > 0) {
FunnyLogger.warning("Deleted defective regions: " + i);
}
}
use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class Flat method loadRegions.
private void loadRegions() {
if (!Settings.getConfig().regionsEnabled) {
FunnyLogger.info("Regions are disabled and thus - not loaded");
return;
}
File[] path = REGIONS.listFiles();
if (path != null) {
for (File file : path) {
Region region = FlatRegion.deserialize(file);
if (region == null) {
file.delete();
} else {
region.changed();
}
}
}
FunnyLogger.info("Loaded regions: " + RegionUtils.getRegions().size());
}
use of net.dzikoysk.funnyguilds.basic.Region 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.basic.Region in project FunnyGuilds by FunnyGuilds.
the class PlayerInteract method onInteract.
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Action eventAction = event.getAction();
Player p = event.getPlayer();
if (eventAction == Action.RIGHT_CLICK_BLOCK || eventAction == Action.LEFT_CLICK_BLOCK) {
Block clicked = event.getClickedBlock();
if (RegionUtils.isIn(clicked.getLocation())) {
Region region = RegionUtils.getAt(clicked.getLocation());
Block heart = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
if (clicked.equals(heart)) {
Guild g = region.getGuild();
if (SecuritySystem.getSecurity().checkPlayer(p, g)) {
return;
}
if (eventAction == Action.LEFT_CLICK_BLOCK) {
WarSystem.getInstance().attack(p, g);
event.setCancelled(true);
return;
} else if (eventAction == Action.RIGHT_CLICK_BLOCK) {
PluginConfig config = Settings.getConfig();
if (config.informationMessageCooldowns.cooldown(p, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
return;
}
new ExcInfo().execute(p, new String[] { g.getTag() });
event.setCancelled(true);
return;
}
}
}
}
if (ProtectionUtils.action(eventAction, event.getClickedBlock())) {
event.setCancelled(false);
}
}
Aggregations