How would I get this to work?

Discussion in 'Plugin Development' started by elementalgodz11, Mar 6, 2014.

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

    elementalgodz11

    I'm trying to return an integer of how many players are at a warp using the following method.
    Code:java
    1. public static Integer getPlayersAtSpawn() {
    2. int amt = 0;
    3. for (Player players : Bukkit.getServer().getOnlinePlayers()) {
    4. if (isAtSpawn(players)) { //LOCATION TO SPAWN
    5. amt = amt + 1;
    6. }
    7. }
    8. return amt;
    9. }


    I then am adding the amount of players at a location to a lore on an ItemStack v
    Code:
    item.setLore(Arrays.asList(new String(ChatColor.LIGHT_PURPLE + "" + getAmountAtSpawn() + " is the integer")));
    However if the players are vanished the integer is not 1 less.

    I could do if(!vanished.contains(players.getName()) { however I want staff members to see the whole integer.

    Thanks.
     
  2. Offline

    FightManiac

    You better add the whole code it's easier to help then.
     
  3. Offline

    Jakeob22

    If I'm interpreting this correctly, you could always just add a boolean parameter where if it's true, it returns the value with the vanished players.
    For example:
    Show Spoiler
    Code:java
    1. public static Integer getPlayersAtSpawn(boolean includeVanished){
    2. int amt = 0;
    3. for (Player players: Bukkit.getServer().getOnlinePlayers()){
    4. if(isAtSpawn(players)){
    5. amt++; //adding ++ like that will add one, just like you have
    6. }else if(vansished.contains(players.getName() && includeVanished == true){
    7. amt++;
    8. }
    9. }
    10. return amt;
    11. }


    Again, I'm not sure if I'm interpreting your problem correctly but that might work. Then, when you call it, you can call getPlayersAtSpawn(true) to include the vanished people or getPlayersAtSpawn(false) to exclude them.

    I hope this helps, just let me know if I completely misinterpreted your problem. :p
     
  4. Offline

    Wolfey

    Yea, add them to a list when they get vanished then remove them when they unvanish.

    When a staff member checks the amount of players in spawn (or if they have access to a certain permission), check out all the online players and the players in the arraylist. Otherwise, just check out the players that are visible.
     
    Jakeob22 likes this.
Thread Status:
Not open for further replies.

Share This Page