Search in sources :

Example 1 with ForwardMessage

use of com.github.games647.changeskin.core.message.ForwardMessage in project ChangeSkin by games647.

the class MessageListener method onCommandForward.

private void onCommandForward(CommandSender invoker, ByteArrayDataInput dataInput) {
    ForwardMessage message = new ForwardMessage();
    message.readFrom(dataInput);
    if (message.isOP() && message.isSource()) {
        // bukkit op and it won't run as bungee console
        invoker.addGroups(plugin.getName() + "-OP");
    }
    String line = message.getCommandName() + ' ' + message.getArgs();
    if (message.isSource()) {
        // the player is the actual invoker other it's the console
        ProxyServer.getInstance().getPluginManager().dispatchCommand(invoker, line);
    } else {
        CommandSender console = ProxyServer.getInstance().getConsole();
        ProxyServer.getInstance().getPluginManager().dispatchCommand(console, line);
    }
}
Also used : ForwardMessage(com.github.games647.changeskin.core.message.ForwardMessage) CommandSender(net.md_5.bungee.api.CommandSender)

Example 2 with ForwardMessage

use of com.github.games647.changeskin.core.message.ForwardMessage 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)

Aggregations

ForwardMessage (com.github.games647.changeskin.core.message.ForwardMessage)2 ChannelMessage (com.github.games647.changeskin.core.message.ChannelMessage)1 CommandSender (net.md_5.bungee.api.CommandSender)1 Player (org.bukkit.entity.Player)1