use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class DatabaseBasic method load.
public void load() {
Database db = Database.getInstance();
PluginConfig config = Settings.getConfig();
usersTable(db);
regionsTable(db);
guildsTable(db);
Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.usersTableName + "`", usersResult -> {
try {
while (usersResult.next()) {
User user = DatabaseUser.deserialize(usersResult);
if (user != null) {
user.changed();
}
}
FunnyLogger.info("Loaded users: " + UserUtils.getUsers().size());
} catch (Exception e) {
if (FunnyLogger.exception(e.getCause())) {
e.printStackTrace();
}
}
});
if (Settings.getConfig().regionsEnabled) {
Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.regionsTableName + "`", regionsResult -> {
try {
while (regionsResult.next()) {
Region region = DatabaseRegion.deserialize(regionsResult);
if (region != null) {
region.changed();
}
}
FunnyLogger.info("Loaded regions: " + RegionUtils.getRegions().size());
} catch (Exception e) {
if (FunnyLogger.exception(e.getCause())) {
e.printStackTrace();
}
}
});
} else {
FunnyLogger.info("Regions are disabled and thus - not loaded");
}
Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.guildsTableName + "`", guildsResult -> {
try {
while (guildsResult.next()) {
Guild guild = DatabaseGuild.deserialize(guildsResult);
if (guild != null) {
guild.changed();
}
}
FunnyLogger.info("Loaded guilds: " + GuildUtils.getGuilds().size());
} catch (Exception e) {
if (FunnyLogger.exception(e.getCause())) {
e.printStackTrace();
}
}
});
// TODO
for (Guild guild : GuildUtils.getGuilds()) {
if (guild.getOwner() != null) {
continue;
}
GuildUtils.deleteGuild(guild);
}
// IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE);
ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
concurrencyManager.postRequests(new PrefixGlobalUpdateRequest());
}
use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class AxcTeleport method execute.
@Override
public void execute(CommandSender sender, String[] args) {
MessagesConfig messages = Messages.getInstance();
Player player = (Player) sender;
if (!Settings.getConfig().regionsEnabled) {
player.sendMessage(messages.regionsDisabled);
return;
}
if (args.length < 1) {
player.sendMessage(messages.generalNoTagGiven);
return;
}
Guild guild = GuildUtils.getByTag(args[0]);
if (guild == null) {
player.sendMessage(messages.generalNoGuildFound);
return;
}
Region region = RegionUtils.get(guild.getRegion());
if (region == null || region.getCenter() == null) {
player.sendMessage(messages.adminNoRegionFound);
return;
}
player.sendMessage(messages.baseTeleport);
player.teleport(region.getCenter());
}
use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class DeserializationUtils method deserializeRegion.
public static Region deserializeRegion(Object[] values) {
if (values == null) {
FunnyLogger.error("Cannot deserialize region! Caused by: null");
return null;
}
Region region = Region.get((String) values[0]);
region.setCenter((Location) values[1]);
region.setSize((int) values[2]);
region.setEnlarge((int) values[3]);
region.update();
return region;
}
use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class BlockPhysics method onPhysics.
@EventHandler
public void onPhysics(BlockPhysicsEvent event) {
MaterialData md = Settings.getConfig().createMaterialData;
if (md == null || !event.getBlock().getState().getData().equals(md)) {
return;
}
Location loc = event.getBlock().getLocation();
Region region = RegionUtils.getAt(loc);
if (region == null) {
return;
}
if (loc.equals(region.getCenter().getBlock().getRelative(BlockFace.DOWN).getLocation())) {
event.setCancelled(true);
}
}
use of net.dzikoysk.funnyguilds.basic.Region in project FunnyGuilds by FunnyGuilds.
the class EntityExplode method onExplode.
@EventHandler
public void onExplode(EntityExplodeEvent event) {
List<Block> destroyedBlocks = event.blockList();
Location explodeLocation = event.getLocation();
PluginConfig pluginConfiguration = Settings.getConfig();
List<Location> sphere = SpaceUtils.sphere(explodeLocation, pluginConfiguration.explodeRadius, pluginConfiguration.explodeRadius, false, true, 0);
Map<Material, Double> materials = pluginConfiguration.explodeMaterials;
destroyedBlocks.removeIf(blocks -> {
Region region = RegionUtils.getAt(blocks.getLocation());
return region != null && region.getGuild() != null && !region.getGuild().canBeAttacked();
});
Region region = RegionUtils.getAt(explodeLocation);
if (region != null) {
Guild guild = region.getGuild();
if (pluginConfiguration.guildTNTProtectionEnabled) {
LocalDateTime start = pluginConfiguration.guildTNTProtectionStartTime;
LocalDateTime end = pluginConfiguration.guildTNTProtectionEndTime;
LocalDateTime now = LocalDateTime.now();
if ((now.isAfter(start) || now.equals(start)) && (now.isBefore(end) || now.equals(end))) {
event.setCancelled(true);
return;
}
}
if (pluginConfiguration.warTntProtection & !guild.canBeAttacked()) {
event.setCancelled(true);
return;
}
Location protect = region.getCenter().getBlock().getRelative(BlockFace.DOWN).getLocation();
destroyedBlocks.removeIf(block -> block.getLocation().equals(protect));
guild.setBuild(System.currentTimeMillis() + Settings.getConfig().regionExplode * 1000L);
for (User user : guild.getMembers()) {
Player player = user.getPlayer();
if (player != null) {
if (informationMessageCooldowns.cooldown(player, TimeUnit.SECONDS, pluginConfiguration.infoPlayerCooldown)) {
player.sendMessage(Messages.getInstance().regionExplode.replace("{TIME}", Integer.toString(Settings.getConfig().regionExplode)));
}
}
}
}
for (Location l : sphere) {
Material material = l.getBlock().getType();
if (!materials.containsKey(material)) {
continue;
}
if (material == Material.WATER || material == Material.LAVA) {
if (SpaceUtils.chance(materials.get(material))) {
l.getBlock().setType(Material.AIR);
}
} else {
if (SpaceUtils.chance(materials.get(material))) {
l.getBlock().breakNaturally();
}
}
}
}
Aggregations