Search in sources :

Example 1 with UCChannel

use of br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel in project DiscordSRV by Scarsz.

the class UltimateChatHook method broadcastMessageToChannel.

public static void broadcastMessageToChannel(String channel, String message) {
    UCChannel chatChannel = getChannelByCaseInsensitiveName(channel);
    // no suitable channel found
    if (chatChannel == null)
        return;
    chatChannel.sendMessage(Bukkit.getServer().getConsoleSender(), ChatColor.translateAlternateColorCodes('&', LangUtil.Message.CHAT_CHANNEL_MESSAGE.toString().replace("%channelcolor%", chatChannel.getColor()).replace("%channelname%", chatChannel.getName()).replace("%channelnickname%", chatChannel.getAlias()).replace("%message%", message)));
    PlayerUtil.notifyPlayersOfMentions(player -> Arrays.asList(UChat.get().getVaultChat().getPlayerGroups(player)).contains(channel), message);
}
Also used : UCChannel(br.net.fabiozumbi12.UltimateChat.Bukkit.UCChannel)

Example 2 with UCChannel

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

the class UCListener method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    UChat.get().getUCLogger().debug("onCommand - Label: " + label + " - CmdName: " + cmd.getName());
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")) {
            sendHelp(sender);
            return true;
        }
        if (args[0].equalsIgnoreCase("reload") && UCPerms.hasPermission(sender, "uchat.cmd.reload")) {
            UChat.get().reload();
            UChat.get().getLang().sendMessage(sender, "plugin.reloaded");
            return true;
        }
    }
    if (sender instanceof Player) {
        Player p = (Player) sender;
        if (cmd.getName().equalsIgnoreCase("channel")) {
            if (args.length == 0) {
                UCChannel ch = UChat.get().getChannel(label);
                if (ch != null) {
                    addPlayerToChannel(ch, p);
                } else {
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.dontexist").replace("{channel}", label));
                }
                return true;
            }
            if (args.length >= 1) {
                UCChannel ch = UChat.get().getChannel(label);
                StringBuilder msgBuild = new StringBuilder();
                for (String arg : args) {
                    msgBuild.append(" ").append(arg);
                }
                String msg = msgBuild.toString().substring(1);
                if (ch != null) {
                    sendMessageToPlayer(ch, p, args, msg);
                    return true;
                }
            }
            // if /ch or /channel
            if (label.equalsIgnoreCase("ch") || label.equalsIgnoreCase("channel")) {
                if (args.length == 1) {
                    // ch list
                    if (args[0].equalsIgnoreCase("list")) {
                        UltimateFancy fancy = new UltimateFancy();
                        fancy.coloredText("&7------------------------------------------\n");
                        fancy.coloredText(UChat.get().getLang().get("help.channels.available").replace("{channels}", "")).next();
                        boolean first = true;
                        for (UCChannel ch : UChat.get().getChannels().values()) {
                            if (UCPerms.channelReadPerm(p, ch) && ch.availableInWorld(p.getWorld())) {
                                if (first) {
                                    fancy.coloredText(ch.getColor() + ch.getName() + "&a");
                                    first = false;
                                } else {
                                    fancy.coloredText(", " + ch.getColor() + ch.getName() + "&a");
                                }
                                fancy.hoverShowText(ch.getColor() + "Alias: " + ch.getAlias()).clickRunCmd("/" + ch.getAlias()).next();
                            }
                        }
                        fancy.coloredText("\n&7------------------------------------------").send(p);
                        return true;
                    }
                    UCChannel ch = UChat.get().getChannel(args[0]);
                    if (ch == null) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.dontexist").replace("{channel}", args[0]));
                        return true;
                    }
                    if (!UCPerms.channelReadPerm(p, ch) && !UCPerms.channelWritePerm(p, ch)) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName()));
                        return true;
                    }
                    if (!ch.availableInWorld(p.getWorld())) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.notavailable").replace("{channel}", ch.getName()));
                        return true;
                    }
                    if (!ch.canLock()) {
                        UChat.get().getLang().sendMessage(p, "help.channels.send");
                        return true;
                    }
                    if (ch.isMember(p)) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.alreadyon").replace("{channel}", ch.getName()));
                        return true;
                    }
                    if (!ch.getPassword().isEmpty()) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.password").replace("{channel}", ch.getAlias()));
                        return true;
                    }
                    // listen change channel event
                    PlayerChangeChannelEvent postEvent = new PlayerChangeChannelEvent(p, UChat.get().getPlayerChannel(p), ch);
                    Bukkit.getPluginManager().callEvent(postEvent);
                    if (postEvent.isCancelled()) {
                        return true;
                    }
                    ch.addMember(p);
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.entered").replace("{channel}", ch.getName()));
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.entered").replace("{channel}", ch.getName()));
                    return true;
                }
            }
            sendChannelHelp(p);
        }
        // Listen cmd chat/uchat
        if (cmd.getName().equalsIgnoreCase("uchat")) {
            if (args.length == 1) {
                if (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) {
                    sendHelp(sender);
                    return true;
                }
                if (args[0].equalsIgnoreCase("msgtoggle")) {
                    if (!UCPerms.cmdPerm(p, "msgtoggle")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    if (UChat.get().msgTogglePlayers.contains(p.getName())) {
                        UChat.get().msgTogglePlayers.remove(p.getName());
                        UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.enabled");
                    } else {
                        UChat.get().msgTogglePlayers.add(p.getName());
                        UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.disabled");
                    }
                    return true;
                }
                if (args[0].equalsIgnoreCase("clear")) {
                    if (!UCPerms.cmdPerm(p, "clear")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    for (int i = 0; i < 100; i++) {
                        if (!p.isOnline()) {
                            break;
                        }
                        UCUtil.performCommand(p, Bukkit.getConsoleSender(), "tellraw " + p.getName() + " {\"text\":\" \"}");
                    }
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.clear.cleared"));
                    return true;
                }
                if (args[0].equalsIgnoreCase("clear-all")) {
                    if (!UCPerms.cmdPerm(p, "clear-all")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    for (Player play : Bukkit.getOnlinePlayers()) {
                        for (int i = 0; i < 100; i++) {
                            if (!play.isOnline()) {
                                continue;
                            }
                            UCUtil.performCommand(play, Bukkit.getConsoleSender(), "tellraw " + play.getName() + " {\"text\":\" \"}");
                        }
                    }
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.clear.cleared"));
                    return true;
                }
                if (args[0].equalsIgnoreCase("spy")) {
                    if (!UCPerms.cmdPerm(p, "spy")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    if (!UChat.get().isSpy.contains(p.getName())) {
                        UChat.get().isSpy.add(p.getName());
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.spy.enabled"));
                    } else {
                        UChat.get().isSpy.remove(p.getName());
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.spy.disabled"));
                    }
                    return true;
                }
            }
            if (args.length == 2) {
                // chat msgtoggle <player>
                if (args[0].equalsIgnoreCase("msgtoggle")) {
                    if (!UCPerms.hasPerm(p, "msgtoggle.others")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    Player vict = Bukkit.getPlayer(args[1]);
                    if (vict != null) {
                        if (UChat.get().msgTogglePlayers.contains(vict.getName())) {
                            UChat.get().msgTogglePlayers.remove(vict.getName());
                            UChat.get().getLang().sendMessage(vict, "cmd.msgtoggle.enabled");
                        } else {
                            UChat.get().msgTogglePlayers.add(vict.getName());
                            UChat.get().getLang().sendMessage(vict, "cmd.msgtoggle.disabled");
                        }
                        return true;
                    }
                }
                // chat delchannel <channel-name>
                if (args[0].equalsIgnoreCase("delchannel")) {
                    if (!UCPerms.cmdPerm(p, "delchannel")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    UCChannel ch = UChat.get().getChannel(args[1]);
                    if (ch == null) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.dontexist").replace("{channel}", args[1]));
                        return true;
                    }
                    List<String> toAdd = new ArrayList<>(ch.getMembers());
                    toAdd.forEach(m -> {
                        UChat.get().getDefChannel(p.getWorld().getName()).addMember(m);
                        // listen change channel event
                        PlayerChangeChannelEvent postEvent = new PlayerChangeChannelEvent(p, null, UChat.get().getDefChannel(p.getWorld().getName()));
                        Bukkit.getPluginManager().callEvent(postEvent);
                    });
                    UChat.get().getUCConfig().delChannel(ch);
                    UChat.get().registerAliases();
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.delchannel.success").replace("{channel}", ch.getName()));
                    return true;
                }
                // chat ignore <channel/player>
                if (args[0].equalsIgnoreCase("ignore")) {
                    UCChannel ch = UChat.get().getChannel(args[1]);
                    if (Bukkit.getPlayer(args[1]) != null) {
                        Player pi = Bukkit.getPlayer(args[1]);
                        if (!UCPerms.cmdPerm(p, "ignore.player")) {
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                            return true;
                        }
                        if (!UCPerms.canIgnore(sender, pi)) {
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.cantignore"));
                            return true;
                        }
                        if (UCMessages.isIgnoringPlayers(p.getName(), pi.getName())) {
                            UCMessages.unIgnorePlayer(p.getName(), pi.getName());
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("player.unignoring").replace("{player}", pi.getName()));
                        } else {
                            UCMessages.ignorePlayer(p.getName(), pi.getName());
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("player.ignoring").replace("{player}", pi.getName()));
                        }
                        return true;
                    } else if (ch != null) {
                        if (!UCPerms.cmdPerm(p, "ignore.channel")) {
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                            return true;
                        }
                        if (!UCPerms.canIgnore(sender, ch)) {
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.cantignore"));
                            return true;
                        }
                        if (ch.isIgnoring(p.getName())) {
                            ch.unIgnoreThis(p.getName());
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.notignoring").replace("{channel}", ch.getName()));
                        } else {
                            ch.ignoreThis(p.getName());
                            UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.ignoring").replace("{channel}", ch.getName()));
                        }
                        return true;
                    } else {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.dontexist").replace("{channel}", args[1]));
                        return true;
                    }
                }
                // chat mute <player>
                if (args[0].equalsIgnoreCase("mute")) {
                    if (!UCPerms.cmdPerm(p, "mute")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    String pname = args[1];
                    if (Bukkit.getPlayer(args[1]) != null) {
                        pname = Bukkit.getPlayer(args[1]).getName();
                    }
                    if (UChat.get().mutes.contains(pname)) {
                        UChat.get().mutes.remove(pname);
                        UChat.get().unMuteInAllChannels(pname);
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.unmuted.all").replace("{player}", pname));
                        if (Bukkit.getPlayer(pname) != null) {
                            UChat.get().getLang().sendMessage(Bukkit.getPlayer(args[1]), "channel.player.unmuted.all");
                        }
                    } else {
                        UChat.get().mutes.add(pname);
                        UChat.get().muteInAllChannels(pname);
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.muted.all").replace("{player}", pname));
                        if (Bukkit.getPlayer(pname) != null) {
                            UChat.get().getLang().sendMessage(Bukkit.getPlayer(args[1]), "channel.player.muted.all");
                        }
                    }
                    return true;
                }
            }
            if (args.length == 3) {
                // chat tempmute <minutes> <player>
                if (args[0].equalsIgnoreCase("tempmute")) {
                    if (!UCPerms.cmdPerm(p, "tempmute")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    int time = 0;
                    try {
                        time = Integer.parseInt(args[1]);
                    } catch (Exception ex) {
                        UChat.get().getLang().sendMessage(p, "cmd.tempmute.number");
                        return true;
                    }
                    String pname = args[2];
                    if (Bukkit.getPlayer(args[2]) != null) {
                        pname = Bukkit.getPlayer(args[2]).getName();
                    }
                    if (UChat.get().mutes.contains(pname)) {
                        UChat.get().getLang().sendMessage(p, "channel.already.muted");
                    } else {
                        UChat.get().mutes.add(pname);
                        UChat.get().muteInAllChannels(pname);
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.tempmuted.all").replace("{player}", pname).replace("{time}", String.valueOf(time)));
                        if (Bukkit.getPlayer(pname) != null) {
                            UChat.get().getLang().sendMessage(Bukkit.getPlayer(args[2]), UChat.get().getLang().get("channel.player.tempmuted.all").replace("{time}", String.valueOf(time)));
                        }
                        // mute counter
                        new MuteCountDown(pname, time).runTaskTimer(UChat.get(), 20, 20);
                    }
                    return true;
                }
                // chat mute <player> <channel>
                if (args[0].equalsIgnoreCase("mute")) {
                    if (!UCPerms.cmdPerm(p, "mute")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    UCChannel ch = UChat.get().getChannel(args[2]);
                    if (ch == null) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.dontexist").replace("{channel}", args[2]));
                        return true;
                    }
                    String pname = args[1];
                    if (Bukkit.getPlayer(args[1]) != null) {
                        pname = Bukkit.getPlayer(args[1]).getName();
                    }
                    if (ch.isMuted(pname)) {
                        ch.unMuteThis(pname);
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.unmuted.this").replace("{player}", pname).replace("{channel}", ch.getName()));
                        if (Bukkit.getPlayer(pname) != null) {
                            UChat.get().getLang().sendMessage(Bukkit.getPlayer(args[1]), UChat.get().getLang().get("channel.player.unmuted.this").replace("{channel}", ch.getName()));
                        }
                    } else {
                        ch.muteThis(pname);
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.muted.this").replace("{player}", pname).replace("{channel}", ch.getName()));
                        if (Bukkit.getPlayer(pname) != null) {
                            UChat.get().getLang().sendMessage(Bukkit.getPlayer(args[1]), UChat.get().getLang().get("channel.player.muted.this").replace("{channel}", ch.getName()));
                        }
                    }
                    return true;
                }
            }
            if (args.length == 4) {
                // chat newchannel <channel-name> <alias> <color>
                if (args[0].equalsIgnoreCase("newchannel")) {
                    if (!UCPerms.cmdPerm(p, "newchannel")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    UCChannel ch = UChat.get().getChannel(args[1]);
                    if (ch != null) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.alreadyexists").replace("{channel}", ch.getName()));
                        return true;
                    }
                    String color = args[3];
                    if (color.length() != 2 || !color.matches("(&([A-Fa-fK-Ok-oRr0-9]))$")) {
                        UChat.get().getLang().sendMessage(p, "channel.invalidcolor");
                        return true;
                    }
                    UCChannel newch = new UCChannel(args[1], args[2], args[3]);
                    try {
                        UChat.get().getUCConfig().addChannel(newch);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    UChat.get().registerAliases();
                    UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.newchannel.success").replace("{channel}", newch.getName()));
                    return true;
                }
                // chat chconfig <channel> <key> <value>
                if (args[0].equalsIgnoreCase("chconfig")) {
                    if (!UCPerms.cmdPerm(p, "chconfig")) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("cmd.nopermission"));
                        return true;
                    }
                    UCChannel ch = UChat.get().getChannel(args[1]);
                    if (ch == null) {
                        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.dontexist").replace("{channel}", args[1]));
                        return true;
                    }
                    if (!ch.getProperties().containsKey(args[2])) {
                        UChat.get().getLang().sendMessage(p, "cmd.chconfig.invalidkey");
                        return true;
                    }
                    UChat.get().getUCConfig().delChannel(ch);
                    ch.setProperty(args[2], args[3]);
                    try {
                        UChat.get().getUCConfig().addChannel(ch);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    UChat.get().registerAliases();
                    UChat.get().getLang().sendMessage(p, "cmd.chconfig.success");
                    return true;
                }
            }
        }
    } else {
        if (UChat.get().getChAliases().contains(label.toLowerCase())) {
            if (args.length >= 1) {
                UCChannel ch = UChat.get().getChannel(label);
                StringBuilder msgb = new StringBuilder();
                for (String arg : args) {
                    msgb.append(" ").append(arg);
                }
                String msg = msgb.toString().substring(1);
                UCMessages.sendFancyMessage(new String[0], msg, ch, sender, null);
                return true;
            }
        }
    }
    if (cmd.getName().equalsIgnoreCase("ubroadcast") && UCPerms.cmdPerm(sender, "broadcast")) {
        if (!UCUtil.sendBroadcast(sender, args, false)) {
            sendHelp(sender);
        }
        return true;
    }
    if (cmd.getName().equalsIgnoreCase("umsg") && UCPerms.cmdPerm(sender, "umsg")) {
        if (!UCUtil.sendUmsg(sender, args)) {
            sendHelp(sender);
        }
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(ChatColor.AQUA + "---------------- " + UChat.get().getPDF().getFullName() + " ----------------");
        sender.sendMessage(ChatColor.AQUA + "Developed by " + ChatColor.GOLD + UChat.get().getPDF().getAuthors() + ".");
        sender.sendMessage(ChatColor.AQUA + "For more information about the commands, type [" + ChatColor.GOLD + "/" + label + " ?" + ChatColor.AQUA + "].");
        sender.sendMessage(ChatColor.AQUA + "---------------------------------------------------");
        return true;
    } else {
        sendHelp(sender);
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) PlayerChangeChannelEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.PlayerChangeChannelEvent) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with UCChannel

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

the class UCListener method addPlayerToChannel.

private void addPlayerToChannel(UCChannel ch, Player p) {
    if (!UCPerms.channelReadPerm(p, ch) && !UCPerms.channelWritePerm(p, ch)) {
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.nopermission").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.availableInWorld(p.getWorld())) {
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.notavailable").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.canLock()) {
        UChat.get().getLang().sendMessage(p, "help.channels.send");
        return;
    }
    if (ch.isMember(p)) {
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.alreadyon").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.getPassword().isEmpty()) {
        UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("channel.password").replace("{channel}", ch.getAlias()));
        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()));
}
Also used : PlayerChangeChannelEvent(br.net.fabiozumbi12.UltimateChat.Bukkit.API.PlayerChangeChannelEvent)

Example 4 with UCChannel

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

the class UCJedisLoader method sendTellMessage.

public void sendTellMessage(CommandSource sender, String tellReceiver, Text msg) {
    Builder text = Text.builder();
    text.append(UCUtil.toText(this.thisId));
    // send spy
    if (!sender.hasPermission("uchat.chat-spy.bypass")) {
        for (Player receiver : Sponge.getServer().getOnlinePlayers()) {
            if (!receiver.getName().equals(tellReceiver) && !receiver.equals(sender) && UChat.get().isSpy.contains(receiver.getName()) && UChat.get().getPerms().hasSpyPerm(receiver, "private")) {
                String spyformat = UChat.get().getConfig().root().general.spy_format;
                spyformat = spyformat.replace("{output}", UCUtil.stripColor(UCMessages.sendMessage(sender, tellReceiver, msg, new UCChannel("tell"), true).toPlain()));
                receiver.sendMessage(UCUtil.toText(spyformat));
            }
        }
    }
    text.append(UCMessages.sendMessage(sender, tellReceiver, msg, new UCChannel("tell"), false));
    tellPlayers.put(tellReceiver, sender.getName());
    if (Arrays.asList(channels).contains("tellsend")) {
        Sponge.getScheduler().createAsyncExecutor(UChat.get()).execute(() -> {
            try {
                connectPool();
                Jedis jedis = pool.getResource();
                // string 0 1 2
                jedis.publish("tellsend", this.thisId + "$" + tellReceiver + "$" + TextSerializers.JSON.serialize(text.build()));
                jedis.quit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) Player(org.spongepowered.api.entity.living.player.Player) Builder(org.spongepowered.api.text.Text.Builder) UCChannel(br.net.fabiozumbi12.UltimateChat.Sponge.UCChannel) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException)

Example 5 with UCChannel

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

the class UCCommands method addPlayerToChannel.

public static void addPlayerToChannel(UCChannel ch, Player src) {
    if (!ch.canLock()) {
        UChat.get().getLang().sendMessage(src, "help.channels.send");
        return;
    }
    if (ch.isMember(src)) {
        UChat.get().tempChannels.put(src.getName(), ch.getAlias());
        UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.alreadyon").replace("{channel}", ch.getName()));
        return;
    }
    if (!ch.getPassword().isEmpty()) {
        UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.password").replace("{channel}", ch.getAlias()));
        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()));
}
Also used : PlayerChangeChannelEvent(br.net.fabiozumbi12.UltimateChat.Sponge.API.PlayerChangeChannelEvent)

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