Search in sources :

Example 6 with CommandSender

use of org.bukkit.command.CommandSender in project Prism-Bukkit by prism.

the class ActionsQuery method lookup.

/**
     * 
     * @return
     */
public QueryResult lookup(QueryParameters parameters, CommandSender sender) {
    Player player = null;
    if (sender instanceof Player) {
        player = (Player) sender;
    }
    // If lookup, determine if we need to group
    shouldGroup = false;
    if (parameters.getProcessType().equals(PrismProcessType.LOOKUP)) {
        shouldGroup = true;
        // What to default to
        if (!plugin.getConfig().getBoolean("prism.queries.lookup-auto-group")) {
            shouldGroup = false;
        }
        // Any overriding flags passed?
        if (parameters.hasFlag(Flag.NO_GROUP) || parameters.hasFlag(Flag.EXTENDED)) {
            shouldGroup = false;
        }
    }
    // Pull results
    final List<Handler> actions = new ArrayList<Handler>();
    // Build conditions based off final args
    final String query = qb.getQuery(parameters, shouldGroup);
    if (query != null) {
        Connection conn = null;
        PreparedStatement s = null;
        ResultSet rs = null;
        try {
            plugin.eventTimer.recordTimedEvent("query started");
            conn = Prism.dbc();
            // Handle dead connections
            if (conn == null || conn.isClosed()) {
                if (RecordingManager.failedDbConnectionCount == 0) {
                    Prism.log("Prism database error. Connection should be there but it's not. Leaving actions to log in queue.");
                }
                RecordingManager.failedDbConnectionCount++;
                sender.sendMessage(Prism.messenger.playerError("Database connection was closed, please wait and try again."));
                return new QueryResult(actions, parameters);
            } else {
                RecordingManager.failedDbConnectionCount = 0;
            }
            s = conn.prepareStatement(query);
            rs = s.executeQuery();
            plugin.eventTimer.recordTimedEvent("query returned, building results");
            while (rs.next()) {
                if (rs.getString(3) == null)
                    continue;
                // Convert action ID to name
                // Performance-wise this is a lot faster than table joins
                // and the cache data should always be available
                String actionName = "";
                for (final Entry<String, Integer> entry : Prism.prismActions.entrySet()) {
                    if (entry.getValue() == rs.getInt(3)) {
                        actionName = entry.getKey();
                    }
                }
                if (actionName.isEmpty()) {
                    Prism.log("Record contains action ID that doesn't exist in cache: " + rs.getInt(3));
                    continue;
                }
                // Get the action handler
                final ActionType actionType = Prism.getActionRegistry().getAction(actionName);
                if (actionType == null)
                    continue;
                try {
                    final Handler baseHandler = Prism.getHandlerRegistry().getHandler(actionType.getHandler());
                    // Convert world ID to name
                    // Performance-wise this is typically a lot faster than
                    // table joins
                    String worldName = "";
                    for (final Entry<String, Integer> entry : Prism.prismWorlds.entrySet()) {
                        if (entry.getValue() == rs.getInt(5)) {
                            worldName = entry.getKey();
                        }
                    }
                    // Set all shared values
                    baseHandler.setPlugin(plugin);
                    baseHandler.setType(actionType);
                    baseHandler.setId(rs.getInt(1));
                    baseHandler.setUnixEpoch(rs.getString(2));
                    baseHandler.setPlayerName(rs.getString(4));
                    baseHandler.setWorldName(worldName);
                    baseHandler.setX(rs.getInt(6));
                    baseHandler.setY(rs.getInt(7));
                    baseHandler.setZ(rs.getInt(8));
                    baseHandler.setBlockId(rs.getInt(9));
                    baseHandler.setBlockSubId(rs.getInt(10));
                    baseHandler.setOldBlockId(rs.getInt(11));
                    baseHandler.setOldBlockSubId(rs.getInt(12));
                    baseHandler.setData(rs.getString(13));
                    baseHandler.setMaterialAliases(Prism.getItems());
                    // Set aggregate counts if a lookup
                    int aggregated = 0;
                    if (shouldGroup) {
                        aggregated = rs.getInt(14);
                    }
                    baseHandler.setAggregateCount(aggregated);
                    actions.add(baseHandler);
                } catch (final Exception e) {
                    if (!rs.isClosed()) {
                        Prism.log("Ignoring data from record #" + rs.getInt(1) + " because it caused an error:");
                    }
                    e.printStackTrace();
                }
            }
        } catch (final SQLException e) {
            plugin.handleDatabaseException(e);
        } finally {
            if (rs != null)
                try {
                    rs.close();
                } catch (final SQLException ignored) {
                }
            if (s != null)
                try {
                    s.close();
                } catch (final SQLException ignored) {
                }
            if (conn != null)
                try {
                    conn.close();
                } catch (final SQLException ignored) {
                }
        }
    }
    // Build result object
    final QueryResult res = new QueryResult(actions, parameters);
    res.setPerPage(parameters.getPerPage());
    // need a cache.
    if (parameters.getProcessType().equals(PrismProcessType.LOOKUP)) {
        String keyName = "console";
        if (player != null) {
            keyName = player.getName();
        }
        if (plugin.cachedQueries.containsKey(keyName)) {
            plugin.cachedQueries.remove(keyName);
        }
        plugin.cachedQueries.put(keyName, res);
        // We also need to share these results with the -share-with players.
        for (final CommandSender sharedPlayer : parameters.getSharedPlayers()) {
            plugin.cachedQueries.put(sharedPlayer.getName(), res);
        }
    }
    plugin.eventTimer.recordTimedEvent("results object completed");
    // Return it
    return res;
}
Also used : Player(org.bukkit.entity.Player) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) Handler(me.botsko.prism.actions.Handler) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) CommandSender(org.bukkit.command.CommandSender)

Example 7 with CommandSender

use of org.bukkit.command.CommandSender in project Essentials by drtshock.

the class MessagingTest method runConsoleCommand.

private void runConsoleCommand(String command, String[] args) throws Exception {
    IEssentialsCommand cmd;
    CommandSender sender = server.getConsoleSender();
    try {
        cmd = (IEssentialsCommand) Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
        cmd.setEssentials(ess);
        cmd.run(server, new CommandSource(sender), command, null, args);
    } catch (NoChargeException ex) {
    }
}
Also used : NoChargeException(com.earth2me.essentials.commands.NoChargeException) IEssentialsCommand(com.earth2me.essentials.commands.IEssentialsCommand) CommandSender(org.bukkit.command.CommandSender)

Example 8 with CommandSender

use of org.bukkit.command.CommandSender in project Essentials by drtshock.

the class ToggleTest method runConsoleCommand.

private void runConsoleCommand(String command, String[] args) throws Exception {
    IEssentialsCommand cmd;
    CommandSender sender = server.getConsoleSender();
    try {
        cmd = (IEssentialsCommand) Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
        cmd.setEssentials(ess);
        cmd.run(server, new CommandSource(sender), command, null, args);
    } catch (NoChargeException ex) {
    }
}
Also used : NoChargeException(com.earth2me.essentials.commands.NoChargeException) IEssentialsCommand(com.earth2me.essentials.commands.IEssentialsCommand) CommandSender(org.bukkit.command.CommandSender)

Example 9 with CommandSender

use of org.bukkit.command.CommandSender in project SpaciousLib by anhcraft.

the class SpaciousLibTestSpigot method onEnable.

@Override
public void onEnable() {
    new DirectoryManager("plugins/SpaciousLibTest/").mkdirs();
    try {
        new FileManager("plugins/SpaciousLibTest/test.txt").initFile(IOUtils.toByteArray(getClass().getResourceAsStream("/test.txt")));
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        new CommandBuilder("slt", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                for (String str : sCommand.getCommandsAsString(true)) {
                    commandSender.sendMessage(str);
                }
            }
        }).addSubCommand(new SubCommandBuilder("particle spawn", "Spawn a specific type of particle at your location", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                commandSender.sendMessage(sCommand.getCommandAsString(subCommand, true));
            }
        }).addArgument(new CommandArgument("type", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                if (commandSender instanceof Player) {
                    Particle.Type type = StringUtils.get(strings[0].toUpperCase(), Particle.Type.values());
                    if (type == null) {
                        commandSender.sendMessage("Invalid particle type!");
                    } else {
                        Location location = ((Player) commandSender).getLocation();
                        for (int degree = 0; degree < 360; degree++) {
                            double radians = Math.toRadians(degree);
                            double x = Math.cos(radians) * 3;
                            double z = Math.sin(radians) * 3;
                            location.add(x, 0, z);
                            Particle.create(type, location, 10).sendWorld(((Player) commandSender).getWorld());
                            location.subtract(x, 0, z);
                        }
                    }
                }
            }
        }, false), CommandArgument.Type.CUSTOM).addArgument(new CommandArgument("count", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                if (commandSender instanceof Player) {
                    Particle.Type type = StringUtils.get(strings[0], Particle.Type.values());
                    if (type == null) {
                        commandSender.sendMessage("Invalid particle type!");
                    } else {
                        Location location = ((Player) commandSender).getLocation();
                        for (int degree = 0; degree < 360; degree++) {
                            double radians = Math.toRadians(degree);
                            double x = Math.cos(radians) * 3;
                            double z = Math.sin(radians) * 3;
                            location.add(x, 0, z);
                            Particle.create(type, location, StringUtils.toIntegerNumber(strings[1])).sendWorld(((Player) commandSender).getWorld());
                            location.subtract(x, 0, z);
                        }
                    }
                }
            }
        }, true), CommandArgument.Type.INTEGER_NUMBER).hideTypeCommandString()).addSubCommand(new SubCommandBuilder("particle list", "show all types of particle", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                StringBuilder pls = new StringBuilder();
                for (Particle.Type p : Particle.Type.values()) {
                    pls.append(p.toString()).append(" ");
                }
                commandSender.sendMessage(pls.toString());
            }
        })).addSubCommand(new SubCommandBuilder("playerlist set", null, new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                commandSender.sendMessage(sCommand.getCommandAsString(subCommand, true));
            }
        }).addArgument("header", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                commandSender.sendMessage(sCommand.getCommandAsString(subCommand, true));
            }
        }, CommandArgument.Type.CUSTOM, false).addArgument("footer", new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                PlayerList.create(strings[0], strings[1]).sendAll();
            }
        }, CommandArgument.Type.CUSTOM, false)).addSubCommand(new SubCommandBuilder("playerlist remove", null, new CommandRunnable() {

            @Override
            public void run(CommandBuilder sCommand, SubCommandBuilder subCommand, CommandSender commandSender, String[] strings, String s) {
                PlayerList.remove().sendAll();
            }
        })).addSubCommand(new SubCommandBuilder("camera", "View as a random nearby entity", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] strings, String s) {
                if (sender instanceof Player) {
                    Entity e = RandomUtils.pickRandom(((Player) sender).getNearbyEntities(5, 5, 5));
                    Camera.create(e).sendPlayer((Player) sender);
                }
            }
        })).addSubCommand(new SubCommandBuilder("camera reset", "Reset your view to normal", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] strings, String s) {
                if (sender instanceof Player) {
                    if (sender instanceof Player) {
                        Camera.create((Player) sender).sendPlayer((Player) sender);
                    }
                }
            }
        })).addSubCommand(new SubCommandBuilder("bungee tp", "Teleport you or a specific player to a server in Bungee network", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                sender.sendMessage(cmd.getCommandAsString(subcmd, true));
            }
        }).addArgument("server", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                if (sender instanceof Player) {
                    BungeeManager.connect((Player) sender, value);
                }
            }
        }, CommandArgument.Type.CUSTOM, false).addArgument("player", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                if (sender instanceof Player) {
                    BungeeManager.connect(value, args[0]);
                }
            }
        }, CommandArgument.Type.ONLINE_PLAYER, true)).addSubCommand(new SubCommandBuilder("bungee ip", "Get your real IP", new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                if (sender instanceof Player) {
                    BungeeManager.getIP((Player) sender, new BungeePlayerIPResponse() {

                        @Override
                        public void result(String ip, int port) {
                            sender.sendMessage(ip + ":" + port);
                        }
                    });
                }
            }
        })).buildExecutor(this).addSubCommand(new SubCommandBuilder("bungee data", null, new CommandRunnable() {

            @Override
            public void run(CommandBuilder cmd, SubCommandBuilder subcmd, CommandSender sender, String[] args, String value) {
                sender.sendMessage("sent successfully!");
                ByteArrayOutputStream bytedata = new ByteArrayOutputStream();
                DataOutputStream data = new DataOutputStream(bytedata);
                try {
                    data.writeUTF(sender.getName());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                BungeeManager.forwardData("slt", bytedata.toByteArray());
            }
        })).buildExecutor(this).clone("sl").buildExecutor(this).clone("spaciouslib").buildExecutor(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
    getServer().getPluginManager().registerEvents(this, this);
    System.out.println("Starting socket server...");
    SocketManager.registerServer(25568, new ServerSocketRequestHandler() {

        @Override
        public void request(ServerSocketClientHandler client, String data) {
            System.out.println("Client >> " + data);
        }
    });
    for (Placeholder placeholder : PlaceholderManager.getPlaceholders()) {
        System.out.println(placeholder.getPlaceholder());
    }
}
Also used : Entity(org.bukkit.entity.Entity) Placeholder(org.anhcraft.spaciouslib.placeholder.Placeholder) DataOutputStream(java.io.DataOutputStream) CommandArgument(org.anhcraft.spaciouslib.command.CommandArgument) ServerSocketRequestHandler(org.anhcraft.spaciouslib.socket.ServerSocketRequestHandler) Particle(org.anhcraft.spaciouslib.protocol.Particle) SubCommandBuilder(org.anhcraft.spaciouslib.command.SubCommandBuilder) Player(org.bukkit.entity.Player) DirectoryManager(org.anhcraft.spaciouslib.io.DirectoryManager) CommandRunnable(org.anhcraft.spaciouslib.command.CommandRunnable) BungeePlayerIPResponse(org.anhcraft.spaciouslib.bungee.BungeePlayerIPResponse) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileManager(org.anhcraft.spaciouslib.io.FileManager) IOException(java.io.IOException) ServerSocketClientHandler(org.anhcraft.spaciouslib.socket.ServerSocketClientHandler) CommandSender(org.bukkit.command.CommandSender) CommandBuilder(org.anhcraft.spaciouslib.command.CommandBuilder) SubCommandBuilder(org.anhcraft.spaciouslib.command.SubCommandBuilder) Location(org.bukkit.Location)

Example 10 with CommandSender

use of org.bukkit.command.CommandSender in project VotingPlugin by Ben12345rocks.

the class CommandLoader method loadVoteCommand.

/**
 * Load vote command.
 */
private void loadVoteCommand() {
    plugin.voteCommand = new ArrayList<CommandHandler>();
    plugin.voteCommand.add(new CommandHandler(new String[] { "Help&?" }, "VotingPlugin.Commands.Vote.Help|" + playerPerm, "View this page") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendJson(Commands.getInstance().voteHelpText(sender));
            } else {
                sender.sendMessage(ArrayUtils.getInstance().convert(ArrayUtils.getInstance().comptoString(Commands.getInstance().voteHelpText(sender))));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Shop" }, "VotingPlugin.Commands.Vote.Shop|" + playerPerm, "Open VoteShop GUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            VoteShop.getInstance().voteShop((Player) sender);
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "URL" }, "VotingPlugin.Commands.Vote.URL|" + playerPerm, "Open VoteURL GUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            PlayerGUIs.getInstance().openVoteURL((Player) sender);
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "URL", "(SiteName)" }, "VotingPlugin.Commands.Vote.URL.VoteSite|" + playerPerm, "Open VoteURL GUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            PlayerGUIs.getInstance().openVoteURL((Player) sender, args[1]);
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Reward" }, "VotingPlugin.Commands.Vote.Reward|" + playerPerm, "Open VoteReward GUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            PlayerGUIs.getInstance().voteReward((Player) sender, "");
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Reward", "(SiteName)" }, "VotingPlugin.Commands.Vote.Reward|" + playerPerm, "Open VoteURL GUI for VoteSIte", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            PlayerGUIs.getInstance().voteReward((Player) sender, args[1]);
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Last", "(player)" }, "VotingPlugin.Commands.Vote.Last.Other|" + modPerm, "See other players last votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                if (!Config.getInstance().getCommandsUseGUILast() || !(sender instanceof Player)) {
                    String playerName = args[1];
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(Commands.getInstance().voteCommandLast(UserManager.getInstance().getVotingPluginUser(playerName)));
                    } else {
                        sender.sendMessage(ArrayUtils.getInstance().colorize(Commands.getInstance().voteCommandLast(UserManager.getInstance().getVotingPluginUser(playerName))));
                    }
                } else {
                    PlayerGUIs.getInstance().openVoteLast((Player) sender, UserManager.getInstance().getVotingPluginUser(args[1]));
                }
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Last" }, "VotingPlugin.Commands.Vote.Last|" + playerPerm, "See your last votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUILast()) {
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(Commands.getInstance().voteCommandLast(user));
                } else {
                    sender.sendMessage("You must be a player to do this!");
                }
            } else if (sender instanceof Player) {
                PlayerGUIs.getInstance().openVoteLast((Player) sender, UserManager.getInstance().getVotingPluginUser(sender.getName()));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Next", "(player)" }, "VotingPlugin.Commands.Vote.Next.Other|" + modPerm, "See other players next votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                if (!Config.getInstance().getCommandsUseGUINext() || !(sender instanceof Player)) {
                    String playerName = args[1];
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(Commands.getInstance().voteCommandNext(UserManager.getInstance().getVotingPluginUser(playerName)));
                    } else {
                        sender.sendMessage(ArrayUtils.getInstance().colorize(Commands.getInstance().voteCommandNext(UserManager.getInstance().getVotingPluginUser(playerName))));
                    }
                } else {
                    PlayerGUIs.getInstance().openVoteNext((Player) sender, UserManager.getInstance().getVotingPluginUser(args[1]));
                }
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Points", "(player)" }, "VotingPlugin.Commands.Vote.Points.Other|" + modPerm, "View pints of other player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                User user = UserManager.getInstance().getVotingPluginUser(args[1]);
                String msg = Config.getInstance().getFormatCommandVotePoints().replace("%Player%", user.getPlayerName()).replace("%Points%", "" + user.getPoints());
                if (sender instanceof Player) {
                    UserManager.getInstance().getVotingPluginUser((Player) sender).sendMessage(msg);
                } else {
                    sender.sendMessage(StringUtils.getInstance().colorize(msg));
                }
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Points" }, "VotingPlugin.Commands.Vote.Points|" + playerPerm, "View your points") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                String msg = Config.getInstance().getFormatCommandVotePoints().replace("%Player%", user.getPlayerName()).replace("%Points%", "" + user.getPoints());
                user.sendMessage(msg);
            } else {
                sender.sendMessage("Must be a player to use this!");
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Next" }, "VotingPlugin.Commands.Vote.Next|" + playerPerm, "See your next votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUINext()) {
                if (sender instanceof Player) {
                    String playerName = sender.getName();
                    User user = UserManager.getInstance().getVotingPluginUser(playerName);
                    user.sendMessage(Commands.getInstance().voteCommandNext(user));
                } else {
                    sender.sendMessage("You must be a player to do this!");
                }
            } else if (sender instanceof Player) {
                PlayerGUIs.getInstance().openVoteNext((Player) sender, UserManager.getInstance().getVotingPluginUser(sender.getName()));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "GUI" }, "VotingPlugin.Commands.Vote.GUI|" + playerPerm, "Open VoteGUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            Player player = (Player) sender;
            PlayerGUIs.getInstance().openVoteGUI(player, UserManager.getInstance().getVotingPluginUser(player));
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "GUI", "(player)" }, "VotingPlugin.Commands.Vote.GUI.Other|" + modPerm, "Open VoteGUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            Player player = (Player) sender;
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                PlayerGUIs.getInstance().openVoteGUI(player, UserManager.getInstance().getVotingPluginUser(args[1]));
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Top" }, "VotingPlugin.Commands.Vote.Top|" + playerPerm, "Open list of Top Voters") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUITopVoter()) {
                int page = 1;
                String str = Config.getInstance().getVoteTopDefault();
                if (str.equalsIgnoreCase("monthly")) {
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(TopVoterHandler.getInstance().topVoterMonthly(page));
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {

                            @Override
                            public void run() {
                                Commands.getInstance().sendTopVoterMonthlyScoreBoard((Player) sender, page);
                            }
                        });
                    } else {
                        sender.sendMessage(TopVoterHandler.getInstance().topVoterMonthly(page));
                    }
                } else if (str.equalsIgnoreCase("weekly")) {
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(TopVoterHandler.getInstance().topVoterWeekly(page));
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {

                            @Override
                            public void run() {
                                Commands.getInstance().sendTopVoterWeeklyScoreBoard((Player) sender, page);
                            }
                        });
                    } else {
                        sender.sendMessage(TopVoterHandler.getInstance().topVoterWeekly(page));
                    }
                } else if (str.equalsIgnoreCase("daily")) {
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(TopVoterHandler.getInstance().topVoterDaily(page));
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {

                            @Override
                            public void run() {
                                Commands.getInstance().sendTopVoterDailyScoreBoard((Player) sender, page);
                            }
                        });
                    } else {
                        sender.sendMessage(TopVoterHandler.getInstance().topVoterDaily(page));
                    }
                } else if (str.equalsIgnoreCase("all")) {
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(TopVoterHandler.getInstance().topVoterAllTime(page));
                        Bukkit.getScheduler().runTask(plugin, new Runnable() {

                            @Override
                            public void run() {
                                Commands.getInstance().sendTopVoterAllTimeScoreBoard((Player) sender, page);
                            }
                        });
                    } else {
                        sender.sendMessage(TopVoterHandler.getInstance().topVoterAllTime(page));
                    }
                }
            } else if (sender instanceof Player) {
                PlayerGUIs.getInstance().openVoteTop((Player) sender, null);
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Top", "(number)" }, "VotingPlugin.Commands.Vote.Top|" + playerPerm, "Open page of Top Voters") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = Integer.parseInt(args[1]);
            String str = Config.getInstance().getVoteTopDefault();
            if (str.equalsIgnoreCase("monthly")) {
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(TopVoterHandler.getInstance().topVoterMonthly(page));
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            Commands.getInstance().sendTopVoterMonthlyScoreBoard((Player) sender, page);
                        }
                    });
                } else {
                    sender.sendMessage(TopVoterHandler.getInstance().topVoterMonthly(page));
                }
            } else if (str.equalsIgnoreCase("weekly")) {
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(TopVoterHandler.getInstance().topVoterWeekly(page));
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            Commands.getInstance().sendTopVoterWeeklyScoreBoard((Player) sender, page);
                        }
                    });
                } else {
                    sender.sendMessage(TopVoterHandler.getInstance().topVoterWeekly(page));
                }
            } else if (str.equalsIgnoreCase("daily")) {
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(TopVoterHandler.getInstance().topVoterDaily(page));
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            Commands.getInstance().sendTopVoterDailyScoreBoard((Player) sender, page);
                        }
                    });
                } else {
                    sender.sendMessage(TopVoterHandler.getInstance().topVoterDaily(page));
                }
            } else if (str.equalsIgnoreCase("all")) {
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(TopVoterHandler.getInstance().topVoterAllTime(page));
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            Commands.getInstance().sendTopVoterAllTimeScoreBoard((Player) sender, page);
                        }
                    });
                } else {
                    sender.sendMessage(TopVoterHandler.getInstance().topVoterAllTime(page));
                }
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Top", "(number)", "Monthly" }, "VotingPlugin.Commands.Vote.Top.Monthly|" + playerPerm, "Open page of Top Voters") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = Integer.parseInt(args[1]);
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendMessage(TopVoterHandler.getInstance().topVoterMonthly(page));
                Bukkit.getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        Commands.getInstance().sendTopVoterMonthlyScoreBoard((Player) sender, page);
                    }
                });
            } else {
                sender.sendMessage(TopVoterHandler.getInstance().topVoterMonthly(page));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Top", "(number)", "All" }, "VotingPlugin.Commands.Vote.Top.All|" + playerPerm, "Open page of Top Voters All Time") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = Integer.parseInt(args[1]);
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendMessage(TopVoterHandler.getInstance().topVoterAllTime(page));
                Bukkit.getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        Commands.getInstance().sendTopVoterAllTimeScoreBoard((Player) sender, page);
                    }
                });
            } else {
                sender.sendMessage(TopVoterHandler.getInstance().topVoterAllTime(page));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Top", "(number)", "Weekly" }, "VotingPlugin.Commands.Vote.Top.Weekly|" + playerPerm, "Open page of Top Voters") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = Integer.parseInt(args[1]);
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendMessage(TopVoterHandler.getInstance().topVoterWeekly(page));
                Bukkit.getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        Commands.getInstance().sendTopVoterWeeklyScoreBoard((Player) sender, page);
                    }
                });
            } else {
                sender.sendMessage(TopVoterHandler.getInstance().topVoterWeekly(page));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Top", "(number)", "Daily" }, "VotingPlugin.Commands.Vote.Top.Daily|" + playerPerm, "Open page of Top Voters") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = Integer.parseInt(args[1]);
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendMessage(TopVoterHandler.getInstance().topVoterDaily(page));
                Bukkit.getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        Commands.getInstance().sendTopVoterDailyScoreBoard((Player) sender, page);
                    }
                });
            } else {
                sender.sendMessage(TopVoterHandler.getInstance().topVoterDaily(page));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Party" }, "VotingPlugin.Commands.Vote.Party|" + playerPerm, "View current amount of votes and how many more needed") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            VoteParty.getInstance().commandVoteParty(sender);
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Today", "(number)" }, "VotingPlugin.Commands.Vote.Today|" + playerPerm, "Open page of who Voted Today") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUIToday() || !(sender instanceof Player)) {
                int page = Integer.parseInt(args[1]);
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(Commands.getInstance().commandVoteToday(page));
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            Commands.getInstance().sendVoteTodayScoreBoard((Player) sender, page);
                        }
                    });
                } else {
                    sender.sendMessage(Commands.getInstance().commandVoteToday(page));
                }
            } else {
                PlayerGUIs.getInstance().openVoteToday((Player) sender);
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Today" }, "VotingPlugin.Commands.Vote.Today|" + playerPerm, "View who list of who voted today") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUIToday() || !(sender instanceof Player)) {
                int page = 1;
                if (sender instanceof Player) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(Commands.getInstance().commandVoteToday(page));
                    Bukkit.getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            Commands.getInstance().sendVoteTodayScoreBoard((Player) sender, page);
                        }
                    });
                } else {
                    sender.sendMessage(Commands.getInstance().commandVoteToday(page));
                }
            } else {
                PlayerGUIs.getInstance().openVoteToday((Player) sender);
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Total", "All" }, "VotingPlugin.Commands.Vote.Total.All|" + playerPerm, "View server total votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendMessage(Commands.getInstance().voteCommandTotalAll());
            } else {
                sender.sendMessage(Commands.getInstance().voteCommandTotalAll());
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Total", "(player)" }, "VotingPlugin.Commands.Vote.Total.Other|" + modPerm, "View other players total votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                if (!Config.getInstance().getCommandsUseGUITotal() || !(sender instanceof Player)) {
                    String playerName = args[1];
                    if (sender instanceof Player) {
                        User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                        user.sendMessage(Commands.getInstance().voteCommandTotal(UserManager.getInstance().getVotingPluginUser(playerName)));
                    } else {
                        sender.sendMessage(ArrayUtils.getInstance().colorize(Commands.getInstance().voteCommandTotal(UserManager.getInstance().getVotingPluginUser(playerName))));
                    }
                } else {
                    PlayerGUIs.getInstance().openVoteTotal((Player) sender, UserManager.getInstance().getVotingPluginUser(args[1]));
                }
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Total" }, "VotingPlugin.Commands.Vote.Total|" + playerPerm, "View your total votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUITotal() || !(sender instanceof Player)) {
                if (sender instanceof Player) {
                    String playerName = sender.getName();
                    User user = UserManager.getInstance().getVotingPluginUser(playerName);
                    user.sendMessage(Commands.getInstance().voteCommandTotal(user));
                } else {
                    sender.sendMessage("You must be a player to do this!");
                }
            } else {
                PlayerGUIs.getInstance().openVoteTotal((Player) sender, UserManager.getInstance().getVotingPluginUser(sender.getName()));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Best" }, "VotingPlugin.Commands.Vote.Best|" + playerPerm, "View your best voting", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUIBest() || !(sender instanceof Player)) {
                sender.sendMessage(Commands.getInstance().best(sender, sender.getName()));
            } else {
                PlayerGUIs.getInstance().openVoteBest((Player) sender, UserManager.getInstance().getVotingPluginUser(sender.getName()));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Best", "(player)" }, "VotingPlugin.Commands.Vote.Best.Other|" + modPerm, "View someone's best voting") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                if (!Config.getInstance().getCommandsUseGUIBest() || !(sender instanceof Player)) {
                    sender.sendMessage(Commands.getInstance().best(sender, args[1]));
                } else {
                    PlayerGUIs.getInstance().openVoteBest((Player) sender, UserManager.getInstance().getVotingPluginUser(args[1]));
                }
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Streak" }, "VotingPlugin.Commands.Vote.Streak|" + playerPerm, "View your voting streak", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUIStreak() || !(sender instanceof Player)) {
                sender.sendMessage(Commands.getInstance().streak(sender, sender.getName()));
            } else {
                PlayerGUIs.getInstance().openVoteStreak((Player) sender, UserManager.getInstance().getVotingPluginUser(sender.getName()));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] { "Streak", "(player)" }, "VotingPlugin.Commands.Vote.Streak.Other|" + modPerm, "View someone's voting streak") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (com.Ben12345rocks.AdvancedCore.UserManager.UserManager.getInstance().userExist(args[1])) {
                if (!Config.getInstance().getCommandsUseGUIStreak() || !(sender instanceof Player)) {
                    sender.sendMessage(Commands.getInstance().streak(sender, args[1]));
                } else {
                    PlayerGUIs.getInstance().openVoteStreak((Player) sender, UserManager.getInstance().getVotingPluginUser(args[1]));
                }
            } else {
                sendMessage(sender, StringUtils.getInstance().replacePlaceHolder(Config.getInstance().getFormatUserNotExist(), "player", args[1]));
            }
        }
    });
    plugin.voteCommand.add(new CommandHandler(new String[] {}, "", "See voting URLs") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (!Config.getInstance().getCommandsUseGUIVote() || !(sender instanceof Player)) {
                if (isPlayer(sender)) {
                    User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                    user.sendMessage(Commands.getInstance().voteURLs(user));
                } else {
                    sender.sendMessage(Commands.getInstance().voteURLs(null));
                }
            } else {
                PlayerGUIs.getInstance().openVoteURL((Player) sender);
            }
        }
    });
    ArrayList<CommandHandler> avCommands = com.Ben12345rocks.AdvancedCore.Commands.CommandLoader.getInstance().getBasicCommands("VotingPlugin");
    for (CommandHandler cmd : avCommands) {
        cmd.setPerm(cmd.getPerm() + "|" + playerPerm);
    }
    plugin.voteCommand.addAll(avCommands);
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.Ben12345rocks.VotingPlugin.Objects.User) CommandSender(org.bukkit.command.CommandSender) CommandHandler(com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)

Aggregations

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6