use of com.sk89q.worldedit.util.formatting.text.TranslatableComponent 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.sk89q.worldedit.util.formatting.text.TranslatableComponent in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method summary.
@Command(name = "info", aliases = { "summary", "summarize" }, desc = "Summarize an edit")
@CommandPermissions("worldedit.history.info")
public synchronized void summary(Player player, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index) throws WorldEditException, ExecutionException, InterruptedException {
RollbackOptimizedHistory edit = database.getEdit(other, index).get();
if (edit == null) {
player.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
return;
}
Location origin = player.getLocation();
String name = Fawe.platform().getName(edit.getUUID());
String cmd = edit.getCommand();
BlockVector3 pos1 = edit.getMinimumPoint();
BlockVector3 pos2 = edit.getMaximumPoint();
double distanceX = Math.min(Math.abs(pos1.getX() - origin.getX()), Math.abs(pos2.getX() - origin.getX()));
double distanceZ = Math.min(Math.abs(pos1.getZ() - origin.getZ()), Math.abs(pos2.getZ() - origin.getZ()));
int distance = (int) Math.sqrt(distanceX * distanceX + distanceZ * distanceZ);
BlockVector2 dirVec = BlockVector2.at(edit.getOriginX() - origin.getX(), edit.getOriginZ() - origin.getZ());
Direction direction = Direction.findClosest(dirVec.toVector3(), Direction.Flag.ALL);
long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
String timeStr = MainUtil.secToTime(seconds);
int size = edit.size();
boolean biomes = edit.getBioFile().exists();
boolean createdEnts = edit.getEnttFile().exists();
boolean removedEnts = edit.getEntfFile().exists();
boolean createdTiles = edit.getNbttFile().exists();
boolean removedTiles = edit.getNbtfFile().exists();
TranslatableComponent header = Caption.of("fawe.worldedit.history.find.element", name, timeStr, distance, direction.name(), cmd);
String sizeStr = StringMan.humanReadableByteCountBin(edit.getSizeOnDisk());
String extra = "";
if (biomes) {
extra += "biomes, ";
}
if (createdEnts) {
extra += "+entity, ";
}
if (removedEnts) {
extra += "-entity, ";
}
if (createdTiles) {
extra += "+tile, ";
}
if (removedTiles) {
extra += "-tile, ";
}
TranslatableComponent body = Caption.of("fawe.worldedit.history.find.element.more", size, edit.getMinimumPoint(), edit.getMaximumPoint(), extra.trim(), sizeStr);
Component distr = TextComponent.of("/history distr").clickEvent(ClickEvent.suggestCommand("//history distr " + other + " " + index));
TextComponentProducer content = new TextComponentProducer().append(header).newline().append(body).newline().append(distr);
player.print(content.create());
}
Aggregations