Retrieve all data after a certain point

Discussion in 'Spigot Plugin Development' started by ZevoGaems, May 3, 2017.

  1. I am making a custom punishment plugin and I need to get all of the data for the reasons so I need to retrieve everything after that. I forgot how to retrieve all of the data after a certain point in the arguments. Please just tell me how to do it and I should remember. Thanks!
     
  2. This makes no sense? How is your data saved and what do you mean by "after a certain point in the arguments"?
     
  3. Like how would I retrieve all of the words in the reason like the command works like /kick (player) (reason) so for example "/kick ZevoGaems You are a bad person" how would I retrieve everything in the reason
     
  4. Could I see your command executer code?
     
  5. I will just put the whole code
    Code (Text):
    package pw.LoopTurn.Punishment;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
        public void onEnable() {
            getLogger().info("Punishments have been enabled");
        }
        public void onDisble() {
            getLogger().info("Punishments have been disabled");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("kick")) {
                if (!sender.hasPermission("minegrid.punish")) {
                    sender.sendMessage(ChatColor.RED + "You do not have permission");
                    return true;
                } else if (sender.hasPermission("minegrid.punish")) {
                    if (args.length == 0) {
                        sender.sendMessage(ChatColor.RED + "Usage: /kick <player> <reason>");
                        return true;
                    }
                    if (args.length != 0) {
                        if ((args[0].length() > 3) && args[0].length() < 16) {

                            String pName = args[0];
                            final Player target = Bukkit.getPlayerExact(pName);

                            if (target != null) {
                                StringBuilder message = new StringBuilder();

                                for (int i = 1; i < args.length; i++) {
                                    message.append(args[i] + " ");
                                }
                                target.kickPlayer(ChatColor.RED + "You have been kicked from the server" + "\n"
                                        + ChatColor.RED + "Reason: " + ChatColor.RED + message);
                                sender.sendMessage(ChatColor.GREEN + target.getName() + ChatColor.GREEN + " has succesfully been kicked!" + "\n"
                                        + ChatColor.GREEN + "Reason: " + message);
                                return true;

                            } else if (target == null) {
                                sender.sendMessage(ChatColor.RED + "" + ChatColor.UNDERLINE + pName + ChatColor.RED
                                        + " does not exist");
                                return true;
                            }
                        } else if (args[0].length() < 3) {
                            sender.sendMessage(ChatColor.RED + "Username is too short!");
                            return true;
                        } else if (args[0].length() > 16) {
                            sender.sendMessage(ChatColor.RED + "Username is too long!");
                            return true;
                        }

                        else {
                            sender.sendMessage(ChatColor.RED + "Usage: /kick <player> <reason>");
                            return true;
                        }
                    }
        }
    } else if (cmd.getName().equalsIgnoreCase("ban"))
        if (!sender.hasPermission("minegrid.punish")) {
            sender.sendMessage(ChatColor.RED + "You do not have permission");
            return true;
        } else if (sender.hasPermission("minegrid.punish")) {
            if (args.length == 0) {
                sender.sendMessage(ChatColor.RED + "Usage: /ban <player> <reason>");
                return true;
            }
            if (args.length != 0) {
                if ((args[0].length() > 3) && args[0].length() < 16) {

                    String pName = args[0];
                    final Player target = Bukkit.getPlayerExact(pName);

                    if (target != null) {
                        StringBuilder message = new StringBuilder();

                        for (int i = 1; i < args.length; i++) {
                            message.append(args[i] + " ");
                        }
                        target.kickPlayer(ChatColor.RED + "You have been banned from the server" + "\n"
                                + ChatColor.RED + "Reason: " + ChatColor.RED + message);
                        sender.sendMessage(ChatColor.GREEN + target.getName() + ChatColor.GREEN + " has succesfully been kicked!" + "\n"
                                + ChatColor.GREEN + "Reason: " + message);
                        return true;

                    } else if (target == null) {
                        sender.sendMessage(ChatColor.RED + "" + ChatColor.UNDERLINE + pName + ChatColor.RED
                                + " does not exist");
                        return true;
                    }
                } else if (args[0].length() < 3) {
                    sender.sendMessage(ChatColor.RED + "Username is too short!");
                    return true;
                } else if (args[0].length() > 16) {
                    sender.sendMessage(ChatColor.RED + "Username is too long!");
                    return true;
                }

                else {
                    sender.sendMessage(ChatColor.RED + "Usage: /ban <player> <reason>");
                    return true;
                }
            }
    }
        }
    }
     
     
  6. Hi here is sime sudo code

    Create a new StringBuilder
    create a for loop from the start arg to the last arg in the array
    call .append from the string builder on the args from the for loop
    then call .tostring from the string builder to get the string.

    p.s using my phone so sorry not very descriptive
     
  7. Serialize and call the data.