2014-12-28 13:02:30 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// 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, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
package com.intellectualcrafters.plot.generator;
|
|
|
|
|
2015-07-03 13:21:21 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
2015-07-19 15:12:48 +02:00
|
|
|
import java.util.ArrayList;
|
2015-07-03 13:21:21 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.commands.Template;
|
2015-07-19 15:12:48 +02:00
|
|
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.object.FileBytes;
|
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotLoc;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
2015-07-25 20:12:35 +02:00
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
|
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
|
|
|
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
|
|
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
|
|
|
|
2015-02-20 07:34:19 +01:00
|
|
|
public class HybridPlotManager extends ClassicPlotManager {
|
2015-04-30 06:33:57 +02:00
|
|
|
|
2015-02-25 08:50:17 +01:00
|
|
|
@Override
|
2015-04-30 06:33:57 +02:00
|
|
|
public void exportTemplate(final PlotWorld plotworld) throws IOException {
|
|
|
|
final HashSet<FileBytes> files = new HashSet<>(Arrays.asList(new FileBytes("templates/" + "tmp-data.yml", Template.getBytes(plotworld))));
|
2015-07-03 14:15:20 +02:00
|
|
|
final String psRoot = PS.get().IMP.getDirectory() + File.separator;
|
2015-04-30 06:33:57 +02:00
|
|
|
final String dir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plotworld.worldname + File.separator;
|
|
|
|
final String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + "__TEMP_DIR__" + File.separator;
|
2015-02-25 09:25:22 +01:00
|
|
|
try {
|
2015-04-30 06:33:57 +02:00
|
|
|
final File sideroad = new File(psRoot + dir + "sideroad.schematic");
|
|
|
|
if (sideroad.exists()) {
|
|
|
|
files.add(new FileBytes(newDir + "sideroad.schematic", Files.readAllBytes(sideroad.toPath())));
|
|
|
|
}
|
|
|
|
final File intersection = new File(psRoot + dir + "intersection.schematic");
|
|
|
|
if (intersection.exists()) {
|
|
|
|
files.add(new FileBytes(newDir + "intersection.schematic", Files.readAllBytes(intersection.toPath())));
|
|
|
|
}
|
|
|
|
final File plot = new File(psRoot + dir + "plot.schematic");
|
|
|
|
if (plot.exists()) {
|
|
|
|
files.add(new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath())));
|
|
|
|
}
|
2015-02-25 09:25:22 +01:00
|
|
|
}
|
2015-04-30 06:33:57 +02:00
|
|
|
catch (final Exception e) {
|
2015-02-25 09:25:22 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
Template.zipAll(plotworld.worldname, files);
|
2015-02-25 08:50:17 +01:00
|
|
|
}
|
2015-04-30 06:33:57 +02:00
|
|
|
|
2015-04-30 15:57:44 +02:00
|
|
|
@Override
|
|
|
|
public boolean createRoadEast(PlotWorld plotworld, Plot plot) {
|
|
|
|
super.createRoadEast(plotworld, plot);
|
2015-05-01 16:12:27 +02:00
|
|
|
HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
|
|
|
|
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
PlotId id = plot.id;
|
|
|
|
PlotId id2 = new PlotId(id.x + 1, id.y);
|
|
|
|
Location bot = getPlotBottomLocAbs(hpw, id2);
|
|
|
|
Location top = getPlotTopLocAbs(hpw, id);
|
2015-05-02 13:11:15 +02:00
|
|
|
Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ());
|
2015-07-22 18:33:22 +02:00
|
|
|
Location pos2 = new Location(plot.world, bot.getX(), 255, top.getZ() + 1);
|
2015-05-14 16:55:28 +02:00
|
|
|
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
|
2015-04-30 15:57:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-14 16:55:28 +02:00
|
|
|
public void createSchemAbs(HybridPlotWorld hpw, Location pos1, Location pos2, int height, boolean clear) {
|
2015-05-01 16:12:27 +02:00
|
|
|
final int size = hpw.SIZE;
|
|
|
|
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
|
2015-07-21 08:03:27 +02:00
|
|
|
short absX = (short) ((x - hpw.ROAD_OFFSET_X) % size);
|
|
|
|
if (absX < 0) {
|
|
|
|
absX += size;
|
|
|
|
}
|
2015-05-01 16:12:27 +02:00
|
|
|
for (int z = pos1.getZ(); z <= pos2.getZ(); z++) {
|
2015-07-21 08:03:27 +02:00
|
|
|
short absZ = (short) ((z - hpw.ROAD_OFFSET_Z) % size);
|
2015-05-01 16:12:27 +02:00
|
|
|
if (absZ < 0) {
|
|
|
|
absZ += size;
|
|
|
|
}
|
|
|
|
final PlotLoc loc = new PlotLoc(absX, absZ);
|
|
|
|
final HashMap<Short, Short> blocks = hpw.G_SCH.get(loc);
|
2015-05-14 16:55:28 +02:00
|
|
|
if (clear) {
|
|
|
|
for (short y = (short) (height); y <= (height + hpw.SCHEMATIC_HEIGHT); y++) {
|
|
|
|
SetBlockQueue.setBlock(hpw.worldname, x, y + y, z, 0);
|
|
|
|
}
|
2015-05-01 16:12:27 +02:00
|
|
|
}
|
|
|
|
if (blocks != null) {
|
|
|
|
final HashMap<Short, Byte> datas = hpw.G_SCH_DATA.get(loc);
|
|
|
|
if (datas == null) {
|
|
|
|
for (final Short y : blocks.keySet()) {
|
2015-05-14 16:55:28 +02:00
|
|
|
SetBlockQueue.setBlock(hpw.worldname, x, height + y, z, blocks.get(y));
|
2015-05-01 16:12:27 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (final Short y : blocks.keySet()) {
|
|
|
|
Byte data = datas.get(y);
|
|
|
|
if (data == null) {
|
|
|
|
data = 0;
|
|
|
|
}
|
2015-05-14 16:55:28 +02:00
|
|
|
SetBlockQueue.setBlock(hpw.worldname, x, height + y, z, new PlotBlock(blocks.get(y), data));
|
2015-05-01 16:12:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 15:57:44 +02:00
|
|
|
@Override
|
|
|
|
public boolean createRoadSouth(PlotWorld plotworld, Plot plot) {
|
|
|
|
super.createRoadSouth(plotworld, plot);
|
2015-05-01 16:12:27 +02:00
|
|
|
HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
|
|
|
|
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
PlotId id = plot.id;
|
|
|
|
PlotId id2 = new PlotId(id.x, id.y + 1);
|
|
|
|
Location bot = getPlotBottomLocAbs(hpw, id2);
|
|
|
|
Location top = getPlotTopLocAbs(hpw, id);
|
2015-05-02 13:11:15 +02:00
|
|
|
Location pos1 = new Location(plot.world, bot.getX(), 0, top.getZ() + 1);
|
2015-07-22 18:33:22 +02:00
|
|
|
Location pos2 = new Location(plot.world, top.getX() + 1, 255, bot.getZ());
|
2015-05-14 16:55:28 +02:00
|
|
|
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
|
2015-04-30 15:57:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean createRoadSouthEast(PlotWorld plotworld, Plot plot) {
|
|
|
|
super.createRoadSouthEast(plotworld, plot);
|
2015-05-01 16:12:27 +02:00
|
|
|
HybridPlotWorld hpw = (HybridPlotWorld) plotworld;
|
|
|
|
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
PlotId id = plot.id;
|
|
|
|
PlotId id2 = new PlotId(id.x + 1, id.y + 1);
|
|
|
|
Location pos1 = getPlotTopLocAbs(hpw, id).add(1, 0, 1);
|
|
|
|
Location pos2 = getPlotBottomLocAbs(hpw, id2);
|
|
|
|
pos1.setY(0);
|
|
|
|
pos2.setY(256);
|
2015-05-14 16:55:28 +02:00
|
|
|
createSchemAbs(hpw, pos1, pos2, hpw.ROAD_HEIGHT, true);
|
2015-04-30 15:57:44 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-28 13:02:30 +01:00
|
|
|
/**
|
2015-04-30 06:33:57 +02:00
|
|
|
* Clearing the plot needs to only consider removing the blocks - This implementation has used the setCuboidAsync
|
2014-12-28 13:02:30 +01:00
|
|
|
* function, as it is fast, and uses NMS code - It also makes use of the fact that deleting chunks is a lot faster
|
|
|
|
* than block updates This code is very messy, but you don't need to do something quite as complex unless you happen
|
|
|
|
* to have 512x512 sized plots
|
|
|
|
*/
|
|
|
|
@Override
|
2015-02-21 02:59:28 +01:00
|
|
|
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final boolean isDelete, final Runnable whenDone) {
|
|
|
|
final String world = plotworld.worldname;
|
2015-02-17 12:51:58 +01:00
|
|
|
final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld);
|
2015-07-21 08:03:27 +02:00
|
|
|
|
2015-02-20 12:23:48 +01:00
|
|
|
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.id).add(1, 0, 1);
|
|
|
|
final Location pos2 = MainUtil.getPlotTopLocAbs(world, plot.id);
|
2015-07-25 20:12:35 +02:00
|
|
|
// If augmented
|
2015-07-19 15:12:48 +02:00
|
|
|
final boolean canRegen = plotworld.TYPE == 0 && plotworld.TERRAIN == 0;
|
2015-07-25 20:12:35 +02:00
|
|
|
// The component blocks
|
2014-12-28 13:55:02 +01:00
|
|
|
final PlotBlock[] plotfloor = dpw.TOP_BLOCK;
|
|
|
|
final PlotBlock[] filling = dpw.MAIN_BLOCK;
|
2015-07-18 19:03:59 +02:00
|
|
|
final PlotBlock[] bedrock = (dpw.PLOT_BEDROCK ? new PlotBlock[] { new PlotBlock((short) 7, (byte) 0) } : filling);
|
2015-07-19 15:12:48 +02:00
|
|
|
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
|
|
|
|
|
2015-07-25 20:12:35 +02:00
|
|
|
setWallFilling(dpw, plot.id, new PlotBlock[] { dpw.WALL_FILLING });
|
2015-07-19 15:12:48 +02:00
|
|
|
|
2015-07-25 20:12:35 +02:00
|
|
|
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
2015-07-19 15:12:48 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-07-25 20:12:35 +02:00
|
|
|
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
|
|
|
|
if (canRegen && value[6] == 0) {
|
|
|
|
BukkitUtil.regenerateChunk(world, value[0], value[1]);
|
|
|
|
return;
|
2015-04-30 06:33:57 +02:00
|
|
|
}
|
2015-07-25 20:12:35 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Otherwise we need to set each component, as we don't want to regenerate the road or other plots that share the same chunk //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Set the biome
|
|
|
|
BukkitUtil.setBiome(plot.world, value[2], value[3], value[4], value[5], dpw.PLOT_BIOME);
|
|
|
|
// These two locations are for each component (e.g. bedrock, main block, floor, air)
|
|
|
|
Location bot = new Location(world, value[2], 0, value[3]);
|
|
|
|
Location top = new Location(world, value[4] + 1, 1, value[5] + 1);
|
|
|
|
MainUtil.setCuboidAsync(world, bot, top, bedrock);
|
|
|
|
// Each component has a different layer
|
|
|
|
bot.setY(1);
|
|
|
|
top.setY(dpw.PLOT_HEIGHT);
|
|
|
|
MainUtil.setCuboidAsync(world, bot, top, filling);
|
|
|
|
bot.setY(dpw.PLOT_HEIGHT);
|
|
|
|
top.setY(dpw.PLOT_HEIGHT + 1);
|
|
|
|
MainUtil.setCuboidAsync(world, bot, top, plotfloor);
|
|
|
|
bot.setY(dpw.PLOT_HEIGHT + 1);
|
|
|
|
top.setY(256);
|
|
|
|
MainUtil.setSimpleCuboidAsync(world, bot, top, air);
|
|
|
|
// And finally set the schematic, the y value is unimportant for this function
|
|
|
|
pastePlotSchematic(dpw, bot, top);
|
|
|
|
}
|
|
|
|
}, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
// When we are done with the inside of the plot, we can reset the wall / border
|
|
|
|
final PlotBlock wall = isDelete ? dpw.WALL_BLOCK : dpw.CLAIMED_WALL_BLOCK;
|
|
|
|
setWall(dpw, plot.id, new PlotBlock[] { wall });
|
|
|
|
// And notify whatever called this when plot clearing is done
|
|
|
|
SetBlockQueue.addNotify(whenDone);
|
2014-12-28 13:55:02 +01:00
|
|
|
}
|
2015-07-25 20:12:35 +02:00
|
|
|
}, 5);
|
2014-12-28 13:55:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-05-14 16:55:28 +02:00
|
|
|
|
|
|
|
public void pastePlotSchematic(HybridPlotWorld plotworld, Location l1, Location l2) {
|
|
|
|
if (!plotworld.PLOT_SCHEMATIC) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 08:03:27 +02:00
|
|
|
createSchemAbs(plotworld, l1, l2, plotworld.PLOT_HEIGHT, false);
|
2015-05-14 16:55:28 +02:00
|
|
|
}
|
|
|
|
|
2014-12-28 13:02:30 +01:00
|
|
|
}
|