Search in sources :

Example 6 with UCChannel

use of br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel in project UltimateChat by FabioZumbi12.

the class UCCommands method sendMessageToPlayer.

public static void sendMessageToPlayer(Player src, UCChannel ch, String msg) {
    if (UChat.get().mutes.contains(src.getName()) || ch.isMuted(src.getName())) {
        if (UChat.get().timeMute.containsKey(src.getName())) {
            UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.tempmuted").replace("{time}", String.valueOf(UChat.get().timeMute.get(src.getName()))));
        } else {
            UChat.get().getLang().sendMessage(src, "channel.muted");
        }
        return;
    }
    if (!UChat.get().getPerms().channelWritePerm(src, ch)) {
        UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.availableInWorld(src.getWorld())) {
        UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.notavailable").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.getPassword().isEmpty() && !ch.isMember(src)) {
        if (msg.split(" ").length != 1 || !ch.getPassword().equals(msg.split(" ")[0])) {
            UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.password").replace("{channel}", ch.getAlias()));
            return;
        }
        if (!UChat.get().getPerms().hasPerm(src, "password")) {
            UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("chat.nopermission"));
            return;
        }
        // fire event
        PlayerChangeChannelEvent event = new PlayerChangeChannelEvent((Player) src, UChat.get().getPlayerChannel(src), ch);
        Sponge.getEventManager().post(event);
        if (event.isCancelled()) {
            return;
        }
        ch.addMember(src);
        UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.entered").replace("{channel}", ch.getName()));
        return;
    }
    UChat.get().tempChannels.put(src.getName(), ch.getAlias());
    UChat.get().getLogger().timings(UCLogger.timingType.START, "UCListener#sendPreTell()|Fire AsyncPlayerChatEvent");
    // run sponge chat event
    Text msgt = Text.of(msg);
    MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(UChat.get().getVHelper().getCause(src), src.getMessageChannel(), Optional.of(src.getMessageChannel()), new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ").onShiftClick(TextActions.insertText(src.getName())).onClick(TextActions.suggestCommand("/msg " + src.getName())).build(), msgt), msgt, false);
    Sponge.getEventManager().post(event);
}
Also used : PlayerChangeChannelEvent(br.net.fabiozumbi12.UltimateChat.Sponge.API.PlayerChangeChannelEvent) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) MessageEvent(org.spongepowered.api.event.message.MessageEvent) Text(org.spongepowered.api.text.Text)

Example 7 with UCChannel

use of br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel in project UltimateChat by FabioZumbi12.

the class UCConfig method loadChannels.

/* Channels */
private void loadChannels() throws IOException {
    File chfolder = new File(UChat.get().getDataFolder(), "channels");
    if (!chfolder.exists()) {
        chfolder.mkdir();
        UChat.get().getUCLogger().info("Created folder: " + chfolder.getPath());
    }
    if (UChat.get().getChannels() == null) {
        UChat.get().setChannels(new HashMap<>());
    }
    File[] listOfFiles = chfolder.listFiles();
    YamlConfiguration channel;
    if (Objects.requireNonNull(listOfFiles).length == 0) {
        // create default channels
        File g = new File(chfolder, "global.yml");
        channel = YamlConfiguration.loadConfiguration(g);
        channel.set("name", "Global");
        channel.set("alias", "g");
        channel.set("color", "&2");
        channel.set("jedis", true);
        channel.save(g);
        File l = new File(chfolder, "local.yml");
        channel = YamlConfiguration.loadConfiguration(l);
        channel.set("name", "Local");
        channel.set("alias", "l");
        channel.set("color", "&e");
        channel.set("across-worlds", false);
        channel.set("distance", 40);
        channel.save(l);
        File ad = new File(chfolder, "admin.yml");
        channel = YamlConfiguration.loadConfiguration(ad);
        channel.set("name", "Admin");
        channel.set("alias", "ad");
        channel.set("color", "&b");
        channel.set("jedis", true);
        channel.save(ad);
        listOfFiles = chfolder.listFiles();
    }
    for (File file : Objects.requireNonNull(listOfFiles)) {
        if (file.getName().endsWith(".yml")) {
            channel = YamlConfiguration.loadConfiguration(file);
            UCChannel ch = new UCChannel(channel.getValues(true));
            try {
                addChannel(ch);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) UCChannel(br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel)

Example 8 with UCChannel

use of br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel in project UltimateChat by FabioZumbi12.

the class UCConfig method delChannel.

public void delChannel(UCChannel ch) {
    UChat.get().getCmds().unregisterCmd(ch.getAlias());
    UChat.get().getCmds().unregisterCmd(ch.getName());
    for (Entry<List<String>, UCChannel> ch0 : UChat.get().getChannels().entrySet()) {
        if (ch0.getValue().equals(ch)) {
            UChat.get().getChannels().remove(ch0.getKey());
            break;
        }
    }
    File defch = new File(UChat.get().configDir(), "channels" + File.separator + ch.getName().toLowerCase() + ".conf");
    if (defch.exists()) {
        defch.delete();
    }
}
Also used : File(java.io.File) UCChannel(br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel)

Example 9 with UCChannel

use of br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel in project UltimateChat by FabioZumbi12.

the class UCListener method sendMessageToPlayer.

private void sendMessageToPlayer(UCChannel ch, Player p, String[] args, String msg) {
    if (UChat.get().mutes.contains(p.getName()) || ch.isMuted(p.getName())) {
        if (UChat.get().timeMute.containsKey(p.getName())) {
            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.tempmuted").replace("{time}", String.valueOf(UChat.get().timeMute.get(p.getName()))));
        } else {
            UChat.get().getLang().sendMessage(p, "channel.muted");
        }
        return;
    }
    if (!UCPerms.channelWritePerm(p, ch)) {
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.getPassword().isEmpty() && !ch.isMember(p)) {
        if (args.length != 1 || !ch.getPassword().equals(args[0])) {
            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.password").replace("{channel}", ch.getAlias()));
            return;
        }
        if (!UCPerms.hasPerm(p, "password")) {
            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.nopermission"));
            return;
        }
        // listen change channel event
        PlayerChangeChannelEvent postEvent = new PlayerChangeChannelEvent(p, UChat.get().getPlayerChannel(p), ch);
        Bukkit.getPluginManager().callEvent(postEvent);
        if (postEvent.isCancelled()) {
            return;
        }
        ch.addMember(p);
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.entered").replace("{channel}", ch.getName()));
    }
    // run bukkit chat event
    Set<Player> pls = new HashSet<>(Bukkit.getOnlinePlayers());
    UChat.get().tempChannels.put(p.getName(), ch.getAlias());
    AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(true, p, msg, pls);
    Bukkit.getScheduler().runTaskAsynchronously(UChat.get(), () -> {
        UChat.get().getUCLogger().timings(timingType.START, "UCListener#onCommand()|Fire AsyncPlayerChatEvent");
        UChat.get().getServer().getPluginManager().callEvent(event);
    });
}
Also used : Player(org.bukkit.entity.Player) PlayerChangeChannelEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.PlayerChangeChannelEvent)

Example 10 with UCChannel

use of br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel in project UltimateChat by FabioZumbi12.

the class UCMessages method sendFancyMessage.

protected static boolean sendFancyMessage(String[] format, String msg, UCChannel channel, CommandSender sender, CommandSender tellReceiver) {
    // Execute listener:
    HashMap<String, String> tags = new HashMap<>();
    for (String str : UChat.get().getUCConfig().getStringList("api.legendchat-tags")) {
        tags.put(str, str);
    }
    SendChannelMessageEvent event = new SendChannelMessageEvent(tags, format, sender, channel, msg);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return event.getCancelIncomingChat();
    }
    boolean cancel = event.getCancelIncomingChat();
    // String toConsole = "";
    registeredReplacers = event.getResgisteredTags();
    defFormat = event.getDefFormat();
    String evmsg = event.getMessage();
    HashMap<CommandSender, UltimateFancy> msgPlayers = new HashMap<>();
    evmsg = composeColor(sender, evmsg);
    if (event.getChannel() != null) {
        UCChannel ch = event.getChannel();
        if (sender instanceof Player && !ch.availableWorlds().isEmpty() && !ch.availableInWorld(((Player) sender).getWorld())) {
            UChat.get().getLang().sendMessage(sender, UChat.get().getLang().get("channel.notavailable").replace("{channel}", ch.getName()));
            return cancel;
        }
        if (!UCPerms.channelWritePerm(sender, ch)) {
            UChat.get().getLang().sendMessage(sender, UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName()));
            return cancel;
        }
        if (ch.isMuted(sender.getName())) {
            UChat.get().getLang().sendMessage(sender, "channel.muted");
            return cancel;
        }
        if (!UCPerms.hasPerm(sender, "bypass.cost") && UChat.get().getVaultEco() != null && sender instanceof Player && ch.getCost() > 0) {
            if (UChat.get().getVaultEco().getBalance((Player) sender, ((Player) sender).getWorld().getName()) < ch.getCost()) {
                UChat.get().getLang().sendMessage(sender, UChat.get().getLang().get("channel.cost").replace("{value}", "" + ch.getCost()));
                return cancel;
            } else {
                UChat.get().getVaultEco().withdrawPlayer((Player) sender, ((Player) sender).getWorld().getName(), ch.getCost());
            }
        }
        List<Player> receivers = new ArrayList<>();
        int noWorldReceived = 0;
        int vanish = 0;
        // put sender
        msgPlayers.put(sender, sendMessage(sender, sender, evmsg, ch, false));
        if (ch.getDistance() > 0 && sender instanceof Player) {
            for (Player play : ((Player) sender).getNearbyEntities(ch.getDistance(), ch.getDistance(), ch.getDistance()).stream().filter(ent -> ent instanceof Player).map(ent -> (Player) ent).collect(Collectors.toList())) {
                if (UCPerms.channelReadPerm(play, ch)) {
                    if (!ch.availableWorlds().isEmpty() && !ch.availableInWorld(play.getWorld())) {
                        continue;
                    }
                    if (ch.isIgnoring(play.getName())) {
                        continue;
                    }
                    if (isIgnoringPlayers(play.getName(), sender.getName())) {
                        noWorldReceived++;
                        continue;
                    }
                    if (!((Player) sender).canSee(play)) {
                        vanish++;
                    }
                    if (!ch.neeFocus() || ch.isMember(play)) {
                        msgPlayers.put(play, sendMessage(sender, play, evmsg, ch, false));
                        receivers.add(play);
                    }
                }
            }
        } else {
            for (Player receiver : UChat.get().getServer().getOnlinePlayers()) {
                if (receiver.equals(sender) || !UCPerms.channelReadPerm(receiver, ch) || (!ch.crossWorlds() && (sender instanceof Player && !receiver.getWorld().equals(((Player) sender).getWorld())))) {
                    continue;
                }
                if (!ch.availableWorlds().isEmpty() && !ch.availableInWorld(receiver.getWorld())) {
                    continue;
                }
                if (ch.isIgnoring(receiver.getName())) {
                    continue;
                }
                if (isIgnoringPlayers(receiver.getName(), sender.getName())) {
                    noWorldReceived++;
                    continue;
                }
                if (sender instanceof Player && (!((Player) sender).canSee(receiver))) {
                    vanish++;
                } else {
                    noWorldReceived++;
                }
                if (!ch.neeFocus() || ch.isMember(receiver)) {
                    msgPlayers.put(receiver, sendMessage(sender, receiver, evmsg, ch, false));
                    receivers.add(receiver);
                }
            }
        }
        // chat spy
        if (!UCPerms.hasPermission(sender, "uchat.chat-spy.bypass")) {
            for (Player receiver : UChat.get().getServer().getOnlinePlayers()) {
                if (!receiver.equals(sender) && !receivers.contains(receiver) && !receivers.contains(sender) && UChat.get().isSpy.contains(receiver.getName()) && UCPerms.hasSpyPerm(receiver, ch.getName())) {
                    String spyformat = UChat.get().getUCConfig().getString("general.spy-format");
                    spyformat = spyformat.replace("{output}", ChatColor.stripColor(sendMessage(sender, receiver, evmsg, ch, true).toOldFormat()));
                    receiver.sendMessage(ChatColor.translateAlternateColorCodes('&', spyformat));
                }
            }
        }
        if (ch.getDistance() == 0 && noWorldReceived <= 0) {
            if (ch.getReceiversMsg()) {
                UChat.get().getLang().sendMessage(sender, "channel.noplayer.world");
            }
        }
        if ((receivers.size() - vanish) <= 0) {
            if (ch.getReceiversMsg()) {
                UChat.get().getLang().sendMessage(sender, "channel.noplayer.near");
            }
        }
    } else {
        if (UChat.get().msgTogglePlayers.contains(tellReceiver.getName()) && !sender.hasPermission("uchat.msgtoggle.exempt")) {
            UChat.get().getLang().sendMessage(sender, "cmd.msgtoggle.msgdisabled");
            return cancel;
        }
        channel = new UCChannel("tell");
        // send spy
        if (!UCPerms.hasPermission(sender, "uchat.chat-spy.bypass")) {
            for (Player receiver : UChat.get().getServer().getOnlinePlayers()) {
                if (!receiver.equals(tellReceiver) && !receiver.equals(sender) && UChat.get().isSpy.contains(receiver.getName()) && UCPerms.hasSpyPerm(receiver, "private")) {
                    String spyformat = UChat.get().getUCConfig().getString("general.spy-format");
                    if (isIgnoringPlayers(tellReceiver.getName(), sender.getName())) {
                        spyformat = UChat.get().getLang().get("chat.ignored") + spyformat;
                    }
                    spyformat = spyformat.replace("{output}", ChatColor.stripColor(sendMessage(sender, tellReceiver, evmsg, channel, true).toOldFormat()));
                    receiver.sendMessage(ChatColor.translateAlternateColorCodes('&', spyformat));
                }
            }
        }
        msgPlayers.put(sender, sendMessage(sender, tellReceiver, evmsg, channel, false));
        if (!isIgnoringPlayers(tellReceiver.getName(), sender.getName())) {
            msgPlayers.put(tellReceiver, sendMessage(sender, tellReceiver, evmsg, channel, false));
        }
        if (isIgnoringPlayers(tellReceiver.getName(), sender.getName())) {
            msgPlayers.put(UChat.get().getServer().getConsoleSender(), new UltimateFancy(UChat.get().getLang().get("chat.ignored") + msgPlayers.get(sender).toOldFormat()));
        }
    }
    if (!msgPlayers.keySet().contains(UChat.get().getServer().getConsoleSender())) {
        msgPlayers.put(UChat.get().getServer().getConsoleSender(), msgPlayers.get(sender));
    }
    // fire post event
    PostFormatChatMessageEvent postEvent = new PostFormatChatMessageEvent(sender, msgPlayers, channel, msg);
    Bukkit.getPluginManager().callEvent(postEvent);
    if (postEvent.isCancelled()) {
        return cancel;
    }
    if (channel != null && !channel.isTell() && channel.isBungee()) {
        UChatBungee.sendBungee(channel, msgPlayers.get(sender));
    } else {
        msgPlayers.forEach((send, text) -> {
            UChat.get().getUCLogger().timings(timingType.END, "UCMessages#send()|before send");
            text.send(send);
            UChat.get().getUCLogger().timings(timingType.END, "UCMessages#send()|after send");
        });
    }
    if (channel != null) {
        // send to jedis
        if (!channel.isTell() && UChat.get().getJedis() != null) {
            UChat.get().getJedis().sendMessage(channel.getName().toLowerCase(), msgPlayers.get(sender));
        }
        // send to jda
        if (UChat.get().getUCJDA() != null) {
            if (channel.isTell()) {
                UChat.get().getUCJDA().sendTellToDiscord(msgPlayers.get(sender).toOldFormat());
            } else {
                UChat.get().getUCJDA().sendToDiscord(sender, evmsg, channel);
            }
        }
    }
    return cancel;
}
Also used : PostFormatChatMessageEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.PostFormatChatMessageEvent) UCLogger.timingType(br.net.fabiozumbi12.UltimateChat.Bukkit.UCLogger.timingType) StringUtils(org.apache.commons.lang.StringUtils) CommandSender(org.bukkit.command.CommandSender) java.util(java.util) Entity(org.bukkit.entity.Entity) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) SimpleDateFormat(java.text.SimpleDateFormat) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) PlaceholderAPI(me.clip.placeholderapi.PlaceholderAPI) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) UChatBungee(br.net.fabiozumbi12.UltimateChat.Bukkit.Bungee.UChatBungee) SettingsManager(net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager) Entry(java.util.Map.Entry) SendChannelMessageEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.SendChannelMessageEvent) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) ClanPlayer(net.sacredlabyrinth.phaed.simpleclans.ClanPlayer) Player(org.bukkit.entity.Player) PostFormatChatMessageEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.PostFormatChatMessageEvent) CommandSender(org.bukkit.command.CommandSender) SendChannelMessageEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.SendChannelMessageEvent)

Aggregations

UCChannel (br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel)5 Player (org.spongepowered.api.entity.living.player.Player)5 UCChannel (br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel)4 PlayerChangeChannelEvent (br.net.fabiozumbi12.UltimateChat.Sponge.API.PlayerChangeChannelEvent)4 Player (org.bukkit.entity.Player)4 PlayerChangeChannelEvent (br.net.fabiozumbi12.UltimateChat.Bukkit.API.PlayerChangeChannelEvent)3 File (java.io.File)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Text (org.spongepowered.api.text.Text)3 Builder (org.spongepowered.api.text.Text.Builder)3 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Sponge (org.spongepowered.api.Sponge)2 TextActions (org.spongepowered.api.text.action.TextActions)2 PostFormatChatMessageEvent (br.net.fabiozumbi12.UltimateChat.Bukkit.API.PostFormatChatMessageEvent)1 SendChannelMessageEvent (br.net.fabiozumbi12.UltimateChat.Bukkit.API.SendChannelMessageEvent)1 UChatBungee (br.net.fabiozumbi12.UltimateChat.Bukkit.Bungee.UChatBungee)1