Search in sources :

Example 11 with MessageTranslator

use of net.dzikoysk.funnyguilds.data.util.MessageTranslator in project FunnyGuilds by FunnyGuilds.

the class AxcDelete method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildDeleteEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild))) {
        return;
    }
    GuildUtils.deleteGuild(guild);
    Player owner = guild.getOwner().getPlayer();
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{ADMIN}", sender.getName()).register("{PLAYER}", sender.getName());
    if (owner != null) {
        owner.sendMessage(translator.translate(messages.adminGuildBroken));
    }
    sender.sendMessage(translator.translate(messages.deleteSuccessful));
    Bukkit.getServer().broadcastMessage(translator.translate(messages.broadcastDelete));
}
Also used : GuildDeleteEvent(net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 12 with MessageTranslator

use of net.dzikoysk.funnyguilds.data.util.MessageTranslator 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)

Aggregations

Guild (net.dzikoysk.funnyguilds.basic.Guild)12 User (net.dzikoysk.funnyguilds.basic.User)12 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)12 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)12 Player (org.bukkit.entity.Player)12 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)6 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 Region (net.dzikoysk.funnyguilds.basic.Region)2 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)2 GuildDeleteEvent (net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent)2 GuildMemberJoinEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent)2 GuildMemberKickEvent (net.dzikoysk.funnyguilds.event.guild.member.GuildMemberKickEvent)2 Location (org.bukkit.Location)2 ItemStack (org.bukkit.inventory.ItemStack)2 PrefixGlobalAddGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddGuildRequest)1 RankUpdateGuildRequest (net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateGuildRequest)1 GuildBanEvent (net.dzikoysk.funnyguilds.event.guild.GuildBanEvent)1 GuildCreateEvent (net.dzikoysk.funnyguilds.event.guild.GuildCreateEvent)1