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,5 +1,7 @@
|
||||
package me.youhavetrouble.blockedit.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -8,18 +10,38 @@ import java.util.Map;
|
||||
|
||||
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 void setBlocks(HashMap<RelativeLocation, BlockState> newClipboard) {
|
||||
this.blocks = newClipboard;
|
||||
public Clipboard(Location baseLocation) {
|
||||
this.baseLocation = baseLocation;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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() {
|
||||
this.blocks.clear();
|
||||
}
|
||||
@@ -27,4 +49,16 @@ public class Clipboard {
|
||||
public boolean 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user