Skip to content

Commit

Permalink
Add option to ignore water when saving blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 22, 2025
1 parent caf32da commit 1735638
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public boolean execute(User user, String label, List<String> args)

boolean copyAir = args.stream().anyMatch(key -> key.equalsIgnoreCase("air"));
boolean copyBiome = args.stream().anyMatch(key -> key.equalsIgnoreCase("biome"));
boolean noWater = args.stream().anyMatch(key -> key.equalsIgnoreCase("nowater"));

return clipboard.copy(user, copyAir, copyBiome);
return clipboard.copy(user, copyAir, copyBiome, noWater);
}


@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args)
{
return Optional.of(List.of("air", "biome"));
return Optional.of(List.of("air", "biome", "nowater"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public BlueprintClipboard() {
* @param user - user
* @return true if successful, false if pos1 or pos2 are undefined.
*/
public boolean copy(User user, boolean copyAir, boolean copyBiome) {
public boolean copy(User user, boolean copyAir, boolean copyBiome, boolean noWater) {
if (copying) {
user.sendMessage("commands.admin.blueprint.mid-copy");
return false;
Expand Down Expand Up @@ -137,11 +137,13 @@ public boolean copy(User user, boolean copyAir, boolean copyBiome) {

int speed = plugin.getSettings().getPasteSpeed();
List<Vector> vectorsToCopy = getVectors(toCopy);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> copyAsync(world, user, vectorsToCopy, speed, copyAir, copyBiome));
Bukkit.getScheduler().runTaskAsynchronously(plugin,
() -> copyAsync(world, user, vectorsToCopy, speed, copyAir, copyBiome, noWater));
return true;
}

private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int speed, boolean copyAir, boolean copyBiome) {
private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int speed, boolean copyAir,
boolean copyBiome, boolean noWater) {
copying = false;
// FancyNpcs
if (npc.isPresent()) {
Expand All @@ -167,7 +169,7 @@ private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int s
.filter(e -> new Vector(e.getLocation().getBlockX(), e.getLocation().getBlockY(),
e.getLocation().getBlockZ()).equals(v))
.toList();
if (copyBlock(v.toLocation(world), copyAir, copyBiome, ents)) {
if (copyBlock(v.toLocation(world), copyAir, copyBiome, ents, noWater)) {
count++;
}
});
Expand Down Expand Up @@ -208,11 +210,14 @@ protected List<Vector> getVectors(BoundingBox b) {
return r;
}

private boolean copyBlock(Location l, boolean copyAir, boolean copyBiome, List<Entity> ents) {
private boolean copyBlock(Location l, boolean copyAir, boolean copyBiome, List<Entity> ents, boolean noWater) {
Block block = l.getBlock();
if (!copyAir && block.getType().equals(Material.AIR) && ents.isEmpty()) {
return false;
}
if (noWater && block.getType() == Material.WATER && ents.isEmpty()) {
return false;
}
// Create position
Vector origin2 = origin == null ? new Vector(0,0,0) : origin;
int x = l.getBlockX() - origin2.getBlockX();
Expand All @@ -231,6 +236,9 @@ private boolean copyBlock(Location l, boolean copyAir, boolean copyBiome, List<E
if (!copyAir && block.getType().equals(Material.AIR) && !ents.isEmpty()) {
return true;
}
if (noWater && block.getType().equals(Material.WATER) && !ents.isEmpty()) {
return true;
}
BlueprintBlock b = bluePrintBlock(pos, block, copyBiome);
if (b != null) {
this.bpBlocks.put(pos, b);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ commands:
mid-copy: '&c You are mid-copy. Wait until the copy is done.'
copied-percent: '&6 Copied [number]%'
copy:
parameters: '[air]'
description: copy the clipboard set by pos1 and pos2 and optionally the air
parameters: '[air] [biome] [nowater]'
description: copy the clipboard set by pos1 and pos2 and optionally the air, biome, and water
blocks
delete:
parameters: <name>
Expand Down

0 comments on commit 1735638

Please sign in to comment.