Search in sources :

Example 6 with Message

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

the class PlayerListener method onPlayerChat.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) {
    if (event.isCancelled() && !DiscordBotCore.getInstance().getConfiguration().isForceChat()) {
        return;
    }
    Player player = event.getPlayer();
    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("*") || player.hasPermission(permission)) {
        hasPermission = true;
    }
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerChat() || !hasPermission || DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(player.getUniqueId())) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get("Global")).setName(player.getName()).setNick(player.getDisplayName()).setServer("Unknown").setMessage(event.getMessage()).setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (player.getServer() != null && player.getServer().getName() != null) {
        message.setServer(player.getServer().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Player(org.bukkit.entity.Player) Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Message

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

the class PlayerListener method onPlayerDeath.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) {
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerDeath() || event.getEntity().hasPermission("DiscordBot.Silent")) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("InGame").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get("InGame")).setName(event.getEntity().getName()).setNick(event.getEntity().getDisplayName()).setServer("Unknown").setMessage(event.getDeathMessage()).setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (event.getEntity().getServer() != null && event.getEntity().getServer().getName() != null) {
        message.setServer(event.getEntity().getServer().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Message

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

the class DiscordChatCommand method onCommand.

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!sender.hasPermission(this.permission)) {
        sender.sendMessage(ChatColor.RED + "You do not have permission!");
        return true;
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (String arg : args) {
        stringBuilder.append(arg + " ");
    }
    if (stringBuilder.toString().trim().length() == 0) {
        sender.sendMessage(ChatColor.RED + "Message cannot be blank!");
        return true;
    }
    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 Player) {
        Player player = (Player) sender;
        if (DiscordBotCore.getInstance().getDatabaseManager().checkDatabase(player.getUniqueId())) {
            player.sendMessage(ChatColor.RED + "DiscordChat disabled. '/DiscordBot Toggle' to enable");
            return true;
        }
        message.setName(player.getName()).setNick(player.getDisplayName());
        if (player.getServer() != null && player.getServer().getName() != null) {
            message.setServer(player.getServer().getName());
        }
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return true;
}
Also used : Player(org.bukkit.entity.Player) Message(io.github.lxgaming.discordbot.entries.Message)

Example 9 with Message

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

the class PlayerListener method onPlayerJoin.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerJoin() || event.getPlayer().hasPermission("DiscordBot.Silent")) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("InGame").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get("InGame")).setName(event.getPlayer().getName()).setNick(event.getPlayer().getDisplayName()).setServer("Unknown").setMessage("Joined").setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (event.getPlayer().getServer() != null && event.getPlayer().getServer().getName() != null) {
        message.setServer(event.getPlayer().getServer().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Message

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

the class PlayerListener method onPlayerQuit.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerQuit() || event.getPlayer().hasPermission("DiscordBot.Silent")) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("InGame").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getChannelFormat().get("InGame")).setName(event.getPlayer().getName()).setNick(event.getPlayer().getDisplayName()).setServer("Unknown").setMessage("Quit").setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (event.getPlayer().getServer() != null && event.getPlayer().getServer().getName() != null) {
        message.setServer(event.getPlayer().getServer().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(org.bukkit.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