Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 02:20:07 +01:00
Added basic copy/paste functions.
Dieser Commit ist enthalten in:
Ursprung
8e2c6ece61
Commit
4c7e14a76b
91
src/RegionClipboard.java
Normale Datei
91
src/RegionClipboard.java
Normale Datei
@ -0,0 +1,91 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Albert
|
||||
*/
|
||||
public class RegionClipboard {
|
||||
private int[][][] data;
|
||||
private Point<Integer> min;
|
||||
private Point<Integer> max;
|
||||
private Point<Integer> origin;
|
||||
|
||||
/**
|
||||
* Constructs the region instance. The minimum and maximum points must be
|
||||
* the respective minimum and maximum numbers!
|
||||
*
|
||||
* @param min
|
||||
* @param max
|
||||
* @param origin
|
||||
*/
|
||||
public RegionClipboard(Point<Integer> min, Point<Integer> max, Point<Integer> origin) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.origin = origin;
|
||||
data = new int[(max.getX()) - min.getX() + 1]
|
||||
[max.getY() - min.getY() + 1]
|
||||
[max.getZ() - min.getZ() + 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy to the clipboard.
|
||||
*
|
||||
* @param editSession
|
||||
*/
|
||||
public void copy(EditSession editSession) {
|
||||
for (int x = min.getX(); x <= max.getX(); x++) {
|
||||
for (int y = min.getY(); y <= max.getY(); y++) {
|
||||
for (int z = min.getZ(); z <= max.getZ(); z++) {
|
||||
data[x - min.getX()][y - min.getY()][z - min.getZ()] =
|
||||
editSession.getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste from the clipboard.
|
||||
*
|
||||
* @param editSession
|
||||
* @param origin Position to paste it from
|
||||
* @param noAir True to not paste air
|
||||
*/
|
||||
public void paste(EditSession editSession, Point<Integer> newOrigin, boolean noAir) {
|
||||
int xs = max.getX() - min.getX();
|
||||
int ys = max.getY() - min.getY();
|
||||
int zs = max.getZ() - min.getZ();
|
||||
int offsetX = min.getX() - origin.getX() + newOrigin.getX();
|
||||
int offsetY = min.getY() - origin.getY() + newOrigin.getY();
|
||||
int offsetZ = min.getZ() - origin.getZ() + newOrigin.getZ();
|
||||
|
||||
for (int x = 0; x < xs; x++) {
|
||||
for (int y = 0; y <= ys; y++) {
|
||||
for (int z = 0; z <= zs; z++) {
|
||||
if (noAir && data[x][y][z] == 0) { continue; }
|
||||
|
||||
editSession.setBlock(x + offsetX, y + offsetY, z + offsetZ,
|
||||
data[x][y][z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -46,6 +46,9 @@ public class WorldEdit extends Plugin {
|
||||
commands.put("/editreplace", "<ID> - Replace all existing blocks inside region");
|
||||
commands.put("/editoverlay", "<ID> - Overlay the area one layer");
|
||||
commands.put("/removeabove", "<Size> - Remove blocks above head");
|
||||
commands.put("/editcopy", "Copies the currently selected region");
|
||||
commands.put("/editpaste", "Pastes the clipboard");
|
||||
commands.put("/editpasteair", "Pastes the clipboard (with air)");
|
||||
commands.put("/editfill", "<ID> <Radius> <Depth> - Fill a hole");
|
||||
commands.put("/editscript", "<Filename> [Args...] - Run an editscript");
|
||||
}
|
||||
@ -227,6 +230,24 @@ public class WorldEdit extends Plugin {
|
||||
}
|
||||
return true;
|
||||
|
||||
// Paste
|
||||
} else if (split[0].equalsIgnoreCase("/editpasteair") ||
|
||||
split[0].equalsIgnoreCase("/editpaste")) {
|
||||
if (session.getClipboard() == null) {
|
||||
player.sendMessage(Colors.Rose + "Nothing is in your clipboard.");
|
||||
} else {
|
||||
Point<Integer> pos = new Point<Integer>((int)Math.floor(player.getX()),
|
||||
(int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()));
|
||||
session.getClipboard().paste(editSession, pos,
|
||||
split[0].equalsIgnoreCase("/editpaste"));
|
||||
session.remember(editSession);
|
||||
logger.log(Level.INFO, player.getName() + " used " + split[0]);
|
||||
player.sendMessage(Colors.LightPurple + "Pasted.");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
// Fill a hole
|
||||
} else if (split[0].equalsIgnoreCase("/editfill")) {
|
||||
checkArgs(split, 1);
|
||||
@ -432,6 +453,23 @@ public class WorldEdit extends Plugin {
|
||||
|
||||
session.remember(editSession);
|
||||
|
||||
return true;
|
||||
|
||||
// Copy
|
||||
} else if (split[0].equalsIgnoreCase("/editcopy")) {
|
||||
Point<Integer> min = new Point<Integer>(lowerX, lowerY, lowerZ);
|
||||
Point<Integer> max = new Point<Integer>(upperX, upperY, upperZ);
|
||||
Point<Integer> pos = new Point<Integer>((int)Math.floor(player.getX()),
|
||||
(int)Math.floor(player.getY()),
|
||||
(int)Math.floor(player.getZ()));
|
||||
|
||||
RegionClipboard clipboard = new RegionClipboard(min, max, pos);
|
||||
clipboard.copy(editSession);
|
||||
session.setClipboard(clipboard);
|
||||
|
||||
logger.log(Level.INFO, player.getName() + " used /editcopy");
|
||||
player.sendMessage(Colors.LightPurple + "Block(s) copied.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ public class WorldEditSession {
|
||||
private boolean hasSetPos2 = false;
|
||||
private LinkedList<EditSession> history = new LinkedList<EditSession>();
|
||||
private int historyPointer = 0;
|
||||
private RegionClipboard clipboard;
|
||||
|
||||
/**
|
||||
* Get the edit session.
|
||||
@ -157,4 +158,18 @@ public class WorldEditSession {
|
||||
(getUpperY() - getLowerY() + 1) *
|
||||
(getUpperZ() - getLowerZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public RegionClipboard getClipboard() {
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clipboard
|
||||
*/
|
||||
public void setClipboard(RegionClipboard clipboard) {
|
||||
this.clipboard = clipboard;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren