Search in sources :

Example 11 with CommandSender

use of net.md_5.bungee.api.CommandSender in project Bukkit_Bungee_PluginLib by GeorgH93.

the class MessageTest method testSend.

@Test
public void testSend() throws Exception {
    int sendMessageCalls = 0;
    int doSendCalls = 0;
    Message message = new Message("");
    CommandSender mockedCommandSender = mock(CommandSender.class);
    ProxiedPlayer mockedProxiedPlayer = mock(ProxiedPlayer.class);
    Field method = Message.class.getDeclaredField("method");
    method.setAccessible(true);
    ChatSender mockedSender = mock(ChatSender.class);
    doNothing().when(mockedSender).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    SendMethod sendMethod = (SendMethod) method.get(message);
    Field defaultSender = sendMethod.getClass().getDeclaredField("defaultSender");
    defaultSender.setAccessible(true);
    defaultSender.set(sendMethod, mockedSender);
    message.send(mockedCommandSender, (Object[]) null);
    // noinspection deprecation
    verify(mockedCommandSender, times(++sendMessageCalls)).sendMessage(anyString());
    message.send(mockedCommandSender);
    // noinspection deprecation
    verify(mockedCommandSender, times(++sendMessageCalls)).sendMessage(anyString());
    message.send(mockedCommandSender, "Test");
    // noinspection deprecation
    verify(mockedCommandSender, times(++sendMessageCalls)).sendMessage(anyString());
    message.send(mockedProxiedPlayer, (Object[]) null);
    verify(mockedSender, times(++doSendCalls)).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    message.send(mockedProxiedPlayer);
    verify(mockedSender, times(++doSendCalls)).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    message.send(mockedProxiedPlayer, "Test");
    verify(mockedSender, times(++doSendCalls)).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    doSendCalls = 0;
    List<ProxiedPlayer> proxiedPlayers = new ArrayList<>();
    message.send(proxiedPlayers);
    verify(mockedSender, times(doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    proxiedPlayers.add(mockedProxiedPlayer);
    message.send(proxiedPlayers, (Object[]) null);
    verify(mockedSender, times(++doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    message.send(proxiedPlayers);
    verify(mockedSender, times(++doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    message.send(proxiedPlayers, "Test");
    verify(mockedSender, times(++doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    message.setSendMethod(null);
    message.send(mockedCommandSender);
    // noinspection deprecation
    verify(mockedCommandSender, times(sendMessageCalls)).sendMessage(anyString());
    message.send(proxiedPlayers);
    verify(mockedSender, times(doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    defaultSender.setAccessible(false);
    method.setAccessible(false);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Field(java.lang.reflect.Field) ChatSender(at.pcgamingfreaks.Bungee.Message.Sender.ChatSender) SendMethod(at.pcgamingfreaks.Bungee.Message.Sender.SendMethod) ArrayList(java.util.ArrayList) CommandSender(net.md_5.bungee.api.CommandSender) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with CommandSender

use of net.md_5.bungee.api.CommandSender in project SkinsRestorerX by DoNotSpamPls.

the class SkinsRestorer method onEnable.

@Override
public void onEnable() {
    @SuppressWarnings("unused") MetricsLite metrics = new MetricsLite(this);
    instance = this;
    Config.load(getResourceAsStream("config.yml"));
    Locale.load();
    if (Config.USE_MYSQL) {
        SkinStorage.init(mysql = new MySQL(Config.MYSQL_HOST, Config.MYSQL_PORT, Config.MYSQL_DATABASE, Config.MYSQL_USERNAME, Config.MYSQL_PASSWORD));
    } else {
        SkinStorage.init(getDataFolder());
    }
    getProxy().getPluginManager().registerListener(this, new LoginListener());
    getProxy().getPluginManager().registerCommand(this, new AdminCommands());
    getProxy().getPluginManager().registerCommand(this, new PlayerCommands());
    getProxy().registerChannel("SkinsRestorer");
    SkinApplier.init();
    multibungee = Config.MULTIBUNGEE_ENABLED || ProxyServer.getInstance().getPluginManager().getPlugin("RedisBungee") != null;
    ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
        CommandSender console = getProxy().getConsole();
        if (Config.UPDATER_ENABLED)
            if (checkVersion(console).equals(getVersion())) {
                outdated = false;
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    | SkinsRestorer |"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §b    Current version: §a" + getVersion()));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    This is the latest version!"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
            } else {
                outdated = true;
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    | SkinsRestorer |"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a    +===============+"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §b    Current version: §c" + getVersion()));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §e    A new version is available! Download it at:"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §e    https://www.spigotmc.org/resources/skinsrestorer.2124"));
                console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §a----------------------------------------------"));
            }
        if (Config.DEFAULT_SKINS_ENABLED)
            for (String skin : Config.DEFAULT_SKINS) try {
                SkinStorage.setSkinData(skin, MojangAPI.getSkinProperty(MojangAPI.getUUID(skin)));
            } catch (SkinRequestException e) {
                if (SkinStorage.getSkinData(skin) == null)
                    console.sendMessage(new TextComponent("§e[§2SkinsRestorer§e] §cDefault Skin '" + skin + "' request error:" + e.getReason()));
            }
    });
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) MetricsLite(org.bstats.bungeecord.MetricsLite) LoginListener(skinsrestorer.bungee.listeners.LoginListener) MySQL(skinsrestorer.shared.utils.MySQL) AdminCommands(skinsrestorer.bungee.commands.AdminCommands) PlayerCommands(skinsrestorer.bungee.commands.PlayerCommands) CommandSender(net.md_5.bungee.api.CommandSender) SkinRequestException(skinsrestorer.shared.utils.MojangAPI.SkinRequestException)

Example 13 with CommandSender

use of net.md_5.bungee.api.CommandSender in project SkinsRestorerX by DoNotSpamPls.

the class PlayerCommands method execute.

public void execute(CommandSender sender, final String[] args) {
    if (!(sender instanceof ProxiedPlayer)) {
        sender.sendMessage(new TextComponent(Locale.NOT_PLAYER));
        return;
    }
    final ProxiedPlayer p = (ProxiedPlayer) sender;
    // Skin Help
    if (args.length == 0 || args.length > 2) {
        if (!Config.SKINWITHOUTPERM) {
            if (p.hasPermission("skinsrestorer.playercmds")) {
                help(p);
            } else {
                p.sendMessage(new TextComponent(Locale.PLAYER_HAS_NO_PERMISSION));
            }
        } else {
            help(p);
        }
    }
    // Skin Clear and Skin (name)
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("clear")) {
            CooldownStorage.resetCooldown(p.getName());
            CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                SkinStorage.removePlayerSkin(p.getName());
                SkinStorage.setPlayerSkin(p.getName(), p.getName());
                SkinApplier.applySkin(p);
                p.sendMessage(new TextComponent(Locale.SKIN_CLEAR_SUCCESS));
            });
        } else {
            // skin <skin>
            final String skin = args[0];
            if (Config.DISABLED_SKINS_ENABLED)
                if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
                    for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
                        p.sendMessage(new TextComponent(Locale.SKIN_DISABLED));
                        return;
                    }
                }
            if (!p.hasPermission("skinsrestorer.bypasscooldown") && CooldownStorage.hasCooldown(p.getName())) {
                p.sendMessage(new TextComponent(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName()))));
                return;
            }
            CooldownStorage.resetCooldown(p.getName());
            CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                try {
                    MojangAPI.getUUID(skin);
                    SkinStorage.setPlayerSkin(p.getName(), skin);
                    SkinApplier.applySkin(p);
                    p.sendMessage(new TextComponent(Locale.SKIN_CHANGE_SUCCESS));
                } catch (SkinRequestException e) {
                    p.sendMessage(new TextComponent(e.getReason()));
                }
            });
            return;
        }
    }
    // skin set
    if (args.length == 2) {
        if (args[0].equalsIgnoreCase("set")) {
            final String skin = args[1];
            if (Config.DISABLED_SKINS_ENABLED)
                if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
                    for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
                        p.sendMessage(new TextComponent(Locale.SKIN_DISABLED));
                        return;
                    }
                }
            if (!p.hasPermission("skinsrestorer.bypasscooldown") && CooldownStorage.hasCooldown(p.getName())) {
                p.sendMessage(new TextComponent(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName()))));
                return;
            }
            CooldownStorage.resetCooldown(p.getName());
            CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                try {
                    MojangAPI.getUUID(skin);
                    SkinStorage.setPlayerSkin(p.getName(), skin);
                    SkinApplier.applySkin(p);
                    p.sendMessage(new TextComponent(Locale.SKIN_CHANGE_SUCCESS));
                } catch (SkinRequestException e) {
                    p.sendMessage(new TextComponent(e.getReason()));
                }
            });
        } else {
            help(p);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) SkinRequestException(skinsrestorer.shared.utils.MojangAPI.SkinRequestException)

Example 14 with CommandSender

use of net.md_5.bungee.api.CommandSender in project FireAPI by FireBlade-Serv.

the class FireRankCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (this.rank.hasRankAndSupOrConsole(sender, Rank.STAFF_MANAGER)) {
        if (args.length == 0) {
            sender.sendMessage(new TextComponent(this.pre + "/firerank show <pseudo>"));
            sender.sendMessage(new TextComponent(this.pre + "/firerank set <pseudo> <rang>"));
        } else if (args.length == 1) {
            if (args[0].equalsIgnoreCase("show")) {
                sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firerank show <pseudo>"));
            } else if (args[0].equalsIgnoreCase("set")) {
                sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firerank set <pseudo> <rang>"));
            } else {
                sender.sendMessage(new TextComponent(this.pre + "/firerank show <pseudo>"));
                sender.sendMessage(new TextComponent(this.pre + "/firerank set <pseudo> <rang>"));
            }
        } else if (args.length == 2) {
            if (args[0].equalsIgnoreCase("show")) {
                if (this.sql.hasFireAccount(args[1])) {
                    sender.sendMessage(new TextComponent(this.pre + "Le joueur §a" + args[1] + "§r est §e" + this.rank.getPlayerRank(args[1]).name() + "§r !"));
                } else {
                    sender.sendMessage(new TextComponent(this.pre + "§cImpossible de trouver le joueur \"" + args[1] + "\" !"));
                }
            } else if (args[0].equalsIgnoreCase("set")) {
                sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firerank set <pseudo> <rang>"));
            } else {
                sender.sendMessage(new TextComponent(this.pre + "/firerank show <pseudo>"));
                sender.sendMessage(new TextComponent(this.pre + "/firerank set <pseudo> <rang>"));
            }
        } else if (args.length == 3) {
            if (args[0].equalsIgnoreCase("show")) {
                sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firerank show <pseudo>"));
            } else if (args[0].equalsIgnoreCase("set")) {
                if (this.sql.hasFireAccount(args[1])) {
                    if (containsRank(args[2])) {
                        this.rank.setPlayerRank(args[1], getApproximative(args[2]));
                        sender.sendMessage(new TextComponent(this.pre + "§e" + args[1] + " §rpossède maintenant le grade de §e" + getApproximative(args[2]).name() + "§r !"));
                    } else {
                        sender.sendMessage(new TextComponent(this.pre + "§cErreur, ce grade n'existe pas !"));
                        sender.sendMessage(new TextComponent(this.pre + "§cVoici la liste des grades disponibles : " + getRankList()));
                    }
                } else {
                    sender.sendMessage(new TextComponent(this.pre + "§cImpossible de trouver le joueur \"" + args[1] + "\" !"));
                }
            }
        }
    } else {
        sender.sendMessage(new TextComponent(this.pre + "§cVous n'avez pas la permission d'utiliser cette commande !"));
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent)

Example 15 with CommandSender

use of net.md_5.bungee.api.CommandSender in project FireAPI by FireBlade-Serv.

the class FireWhiteListCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!this.api.getRankSystem().hasRankAndSupOrConsole(sender, Rank.MANAGER_IG)) {
        sender.sendMessage(new TextComponent(this.pre + "§cVous n'avez pas la permission d'utiliser cette commande !"));
        return;
    }
    if (args.length == 0) {
        sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firewl <add/remove/on/off> (<pseudo>)"));
        return;
    } else if (args.length == 1) {
        if (args[0].equalsIgnoreCase("on")) {
            File file = new File(this.api.getBungeePlugin().getDataFolder(), "whitelist.yml");
            try {
                Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
                config.set("enable", true);
                ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
                sender.sendMessage(new TextComponent(this.pre + "§aLe plugin est activé !"));
                this.api.getWhitelistSystem().setEnable(true);
            } catch (IOException e) {
                sender.sendMessage(new TextComponent(this.pre + "§cUne erreur interne au plugin est survenue !"));
            }
        } else if (args[0].equalsIgnoreCase("off")) {
            File file = new File(this.api.getBungeePlugin().getDataFolder(), "whitelist.yml");
            try {
                Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
                config.set("enable", false);
                ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
                sender.sendMessage(new TextComponent(this.pre + "§aLe plugin est désactivé !"));
                this.api.getWhitelistSystem().setEnable(false);
            } catch (IOException e) {
                sender.sendMessage(new TextComponent(this.pre + "§cUne erreur interne au plugin est survenue !"));
            }
        } else {
            sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firewl <add/remove/on/off> (<pseudo>)"));
            return;
        }
    } else if (args.length == 2) {
        if (this.api.getWhitelistSystem().isEnable() == false) {
            sender.sendMessage(new TextComponent(this.pre + "§cLe plugin est désactivé !"));
            return;
        }
        if (args[0].equalsIgnoreCase("add")) {
            try {
                File file = new File(this.api.getBungeePlugin().getDataFolder(), "whitelist.yml");
                Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
                if (config.getBoolean("players." + args[1] + ".accepted") == true) {
                    sender.sendMessage(new TextComponent(this.pre + "§cLe joueur " + args[1] + " est déjà dans la whitelist !"));
                    return;
                }
                config.set("players." + args[1] + ".accepted", true);
                ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
                sender.sendMessage(new TextComponent(this.pre + "§aVous avez ajouté le joueur " + args[1] + " à la whitelist !"));
                return;
            } catch (IOException e) {
                sender.sendMessage(new TextComponent(this.pre + "§cUne erreur interne au plugin est survenue !"));
            }
        } else if (args[0].equalsIgnoreCase("remove")) {
            try {
                File file = new File(this.api.getBungeePlugin().getDataFolder(), "whitelist.yml");
                Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
                if (config.getBoolean("players." + args[1] + ".accepted") == false) {
                    sender.sendMessage(new TextComponent(this.pre + "§cLe joueur " + args[1] + " n'existe pas !"));
                    return;
                }
                config.set("players." + args[1] + ".accepted", false);
                ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
                sender.sendMessage(new TextComponent(this.pre + "§aVous avez retiré le joueur " + args[1] + " de la WhiteList !"));
            } catch (IOException e) {
                sender.sendMessage(new TextComponent(this.pre + "§cUne erreur interne au plugin est survenue !"));
            }
        } else {
            sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firewl <add/remove/on/off> (<pseudo>)"));
            return;
        }
    } else {
        sender.sendMessage(new TextComponent(this.pre + "§cUsage : /firewl <add/remove/on/off> (<pseudo>)"));
        return;
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) IOException(java.io.IOException) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File)

Aggregations

TextComponent (net.md_5.bungee.api.chat.TextComponent)22 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)15 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)11 CommandSender (net.md_5.bungee.api.CommandSender)9 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)8 Player (org.bukkit.entity.Player)8 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)6 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)6 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)5 ArrayList (java.util.ArrayList)4 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)3 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)3 ChatSender (at.pcgamingfreaks.Bungee.Message.Sender.ChatSender)2 SendMethod (at.pcgamingfreaks.Bungee.Message.Sender.SendMethod)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 SoliniaActiveSpell (com.solinia.solinia.Models.SoliniaActiveSpell)2 SoliniaEntitySpells (com.solinia.solinia.Models.SoliniaEntitySpells)2 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2