Disables biome copying by default in blueprints.

Biome will be copied only if it is required by copy command parameter.

Fixes #1862
This commit is contained in:
BONNe 2022-07-07 00:08:15 +03:00
parent 9ec8730359
commit 927fcba15a
2 changed files with 41 additions and 19 deletions

View File

@ -1,35 +1,54 @@
package world.bentobox.bentobox.api.commands.admin.blueprints;
import java.util.List;
import java.util.Optional;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.blueprints.BlueprintClipboard;
public class AdminBlueprintCopyCommand extends CompositeCommand {
public AdminBlueprintCopyCommand(AdminBlueprintCommand parent) {
public class AdminBlueprintCopyCommand extends CompositeCommand
{
public AdminBlueprintCopyCommand(AdminBlueprintCommand parent)
{
super(parent, "copy");
}
@Override
public void setup() {
public void setup()
{
inheritPermission();
setParametersHelp("commands.admin.blueprint.copy.parameters");
setDescription("commands.admin.blueprint.copy.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
if (args.size() > 1) {
showHelp(this, user);
public boolean execute(User user, String label, List<String> args)
{
if (args.size() > 2)
{
this.showHelp(this, user);
return false;
}
AdminBlueprintCommand parent = (AdminBlueprintCommand) getParent();
BlueprintClipboard clipboard = parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
boolean copyAir = (args.size() == 1 && args.get(0).equalsIgnoreCase("air"));
return clipboard.copy(user, copyAir);
BlueprintClipboard clipboard =
parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
boolean copyAir = args.stream().anyMatch(key -> key.equalsIgnoreCase("air"));
boolean copyBiome = args.stream().anyMatch(key -> key.equalsIgnoreCase("biome"));
return clipboard.copy(user, copyAir, copyBiome);
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args)
{
return Optional.of(List.of("air", "biome"));
}
}

View File

@ -85,7 +85,7 @@ public class BlueprintClipboard {
* @param user - user
* @return true if successful, false if pos1 or pos2 are undefined.
*/
public boolean copy(User user, boolean copyAir) {
public boolean copy(User user, boolean copyAir, boolean copyBiome) {
if (copying) {
user.sendMessage("commands.admin.blueprint.mid-copy");
return false;
@ -120,11 +120,11 @@ public class BlueprintClipboard {
int speed = plugin.getSettings().getPasteSpeed();
List<Vector> vectorsToCopy = getVectors(toCopy);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> copyAsync(world, user, vectorsToCopy, speed, copyAir));
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> copyAsync(world, user, vectorsToCopy, speed, copyAir, copyBiome));
return true;
}
private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int speed, boolean copyAir) {
private void copyAsync(World world, User user, List<Vector> vectorsToCopy, int speed, boolean copyAir, boolean copyBiome) {
copying = false;
copyTask = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
if (copying) {
@ -139,7 +139,7 @@ public class BlueprintClipboard {
Math.rint(e.getLocation().getY()),
Math.rint(e.getLocation().getZ())).equals(v))
.collect(Collectors.toList());
if (copyBlock(v.toLocation(world), copyAir, ents)) {
if (copyBlock(v.toLocation(world), copyAir, copyBiome, ents)) {
count++;
}
});
@ -179,7 +179,7 @@ public class BlueprintClipboard {
return r;
}
private boolean copyBlock(Location l, boolean copyAir, Collection<LivingEntity> entities) {
private boolean copyBlock(Location l, boolean copyAir, boolean copyBiome, Collection<LivingEntity> entities) {
Block block = l.getBlock();
if (!copyAir && block.getType().equals(Material.AIR) && entities.isEmpty()) {
return false;
@ -203,20 +203,23 @@ public class BlueprintClipboard {
return true;
}
BlueprintBlock b = bluePrintBlock(pos, block);
BlueprintBlock b = bluePrintBlock(pos, block, copyBiome);
if (b != null) {
this.bpBlocks.put(pos, b);
}
return true;
}
private BlueprintBlock bluePrintBlock(Vector pos, Block block) {
private BlueprintBlock bluePrintBlock(Vector pos, Block block, boolean copyBiome) {
// Block state
BlockState blockState = block.getState();
BlueprintBlock b = new BlueprintBlock(block.getBlockData().getAsString());
if (copyBiome) {
// Biome
b.setBiome(block.getBiome());
}
// Signs
if (blockState instanceof Sign sign) {
b.setSignLines(Arrays.asList(sign.getLines()));