Search in sources :

Example 16 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig 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();
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Material(org.bukkit.Material) Guild(net.dzikoysk.funnyguilds.basic.Guild) PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Block(org.bukkit.block.Block) Region(net.dzikoysk.funnyguilds.basic.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 17 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class AsynchronouslyRepeater method run.

@Override
public void run() {
    ++banSystem;
    ++validitySystem;
    if (validitySystem >= 10) {
        validitySystem();
    }
    if (banSystem >= 7) {
        banSystem();
    }
    PluginConfig config = Settings.getConfig();
    if (!config.playerlistEnable) {
        return;
    }
    for (Player player : Bukkit.getOnlinePlayers()) {
        if (!AbstractTablist.hasTablist(player)) {
            AbstractTablist.createTablist(config.playerList, config.playerListHeader, config.playerListFooter, config.playerListPing, player);
        }
        AbstractTablist tablist = AbstractTablist.getTablist(player);
        tablist.send();
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) AbstractTablist(net.dzikoysk.funnyguilds.element.tablist.AbstractTablist)

Example 18 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class ExcCreate method execute.

@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!config.guildsEnabled) {
        player.sendMessage(messages.adminGuildsDisabled);
        return;
    }
    boolean isBlockedWorld = this.checkWorld(player);
    if (isBlockedWorld) {
        player.sendMessage(messages.blockedWorld);
        return;
    }
    if (user.hasGuild()) {
        player.sendMessage(messages.generalHasGuild);
        return;
    }
    if (args.length != 2) {
        switch(args.length) {
            case 0:
                player.sendMessage(messages.generalNoTagGiven);
                return;
            case 1:
                player.sendMessage(messages.generalNoNameGiven);
                return;
            default:
                player.sendMessage(messages.createMore);
                return;
        }
    }
    String tag = args[0];
    if (!config.guildTagKeepCase) {
        tag = config.guildTagUppercase ? tag.toUpperCase() : tag.toLowerCase();
    }
    String name = args[1];
    if (tag.length() > config.createTagLength) {
        player.sendMessage(messages.createTagLength.replace("{LENGTH}", Integer.toString(config.createTagLength)));
        return;
    }
    if (tag.length() < config.createTagMinLength) {
        player.sendMessage(messages.createTagMinLength.replace("{LENGTH}", Integer.toString(config.createTagMinLength)));
        return;
    }
    if (name.length() > config.createNameLength) {
        player.sendMessage(messages.createNameLength.replace("{LENGTH}", Integer.toString(config.createNameLength)));
        return;
    }
    if (name.length() < config.createNameMinLength) {
        player.sendMessage(messages.createNameMinLength.replace("{LENGTH}", Integer.toString(config.createNameMinLength)));
        return;
    }
    if (!tag.matches(config.tagRegex.getPattern())) {
        player.sendMessage(messages.createOLTag);
        return;
    }
    if (!name.matches(config.nameRegex.getPattern())) {
        player.sendMessage(messages.createOLName);
        return;
    }
    if (GuildUtils.nameExists(name)) {
        player.sendMessage(messages.createNameExists);
        return;
    }
    if (GuildUtils.tagExists(tag)) {
        player.sendMessage(messages.createTagExists);
        return;
    }
    if (config.checkForRestrictedGuildNames) {
        if (!GuildUtils.isNameValid(name)) {
            player.sendMessage(messages.restrictedGuildName);
            return;
        } else if (!GuildUtils.isTagValid(tag)) {
            player.sendMessage(messages.restrictedGuildTag);
            return;
        }
    }
    Location guildLocation = player.getLocation().getBlock().getLocation();
    if (config.regionsEnabled) {
        if (config.createCenterY != 0) {
            guildLocation.setY(config.createCenterY);
        }
        int d = config.regionSize + config.createDistance;
        if (config.enlargeItems != null) {
            d += config.enlargeItems.size() * config.enlargeSize;
        }
        if (d > player.getWorld().getSpawnLocation().distance(guildLocation)) {
            player.sendMessage(messages.createSpawn.replace("{DISTANCE}", Integer.toString(d)));
            return;
        }
    }
    if (config.rankCreateEnable) {
        int requiredRank = player.hasPermission("funnyguilds.vip.rank") ? config.rankCreateVip : config.rankCreate;
        int points = user.getRank().getPoints();
        if (points < requiredRank) {
            String msg = messages.createRank;
            msg = StringUtils.replace(msg, "{REQUIRED-FORMAT}", IntegerRange.inRange(requiredRank, config.pointsFormat).replace("{POINTS}", "{REQUIRED}"));
            msg = StringUtils.replace(msg, "{REQUIRED}", String.valueOf(requiredRank));
            msg = StringUtils.replace(msg, "{POINTS-FORMAT}", IntegerRange.inRange(points, config.pointsFormat));
            msg = StringUtils.replace(msg, "{POINTS}", String.valueOf(points));
            player.sendMessage(msg);
            return;
        }
    }
    List<ItemStack> requiredItems = player.hasPermission("funnyguilds.vip.items") ? config.createItemsVip : config.createItems;
    int requiredExperience = player.hasPermission("funnyguilds.vip.items") ? config.requiredExperienceVip : config.requiredExperience;
    double requiredMoney = player.hasPermission("funnyguilds.vip.items") ? config.requiredMoneyVip : config.requiredMoney;
    if (!user.getBypass()) {
        if (player.getTotalExperience() < requiredExperience) {
            String msg = messages.createExperience;
            msg = StringUtils.replace(msg, "{EXP}", String.valueOf(requiredExperience));
            player.sendMessage(msg);
            return;
        }
        if (VaultHook.isHooked() && !VaultHook.canAfford(player, requiredMoney)) {
            String notEnoughMoneyMessage = messages.createMoney;
            notEnoughMoneyMessage = StringUtils.replace(notEnoughMoneyMessage, "{MONEY}", Double.toString(requiredMoney));
            player.sendMessage(notEnoughMoneyMessage);
            return;
        }
        for (ItemStack requiredItem : requiredItems) {
            if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
                continue;
            }
            String msg = ItemUtils.translatePlaceholder(messages.createItems, requiredItems, requiredItem);
            player.sendMessage(msg);
            return;
        }
    }
    if (config.regionsEnabled) {
        if (RegionUtils.isIn(guildLocation)) {
            player.sendMessage(messages.createIsNear);
            return;
        }
        if (RegionUtils.isNear(guildLocation)) {
            player.sendMessage(messages.createIsNear);
            return;
        }
        if (config.createMinDistanceFromBorder != -1) {
            WorldBorder border = player.getWorld().getWorldBorder();
            double borderSize = border.getSize() / 2;
            double borderX = border.getCenter().getX() + borderSize;
            double borderZ = border.getCenter().getZ() + borderSize;
            double distanceX = Math.abs(borderX) - Math.abs(player.getLocation().getX());
            double distanceZ = Math.abs(borderZ) - Math.abs(player.getLocation().getZ());
            if ((distanceX < config.createMinDistanceFromBorder) || (distanceZ < config.createMinDistanceFromBorder)) {
                String notEnoughDistanceMessage = messages.createNotEnoughDistanceFromBorder;
                notEnoughDistanceMessage = StringUtils.replace(notEnoughDistanceMessage, "{BORDER-MIN-DISTANCE}", Double.toString(config.createMinDistanceFromBorder));
                player.sendMessage(notEnoughDistanceMessage);
                return;
            }
        }
    }
    if (!SimpleEventHandler.handle(new GuildCreateEvent(EventCause.USER, user, name, tag, guildLocation))) {
        return;
    }
    if (user.getBypass()) {
        user.setBypass(false);
    } else {
        player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
        player.setTotalExperience(player.getTotalExperience() - requiredExperience);
        if (VaultHook.isHooked()) {
            VaultHook.withdrawFromPlayerBank(player, requiredMoney);
        }
    }
    Manager.getInstance().stop();
    Guild guild = new Guild(name);
    guild.setTag(tag);
    guild.setOwner(user);
    guild.setLives(config.warLives);
    guild.setBorn(System.currentTimeMillis());
    guild.setValidity(System.currentTimeMillis() + config.validityStart);
    guild.setAttacked(System.currentTimeMillis() - config.warWait + config.warProtection);
    guild.setPvP(config.damageGuild);
    user.setGuild(guild);
    if (config.regionsEnabled) {
        Region region = new Region(guild, guildLocation, config.regionSize);
        guild.setRegion(region.getName());
        guild.addRegion(region.getName());
        if (config.pasteSchematicOnCreation) {
            if (!SchematicHelper.pasteSchematic(config.guildSchematicFile, guildLocation, config.pasteSchematicWithAir)) {
                player.sendMessage(messages.createGuildCouldNotPasteSchematic);
            }
        } else if (config.createCenterSphere) {
            for (Location l : SpaceUtils.sphere(guildLocation, 4, 4, false, true, 0)) {
                if (l.getBlock().getType() != Material.BEDROCK) {
                    l.getBlock().setType(Material.AIR);
                }
            }
            for (Location l : SpaceUtils.sphere(guildLocation, 4, 4, true, true, 0)) {
                if (l.getBlock().getType() != Material.BEDROCK) {
                    l.getBlock().setType(Material.OBSIDIAN);
                }
            }
        }
        if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
            Block heart = guildLocation.getBlock().getRelative(BlockFace.DOWN);
            heart.setType(config.createMaterialData.getItemType());
            heart.setData(config.createMaterialData.getData());
        } else if (config.createEntityType != null) {
            EntityUtil.spawn(guild);
        }
        player.teleport(guildLocation);
    }
    Manager.getInstance().start();
    /*
        IndependentThread.actions(ActionType.RANK_UPDATE_GUILD, guild);
        IndependentThread.actions(ActionType.PREFIX_GLOBAL_ADD_GUILD, guild);
        IndependentThread.action(ActionType.PREFIX_GLOBAL_ADD_PLAYER, user.getName());
        */
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new RankUpdateGuildRequest(guild), new PrefixGlobalAddGuildRequest(guild), new PrefixGlobalAddPlayerRequest(user.getName()));
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", name).register("{TAG}", tag).register("{PLAYER}", player.getName());
    player.sendMessage(translator.translate(messages.createGuild));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastCreate));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildCreateEvent(net.dzikoysk.funnyguilds.event.guild.GuildCreateEvent) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) Guild(net.dzikoysk.funnyguilds.basic.Guild) PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) RankUpdateGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateGuildRequest) PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) WorldBorder(org.bukkit.WorldBorder) PrefixGlobalAddGuildRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddGuildRequest) Region(net.dzikoysk.funnyguilds.basic.Region) Block(org.bukkit.block.Block) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) ItemStack(org.bukkit.inventory.ItemStack) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator) Location(org.bukkit.Location)

Example 19 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class ExcFunnyGuilds method reload.

private void reload(CommandSender sender) {
    if (!sender.hasPermission("funnyguilds.reload")) {
        sender.sendMessage(Messages.getInstance().permission);
        return;
    }
    Thread thread = new Thread(() -> {
        Manager dm = Manager.getInstance();
        dm.stop();
        dm.save();
        new Messages();
        new Settings();
        dm.start();
        if (Settings.getConfig().playerlistEnable) {
            PluginConfig config = Settings.getConfig();
            AbstractTablist.wipeCache();
            for (Player player : Bukkit.getOnlinePlayers()) {
                AbstractTablist.createTablist(config.playerList, config.playerListHeader, config.playerListFooter, config.playerListPing, player);
            }
        }
        sender.sendMessage(ChatColor.AQUA + "FunnyGuilds " + ChatColor.GRAY + "przeladowano!");
    });
    sender.sendMessage(ChatColor.GRAY + "Przeladowywanie...");
    thread.start();
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) Messages(net.dzikoysk.funnyguilds.data.Messages) Manager(net.dzikoysk.funnyguilds.data.Manager) Settings(net.dzikoysk.funnyguilds.data.Settings)

Example 20 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class ExcInfo method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    String tag = null;
    if (args.length > 0) {
        tag = args[0];
    } else if (sender instanceof Player) {
        User user = User.get((Player) sender);
        if (user.hasGuild()) {
            tag = user.getGuild().getTag();
        }
    }
    if (tag == null || tag.isEmpty()) {
        sender.sendMessage(messages.infoTag);
        return;
    }
    if (!GuildUtils.tagExists(tag)) {
        sender.sendMessage(messages.infoExists);
        return;
    }
    Guild guild = GuildUtils.getByTag(tag);
    if (guild == null) {
        sender.sendMessage(messages.infoExists);
        return;
    }
    String validity = config.dateFormat.format(new Date(guild.getValidity()));
    long now = System.currentTimeMillis();
    long protectionEndTime = guild.getProtectionEndTime();
    for (String messageLine : messages.infoList) {
        messageLine = StringUtils.replace(messageLine, "{GUILD}", guild.getName());
        messageLine = StringUtils.replace(messageLine, "{TAG}", guild.getTag());
        messageLine = StringUtils.replace(messageLine, "{OWNER}", guild.getOwner().getName());
        messageLine = StringUtils.replace(messageLine, "{MEMBERS-ONLINE}", String.valueOf(guild.getOnlineMembers().size()));
        messageLine = StringUtils.replace(messageLine, "{MEMBERS-ALL}", String.valueOf(guild.getMembers().size()));
        messageLine = StringUtils.replace(messageLine, "{MEMBERS}", StringUtils.toString(UserUtils.getOnlineNames(guild.getMembers()), true));
        messageLine = StringUtils.replace(messageLine, "{DEPUTIES}", StringUtils.toString(UserUtils.getNames(guild.getDeputies()), true));
        messageLine = StringUtils.replace(messageLine, "{REGION-SIZE}", String.valueOf(guild.getRegionData().getSize()));
        messageLine = StringUtils.replace(messageLine, "{GUILD-PROTECTION}", protectionEndTime < now ? "Brak" : TimeUtils.getDurationBreakdown(protectionEndTime - now));
        Rank rank = guild.getRank();
        messageLine = StringUtils.replace(messageLine, "{POINTS-FORMAT}", IntegerRange.inRange(rank.getPoints(), config.pointsFormat));
        messageLine = StringUtils.replace(messageLine, "{POINTS}", Integer.toString(rank.getPoints()));
        messageLine = StringUtils.replace(messageLine, "{KILLS}", Integer.toString(rank.getKills()));
        messageLine = StringUtils.replace(messageLine, "{DEATHS}", Integer.toString(rank.getDeaths()));
        messageLine = StringUtils.replace(messageLine, "{KDR}", String.format(Locale.US, "%.2f", rank.getKDR()));
        messageLine = StringUtils.replace(messageLine, "{VALIDITY}", validity);
        messageLine = StringUtils.replace(messageLine, "{LIVES}", Integer.toString(guild.getLives()));
        if (guild.getMembers().size() >= config.minMembersToInclude) {
            messageLine = StringUtils.replace(messageLine, "{RANK}", String.valueOf(rank.getPosition()));
        } else {
            messageLine = StringUtils.replace(messageLine, "{RANK}", messages.minMembersToIncludeNoValue);
        }
        if (!guild.getAllies().isEmpty()) {
            messageLine = StringUtils.replace(messageLine, "{ALLIES}", StringUtils.toString(GuildUtils.getNames(guild.getAllies()), true));
        } else {
            messageLine = StringUtils.replace(messageLine, "{ALLIES}", messages.alliesNoValue);
        }
        if (messageLine.contains("<online>")) {
            String color = ChatColor.getLastColors(messageLine.split("<online>")[0]);
            messageLine = StringUtils.replace(messageLine, "<online>", ChatColor.GREEN + "");
            messageLine = StringUtils.replace(messageLine, "</online>", color);
        }
        sender.sendMessage(messageLine);
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Rank(net.dzikoysk.funnyguilds.basic.Rank) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) Date(java.util.Date)

Aggregations

PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)36 User (net.dzikoysk.funnyguilds.basic.User)25 Player (org.bukkit.entity.Player)25 Guild (net.dzikoysk.funnyguilds.basic.Guild)19 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)17 Region (net.dzikoysk.funnyguilds.basic.Region)13 EventHandler (org.bukkit.event.EventHandler)8 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)6 Block (org.bukkit.block.Block)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 Rank (net.dzikoysk.funnyguilds.basic.Rank)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DummyGlobalUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.dummy.DummyGlobalUpdateUserRequest)2 RankUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest)2 Manager (net.dzikoysk.funnyguilds.data.Manager)2 Messages (net.dzikoysk.funnyguilds.data.Messages)2 Settings (net.dzikoysk.funnyguilds.data.Settings)2