mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-14 23:38:34 +00:00
Start work on the new BaseBlock/BlockState split
This commit is contained in:
@ -34,8 +34,8 @@ import com.sk89q.worldedit.Vector2D;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
@ -624,26 +624,22 @@ public class SelectionCommands {
|
||||
aliases = { "/count" },
|
||||
usage = "<block>",
|
||||
desc = "Counts the number of a certain type of block",
|
||||
flags = "d",
|
||||
min = 1,
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions("worldedit.analysis.count")
|
||||
public void count(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
|
||||
boolean useData = args.hasFlag('d');
|
||||
if (args.getString(0).contains(":")) {
|
||||
useData = true; //override d flag, if they specified data they want it
|
||||
}
|
||||
if (useData) {
|
||||
Set<BaseBlock> searchBlocks = we.getBlocks(player, args.getString(0), true);
|
||||
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
|
||||
player.print("Counted: " + count);
|
||||
} else {
|
||||
Set<Integer> searchIDs = we.getBlockIDs(player, args.getString(0), true);
|
||||
int count = editSession.countBlock(session.getSelection(player.getWorld()), searchIDs);
|
||||
player.print("Counted: " + count);
|
||||
}
|
||||
ParserContext context = new ParserContext();
|
||||
context.setActor(player);
|
||||
context.setExtent(player.getExtent());
|
||||
context.setWorld(player.getWorld());
|
||||
context.setSession(session);
|
||||
context.setRestricted(false);
|
||||
|
||||
Set<BaseBlock> searchBlocks = we.getBlockFactory().parseFromListInput(args.getString(0), context);
|
||||
int count = editSession.countBlocks(session.getSelection(player.getWorld()), searchBlocks);
|
||||
player.print("Counted: " + count);
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -662,49 +658,32 @@ public class SelectionCommands {
|
||||
public void distr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException, CommandException {
|
||||
|
||||
int size;
|
||||
boolean useData = args.hasFlag('d');
|
||||
List<Countable<Integer>> distribution = null;
|
||||
List<Countable<BaseBlock>> distributionData = null;
|
||||
List<Countable<BaseBlock>> distributionData;
|
||||
|
||||
if (args.hasFlag('c')) {
|
||||
// TODO: Update for new clipboard
|
||||
throw new CommandException("Needs to be re-written again");
|
||||
} else {
|
||||
if (useData) {
|
||||
distributionData = editSession.getBlockDistributionWithData(session.getSelection(player.getWorld()));
|
||||
} else {
|
||||
distribution = editSession.getBlockDistribution(session.getSelection(player.getWorld()));
|
||||
}
|
||||
distributionData = editSession.getBlockDistributionWithData(session.getSelection(player.getWorld()));
|
||||
size = session.getSelection(player.getWorld()).getArea();
|
||||
}
|
||||
|
||||
if ((useData && distributionData.size() <= 0)
|
||||
|| (!useData && distribution.size() <= 0)) { // *Should* always be false
|
||||
if (distributionData.size() <= 0) { // *Should* always be false
|
||||
player.printError("No blocks counted.");
|
||||
return;
|
||||
}
|
||||
|
||||
player.print("# total blocks: " + size);
|
||||
|
||||
if (useData) {
|
||||
for (Countable<BaseBlock> c : distributionData) {
|
||||
String name = BlockType.fromID(c.getID().getId()).getName();
|
||||
String str = String.format("%-7s (%.3f%%) %s #%d:%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
name == null ? "Unknown" : name,
|
||||
c.getID().getType(), c.getID().getData());
|
||||
player.print(str);
|
||||
}
|
||||
} else {
|
||||
for (Countable<Integer> c : distribution) {
|
||||
BlockType block = BlockType.fromID(c.getID());
|
||||
String str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
block == null ? "Unknown" : block.getName(), c.getID());
|
||||
player.print(str);
|
||||
}
|
||||
for (Countable<BaseBlock> c : distributionData) {
|
||||
String name = c.getID().getType().getName();
|
||||
String str = String.format("%-7s (%.3f%%) %s #%s%s",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
name,
|
||||
c.getID().getType().getId(),
|
||||
c.getID().getStates());
|
||||
player.print(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user