use of com.fastasyncworldedit.core.history.change.MutableFullBlockChange in project FastAsyncWorldEdit by IntellectualSites.
the class FaweStreamChangeSet method summarize.
@Override
public SimpleChangeSetSummary summarize(Region region, boolean shallow) {
int ox = getOriginX();
int oz = getOriginZ();
SimpleChangeSetSummary summary = summarizeShallow();
if (region != null && !region.contains(ox, oz)) {
return summary;
}
try (FaweInputStream fis = getBlockIS()) {
if (!shallow) {
int amount = (Settings.settings().HISTORY.BUFFER_SIZE - HEADER_SIZE) / 9;
MutableFullBlockChange change = new MutableFullBlockChange(null, 0, false);
for (int i = 0; i < amount; i++) {
int x = posDel.readX(fis) + ox;
int y = posDel.readY(fis);
int z = posDel.readZ(fis) + ox;
idDel.readCombined(fis, change);
summary.add(x, z, change.to);
}
}
} catch (EOFException ignored) {
} catch (IOException e) {
e.printStackTrace();
}
return summary;
}
use of com.fastasyncworldedit.core.history.change.MutableFullBlockChange in project FastAsyncWorldEdit by IntellectualSites.
the class InspectBrush method perform.
public boolean perform(final Player player, LocalSession session, boolean rightClick) {
if (!player.hasPermission("worldedit.tool.inspect")) {
player.print(Caption.of("fawe.error.no-perm", "worldedit.tool.inspect"));
return false;
}
if (!Settings.settings().HISTORY.USE_DATABASE) {
player.print(Caption.of("fawe.error.setting.disable", "history.use-database (Import with /history import )"));
return false;
}
try {
BlockVector3 target = getTarget(player, rightClick).toBlockPoint();
final int x = target.getBlockX();
final int y = target.getBlockY();
final int z = target.getBlockZ();
World world = player.getWorld();
RollbackDatabase db = DBHandler.dbHandler().getDatabase(world);
int count = 0;
for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) {
count++;
RollbackOptimizedHistory edit = supplier.get();
Iterator<MutableFullBlockChange> iter = edit.getFullBlockIterator(null, 0, false);
while (iter.hasNext()) {
MutableFullBlockChange change = iter.next();
if (change.x != x || change.y != y || change.z != z) {
continue;
}
int from = change.from;
int to = change.to;
UUID uuid = edit.getUUID();
String name = Fawe.platform().getName(uuid);
int index = edit.getIndex();
long age = System.currentTimeMillis() - edit.getBDFile().lastModified();
String ageFormatted = MainUtil.secToTime(age / 1000);
BlockState blockFrom = BlockState.getFromOrdinal(from);
BlockState blockTo = BlockState.getFromOrdinal(to);
TranslatableComponent msg = Caption.of("fawe.worldedit.tool.tool.inspect.info", name, blockFrom, blockTo, ageFormatted);
TextComponent hover = TextComponent.of("/tool inspect", TextColor.GOLD);
String infoCmd = "//history summary " + uuid + " " + index;
msg = msg.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, hover));
msg = msg.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, infoCmd));
player.print(msg);
}
}
player.print(Caption.of("fawe.worldedit.tool.tool.inspect.info.footer", count));
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
use of com.fastasyncworldedit.core.history.change.MutableFullBlockChange in project FastAsyncWorldEdit by IntellectualSites.
the class FaweStreamChangeSet method getFullBlockIterator.
public Iterator<MutableFullBlockChange> getFullBlockIterator(BlockBag blockBag, int inventory, final boolean dir) throws IOException {
final FaweInputStream is = new FaweInputStream(getBlockIS());
final MutableFullBlockChange change = new MutableFullBlockChange(blockBag, inventory, dir);
return new Iterator<MutableFullBlockChange>() {
private MutableFullBlockChange last = read();
public MutableFullBlockChange read() {
try {
change.x = posDel.readX(is) + originX;
change.y = posDel.readY(is);
change.z = posDel.readZ(is) + originZ;
idDel.readCombined(is, change);
return change;
} catch (EOFException ignored) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public boolean hasNext() {
return last != null || ((last = read()) != null);
}
@Override
public MutableFullBlockChange next() {
MutableFullBlockChange tmp = last;
if (tmp == null) {
tmp = read();
}
last = null;
return tmp;
}
@Override
public void remove() {
throw new IllegalArgumentException("CANNOT REMOVE");
}
};
}
Aggregations