2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* 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.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.plot.schematic;
|
2018-12-20 00:18:57 +01:00
|
|
|
|
|
|
|
import com.sk89q.jnbt.NBTOutputStream;
|
|
|
|
import com.sk89q.jnbt.Tag;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-11-04 20:55:55 +01:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2018-12-20 00:18:57 +01:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class Schematic {
|
2020-07-17 17:24:45 +02:00
|
|
|
|
2018-12-20 00:18:57 +01:00
|
|
|
// Lossy but fast
|
2020-07-17 17:24:45 +02:00
|
|
|
private final Clipboard clipboard;
|
|
|
|
private Map<String, Tag> flags = new HashMap<>();
|
2018-12-20 00:18:57 +01:00
|
|
|
|
2020-07-17 17:24:45 +02:00
|
|
|
public Schematic(final Clipboard clip) {
|
2018-12-20 00:18:57 +01:00
|
|
|
this.clipboard = clip;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean setBlock(BlockVector3 position, BaseBlock block) throws WorldEditException {
|
|
|
|
if (clipboard.getRegion().contains(position)) {
|
2019-09-08 20:02:45 +02:00
|
|
|
BlockVector3 vector3 = position.subtract(clipboard.getRegion().getMinimumPoint());
|
|
|
|
clipboard.setBlock(vector3, block);
|
2018-12-20 00:18:57 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void save(File file) throws IOException {
|
2019-09-08 20:02:45 +02:00
|
|
|
try (SpongeSchematicWriter schematicWriter = new SpongeSchematicWriter(
|
2021-01-09 22:28:41 +01:00
|
|
|
new NBTOutputStream(new FileOutputStream(file)))) {
|
2019-09-08 20:02:45 +02:00
|
|
|
schematicWriter.write(clipboard);
|
2019-02-15 18:50:43 +01:00
|
|
|
}
|
2018-12-20 00:18:57 +01:00
|
|
|
}
|
2020-07-17 17:24:45 +02:00
|
|
|
|
|
|
|
public Clipboard getClipboard() {
|
|
|
|
return this.clipboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Tag> getFlags() {
|
|
|
|
return this.flags;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
|
|
|
public void setFlags(Map<String, Tag> flags) {
|
|
|
|
this.flags = flags == null ? new HashMap<>() : flags;
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:18:57 +01:00
|
|
|
}
|