Search in sources :

Example 41 with CommandSender

use of net.md_5.bungee.api.CommandSender in project CloudNet by Dytanic.

the class CommandHub method execute.

@Override
public void execute(CommandSender commandSender, String[] args) {
    if (!(commandSender instanceof ProxiedPlayer))
        return;
    ServerInfo serverInfo = CloudProxy.getInstance().getCachedServers().get(((ProxiedPlayer) commandSender).getServer().getInfo().getName());
    if (serverInfo != null)
        if (CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getNamedFallbackes().contains(serverInfo.getServiceId().getGroup())) {
            commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("hub-already")));
            return;
        }
    String fallback = CloudProxy.getInstance().fallbackOnEnabledKick((((ProxiedPlayer) commandSender)), CloudAPI.getInstance().getGroup(), ((ProxiedPlayer) commandSender).getServer().getInfo().getName());
    ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent((ProxiedPlayer) commandSender, CloudAPI.getInstance().getOnlinePlayer(((ProxiedPlayer) commandSender).getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.HUB_COMMAND, fallback);
    ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
    fallback = proxiedPlayerFallbackEvent.getFallback();
    ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
    if (fallback == null)
        commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("hubCommandNoServerFound")));
    else
        ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(fallback));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent)

Example 42 with CommandSender

use of net.md_5.bungee.api.CommandSender in project ChangeSkin by games647.

the class InfoCommand method execute.

@Override
public void execute(CommandSender sender, String[] strings) {
    if (!(sender instanceof ProxiedPlayer)) {
        plugin.sendMessage(sender, "no-console");
        return;
    }
    ProxiedPlayer player = (ProxiedPlayer) sender;
    UserPreference preference = plugin.getLoginSession((PendingConnection) player);
    Optional<SkinModel> optSkin = preference.getTargetSkin();
    if (optSkin.isPresent()) {
        String template = plugin.getCore().getMessage("skin-info");
        sender.sendMessage(TextComponent.fromLegacyText(formatter.apply(template, optSkin.get())));
    } else {
        plugin.sendMessage(sender, "skin-not-found");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) UserPreference(com.github.games647.changeskin.core.model.UserPreference) SkinModel(com.github.games647.changeskin.core.model.skin.SkinModel)

Example 43 with CommandSender

use of net.md_5.bungee.api.CommandSender 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 44 with CommandSender

use of net.md_5.bungee.api.CommandSender in project ChangeSkin by games647.

the class InvalidateCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    boolean isOp = sender.getGroups().contains(plugin.getName() + "-OP");
    if (sender instanceof ProxiedPlayer) {
        sender.removeGroups(plugin.getName() + "-OP");
    }
    if (args.length > 0) {
        ProxiedPlayer targetPlayer = ProxyServer.getInstance().getPlayer(args[0]);
        if (targetPlayer == null) {
            plugin.sendMessage(sender, "not-online");
            return;
        }
        String permPrefix = plugin.getName().toLowerCase() + ".command.skinupdate.other.";
        if (!sender.hasPermission(permPrefix + targetPlayer.getUniqueId()) && !sender.hasPermission(permPrefix + '*')) {
            plugin.sendMessage(sender, "no-permission-other");
            return;
        }
        Runnable skinInvalidate = new SkinInvalidator(plugin, sender, targetPlayer, isOp);
        ProxyServer.getInstance().getScheduler().runAsync(plugin, skinInvalidate);
        return;
    }
    if (!(sender instanceof ProxiedPlayer)) {
        plugin.sendMessage(sender, "no-console");
        return;
    }
    ProxiedPlayer receiver = (ProxiedPlayer) sender;
    Runnable skinInvalidate = new SkinInvalidator(plugin, sender, receiver, isOp);
    ProxyServer.getInstance().getScheduler().runAsync(plugin, skinInvalidate);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) SkinInvalidator(com.github.games647.changeskin.bungee.task.SkinInvalidator)

Example 45 with CommandSender

use of net.md_5.bungee.api.CommandSender in project CitizensAPI by CitizensDev.

the class Messaging method parseAndSendComponents.

private static void parseAndSendComponents(CommandSender sender, String message) {
    ComponentBuilder builder = new ComponentBuilder("");
    Matcher m = COMPONENT_MATCHER.matcher(message);
    int end = 0;
    while (m.find()) {
        String text = m.group(1);
        String type = m.group(2);
        String command = m.group(3);
        ClickEvent.Action action = null;
        switch(type) {
            case "url":
                action = ClickEvent.Action.OPEN_URL;
                break;
            case "command":
                action = ClickEvent.Action.RUN_COMMAND;
                break;
            case "suggest":
                action = ClickEvent.Action.SUGGEST_COMMAND;
                break;
        }
        builder.append(text);
        end = m.end();
        if (action != null) {
            builder.underlined(true);
            builder.event(new ClickEvent(action, command));
        }
        if (m.groupCount() > 3) {
            builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(m.group(4).substring(1))));
        } else {
            builder.event((HoverEvent) null);
        }
    }
    if (end - 1 < message.length()) {
        builder.append(message.substring(end));
        builder.event((ClickEvent) null);
        builder.event((HoverEvent) null);
        builder.underlined(false);
    }
    sender.spigot().sendMessage(builder.create());
}
Also used : HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Matcher(java.util.regex.Matcher) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Text(net.md_5.bungee.api.chat.hover.content.Text) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Aggregations

TextComponent (net.md_5.bungee.api.chat.TextComponent)44 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)24 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)23 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)21 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)18 Player (org.bukkit.entity.Player)17 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)15 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)10 CommandSender (net.md_5.bungee.api.CommandSender)9 ArrayList (java.util.ArrayList)7 ChatColor (net.md_5.bungee.api.ChatColor)6 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)6 CommandSender (org.bukkit.command.CommandSender)5 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)4 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)4 HashMap (java.util.HashMap)4 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)3 ChatSender (at.pcgamingfreaks.Bungee.Message.Sender.ChatSender)2 SendMethod (at.pcgamingfreaks.Bungee.Message.Sender.SendMethod)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)2