Param for force replace not matching blocks

This commit is contained in:
Brokkonaut
2018-08-29 22:26:37 +02:00
parent 404c9b91c0
commit 9c2a93dafb
3 changed files with 17 additions and 6 deletions

View File

@ -92,6 +92,7 @@ public class CommandsHandler implements CommandExecutor {
sender.sendMessage(ChatColor.GOLD + "time [number] [minutes|hours|days] -- Limits time");
sender.sendMessage(ChatColor.GOLD + "since <dd.MM.yyyy> <HH:mm:ss> -- Limits time to a fixed point");
sender.sendMessage(ChatColor.GOLD + "before <dd.MM.yyyy> <HH:mm:ss> -- Affects only blocks before a fixed time");
sender.sendMessage(ChatColor.GOLD + "force -- Forces replacing not matching blocks");
sender.sendMessage(ChatColor.GOLD + "limit <row count> -- Limits the result to count of rows");
sender.sendMessage(ChatColor.GOLD + "sum [none|blocks|players] -- Sums the result");
sender.sendMessage(ChatColor.GOLD + "asc, desc -- Changes the order of the displayed log");
@ -673,7 +674,7 @@ public class CommandsHandler implements CommandExecutor {
sender.sendMessage(ChatColor.DARK_AQUA + "Searching " + params.getTitle() + ":");
}
rs = executeQuery(state, params.getQuery());
final WorldEditor editor = new WorldEditor(logblock, params.world);
final WorldEditor editor = new WorldEditor(logblock, params.world, params.forceReplace);
while (rs.next()) {
ChestAccess chestaccess = null;
@ -762,7 +763,7 @@ public class CommandsHandler implements CommandExecutor {
if (!params.silent) {
sender.sendMessage(ChatColor.DARK_AQUA + "Searching " + params.getTitle() + ":");
}
final WorldEditor editor = new WorldEditor(logblock, params.world);
final WorldEditor editor = new WorldEditor(logblock, params.world, params.forceReplace);
while (rs.next()) {
ChestAccess chestaccess = null;
ItemStack stack = Utils.loadItemStack(rs.getBytes("item"));

View File

@ -50,6 +50,7 @@ public final class QueryParams implements Cloneable {
keywords.put("killer", 1);
keywords.put("victim", 1);
keywords.put("both", 0);
keywords.put("force", 0);
}
public BlockChangeType bct = BlockChangeType.BOTH;
public int limit = -1, before = 0, since = 0, radius = -1;
@ -59,6 +60,7 @@ public final class QueryParams implements Cloneable {
public List<String> killers = new ArrayList<String>();
public List<String> victims = new ArrayList<String>();
public boolean excludePlayersMode = false, excludeKillersMode = false, excludeVictimsMode = false, excludeBlocksMode = false, prepareToolQuery = false, silent = false, noForcedLimit = false;
public boolean forceReplace = false;
public CuboidRegion sel = null;
public SummarizationMode sum = SummarizationMode.NONE;
public List<Material> types = new ArrayList<Material>();
@ -802,6 +804,8 @@ public final class QueryParams implements Cloneable {
needCoords = true;
} else if (param.equals("silent")) {
silent = true;
} else if (param.equals("force")) {
forceReplace = true;
} else if (param.equals("search") || param.equals("match")) {
if (values.length == 0) {
throw new IllegalArgumentException("No arguments for '" + param + "'");

View File

@ -50,10 +50,16 @@ public class WorldEditor implements Runnable {
private int successes = 0, blacklistCollisions = 0;
private long elapsedTime = 0;
public LookupCacheElement[] errors;
private boolean forceReplace;
public WorldEditor(LogBlock logblock, World world) {
this(logblock, world, false);
}
public WorldEditor(LogBlock logblock, World world, boolean forceReplace) {
this.logblock = logblock;
this.world = world;
this.forceReplace = forceReplace;
}
public int getSize() {
@ -170,13 +176,13 @@ public class WorldEditor implements Runnable {
return PerformResult.BLACKLISTED;
}
final Block block = loc.getBlock();
if (!world.isChunkLoaded(block.getChunk())) {
world.loadChunk(block.getChunk());
}
if (BukkitUtils.isEmpty(replacedBlock.getMaterial()) && BukkitUtils.isEmpty(block.getType())) {
return PerformResult.NO_ACTION;
}
BlockState state = block.getState();
if (!world.isChunkLoaded(block.getChunk())) {
world.loadChunk(block.getChunk());
}
if (setBlock.equals(replacedBlock)) {
if (ca != null) {
if (state instanceof InventoryHolder && state.getType() == replacedBlock.getMaterial()) {
@ -194,7 +200,7 @@ public class WorldEditor implements Runnable {
return PerformResult.NO_ACTION;
}
}
if (block.getType() != setBlock.getMaterial() && !block.isEmpty() && !replaceAnyway.contains(block.getType())) {
if (!forceReplace && block.getType() != setBlock.getMaterial() && !block.isEmpty() && !replaceAnyway.contains(block.getType())) {
return PerformResult.NO_ACTION;
}
if (state instanceof InventoryHolder && replacedBlock.getMaterial() != block.getType()) {