Adding Player to a ArrayList

Discussion in 'Plugin Development' started by jordanzilla02, Feb 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    jordanzilla02

    I am working on a plugin that is involving two teams and I am working on the teams functionality right now and I am running into a problem. My problem is that I cannot add the teams functionality because the arraylist is not accepting the Player. Should I change the String from the parenthesis into a Player? I heard that breaks it
     
  2. Offline

    immensebuttpain

    Can you please give me the code you're using to put them in the team, or however you're using your code?
     
  3. Offline

    Pizza371

    immensebuttpain likes this.
  4. Offline

    jordanzilla02

    Let me try that because I actually never thought of that makes me feel and look stupid, lol
     
  5. Offline

    Whomp54

    that does not break it. You should be fine with the <String>. Just be sure to check for "p.getName()" and not just "p" if "p" is your Player.

    "p" by itself will come out as Bukkit makes it come out, which I believe looks something like so:
    [CraftPlayer=Whomp54]
     
  6. Offline

    jordanzilla02

    Thanks Pizza for the help never knew you could change the player into a String
     
  7. Offline

    immensebuttpain

    jordanzilla02 Here is an example of a code i use:
    Code:java
    1. private void randomTeleport(Player p) {
    2. ArrayList<Location> spawns = ffaconfig.getSpawns();
    3. Random num = new Random();
    4. if (spawns.size() >= 1) {
    5. p.closeInventory();
    6. p.teleport(spawns.get(num.nextInt(spawns.size())));
    7. } else {
    8. p.sendMessage(ChatColor.YELLOW + "[FreeForAll] " + ChatColor.RED + "Unable to find defined spawn points.");
    9. }
    10. }

    What this does is teleport the player to a random spawn set in the config.
    Or an example with ArrayList<String>:
    Code:java
    1. if (args[0].equalsIgnoreCase("top")) {
    2. String dispFormat = ChatColor.DARK_AQUA + "{0}: " + ChatColor.RED + "{1}" + ChatColor.YELLOW + " ---- " + ChatColor.RED + " {2}";
    3. String titleFormat = (ChatColor.YELLOW + "----------==[" + ChatColor.GRAY + "FFA Top {0}" + ChatColor.YELLOW + "]==----------");
    4. String bottomFormat = ChatColor.YELLOW + "-----------==[" + ChatColor.GRAY + "FreeForAll" + ChatColor.YELLOW + "]==-----------";
    5. int count = 1;
    6. if (args.length == 2) {
    7. if (args[1].equalsIgnoreCase("kills")) {
    8. player.sendMessage(titleFormat.replace("{0}", "Kills"));
    9. ArrayList<String> top_Kills = DB.getTopKills();
    10. for (String name : top_Kills) {
    11. int player_id = DB.getPlayerId(name);
    12. int kill_count = DB.getKillCount(player_id);
    13. player.sendMessage(dispFormat.replace("{0}", "" + count).replace("{2}", name).replace("{1}", "" + kill_count));
    14. count++;
    15. }
    16. player.sendMessage(bottomFormat);
    17. }

    not really sure if this helps or not...
     
  8. Offline

    Pizza371

Thread Status:
Not open for further replies.

Share This Page