Search in sources :

Example 6 with ChannelMessage

use of com.github.games647.fastlogin.core.message.ChannelMessage in project ChangeSkin by games647.

the class AbstractForwardCommand method onBungeeCord.

protected void onBungeeCord(CommandSender sender, String commandName, String... args) {
    Player proxy;
    boolean isPlayer = sender instanceof Player;
    if (isPlayer) {
        proxy = (Player) sender;
    } else {
        Optional<? extends Player> optPlayer = Bukkit.getOnlinePlayers().stream().findAny();
        if (!optPlayer.isPresent()) {
            sender.sendMessage(ChatColor.DARK_RED + "No player is online to forward this message to Bungee");
            return;
        }
        proxy = optPlayer.get();
    }
    ChannelMessage message = new ForwardMessage(commandName, Joiner.on(' ').join(args), isPlayer, sender.isOp());
    plugin.sendPluginMessage(proxy, message);
}
Also used : Player(org.bukkit.entity.Player) ForwardMessage(com.github.games647.changeskin.core.message.ForwardMessage) ChannelMessage(com.github.games647.changeskin.core.message.ChannelMessage)

Example 7 with ChannelMessage

use of com.github.games647.fastlogin.core.message.ChannelMessage in project FastLogin by games647.

the class ToggleCommand method sendBungeeActivateMessage.

protected void sendBungeeActivateMessage(CommandSender invoker, String target, boolean activate) {
    if (invoker instanceof PluginMessageRecipient) {
        ChannelMessage message = new ChangePremiumMessage(target, activate, true);
        plugin.getBungeeManager().sendPluginMessage((PluginMessageRecipient) invoker, message);
    } else {
        Optional<? extends Player> optPlayer = Bukkit.getServer().getOnlinePlayers().stream().findFirst();
        if (!optPlayer.isPresent()) {
            plugin.getLog().info("No player online to send a plugin message to the proxy");
            return;
        }
        Player sender = optPlayer.get();
        ChannelMessage message = new ChangePremiumMessage(target, activate, false);
        plugin.getBungeeManager().sendPluginMessage(sender, message);
    }
}
Also used : ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) Player(org.bukkit.entity.Player) PluginMessageRecipient(org.bukkit.plugin.messaging.PluginMessageRecipient) ChannelMessage(com.github.games647.fastlogin.core.message.ChannelMessage)

Example 8 with ChannelMessage

use of com.github.games647.fastlogin.core.message.ChannelMessage in project FastLogin by games647.

the class FastLoginBungee method sendPluginMessage.

public void sendPluginMessage(Server server, ChannelMessage message) {
    if (server != null) {
        ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
        message.writeTo(dataOutput);
        NamespaceKey channel = new NamespaceKey(getName(), message.getChannelName());
        server.sendData(channel.getCombinedName(), dataOutput.toByteArray());
    }
}
Also used : NamespaceKey(com.github.games647.fastlogin.core.message.NamespaceKey) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput)

Example 9 with ChannelMessage

use of com.github.games647.fastlogin.core.message.ChannelMessage in project FastLogin by games647.

the class ForceLoginTask method onForceActionSuccess.

@Override
public void onForceActionSuccess(LoginSession session) {
    // sub channel name
    Type type = Type.LOGIN;
    if (session.needsRegistration()) {
        type = Type.REGISTER;
    }
    UUID proxyId = UUID.fromString(ProxyServer.getInstance().getConfig().getUuid());
    ChannelMessage loginMessage = new LoginActionMessage(type, player.getName(), proxyId);
    core.getPlugin().sendPluginMessage(server, loginMessage);
}
Also used : Type(com.github.games647.fastlogin.core.message.LoginActionMessage.Type) LoginActionMessage(com.github.games647.fastlogin.core.message.LoginActionMessage) UUID(java.util.UUID) ChannelMessage(com.github.games647.fastlogin.core.message.ChannelMessage)

Aggregations

ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)4 ChannelMessage (com.github.games647.fastlogin.core.message.ChannelMessage)3 UUID (java.util.UUID)3 ChannelMessage (com.github.games647.changeskin.core.message.ChannelMessage)2 NamespaceKey (com.github.games647.changeskin.core.message.NamespaceKey)2 LoginActionMessage (com.github.games647.fastlogin.core.message.LoginActionMessage)2 Type (com.github.games647.fastlogin.core.message.LoginActionMessage.Type)2 NamespaceKey (com.github.games647.fastlogin.core.message.NamespaceKey)2 Player (org.bukkit.entity.Player)2 CheckPermMessage (com.github.games647.changeskin.core.message.CheckPermMessage)1 ForwardMessage (com.github.games647.changeskin.core.message.ForwardMessage)1 UserPreference (com.github.games647.changeskin.core.model.UserPreference)1 ChangePremiumMessage (com.github.games647.fastlogin.core.message.ChangePremiumMessage)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 Server (net.md_5.bungee.api.connection.Server)1 PluginMessageRecipient (org.bukkit.plugin.messaging.PluginMessageRecipient)1