Search in sources :

Example 21 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project DiscordBot by LXGaming.

the class DiscordBotCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (args.length == 0) {
        sender.sendMessage(new ComponentBuilder("===== ").color(ChatColor.GOLD).append("DiscordBot - Bungeecord Edition").color(ChatColor.GREEN).append(" =====").color(ChatColor.GOLD).create());
        sender.sendMessage(new ComponentBuilder("Version - ").color(ChatColor.GOLD).append(DiscordBotCore.getInstance().getConfiguration().getDiscordBotVersion()).color(ChatColor.AQUA).create());
        sender.sendMessage(new ComponentBuilder("JDA - ").color(ChatColor.GOLD).append(DiscordBotCore.getInstance().getConfiguration().getJDAVersion()).color(ChatColor.AQUA).create());
        sender.sendMessage(new ComponentBuilder("Author - ").color(ChatColor.GOLD).append("LX_Gaming").color(ChatColor.AQUA).create());
        return;
    }
    if (args.length == 1 && args[0].equalsIgnoreCase("reload") && sender.hasPermission("DiscordBot.Reload")) {
        DiscordBot.getInstance().reloadDiscordBot();
        sender.sendMessage(new ComponentBuilder("DiscordBot reloaded.").color(ChatColor.GREEN).create());
        return;
    }
    if (!(sender instanceof ProxiedPlayer)) {
        sender.sendMessage(new ComponentBuilder("Command cannot be run from Console").color(ChatColor.RED).create());
        return;
    }
    ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender;
    if (args.length == 1 && (args[0].equalsIgnoreCase("toggle") || args[0].equalsIgnoreCase("t")) && proxiedPlayer.hasPermission("DiscordBot.Toggle")) {
        DiscordBotCore.getInstance().getDatabaseManager().togglePlayerDatabase(proxiedPlayer.getUniqueId());
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 22 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project DiscordBot by LXGaming.

the class DiscordChatCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    StringBuilder stringBuilder = new StringBuilder();
    for (String arg : args) {
        stringBuilder.append(arg + " ");
    }
    if (stringBuilder.toString().trim().length() == 0) {
        sender.sendMessage(new ComponentBuilder("Message cannot be blank!").color(ChatColor.RED).create());
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get(this.name).getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get(this.name)).setName(sender.getName()).setNick("").setServer("Unknown").setMessage(stringBuilder.toString().trim()).setDiscord(true).setMinecraft(true).setConsole(true).setRedis(true);
    if (sender instanceof ProxiedPlayer) {
        ProxiedPlayer player = (ProxiedPlayer) sender;
        if (DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(player.getUniqueId())) {
            player.sendMessage(new ComponentBuilder("DiscordChat disabled. '/DiscordBot Toggle' to enable").color(ChatColor.RED).create());
            return;
        }
        message.setName(player.getName()).setNick(player.getDisplayName());
        if (player.getServer() != null && player.getServer().getInfo() != null) {
            message.setServer(player.getServer().getInfo().getName());
        }
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Message(io.github.lxgaming.discordbot.entries.Message) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 23 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project DiscordBot by LXGaming.

the class DiscordBotListener method onMessageMinecraft.

@Override
public void onMessageMinecraft(Message message) {
    if (message.sendRedis() && DiscordBot.getInstance().getRedisBungee() != null) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("message", message.getMessage());
        jsonObject.addProperty("permission", message.getData().get("Permission"));
        DiscordBot.getInstance().getRedisBungee().sendChannelMessage("DiscordBot", new Gson().toJson(jsonObject));
    }
    for (Iterator<ProxiedPlayer> iterator = ProxyServer.getInstance().getPlayers().iterator(); iterator.hasNext(); ) {
        ProxiedPlayer proxiedPlayer = iterator.next();
        if (DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(proxiedPlayer.getUniqueId())) {
            return;
        }
        if (message.getData().get("Permission").equals("*") || proxiedPlayer.hasPermission(message.getData().get("Permission"))) {
            proxiedPlayer.sendMessage(new ComponentBuilder(message.getMessage()).create());
        }
    }
    return;
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 24 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project DiscordBot by LXGaming.

the class PlayerListener method onPlayerChat.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(ChatEvent event) {
    if (event.isCommand() || event.getSender() == null) {
        return;
    }
    if (event.isCancelled() && !DiscordBotCore.getInstance().getConfiguration().isForceChat()) {
        return;
    }
    ProxiedPlayer proxiedPlayer = (ProxiedPlayer) event.getSender();
    String permission = DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getPermission();
    boolean hasPermission = false;
    if (permission == null || permission.trim().equals("") || permission.trim().equals("null")) {
        hasPermission = false;
    } else if (permission.equals("*") || proxiedPlayer.hasPermission(permission)) {
        hasPermission = true;
    }
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerChat() || !hasPermission || DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(proxiedPlayer.getUniqueId())) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get("Global")).setName(proxiedPlayer.getName()).setNick(proxiedPlayer.getDisplayName()).setServer("Unknown").setMessage(event.getMessage()).setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (proxiedPlayer.getServer() != null && proxiedPlayer.getServer().getInfo() != null) {
        message.setServer(proxiedPlayer.getServer().getInfo().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(net.md_5.bungee.event.EventHandler)

Example 25 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project Network-depr by Mas281.

the class ServerListener method onProxyLeave.

@EventHandler
public void onProxyLeave(PlayerDisconnectEvent event) {
    ProxiedPlayer player = event.getPlayer();
    ServerInfo info = player.getServer().getInfo();
    UtilServer.sendData(info, "ServerUpdates", "ProxyLeave", player.getName());
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(net.md_5.bungee.api.config.ServerInfo) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)50 EventHandler (net.md_5.bungee.event.EventHandler)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)17 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Configuration (net.md_5.bungee.config.Configuration)6 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)6 UserPreference (com.github.games647.changeskin.core.model.UserPreference)5 Message (at.pcgamingfreaks.Bungee.Message.Message)4 User (me.lucko.luckperms.common.model.User)4 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)4 Test (org.junit.Test)4 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Tristate (me.lucko.luckperms.api.Tristate)3 Chat (net.md_5.bungee.protocol.packet.Chat)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 FirePlayer (fr.glowstoner.fireapi.player.FirePlayer)2 Message (io.github.lxgaming.discordbot.entries.Message)2