Skip to content

Commit

Permalink
Add amount of missing blocks to message when using inventory.
Browse files Browse the repository at this point in the history
  • Loading branch information
wizjany committed Dec 29, 2012
1 parent 79802bd commit e09a0c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/main/java/com/sk89q/worldedit/EditSession.java
Expand Up @@ -124,7 +124,7 @@ public class EditSession {
/**
* List of missing blocks;
*/
private Set<Integer> missingBlocks = new HashSet<Integer>();
private Map<Integer, Integer> missingBlocks = new HashMap<Integer, Integer>();

/**
* Mask to cover operations.
Expand Down Expand Up @@ -208,7 +208,11 @@ public boolean rawSetBlock(Vector pt, BaseBlock block) {
} catch (UnplaceableBlockException e) {
return false;
} catch (BlockBagException e) {
missingBlocks.add(type);
if (!missingBlocks.containsKey(type)) {
missingBlocks.put(type, 1);
} else {
missingBlocks.put(type, missingBlocks.get(type) + 1);
}
return false;
}
}
Expand Down Expand Up @@ -606,9 +610,9 @@ public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean natu
*
* @return
*/
public Set<Integer> popMissingBlocks() {
Set<Integer> missingBlocks = this.missingBlocks;
this.missingBlocks = new HashSet<Integer>();
public Map<Integer, Integer> popMissingBlocks() {
Map<Integer, Integer> missingBlocks = this.missingBlocks;
this.missingBlocks = new HashMap<Integer, Integer>();
return missingBlocks;
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/sk89q/worldedit/WorldEdit.java
Expand Up @@ -1079,21 +1079,23 @@ public void flushBlockBag(LocalPlayer player,
blockBag.flushChanges();
}

Set<Integer> missingBlocks = editSession.popMissingBlocks();
Map<Integer, Integer> missingBlocks = editSession.popMissingBlocks();

if (missingBlocks.size() > 0) {
StringBuilder str = new StringBuilder();
str.append("Missing these blocks: ");
int size = missingBlocks.size();
int i = 0;

for (Integer id : missingBlocks) {
for (Integer id : missingBlocks.keySet()) {
BlockType type = BlockType.fromID(id);

str.append(type != null
? type.getName() + " (" + id + ")"
: id.toString());

str.append(" [Amt: " + missingBlocks.get(id) + "]");

++i;

if (i != size) {
Expand Down

0 comments on commit e09a0c6

Please sign in to comment.