mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 21:46:19 +00:00
clipboard from selection logic
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package me.youhavetrouble.blockedit;
|
package me.youhavetrouble.blockedit;
|
||||||
|
|
||||||
|
import me.youhavetrouble.blockedit.util.Clipboard;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -12,11 +14,14 @@ public class BEPlayer {
|
|||||||
|
|
||||||
private static final HashMap<UUID, BEPlayer> playerHashMap = new HashMap<>();
|
private static final HashMap<UUID, BEPlayer> playerHashMap = new HashMap<>();
|
||||||
private BoundingBox selection;
|
private BoundingBox selection;
|
||||||
|
|
||||||
|
private final Clipboard clipboard;
|
||||||
private Location selectionPoint1, selectionPoint2;
|
private Location selectionPoint1, selectionPoint2;
|
||||||
private final UUID playerUuid;
|
private final UUID playerUuid;
|
||||||
|
|
||||||
public BEPlayer(Player player) {
|
public BEPlayer(Player player) {
|
||||||
this.playerUuid = player.getUniqueId();
|
this.playerUuid = player.getUniqueId();
|
||||||
|
this.clipboard = new Clipboard(player.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
@@ -27,6 +32,26 @@ public class BEPlayer {
|
|||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Clipboard getClipboard() {
|
||||||
|
return clipboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClipboardFromSelection() {
|
||||||
|
if (selection == null) throw new IllegalStateException("Selection is null");
|
||||||
|
// add every block between selection points to clipboard
|
||||||
|
clipboard.setBaseLocation(getPlayer().getLocation());
|
||||||
|
for (int x = (int) selection.getMinX(); x <= selection.getMaxX(); x++) {
|
||||||
|
for (int y = (int) selection.getMinY(); y <= selection.getMaxY(); y++) {
|
||||||
|
for (int z = (int) selection.getMinZ(); z <= selection.getMaxZ(); z++) {
|
||||||
|
Vector relativeLocation = new Vector(x, y, z).subtract(clipboard.getBaseLocationVector());
|
||||||
|
Location location = new Location(selectionPoint1.getWorld(), x, y, z);
|
||||||
|
clipboard.addBlock(relativeLocation, location.getBlock().getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void resetSelection() {
|
public void resetSelection() {
|
||||||
this.selection = null;
|
this.selection = null;
|
||||||
this.selectionPoint1 = null;
|
this.selectionPoint1 = null;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package me.youhavetrouble.blockedit.util;
|
package me.youhavetrouble.blockedit.util;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -8,18 +10,38 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class Clipboard {
|
public class Clipboard {
|
||||||
|
|
||||||
private HashMap<RelativeLocation, BlockState> blocks = new HashMap<>();
|
/**
|
||||||
|
* Map of locations relative to the center of the clipboard and their block states
|
||||||
|
*/
|
||||||
|
private final HashMap<Vector, BlockState> blocks = new HashMap<>();
|
||||||
|
private Location baseLocation;
|
||||||
|
private Vector baseLocationVector;
|
||||||
|
|
||||||
public Clipboard() {}
|
public Clipboard(Location baseLocation) {
|
||||||
|
this.baseLocation = baseLocation;
|
||||||
public void setBlocks(HashMap<RelativeLocation, BlockState> newClipboard) {
|
|
||||||
this.blocks = newClipboard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<RelativeLocation, BlockState> getBlocks() {
|
public void addBlock(Vector relativeLocation, BlockState blockState) {
|
||||||
|
this.blocks.put(relativeLocation, blockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Vector, BlockState> getBlocks() {
|
||||||
return Collections.unmodifiableMap(this.blocks);
|
return Collections.unmodifiableMap(this.blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBaseLocation(Location baseLocation) {
|
||||||
|
this.baseLocation = baseLocation;
|
||||||
|
this.baseLocationVector = baseLocation.toVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getBaseLocation() {
|
||||||
|
return baseLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector getBaseLocationVector() {
|
||||||
|
return baseLocationVector;
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
this.blocks.clear();
|
this.blocks.clear();
|
||||||
}
|
}
|
||||||
@@ -27,4 +49,16 @@ public class Clipboard {
|
|||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return this.blocks.isEmpty();
|
return this.blocks.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotates clipboard by specified degrees around the base location.
|
||||||
|
* @param angle angle in degrees
|
||||||
|
*/
|
||||||
|
public void rotate(int angle) {
|
||||||
|
for (Map.Entry<Vector, BlockState> entry : this.blocks.entrySet()) {
|
||||||
|
Vector relativeLocation = entry.getKey();
|
||||||
|
relativeLocation.rotateAroundAxis(baseLocationVector, angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package me.youhavetrouble.blockedit.util;
|
|
||||||
|
|
||||||
public class RelativeLocation {
|
|
||||||
|
|
||||||
private double x, y, z;
|
|
||||||
|
|
||||||
public RelativeLocation(double x, double y, double z) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setX(double x) {
|
|
||||||
this.x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setY(double y) {
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getZ() {
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZ(double z) {
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user