Program: 58089
Project: 58089
Buggy source:
/** 
 * TODO: <b>Implement better system The whole point of this system is to recycle old plots</b> <br> So why not just allow users to claim old plots, and try to hide the fact that the are owned. <br> <br> Reduce amount of expired plots: <br> - On /plot <br> auto<br> - allow claiming of old plot, clear it so the user doesn't know<br> - On /plot info,<br> - show that the plot is expired and allowed to be claimed Have the task run less often:<br> - Run the task when there are very little, or no players online (great for small servers)<br> - Run the task at startup (also only useful for small servers)<br> Also, in terms of faster code:<br> - Have an array of plots, sorted by expiry time.<br> - Add new plots to the end.<br> - The task then only needs to go through the first few plots
 * @param plugin Plugin
 * @param async  Call async?
 */
private static void checkExpired(final JavaPlugin plugin,final boolean async){
  if (async) {
    Bukkit.getScheduler().runTaskAsynchronously(plugin,new Runnable(){
      @Override public void run(){
        for (        final String world : getPlotWorldsString()) {
          if (plots.containsKey(world)) {
            final ArrayList<Plot> toDeletePlot=new ArrayList<>();
            for (            final Plot plot : plots.get(world).values()) {
              if (plot.owner == null) {
                continue;
              }
              final long lastPlayed=getLastPlayed(plot.owner);
              if (lastPlayed == 0) {
                continue;
              }
              final long compared=System.currentTimeMillis() - lastPlayed;
              if (TimeUnit.MILLISECONDS.toDays(compared) >= Settings.AUTO_CLEAR_DAYS) {
                final PlotDeleteEvent event=new PlotDeleteEvent(world,plot.id);
                Bukkit.getServer().getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                  event.setCancelled(true);
                }
 else {
                  toDeletePlot.add(plot);
                }
              }
            }
            for (            final Plot plot : toDeletePlot) {
              final World worldobj=Bukkit.getWorld(world);
              PlotHelper.clear(worldobj,plot,true);
              PlotHelper.removeSign(worldobj,plot);
              DBFunc.delete(world,plot);
              removePlot(world,plot.id,true);
              if ((Math.abs(plot.id.x) < Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) < Math.abs(Auto.lastPlot.y))) {
                Auto.lastPlot=plot.id;
              }
            }
          }
        }
      }
    }
);
  }
 else {
    for (    final String world : getPlotWorldsString()) {
      if (PlotMain.plots.containsKey(world)) {
        for (        final Plot plot : PlotMain.plots.get(world).values()) {
          if (PlayerFunctions.hasExpired(plot)) {
            final PlotDeleteEvent event=new PlotDeleteEvent(world,plot.id);
            Bukkit.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled()) {
              event.setCancelled(true);
            }
 else {
              DBFunc.delete(world,plot);
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * TODO: <b>Implement better system The whole point of this system is to recycle old plots</b> <br> So why not just allow users to claim old plots, and try to hide the fact that the are owned. <br> <br> Reduce amount of expired plots: <br> - On /plot <br> auto<br> - allow claiming of old plot, clear it so the user doesn't know<br> - On /plot info,<br> - show that the plot is expired and allowed to be claimed Have the task run less often:<br> - Run the task when there are very little, or no players online (great for small servers)<br> - Run the task at startup (also only useful for small servers)<br> Also, in terms of faster code:<br> - Have an array of plots, sorted by expiry time.<br> - Add new plots to the end.<br> - The task then only needs to go through the first few plots
 * @param plugin Plugin
 * @param async  Call async?
 */
private static void checkExpired(final JavaPlugin plugin,final boolean async){
  if (async) {
    Bukkit.getScheduler().runTaskAsynchronously(plugin,new Runnable(){
      @Override public void run(){
        for (        final String world : getPlotWorldsString()) {
          if (plots.containsKey(world)) {
            final ArrayList<Plot> toDeletePlot=new ArrayList<>();
            for (            final Plot plot : plots.get(world).values()) {
              if (plot.owner == null) {
                continue;
              }
              final long lastPlayed=getLastPlayed(plot.owner);
              if (lastPlayed == 0) {
                continue;
              }
              final long compared=System.currentTimeMillis() - lastPlayed;
              if (TimeUnit.MILLISECONDS.toDays(compared) >= Settings.AUTO_CLEAR_DAYS) {
                final PlotDeleteEvent event=new PlotDeleteEvent(world,plot.id);
                Bukkit.getServer().getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                  event.setCancelled(true);
                }
 else {
                  toDeletePlot.add(plot);
                }
              }
            }
            for (            final Plot plot : toDeletePlot) {
              Bukkit.getScheduler().scheduleSyncDelayedTask(plugin,new Runnable(){
                @Override public void run(){
                  final World worldobj=Bukkit.getWorld(world);
                  PlotHelper.clear(worldobj,plot,true);
                  PlotHelper.removeSign(worldobj,plot);
                  DBFunc.delete(world,plot);
                  removePlot(world,plot.id,true);
                  if ((Math.abs(plot.id.x) < Math.abs(Auto.lastPlot.x)) && (Math.abs(plot.id.y) < Math.abs(Auto.lastPlot.y))) {
                    Auto.lastPlot=plot.id;
                  }
                }
              }
);
            }
          }
        }
      }
    }
);
  }
 else {
    for (    final String world : getPlotWorldsString()) {
      if (PlotMain.plots.containsKey(world)) {
        for (        final Plot plot : PlotMain.plots.get(world).values()) {
          if (PlayerFunctions.hasExpired(plot)) {
            final PlotDeleteEvent event=new PlotDeleteEvent(world,plot.id);
            Bukkit.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled()) {
              event.setCancelled(true);
            }
 else {
              DBFunc.delete(world,plot);
            }
          }
        }
      }
    }
  }
}