Search in sources :

Example 1 with AsyncToggleMessage

use of com.github.games647.fastlogin.velocity.task.AsyncToggleMessage in project FastLogin by games647.

the class PluginMessageListener method readMessage.

private void readMessage(Player forPlayer, String channel, byte[] data) {
    FastLoginCore<Player, CommandSource, FastLoginVelocity> core = plugin.getCore();
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
    if (successChannel.equals(channel)) {
        onSuccessMessage(forPlayer);
    } else if (changeChannel.equals(channel)) {
        ChangePremiumMessage changeMessage = new ChangePremiumMessage();
        changeMessage.readFrom(dataInput);
        String playerName = changeMessage.getPlayerName();
        boolean isSourceInvoker = changeMessage.isSourceInvoker();
        if (changeMessage.shouldEnable()) {
            if (playerName.equals(forPlayer.getUsername()) && plugin.getCore().getConfig().get("premium-warning", true) && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
                String message = core.getMessage("premium-warning");
                forPlayer.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(message));
                core.getPendingConfirms().add(forPlayer.getUniqueId());
                return;
            }
            core.getPendingConfirms().remove(forPlayer.getUniqueId());
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        } else {
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        }
    }
}
Also used : ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) AsyncToggleMessage(com.github.games647.fastlogin.velocity.task.AsyncToggleMessage) Player(com.velocitypowered.api.proxy.Player) FastLoginVelocity(com.github.games647.fastlogin.velocity.FastLoginVelocity) CommandSource(com.velocitypowered.api.command.CommandSource) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput)

Example 2 with AsyncToggleMessage

use of com.github.games647.fastlogin.velocity.task.AsyncToggleMessage in project FastLogin by games647.

the class PluginMessageListener method readMessage.

private void readMessage(ProxiedPlayer forPlayer, String channel, byte[] data) {
    FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core = plugin.getCore();
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
    if (successChannel.equals(channel)) {
        onSuccessMessage(forPlayer);
    } else if (changeChannel.equals(channel)) {
        ChangePremiumMessage changeMessage = new ChangePremiumMessage();
        changeMessage.readFrom(dataInput);
        String playerName = changeMessage.getPlayerName();
        boolean isSourceInvoker = changeMessage.isSourceInvoker();
        if (changeMessage.shouldEnable()) {
            if (playerName.equals(forPlayer.getName()) && plugin.getCore().getConfig().get("premium-warning", true) && !core.getPendingConfirms().contains(forPlayer.getUniqueId())) {
                String message = core.getMessage("premium-warning");
                forPlayer.sendMessage(TextComponent.fromLegacyText(message));
                core.getPendingConfirms().add(forPlayer.getUniqueId());
                return;
            }
            core.getPendingConfirms().remove(forPlayer.getUniqueId());
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, true, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        } else {
            Runnable task = new AsyncToggleMessage(core, forPlayer, playerName, false, isSourceInvoker);
            plugin.getScheduler().runAsync(task);
        }
    }
}
Also used : ChangePremiumMessage(com.github.games647.fastlogin.core.message.ChangePremiumMessage) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) AsyncToggleMessage(com.github.games647.fastlogin.bungee.task.AsyncToggleMessage) CommandSender(net.md_5.bungee.api.CommandSender) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) FastLoginBungee(com.github.games647.fastlogin.bungee.FastLoginBungee)

Aggregations

ChangePremiumMessage (com.github.games647.fastlogin.core.message.ChangePremiumMessage)2 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)2 FastLoginBungee (com.github.games647.fastlogin.bungee.FastLoginBungee)1 AsyncToggleMessage (com.github.games647.fastlogin.bungee.task.AsyncToggleMessage)1 FastLoginVelocity (com.github.games647.fastlogin.velocity.FastLoginVelocity)1 AsyncToggleMessage (com.github.games647.fastlogin.velocity.task.AsyncToggleMessage)1 CommandSource (com.velocitypowered.api.command.CommandSource)1 Player (com.velocitypowered.api.proxy.Player)1 CommandSender (net.md_5.bungee.api.CommandSender)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1