Search in sources :

Example 26 with PluginConfig

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

the class FunnyGuilds method onLoad.

@Override
public void onLoad() {
    if (!this.getDataFolder().exists()) {
        this.getDataFolder().mkdir();
    }
    DescriptionManager descriptionManager = new DescriptionManager(super.getDescription());
    version = descriptionManager.extractVersion();
    PluginConfig settings = Settings.getConfig();
    descriptionManager.rename(settings.pluginName);
    this.concurrencyManager = new ConcurrencyManager(settings.concurrencyThreads);
    this.concurrencyManager.printStatus();
    this.reloadHandler = new ReloadHandler();
    this.reloadHandler.init();
    Commands commands = new Commands();
    commands.register();
    this.eventManager = new EventManager();
    this.eventManager.load();
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) EventManager(net.dzikoysk.funnyguilds.system.event.EventManager) ReloadHandler(net.dzikoysk.funnyguilds.util.ReloadHandler) Commands(net.dzikoysk.funnyguilds.command.Commands) DescriptionManager(net.dzikoysk.funnyguilds.util.DescriptionManager)

Example 27 with PluginConfig

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

the class FunnyGuilds method onEnable.

@Override
public void onEnable() {
    new ScoreboardStack(this).start();
    new Manager().start();
    new MetricsCollector(this).start();
    AsynchronouslyRepeater repeater = AsynchronouslyRepeater.getInstance();
    repeater.start();
    PluginManager pluginManager = Bukkit.getPluginManager();
    PluginConfig config = Settings.getConfig();
    pluginManager.registerEvents(new GuiActionHandler(), this);
    pluginManager.registerEvents(new EntityDamage(), this);
    pluginManager.registerEvents(new EntityInteract(), this);
    pluginManager.registerEvents(new PlayerChat(), this);
    pluginManager.registerEvents(new PlayerDeath(), this);
    pluginManager.registerEvents(new PlayerJoin(this), this);
    pluginManager.registerEvents(new PlayerKick(), this);
    pluginManager.registerEvents(new PlayerLogin(), this);
    pluginManager.registerEvents(new PlayerQuit(), this);
    if (config.regionsEnabled) {
        pluginManager.registerEvents(new BlockBreak(), this);
        pluginManager.registerEvents(new BlockIgnite(), this);
        pluginManager.registerEvents(new BlockPlace(), this);
        pluginManager.registerEvents(new BucketAction(), this);
        pluginManager.registerEvents(new EntityExplode(), this);
        pluginManager.registerEvents(new HangingBreak(), this);
        pluginManager.registerEvents(new HangingPlace(), this);
        pluginManager.registerEvents(new PlayerCommand(), this);
        pluginManager.registerEvents(new PlayerInteract(), this);
        if (config.eventMove) {
            pluginManager.registerEvents(new PlayerMove(), this);
        }
        if (config.eventPhysics) {
            pluginManager.registerEvents(new BlockPhysics(), this);
        }
    }
    this.eventManager.enable();
    this.patch();
    Version.isNewAvailable(getServer().getConsoleSender(), true);
    PluginHook.init();
    FunnyLogger.info("~ Created by FunnyGuilds Team ~");
}
Also used : GuiActionHandler(net.dzikoysk.funnyguilds.element.gui.GuiActionHandler) EventManager(net.dzikoysk.funnyguilds.system.event.EventManager) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) Manager(net.dzikoysk.funnyguilds.data.Manager) DescriptionManager(net.dzikoysk.funnyguilds.util.DescriptionManager) PluginManager(org.bukkit.plugin.PluginManager) AsynchronouslyRepeater(net.dzikoysk.funnyguilds.system.AsynchronouslyRepeater) PluginManager(org.bukkit.plugin.PluginManager) MetricsCollector(net.dzikoysk.funnyguilds.util.metrics.MetricsCollector) ScoreboardStack(net.dzikoysk.funnyguilds.element.ScoreboardStack) PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig)

Example 28 with PluginConfig

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

the class PlayerMove method onMove.

@EventHandler
public void onMove(PlayerMoveEvent event) {
    final Location from = event.getFrom();
    final Location to = event.getTo();
    final Player player = event.getPlayer();
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    Bukkit.getScheduler().runTaskAsynchronously(FunnyGuilds.getInstance(), () -> {
        if (from == null || to == null) {
            return;
        }
        if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ()) {
            return;
        }
        User user = User.get(player);
        Region region = RegionUtils.getAt(to);
        if (region == null && user.getEnter()) {
            user.setEnter(false);
            region = RegionUtils.getAt(from);
            if (region != null) {
                Guild guild = region.getGuild();
                FunnyGuilds.getInstance().getServer().getScheduler().runTaskLaterAsynchronously(FunnyGuilds.getInstance(), () -> {
                    if (config.createEntityType != null) {
                        EntityUtil.despawn(guild, player);
                    }
                }, 40L);
                MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag());
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.ACTIONBAR)) {
                    PacketSender.sendPacket(player, NotificationUtil.createActionbarNotification(translator.translate(messages.notificationActionbarLeaveGuildRegion)));
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.BOSSBAR)) {
                    NotificationBar.set(player, translator.translate(messages.notificationBossbarLeaveGuildRegion), 1, config.regionNotificationTime);
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.CHAT)) {
                    player.sendMessage(translator.translate(messages.notificationChatLeaveGuildRegion));
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.TITLE)) {
                    PacketSender.sendPacket(player, NotificationUtil.createTitleNotification(translator.translate(messages.notificationTitleLeaveGuildRegion), translator.translate(messages.notificationSubtitleLeaveGuildRegion), config.notificationTitleFadeIn, config.notificationTitleStay, config.notificationTitleFadeOut));
                }
            }
        } else if (!user.getEnter() && region != null) {
            Guild guild = region.getGuild();
            if (guild == null || guild.getName() == null) {
                return;
            }
            user.setEnter(true);
            FunnyGuilds.getInstance().getServer().getScheduler().runTaskLaterAsynchronously(FunnyGuilds.getInstance(), () -> {
                if (config.createEntityType != null) {
                    EntityUtil.spawn(guild, player);
                }
            }, 40L);
            MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag());
            if (config.regionEnterNotificationStyle.contains(NotificationStyle.ACTIONBAR)) {
                PacketSender.sendPacket(player, NotificationUtil.createActionbarNotification(translator.translate(messages.notificationActionbarEnterGuildRegion)));
            }
            if (config.regionEnterNotificationStyle.contains(NotificationStyle.BOSSBAR)) {
                NotificationBar.set(player, translator.translate(messages.notificationBossbarEnterGuildRegion), 1, config.regionNotificationTime);
            }
            if (config.regionEnterNotificationStyle.contains(NotificationStyle.CHAT)) {
                player.sendMessage(translator.translate(messages.notificationChatEnterGuildRegion));
            }
            if (config.regionEnterNotificationStyle.contains(NotificationStyle.TITLE)) {
                PacketSender.sendPacket(player, NotificationUtil.createTitleNotification(translator.translate(messages.notificationTitleEnterGuildRegion), translator.translate(messages.notificationSubtitleEnterGuildRegion), config.notificationTitleFadeIn, config.notificationTitleStay, config.notificationTitleFadeOut));
            }
            if (player.hasPermission("funnyguilds.admin.notification")) {
                return;
            }
            if (user.getNotificationTime() > 0 && System.currentTimeMillis() < user.getNotificationTime()) {
                return;
            }
            if (!config.regionEnterNotificationGuildMember && user.getGuild() != null && guild.getTag().equals(user.getGuild().getTag())) {
                return;
            }
            translator = new MessageTranslator().register("{PLAYER}", player.getName());
            for (User u : guild.getOnlineMembers()) {
                if (u == null) {
                    continue;
                }
                Player member = u.getPlayer();
                if (member == null || !member.isOnline()) {
                    continue;
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.ACTIONBAR)) {
                    PacketSender.sendPacket(member, NotificationUtil.createActionbarNotification(translator.translate(messages.notificationActionbarIntruderEnterGuildRegion)));
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.BOSSBAR)) {
                    NotificationBar.set(member, translator.translate(messages.notificationBossbarIntruderEnterGuildRegion), 1, config.regionNotificationTime);
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.CHAT)) {
                    member.sendMessage(translator.translate(messages.notificationChatIntruderEnterGuildRegion));
                }
                if (config.regionEnterNotificationStyle.contains(NotificationStyle.TITLE)) {
                    PacketSender.sendPacket(member, NotificationUtil.createTitleNotification(translator.translate(messages.notificationTitleIntruderEnterGuildRegion), translator.translate(messages.notificationSubtitleIntruderEnterGuildRegion), config.notificationTitleFadeIn, config.notificationTitleStay, config.notificationTitleFadeOut));
                }
            }
            user.setNotificationTime(System.currentTimeMillis() + 1000 * config.regionNotificationCooldown);
        }
    });
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Region(net.dzikoysk.funnyguilds.basic.Region) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 29 with PluginConfig

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

the class Parser method parseRank.

public static String parseRank(String var) {
    if (!var.contains("TOP-")) {
        return null;
    }
    int i = getIndex(var);
    if (i <= 0) {
        FunnyLogger.error("Index in TOP- must be greater or equal to 1!");
        return null;
    }
    PluginConfig c = Settings.getConfig();
    List<Guild> rankedGuilds = new ArrayList<>();
    for (int in = 1; in <= RankManager.getInstance().guilds(); in++) {
        Guild guild = RankManager.getInstance().getGuild(in);
        if (guild != null && guild.getMembers().size() >= c.minMembersToInclude) {
            rankedGuilds.add(guild);
        }
    }
    if (var.contains("GTOP")) {
        if (rankedGuilds.isEmpty() || i - 1 >= rankedGuilds.size()) {
            return StringUtils.replace(var, "{GTOP-" + i + '}', Messages.getInstance().gtopNoValue);
        } else {
            Guild guild = rankedGuilds.get(i - 1);
            int points = guild.getRank().getPoints();
            String pointsFormat = c.gtopPoints;
            if (!pointsFormat.isEmpty()) {
                pointsFormat = pointsFormat.replace("{POINTS-FORMAT}", IntegerRange.inRange(points, c.pointsFormat));
                pointsFormat = pointsFormat.replace("{POINTS}", String.valueOf(points));
            }
            return StringUtils.replace(var, "{GTOP-" + i + '}', guild.getTag() + pointsFormat);
        }
    } else if (var.contains("PTOP")) {
        User user = RankManager.getInstance().getUser(i);
        if (user != null) {
            int points = user.getRank().getPoints();
            String pointsFormat = c.ptopPoints;
            if (!pointsFormat.isEmpty()) {
                pointsFormat = pointsFormat.replace("{POINTS-FORMAT}", IntegerRange.inRange(points, c.pointsFormat));
                pointsFormat = pointsFormat.replace("{POINTS}", String.valueOf(points));
            }
            return StringUtils.replace(var, "{PTOP-" + i + '}', (user.isOnline() ? c.ptopOnline : c.ptopOffline) + user.getName() + pointsFormat);
        } else {
            return StringUtils.replace(var, "{PTOP-" + i + '}', Messages.getInstance().ptopNoValue);
        }
    }
    return null;
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) User(net.dzikoysk.funnyguilds.basic.User) ArrayList(java.util.ArrayList) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 30 with PluginConfig

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

the class EntityDamage method onDamage.

@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageByEntityEvent event) {
    Entity entity = event.getEntity();
    Entity damager = event.getDamager();
    if (!(entity instanceof Player)) {
        return;
    }
    Player attacker = null;
    if (damager instanceof Player) {
        attacker = (Player) damager;
    } else if (damager instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) damager).getShooter();
        if (shooter instanceof Player) {
            attacker = (Player) shooter;
        }
    }
    if (attacker == null) {
        return;
    }
    PluginConfig config = Settings.getConfig();
    User victimUser = User.get((Player) event.getEntity());
    User attackerUser = User.get(attacker);
    if (victimUser.hasGuild() && attackerUser.hasGuild()) {
        if (victimUser.getUUID().equals(attackerUser.getUUID())) {
            return;
        }
        if (victimUser.getGuild().equals(attackerUser.getGuild())) {
            if (!victimUser.getGuild().getPvP()) {
                event.setCancelled(true);
                return;
            }
        }
        if (victimUser.getGuild().getAllies().contains(attackerUser.getGuild())) {
            if (!config.damageAlly) {
                event.setCancelled(true);
                return;
            }
        }
    }
    if (config.assistEnable && !event.isCancelled()) {
        victimUser.addDamage(attackerUser, event.getDamage());
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

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