Compare commits

..

1 Commits

Author SHA1 Message Date
9ee3e9a3a4 feature: improve handling of null issues in plot analysis
- Addresses #3865 (does not fix the underlying issue though)
2022-11-11 11:29:56 +00:00
3 changed files with 44 additions and 44 deletions

View File

@ -142,14 +142,6 @@ public class Auto extends SubCommand {
} }
} }
} }
int maxMerge = Permissions.hasPermissionRange(player, Permission.PERMISSION_MERGE, Settings.Limit.MAX_PLOTS);
if (sizeX * sizeZ > maxMerge) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
Template.of("node", Permission.PERMISSION_MERGE + "." + (sizeX * sizeZ))
);
return false;
}
return true; return true;
} }

View File

@ -124,7 +124,7 @@ public class Merge extends SubCommand {
return false; return false;
} }
final int size = plot.getConnectedPlots().size(); final int size = plot.getConnectedPlots().size();
int max = Permissions.hasPermissionRange(player, Permission.PERMISSION_MERGE, Settings.Limit.MAX_PLOTS); int max = Permissions.hasPermissionRange(player, "plots.merge", Settings.Limit.MAX_PLOTS);
PlotMergeEvent event = PlotMergeEvent event =
this.eventDispatcher.callMerge(plot, direction, max, player); this.eventDispatcher.callMerge(plot, direction, max, player);
if (event.getEventResult() == Result.DENY) { if (event.getEventResult() == Result.DENY) {

View File

@ -234,44 +234,52 @@ public class HybridUtils {
Set<BlockType> types = new HashSet<>(); Set<BlockType> types = new HashSet<>();
for (int yIndex = 0; yIndex < height; yIndex++) { for (int yIndex = 0; yIndex < height; yIndex++) {
BlockState old = oldBlocks[yIndex][x][z]; // Nullable BlockState old = oldBlocks[yIndex][x][z]; // Nullable
try { BlockState now = newBlocks[yIndex][x][z]; // Not null
BlockState now = newBlocks[yIndex][x][z]; // Not null if (now == null) {
if (!now.equals(old) && !(old == null && now.getBlockType().equals(BlockTypes.AIR))) { throw new NullPointerException(String.format(
changes[i]++; "\"now\" block null attempting to perform plot analysis. Indexes: x=%d of %d, yIndex=%d" +
} " of %d, z=%d of %d",
if (now.getBlockType().getMaterial().isAir()) { x,
air[i]++; width,
} else { yIndex,
// check vertices height,
// modifications_adjacent z,
if (x > 0 && z > 0 && yIndex > 0 && x < width - 1 && z < length - 1 && yIndex < (height - 1)) { length
if (newBlocks[yIndex - 1][x][z].getBlockType().getMaterial().isAir()) { ));
faces[i]++; }
} if (!now.equals(old) && !(old == null && now.getBlockType().equals(BlockTypes.AIR))) {
if (newBlocks[yIndex][x - 1][z].getBlockType().getMaterial().isAir()) { changes[i]++;
faces[i]++; }
} if (now.getBlockType().getMaterial().isAir()) {
if (newBlocks[yIndex][x][z - 1].getBlockType().getMaterial().isAir()) { air[i]++;
faces[i]++; } else {
} // check vertices
if (newBlocks[yIndex + 1][x][z].getBlockType().getMaterial().isAir()) { // modifications_adjacent
faces[i]++; if (x > 0 && z > 0 && yIndex > 0 && x < width - 1 && z < length - 1 && yIndex < (height - 1)) {
} if (newBlocks[yIndex - 1][x][z].getBlockType().getMaterial().isAir()) {
if (newBlocks[yIndex][x + 1][z].getBlockType().getMaterial().isAir()) { faces[i]++;
faces[i]++;
}
if (newBlocks[yIndex][x][z + 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
} }
if (newBlocks[yIndex][x - 1][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x][z - 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex + 1][x][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x + 1][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x][z + 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
}
if (!now.equals(now.getBlockType().getDefaultState())) { if (!now.equals(now.getBlockType().getDefaultState())) {
data[i]++; data[i]++;
}
types.add(now.getBlockType());
} }
} catch (NullPointerException e) { types.add(now.getBlockType());
e.printStackTrace();
} }
} }
variety[i] = types.size(); variety[i] = types.size();