Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to ignore water when saving blueprint #2603

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setUp() throws Exception {
when(ac.getClipboards()).thenReturn(map);

// Clipboard
when(clip.copy(any(), anyBoolean(), anyBoolean())).thenReturn(true);
when(clip.copy(any(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(true);

// Locales
LocalesManager lm = mock(LocalesManager.class);
Expand Down Expand Up @@ -156,7 +156,7 @@ public void testExecuteUserStringListOfStringHelp() {
@Test
public void testExecuteUserStringListOfStringSuccess() {
assertTrue(abcc.execute(user, "", List.of("air", "biome")));
verify(clip).copy(user, true, true);
verify(clip).copy(user, true, true, false);
}

/**
Expand All @@ -165,7 +165,7 @@ public void testExecuteUserStringListOfStringSuccess() {
@Test
public void testExecuteUserStringListOfStringSuccessCaps() {
assertTrue(abcc.execute(user, "", List.of("AIR", "BIOME")));
verify(clip).copy(user, true, true);
verify(clip).copy(user, true, true, false);
}

/**
Expand All @@ -174,7 +174,7 @@ public void testExecuteUserStringListOfStringSuccessCaps() {
@Test
public void testExecuteUserStringListOfStringJunk() {
assertTrue(abcc.execute(user, "", List.of("junk", "junk")));
verify(clip).copy(user, false, false);
verify(clip).copy(user, false, false, false);
}

/**
Expand All @@ -183,7 +183,7 @@ public void testExecuteUserStringListOfStringJunk() {
@Test
public void testExecuteUserStringListOfStringNothing() {
assertTrue(abcc.execute(user, "", Collections.emptyList()));
verify(clip).copy(user, false, false);
verify(clip).copy(user, false, false, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testBlueprintClipboard() {
*/
@Test
public void testCopy() {
assertFalse(bc.copy(user, false, false));
assertFalse(bc.copy(user, false, false, false));
verify(user, never()).sendMessage("commands.admin.blueprint.mid-copy");
verify(user).sendMessage("commands.admin.blueprint.need-pos1-pos2");
}
Expand Down
Loading