Search in sources :

Example 41 with MessagesConfig

use of net.dzikoysk.funnyguilds.data.configs.MessagesConfig 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 42 with MessagesConfig

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

the class WarUtils method message.

public static void message(Player player, int i, Object... values) {
    MessagesConfig m = Messages.getInstance();
    String message = null;
    switch(i) {
        case 0:
            message = m.warHasNotGuild;
            break;
        case 1:
            message = m.warAlly;
            break;
        case 2:
            message = m.warWait;
            message = StringUtils.replace(message, "{TIME}", TimeUtils.getDurationBreakdown((long) values[0]));
            break;
        case 3:
            message = m.warAttacker;
            message = StringUtils.replace(message, "{ATTACKED}", ((Guild) values[0]).getTag());
            break;
        case 4:
            message = m.warAttacked;
            message = StringUtils.replace(message, "{ATTACKER}", ((Guild) values[0]).getTag());
            break;
    }
    player.sendMessage(message);
}
Also used : MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Aggregations

MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)42 User (net.dzikoysk.funnyguilds.basic.User)39 Player (org.bukkit.entity.Player)38 Guild (net.dzikoysk.funnyguilds.basic.Guild)31 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)17 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)12 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)9 Region (net.dzikoysk.funnyguilds.basic.Region)8 Location (org.bukkit.Location)6 ItemStack (org.bukkit.inventory.ItemStack)6 Rank (net.dzikoysk.funnyguilds.basic.Rank)5 Date (java.util.Date)3 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)3 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)3 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)3 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PrefixUpdateGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixUpdateGuildRequest)2