Fix pasting of blueprints from clipboard. Always pasted at y=0

This commit is contained in:
tastybento 2019-05-17 21:03:20 -07:00
parent cf0b2ccdd5
commit a3f8d2998f
3 changed files with 12 additions and 13 deletions

View File

@ -34,7 +34,7 @@ public class AdminBlueprintOriginCommand extends CompositeCommand {
// Get the block player is looking at // Get the block player is looking at
Block b = user.getPlayer().getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null); Block b = user.getPlayer().getLineOfSight(null, 20).stream().filter(x -> !x.getType().equals(Material.AIR)).findFirst().orElse(null);
if (b != null) { if (b != null) {
clipboard.setOrigin(b.getLocation()); clipboard.setOrigin(b.getLocation().toVector());
user.getPlayer().sendBlockChange(b.getLocation(), Material.REDSTONE_BLOCK.createBlockData()); user.getPlayer().sendBlockChange(b.getLocation(), Material.REDSTONE_BLOCK.createBlockData());
Bukkit.getScheduler().runTaskLater(getPlugin(), Bukkit.getScheduler().runTaskLater(getPlugin(),
() -> user.getPlayer().sendBlockChange(b.getLocation(), b.getBlockData()), 20L); () -> user.getPlayer().sendBlockChange(b.getLocation(), b.getBlockData()), 20L);

View File

@ -53,7 +53,7 @@ public class BlueprintClipboard {
private @Nullable Blueprint blueprint; private @Nullable Blueprint blueprint;
private @Nullable Location pos1; private @Nullable Location pos1;
private @Nullable Location pos2; private @Nullable Location pos2;
private @Nullable Location origin; private @Nullable Vector origin;
private BukkitTask copyTask; private BukkitTask copyTask;
private int count; private int count;
private boolean copying; private boolean copying;
@ -85,12 +85,13 @@ public class BlueprintClipboard {
user.sendMessage("commands.admin.blueprint.mid-copy"); user.sendMessage("commands.admin.blueprint.mid-copy");
return false; return false;
} }
origin = origin == null ? user.getLocation() : origin;
if (pos1 == null || pos2 == null) { if (pos1 == null || pos2 == null) {
user.sendMessage("commands.admin.blueprint.need-pos1-pos2"); user.sendMessage("commands.admin.blueprint.need-pos1-pos2");
return false; return false;
} }
if (origin == null) {
setOrigin(user.getLocation().toVector());
}
user.sendMessage("commands.admin.blueprint.copying"); user.sendMessage("commands.admin.blueprint.copying");
// World // World
@ -166,15 +167,15 @@ public class BlueprintClipboard {
return r; return r;
} }
private boolean copyBlock(Location l, Location copyOrigin, boolean copyAir, Collection<LivingEntity> entities) { private boolean copyBlock(Location l, @Nullable Vector origin2, boolean copyAir, Collection<LivingEntity> entities) {
Block block = l.getBlock(); Block block = l.getBlock();
if (!copyAir && block.getType().equals(Material.AIR) && entities.isEmpty()) { if (!copyAir && block.getType().equals(Material.AIR) && entities.isEmpty()) {
return false; return false;
} }
// Create position // Create position
int x = l.getBlockX() - copyOrigin.getBlockX(); int x = l.getBlockX() - origin2.getBlockX();
int y = l.getBlockY() - copyOrigin.getBlockY(); int y = l.getBlockY() - origin2.getBlockY();
int z = l.getBlockZ() - copyOrigin.getBlockZ(); int z = l.getBlockZ() - origin2.getBlockZ();
Vector pos = new Vector(x, y, z); Vector pos = new Vector(x, y, z);
// Set entities // Set entities
@ -279,7 +280,7 @@ public class BlueprintClipboard {
* @return the origin * @return the origin
*/ */
@Nullable @Nullable
public Location getOrigin() { public Vector getOrigin() {
return origin; return origin;
} }
/** /**
@ -304,7 +305,7 @@ public class BlueprintClipboard {
/** /**
* @param origin the origin to set * @param origin the origin to set
*/ */
public void setOrigin(@Nullable Location origin) { public void setOrigin(@Nullable Vector origin) {
this.origin = origin; this.origin = origin;
} }

View File

@ -80,9 +80,7 @@ public class BlueprintPaster {
this.plugin = plugin; this.plugin = plugin;
this.clipboard = clipboard; this.clipboard = clipboard;
// Calculate location for pasting // Calculate location for pasting
Vector offset = clipboard.getOrigin() != null ? clipboard.getOrigin().toVector() : new Vector(0, 0, 0); paste(location.getWorld(), null, location, clipboard.getBlueprint(), task);
Location loc = location.toVector().subtract(offset).toLocation(location.getWorld());
paste(location.getWorld(), null, loc, clipboard.getBlueprint(), task);
} }
/** /**