Writing to the config too many times

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, May 23, 2016.

  1. So the plugin should test if the block under a player is blue/red wool, and if so it adds them to the config and if not it removes them, but it keeps adding a player continously and when i checked it i saw this:

    Anyone see why it would keep adding it to the config?

    Relevant code:
    Code (Text):

    public class GameStart implements Listener {
        Main pl;
        public GameStart(Main pl){
            this.pl = pl;
        List<String> red = new ArrayList<String>();
        List<String> blue = new ArrayList<String>();
        public void onPlayerMove(PlayerMoveEvent event){
            TeamData td = new TeamData(pl);
            FileConfiguration teams = td.getData();
            Player p = event.getPlayer();
                Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
                if(b.getState().getData() instanceof Wool){
                    Wool wool = (Wool) b.getState().getData();
                    DyeColor dc = wool.getColor();
                    if(dc.toString() == "BLUE"){
                        if(!teams.contains("Teams.Blue." + p.getName())){
                                teams.set("Teams.Blue", blue);
                    }else if(dc.toString() == "RED"){
                        if(!teams.contains("Teams.Red." + p.getName())){
                                teams.set("Teams.Red", red);
  2. Because on each iteration you use td.saveData()?
  3. You also add the player to the arraylists without considering if they are already in it before
    • Agree Agree x 2
  4. use if statements to check their name's existence in the list. :D goodLuck looking forward.
  5. Just realised this was in your code. Remove the "Teams.Red" part, because you only store the player name in your list