use of org.cubeengine.module.log.action.BaseAction.Coordinate in project modules-extra by CubeEngine.
the class QueryResults method redo.
public void redo(LogAttachment attachment, boolean preview) {
// Find the newest entry at a location
Map<Coordinate, Redoable> finalBlock = new HashMap<>();
Map<Coordinate, LinkedList<Redoable>> blockChanges = new HashMap<>();
TreeSet<Redoable> filteredLogs = new TreeSet<>();
for (BaseAction logEntry : this.logEntries) {
if (// can redo
logEntry instanceof Redoable) {
if (logEntry.coord.getWorld() == null) {
continue;
}
if (((Redoable) logEntry).isBlockBound()) {
if (((Redoable) logEntry).isStackable()) {
LinkedList<Redoable> changes = blockChanges.get(logEntry.coord);
if (changes == null) {
changes = new LinkedList<>();
blockChanges.put(logEntry.coord, changes);
}
changes.add((Redoable) logEntry);
} else {
// Clear blockChanges when new final block
blockChanges.remove(logEntry.coord);
finalBlock.put(logEntry.coord, (Redoable) logEntry);
}
} else {
// Not a block change at the location -> do rollback
filteredLogs.add((Redoable) logEntry);
}
}
}
// Finished filtering! Merge back together...
for (LinkedList<Redoable> entries : blockChanges.values()) {
filteredLogs.addAll(entries);
}
filteredLogs.addAll(finalBlock.values());
// Start Rollback 1st Round
Set<Redoable> rollbackRound2 = new LinkedHashSet<>();
for (// Rollback normal blocks
Redoable logEntry : // Rollback normal blocks
filteredLogs.descendingSet()) {
if (!logEntry.redo(attachment, false, // Redo failed (cannot set yet (torches etc)) try again later
preview)) {
rollbackRound2.add(logEntry);
}
}
ShowParameter show = new ShowParameter();
// Start Rollback 2nd Round (Attachables etc.)
for (// Rollback attached blocks
Redoable logEntry : // Rollback attached blocks
rollbackRound2) {
if (!logEntry.redo(attachment, true, preview)) {
attachment.getHolder().sendTranslated(NEGATIVE, "Could not Redo:");
((BaseAction) logEntry).showAction(attachment.getHolder(), show);
CubeEngine.getLog().warn("Could not redo!");
}
}
}
use of org.cubeengine.module.log.action.BaseAction.Coordinate in project modules-extra by CubeEngine.
the class QueryResults method rollback.
public void rollback(LogAttachment attachment, boolean preview) {
// Find the oldest entry at a location
Map<Coordinate, Rollbackable> finalBlock = new HashMap<>();
Map<Coordinate, LinkedList<Rollbackable>> blockChanges = new HashMap<>();
TreeSet<Rollbackable> filteredLogs = new TreeSet<>();
for (BaseAction logEntry : this.logEntries.descendingSet()) {
if (// can rollback
logEntry instanceof Rollbackable) {
if (logEntry.coord.getWorld() == null) {
continue;
}
if (logEntry instanceof DeathMonster && !this.lookup.getQueryParameter().containsAction(DeathMonster.class)) {
// ignoring Monster-respawning when not explicitly wanted
continue;
}
if (((Rollbackable) logEntry).isBlockBound()) {
if (((Rollbackable) logEntry).isStackable()) {
LinkedList<Rollbackable> changes = blockChanges.get(logEntry.coord);
if (changes == null) {
changes = new LinkedList<>();
blockChanges.put(logEntry.coord, changes);
}
changes.add((Rollbackable) logEntry);
} else {
// Clear blockChanges when new final block
blockChanges.remove(logEntry.coord);
finalBlock.put(logEntry.coord, (Rollbackable) logEntry);
}
} else {
// Not a block change at the location -> do rollback
filteredLogs.add((Rollbackable) logEntry);
}
}
}
// Finished filtering! Merge back together...
for (LinkedList<Rollbackable> entries : blockChanges.values()) {
filteredLogs.addAll(entries);
}
filteredLogs.addAll(finalBlock.values());
// Start Rollback 1st Round
Set<Rollbackable> rollbackRound2 = new LinkedHashSet<>();
// Rollback normal blocks
for (Rollbackable logEntry : filteredLogs.descendingSet()) {
if (!logEntry.rollback(attachment, false, preview)) {
// Rollback failed (cannot set yet (torches etc)) try again later
rollbackRound2.add(logEntry);
}
}
ShowParameter show = new ShowParameter();
// Start Rollback 2nd Round (Attachables etc.)
for (// Rollback attached blocks
Rollbackable logEntry : // Rollback attached blocks
rollbackRound2) {
if (!logEntry.rollback(attachment, true, preview)) {
attachment.getHolder().sendTranslated(NEGATIVE, "Could not Rollback:");
((BaseAction) logEntry).showAction(attachment.getHolder(), show);
CubeEngine.getLog().warn("Could not rollback!");
}
}
}
Aggregations