Last active
August 29, 2015 14:04
-
-
Save DarkArc/481ed4438ddc51b7c3ca to your computer and use it in GitHub Desktop.
Distrusted Paste
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void paste(String newMirage) throws IOException, DataException, CommandException { | |
File file = getFile(newMirage); | |
if (!file.exists()) { | |
throw new FileNotFoundException(); | |
} | |
EditSession editor = new EditSession(new BukkitWorld(world), -1); | |
// editor.setFastMode(true); Don't do this unless you plan to resend chunks later | |
CuboidClipboard clipboard = SchematicFormat.MCEDIT.load(file); | |
int maxX = clipboard.getWidth(); | |
int maxY = clipboard.getHeight(); | |
int maxZ = clipboard.getLength(); | |
callEdit(editor, clipboard, 0, 0, maxX, maxY, maxZ); | |
} | |
public void callEdit(EditSession editor, CuboidClipboard board, | |
int cx, int cy, int maxX, int maxY, int maxZ) { | |
if (cy >= maxY) { | |
return; | |
} | |
long start = System.currentTimeMillis(); | |
edit: | |
{ | |
for (int x = cx; x < maxX; ++x) { | |
for (int z = 0; z < maxZ; ++z) { | |
Vector v = new Vector(x, cy, z); | |
Vector target = v.add(region.getMinimumPoint()); | |
BaseBlock targetBlock = board.getBlock(v); | |
try { | |
editor.setBlock(target, targetBlock); | |
} catch (MaxChangedBlocksException e) { | |
e.printStackTrace(); | |
} | |
} | |
if (System.currentTimeMillis() - start >= 100) { | |
cx = x; | |
break edit; | |
} | |
} | |
cx = 0; | |
cy++; | |
} | |
long post = System.currentTimeMillis() - start; | |
final int finalCy = cy; | |
final int finalCx = cx; | |
server.getScheduler().runTaskLater(inst, () -> { | |
callEdit(editor, board, finalCx, finalCy, maxX, maxY, maxZ); | |
}, post / 5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment