Program: 58055
Project: 58055
Buggy source:
@Override public boolean execute(final PlotPlayer plr,final String... args){
  final Location loc=plr.getLocationFull();
  final Plot plot=MainUtil.getPlot(loc);
  if (plot == null) {
    return !sendMessage(plr,C.NOT_IN_PLOT);
  }
  if ((plot == null) || !plot.hasOwner()) {
    MainUtil.sendMessage(plr,C.PLOT_UNOWNED);
    return false;
  }
  final boolean admin=Permissions.hasPermission(plr,"String_Node_Str");
  if (!plot.getOwner().equals(UUIDHandler.getUUID(plr)) && !admin) {
    MainUtil.sendMessage(plr,C.NO_PLOT_PERMS);
    return false;
  }
  if (args.length < 1) {
    MainUtil.sendMessage(plr,C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
    MainUtil.sendMessage(plr,C.DIRECTION.s().replaceAll("String_Node_Str",direction(loc.getYaw())));
    return false;
  }
  int direction=-1;
  for (int i=0; i < values.length; i++) {
    if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
      direction=i;
      break;
    }
  }
  if (direction == -1) {
    MainUtil.sendMessage(plr,C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
    MainUtil.sendMessage(plr,C.DIRECTION.s().replaceAll("String_Node_Str",direction(loc.getYaw())));
    return false;
  }
  PlotId bot=MainUtil.getBottomPlot(plot).id;
  PlotId top=MainUtil.getTopPlot(plot).id;
  ArrayList<PlotId> selPlots;
  final String world=loc.getWorld();
switch (direction) {
case 0:
    selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x,bot.y - 1),new PlotId(top.x,top.y));
  break;
case 1:
selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x,bot.y),new PlotId(top.x + 1,top.y));
break;
case 2:
selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x,bot.y),new PlotId(top.x,top.y + 1));
break;
case 3:
selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x - 1,bot.y),new PlotId(top.x,top.y));
break;
default :
return false;
}
final PlotId botId=selPlots.get(0);
final PlotId topId=selPlots.get(selPlots.size() - 1);
final PlotId bot1=MainUtil.getBottomPlot(MainUtil.getPlot(world,botId)).id;
final PlotId bot2=MainUtil.getBottomPlot(MainUtil.getPlot(world,topId)).id;
final PlotId top1=MainUtil.getTopPlot(MainUtil.getPlot(world,topId)).id;
final PlotId top2=MainUtil.getTopPlot(MainUtil.getPlot(world,botId)).id;
bot=new PlotId(Math.min(bot1.x,bot2.x),Math.min(bot1.y,bot2.y));
top=new PlotId(Math.max(top1.x,top2.x),Math.max(top1.y,top2.y));
final ArrayList<PlotId> plots=MainUtil.getMaxPlotSelectionIds(world,bot,top);
boolean multiMerge=false;
final HashSet<UUID> multiUUID=new HashSet<UUID>();
HashSet<PlotId> multiPlots=new HashSet<>();
final UUID u1=plot.getOwner();
for (final PlotId myid : plots) {
final Plot myplot=PlotSquared.getPlots(world).get(myid);
UUID u2=myplot.getOwner();
if (myplot == null || u2 == null) {
MainUtil.sendMessage(plr,C.NO_PERM_MERGE.s().replaceAll("String_Node_Str",myid.toString()));
return false;
}
if (u2.equals(u1)) {
continue;
}
PlotPlayer p2=UUIDHandler.getPlayer(u2);
if (p2 == null) {
MainUtil.sendMessage(plr,C.NO_PERM_MERGE.s().replaceAll("String_Node_Str",myid.toString()));
return false;
}
multiMerge=true;
multiPlots.add(myid);
}
if (multiMerge) {
for (final UUID uuid : multiUUID) {
CmdConfirm.addPending(UUIDHandler.getPlayer(uuid),"String_Node_Str",new Runnable(){
@Override public void run(){
PlotPlayer accepter=UUIDHandler.getPlayer(uuid);
multiUUID.remove(uuid);
if (multiUUID.size() == 0) {
PlotPlayer pp=UUIDHandler.getPlayer(u1);
if (pp == null) {
sendMessage(plr,C.MERGE_NOT_VALID);
return;
}
final PlotWorld plotWorld=PlotSquared.getPlotWorld(world);
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
double cost=plotWorld.MERGE_PRICE;
cost=plots.size() * cost;
if (cost > 0d) {
if (EconHandler.getBalance(plr) < cost) {
sendMessage(plr,C.CANNOT_AFFORD_MERGE,cost + "String_Node_Str");
return;
}
EconHandler.withdrawPlayer(plr,cost);
sendMessage(plr,C.REMOVED_BALANCE,cost + "String_Node_Str");
}
}
final boolean result=EventUtil.manager.callMerge(world,plot,plots);
if (!result) {
MainUtil.sendMessage(plr,"String_Node_Str");
return;
}
MainUtil.sendMessage(plr,C.SUCCESS_MERGE);
MainUtil.mergePlots(world,plots,true);
MainUtil.setSign(UUIDHandler.getName(plot.owner),plot);
MainUtil.update(loc);
}
MainUtil.sendMessage(accepter,C.MERGE_ACCEPTED);
}
}
);
}
return true;
}
final PlotWorld plotWorld=PlotSquared.getPlotWorld(world);
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
double cost=plotWorld.MERGE_PRICE;
cost=plots.size() * cost;
if (cost > 0d) {
if (EconHandler.getBalance(plr) < cost) {
sendMessage(plr,C.CANNOT_AFFORD_MERGE,cost + "String_Node_Str");
return false;
}
EconHandler.withdrawPlayer(plr,cost);
sendMessage(plr,C.REMOVED_BALANCE,cost + "String_Node_Str");
}
}
final boolean result=EventUtil.manager.callMerge(world,plot,plots);
if (!result) {
MainUtil.sendMessage(plr,"String_Node_Str");
return false;
}
MainUtil.sendMessage(plr,C.SUCCESS_MERGE);
MainUtil.mergePlots(world,plots,true);
MainUtil.setSign(UUIDHandler.getName(plot.owner),plot);
MainUtil.update(loc);
return true;
}

Fixed version (ground truth):
@Override public boolean execute(final PlotPlayer plr,final String... args){
  final Location loc=plr.getLocationFull();
  final Plot plot=MainUtil.getPlot(loc);
  if (plot == null) {
    return !sendMessage(plr,C.NOT_IN_PLOT);
  }
  if ((plot == null) || !plot.hasOwner()) {
    MainUtil.sendMessage(plr,C.PLOT_UNOWNED);
    return false;
  }
  final boolean admin=Permissions.hasPermission(plr,"String_Node_Str");
  if (!plot.isOwner(plr.getUUID()) && !admin) {
    MainUtil.sendMessage(plr,C.NO_PLOT_PERMS);
    return false;
  }
  if (args.length < 1) {
    MainUtil.sendMessage(plr,C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
    MainUtil.sendMessage(plr,C.DIRECTION.s().replaceAll("String_Node_Str",direction(loc.getYaw())));
    return false;
  }
  int direction=-1;
  for (int i=0; i < values.length; i++) {
    if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
      direction=i;
      break;
    }
  }
  if (direction == -1) {
    MainUtil.sendMessage(plr,C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values,C.BLOCK_LIST_SEPARATER.s()));
    MainUtil.sendMessage(plr,C.DIRECTION.s().replaceAll("String_Node_Str",direction(loc.getYaw())));
    return false;
  }
  PlotId bot=MainUtil.getBottomPlot(plot).id;
  PlotId top=MainUtil.getTopPlot(plot).id;
  ArrayList<PlotId> selPlots;
  final String world=loc.getWorld();
switch (direction) {
case 0:
    selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x,bot.y - 1),new PlotId(top.x,top.y));
  break;
case 1:
selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x,bot.y),new PlotId(top.x + 1,top.y));
break;
case 2:
selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x,bot.y),new PlotId(top.x,top.y + 1));
break;
case 3:
selPlots=MainUtil.getMaxPlotSelectionIds(world,new PlotId(bot.x - 1,bot.y),new PlotId(top.x,top.y));
break;
default :
return false;
}
final PlotId botId=selPlots.get(0);
final PlotId topId=selPlots.get(selPlots.size() - 1);
final PlotId bot1=MainUtil.getBottomPlot(MainUtil.getPlot(world,botId)).id;
final PlotId bot2=MainUtil.getBottomPlot(MainUtil.getPlot(world,topId)).id;
final PlotId top1=MainUtil.getTopPlot(MainUtil.getPlot(world,topId)).id;
final PlotId top2=MainUtil.getTopPlot(MainUtil.getPlot(world,botId)).id;
bot=new PlotId(Math.min(bot1.x,bot2.x),Math.min(bot1.y,bot2.y));
top=new PlotId(Math.max(top1.x,top2.x),Math.max(top1.y,top2.y));
final ArrayList<PlotId> plots=MainUtil.getMaxPlotSelectionIds(world,bot,top);
boolean multiMerge=false;
final HashSet<UUID> multiUUID=new HashSet<UUID>();
HashSet<PlotId> multiPlots=new HashSet<>();
final UUID u1=plot.owner_;
for (final PlotId myid : plots) {
final Plot myplot=PlotSquared.getPlots(world).get(myid);
UUID u2=myplot.owner_;
if (myplot == null || u2 == null) {
MainUtil.sendMessage(plr,C.NO_PERM_MERGE.s().replaceAll("String_Node_Str",myid.toString()));
return false;
}
if (u2.equals(u1)) {
continue;
}
PlotPlayer p2=UUIDHandler.getPlayer(u2);
if (p2 == null) {
MainUtil.sendMessage(plr,C.NO_PERM_MERGE.s().replaceAll("String_Node_Str",myid.toString()));
return false;
}
multiMerge=true;
multiPlots.add(myid);
}
if (multiMerge) {
for (final UUID uuid : multiUUID) {
CmdConfirm.addPending(UUIDHandler.getPlayer(uuid),"String_Node_Str",new Runnable(){
@Override public void run(){
PlotPlayer accepter=UUIDHandler.getPlayer(uuid);
multiUUID.remove(uuid);
if (multiUUID.size() == 0) {
PlotPlayer pp=UUIDHandler.getPlayer(u1);
if (pp == null) {
sendMessage(plr,C.MERGE_NOT_VALID);
return;
}
final PlotWorld plotWorld=PlotSquared.getPlotWorld(world);
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
double cost=plotWorld.MERGE_PRICE;
cost=plots.size() * cost;
if (cost > 0d) {
if (EconHandler.getBalance(plr) < cost) {
sendMessage(plr,C.CANNOT_AFFORD_MERGE,cost + "String_Node_Str");
return;
}
EconHandler.withdrawPlayer(plr,cost);
sendMessage(plr,C.REMOVED_BALANCE,cost + "String_Node_Str");
}
}
final boolean result=EventUtil.manager.callMerge(world,plot,plots);
if (!result) {
MainUtil.sendMessage(plr,"String_Node_Str");
return;
}
MainUtil.sendMessage(plr,C.SUCCESS_MERGE);
MainUtil.mergePlots(world,plots,true);
MainUtil.setSign(UUIDHandler.getName(plot.owner_),plot);
MainUtil.update(loc);
}
MainUtil.sendMessage(accepter,C.MERGE_ACCEPTED);
}
}
);
}
return true;
}
final PlotWorld plotWorld=PlotSquared.getPlotWorld(world);
if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) {
double cost=plotWorld.MERGE_PRICE;
cost=plots.size() * cost;
if (cost > 0d) {
if (EconHandler.getBalance(plr) < cost) {
sendMessage(plr,C.CANNOT_AFFORD_MERGE,cost + "String_Node_Str");
return false;
}
EconHandler.withdrawPlayer(plr,cost);
sendMessage(plr,C.REMOVED_BALANCE,cost + "String_Node_Str");
}
}
final boolean result=EventUtil.manager.callMerge(world,plot,plots);
if (!result) {
MainUtil.sendMessage(plr,"String_Node_Str");
return false;
}
MainUtil.sendMessage(plr,C.SUCCESS_MERGE);
MainUtil.mergePlots(world,plots,true);
MainUtil.setSign(UUIDHandler.getName(plot.owner_),plot);
MainUtil.update(loc);
return true;
}