Search in sources :

Example 41 with EventHandler

use of net.md_5.bungee.event.EventHandler in project ChangeSkin by games647.

the class MessageListener method onPluginMessage.

@EventHandler
public void onPluginMessage(PluginMessageEvent messageEvent) {
    String channel = messageEvent.getTag();
    if (messageEvent.isCancelled() || !plugin.getName().equals(channel)) {
        return;
    }
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(messageEvent.getData());
    String subChannel = dataInput.readUTF();
    ProxiedPlayer invoker = (ProxiedPlayer) messageEvent.getReceiver();
    if ("PermissionResult".equals(subChannel)) {
        PermResultMessage message = new PermResultMessage();
        message.readFrom(dataInput);
        if (message.isAllowed()) {
            onPermissionSuccess(message, invoker);
        } else {
            plugin.sendMessage(invoker, "no-permission");
        }
    } else if ("ForwardCmd".equals(subChannel)) {
        onCommandForward(invoker, dataInput);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) PermResultMessage(com.github.games647.changeskin.core.message.PermResultMessage) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) EventHandler(net.md_5.bungee.event.EventHandler)

Example 42 with EventHandler

use of net.md_5.bungee.event.EventHandler in project Ublisk by Derkades.

the class Chat method onChat.

@EventHandler(priority = EventPriority.HIGHEST)
public void onChat(AsyncPlayerChatEvent event) {
    // Don't send chat message, we'll send a custom message
    event.setCancelled(true);
    UPlayer player = new UPlayer(event);
    if (Chat.IS_MUTED.get(player.getUniqueId())) {
        player.sendMessage(Message.CANT_CHAT_MUTED);
        event.setCancelled(true);
        return;
    }
    for (Trigger trigger : Trigger.values()) {
        if (event.getMessage().equals(trigger.getTrigger())) {
            event.setMessage(trigger.getMessage());
        }
    }
    ChatColor chatColor = ChatColor.WHITE;
    if (IS_SOFT_MUTED.get(player.getUniqueId()))
        chatColor = ChatColor.GRAY;
    int level = player.getLevel();
    BaseComponent[] message = new ComponentBuilder("").append("[").reset().color(ChatColor.DARK_GRAY).append(level + "").reset().color(ChatColor.GRAY).append("] ").reset().color(ChatColor.DARK_GRAY).append(player.getGroup().getName()).color(player.getGroup().getPrefixColor()).bold(player.getGroup().nameBold()).append(":").reset().color(ChatColor.DARK_GRAY).append(" ").create();
    message = ArrayUtils.addAll(message, player.getDisplayName(player.getGroup().getNameColor(), player.getGroup().nameBold()));
    message = ArrayUtils.addAll(message, new ComponentBuilder("").append(": ").reset().color(ChatColor.DARK_GRAY).bold(true).append(event.getMessage()).reset().color(chatColor).create());
    Ublisk.getServer().spigot().broadcast(message);
}
Also used : BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) Trigger(xyz.derkades.ublisk.chat.Trigger) ChatColor(net.md_5.bungee.api.ChatColor) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)37 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)7 IOException (java.io.IOException)5 User (me.lucko.luckperms.common.model.User)4 EventHandler (org.bukkit.event.EventHandler)4 UserPreference (com.github.games647.changeskin.core.model.UserPreference)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Message (io.github.lxgaming.discordbot.entries.Message)3 Tristate (me.lucko.luckperms.api.Tristate)3 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)3 PendingConnection (net.md_5.bungee.api.connection.PendingConnection)3 Entity (org.bukkit.entity.Entity)3 Player (org.bukkit.entity.Player)3 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2