mirror of
https://github.com/YouHaveTrouble/BlockEdit.git
synced 2026-06-29 13:36:19 +00:00
use snapshot for clipboards instead of the same object to prevent issues with concurrecy later
This commit is contained in:
@@ -6,6 +6,7 @@ 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.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -15,7 +16,7 @@ public class BEPlayer {
|
|||||||
private static final HashMap<UUID, BEPlayer> playerHashMap = new HashMap<>();
|
private static final HashMap<UUID, BEPlayer> playerHashMap = new HashMap<>();
|
||||||
private Selection selection;
|
private Selection selection;
|
||||||
|
|
||||||
private final Clipboard clipboard;
|
private Clipboard clipboard;
|
||||||
private Location selectionPoint1, selectionPoint2;
|
private Location selectionPoint1, selectionPoint2;
|
||||||
private final UUID playerUuid;
|
private final UUID playerUuid;
|
||||||
|
|
||||||
@@ -39,8 +40,7 @@ public class BEPlayer {
|
|||||||
public void setClipboardFromSelection() {
|
public void setClipboardFromSelection() {
|
||||||
if (selection == null) throw new IllegalStateException("Selection is null");
|
if (selection == null) throw new IllegalStateException("Selection is null");
|
||||||
// add every block between selection points to clipboard
|
// add every block between selection points to clipboard
|
||||||
clipboard.clear();
|
Clipboard clipboard = new Clipboard(getPlayer().getLocation().toBlockLocation());
|
||||||
clipboard.setBaseLocation(getPlayer().getLocation().toBlockLocation());
|
|
||||||
for (int x = (int) selection.getMinX(); x <= selection.getMaxX(); x++) {
|
for (int x = (int) selection.getMinX(); x <= selection.getMaxX(); x++) {
|
||||||
for (int y = (int) selection.getMinY(); y <= selection.getMaxY(); y++) {
|
for (int y = (int) selection.getMinY(); y <= selection.getMaxY(); y++) {
|
||||||
for (int z = (int) selection.getMinZ(); z <= selection.getMaxZ(); z++) {
|
for (int z = (int) selection.getMinZ(); z <= selection.getMaxZ(); z++) {
|
||||||
@@ -50,6 +50,15 @@ public class BEPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setClipboard(clipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClipboard(@Nullable Clipboard clipboard) {
|
||||||
|
if (clipboard == null) {
|
||||||
|
this.clipboard.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.clipboard = clipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetSelection() {
|
public void resetSelection() {
|
||||||
|
|||||||
Reference in New Issue
Block a user