Search in sources :

Example 11 with Message

use of io.github.lxgaming.discordbot.entries.Message 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 12 with Message

use of io.github.lxgaming.discordbot.entries.Message in project DiscordBot by LXGaming.

the class RedisListener method onMessage.

public void onMessage(PubSubMessageEvent event) {
    try {
        if (!event.getChannel().equals("DiscordBot")) {
            return;
        }
        JsonObject jsonObject = new JsonParser().parse(event.getMessage()).getAsJsonObject();
        if (jsonObject == null || !jsonObject.has("format") || !jsonObject.has("name") || !jsonObject.has("nick") || !jsonObject.has("server") || !jsonObject.has("message")) {
            throw new IllegalArgumentException();
        }
        DiscordBotCore.getInstance().getMessageSender().sendMessage(new Message().setFormat(DiscordBotCore.getInstance().getConfiguration().getPlayerFormat().get(jsonObject.get("format").getAsString())).setName(jsonObject.get("name").getAsString()).setNick(jsonObject.get("nick").getAsString()).setServer(jsonObject.get("server").getAsString()).setMessage(jsonObject.get("message").getAsString()).setDiscord(false).setMinecraft(true).setConsole(false).setRedis(false));
    } catch (IllegalArgumentException | JsonParseException ex) {
        DiscordBot.getInstance().getLogger().warning("Exception reading redis message!");
        ex.printStackTrace();
    }
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) JsonParser(com.google.gson.JsonParser)

Example 13 with Message

use of io.github.lxgaming.discordbot.entries.Message in project DiscordBot by LXGaming.

the class VoiceListener method onGuildVoiceMute.

@Override
public void onGuildVoiceMute(GuildVoiceMuteEvent event) {
    if (!DiscordBotCore.getInstance().getConfiguration().isVoiceMute()) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getChannelManager().getChannelId("Bot")).setName(event.getMember().getEffectiveName()).setNick(event.getMember().getNickname()).setServer(DiscordBotCore.getInstance().getChannelManager().getGuild().getName()).setDiscord(true).setMinecraft(true).setConsole(false).setRedis(false);
    if (event.isMuted()) {
        message.setFormat(DiscordBotCore.getInstance().getConfiguration().getVoiceMuteFormat().get("Muted")).setMessage("Muted");
    } else {
        message.setFormat(DiscordBotCore.getInstance().getConfiguration().getVoiceMuteFormat().get("Unmuted")).setMessage("Unmuted");
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message)

Example 14 with Message

use of io.github.lxgaming.discordbot.entries.Message 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)

Aggregations

Message (io.github.lxgaming.discordbot.entries.Message)14 EventHandler (org.bukkit.event.EventHandler)4 EventHandler (net.md_5.bungee.event.EventHandler)3 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 Player (org.bukkit.entity.Player)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 JsonParser (com.google.gson.JsonParser)1 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)1