Added -c flag to //distr to print to console.

This commit is contained in:
sk89q 2011-02-18 21:24:12 -08:00
parent 5642f95962
commit fd4b167ac7

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.commands;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Logger;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
@ -380,6 +381,7 @@ public class SelectionCommands {
aliases = {"/distr"}, aliases = {"/distr"},
usage = "", usage = "",
desc = "Get the distribution of blocks in the selection", desc = "Get the distribution of blocks in the selection",
flags = "c",
min = 0, min = 0,
max = 0 max = 0
) )
@ -391,16 +393,28 @@ public class SelectionCommands {
List<Countable<Integer>> distribution = List<Countable<Integer>> distribution =
editSession.getBlockDistribution(session.getRegion()); editSession.getBlockDistribution(session.getRegion());
Logger logger = Logger.getLogger("Minecraft.WorldEdit");
if (distribution.size() > 0) { // *Should* always be true if (distribution.size() > 0) { // *Should* always be true
int size = session.getRegion().getSize(); int size = session.getRegion().getSize();
player.print("# total blocks: " + size); player.print("# total blocks: " + size);
if (args.hasFlag('c')) {
logger.info("Block distribution (req. by " + player.getName() + "):");
logger.info("# total blocks: " + size);
}
for (Countable<Integer> c : distribution) { for (Countable<Integer> c : distribution) {
player.print(String.format("%-7s (%.3f%%) %s #%d", String str = String.format("%-7s (%.3f%%) %s #%d",
String.valueOf(c.getAmount()), String.valueOf(c.getAmount()),
c.getAmount() / (double)size * 100, c.getAmount() / (double)size * 100,
BlockType.fromID(c.getID()).getName(), c.getID())); BlockType.fromID(c.getID()).getName(), c.getID());
player.print(str);
if (args.hasFlag('c')) {
logger.info(str);
}
} }
} else { } else {
player.printError("No blocks counted."); player.printError("No blocks counted.");