use of com.plotsquared.core.plot.schematic.Schematic in project PlotSquared by IntellectualSites.
the class Load method onCommand.
@Override
public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
final String world = player.getLocation().getWorldName();
if (!this.plotAreaManager.hasPlotArea(world)) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
return false;
}
final Plot plot = player.getCurrentPlot();
if (plot == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
return false;
}
if (!plot.hasOwner()) {
player.sendMessage(TranslatableCaption.of("info.plot_unowned"));
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_COMMAND_LOAD)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false;
}
if (plot.getRunning() > 0) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
return false;
}
try (final MetaDataAccess<List<String>> metaDataAccess = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_SCHEMATICS)) {
if (args.length != 0) {
if (args.length == 1) {
List<String> schematics = metaDataAccess.get().orElse(null);
if (schematics == null) {
// No schematics found:
player.sendMessage(TranslatableCaption.of("web.load_null"), Template.of("command", "/plot load"));
return false;
}
String schematic;
try {
schematic = schematics.get(Integer.parseInt(args[0]) - 1);
} catch (Exception ignored) {
// use /plot load <index>
player.sendMessage(TranslatableCaption.of("invalid.not_valid_number"), Template.of("value", "(1, " + schematics.size() + ')'));
return false;
}
final URL url;
try {
url = new URL(Settings.Web.URL + "saves/" + player.getUUID() + '/' + schematic);
} catch (MalformedURLException e) {
e.printStackTrace();
player.sendMessage(TranslatableCaption.of("web.load_failed"));
return false;
}
plot.addRunning();
player.sendMessage(TranslatableCaption.of("working.generating_component"));
TaskManager.runTaskAsync(() -> {
Schematic taskSchematic = this.schematicHandler.getSchematic(url);
if (taskSchematic == null) {
plot.removeRunning();
player.sendMessage(TranslatableCaption.of("schematics.schematic_invalid"), Template.of("reason", "non-existent or not in gzip format"));
return;
}
PlotArea area = plot.getArea();
this.schematicHandler.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, player, new RunnableVal<>() {
@Override
public void run(Boolean value) {
plot.removeRunning();
if (value) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
} else {
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
}
}
});
});
return true;
}
plot.removeRunning();
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot load <index>"));
return false;
}
// list schematics
List<String> schematics = metaDataAccess.get().orElse(null);
if (schematics == null) {
plot.addRunning();
TaskManager.runTaskAsync(() -> {
List<String> schematics1 = this.schematicHandler.getSaves(player.getUUID());
plot.removeRunning();
if ((schematics1 == null) || schematics1.isEmpty()) {
player.sendMessage(TranslatableCaption.of("web.load_failed"));
return;
}
metaDataAccess.set(schematics1);
displaySaves(player);
});
} else {
displaySaves(player);
}
}
return true;
}
use of com.plotsquared.core.plot.schematic.Schematic in project FastAsyncWorldEdit by IntellectualSites.
the class FaweDelegateSchematicHandler method getSchematic.
public Schematic getSchematic(@Nonnull InputStream is) {
try {
FastSchematicReader schematicReader = new FastSchematicReader(new NBTInputStream(new BufferedInputStream(new GZIPInputStream(new BufferedInputStream(is)))));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e) {
if (e instanceof EOFException) {
e.printStackTrace();
return null;
}
try {
SpongeSchematicReader schematicReader = new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e2) {
if (e2 instanceof EOFException) {
e.printStackTrace();
return null;
}
try {
MCEditSchematicReader schematicReader = new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e3) {
LOGGER.warn("{} | {} : {}", is, is.getClass().getCanonicalName(), e.getMessage());
e.printStackTrace();
}
}
}
return null;
}
use of com.plotsquared.core.plot.schematic.Schematic in project PlotSquared by IntellectualSites.
the class HybridPlotWorld method setupSchematics.
public void setupSchematics() throws SchematicHandler.UnsupportedFormatException {
this.G_SCH = new HashMap<>();
this.G_SCH_B = new HashMap<>();
// directories
if (!(root = FileUtils.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName() + "/" + this.getId())).exists()) {
root = FileUtils.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName());
}
File schematic1File = new File(root, "sideroad.schem");
if (!schematic1File.exists()) {
schematic1File = new File(root, "sideroad.schematic");
}
File schematic2File = new File(root, "intersection.schem");
if (!schematic2File.exists()) {
schematic2File = new File(root, "intersection.schematic");
}
File schematic3File = new File(root, "plot.schem");
if (!schematic3File.exists()) {
schematic3File = new File(root, "plot.schematic");
}
Schematic schematic1 = this.schematicHandler.getSchematic(schematic1File);
Schematic schematic2 = this.schematicHandler.getSchematic(schematic2File);
Schematic schematic3 = this.schematicHandler.getSchematic(schematic3File);
int shift = this.ROAD_WIDTH / 2;
int oddshift = (this.ROAD_WIDTH & 1);
SCHEM_Y = schematicStartHeight();
int plotY = PLOT_HEIGHT - SCHEM_Y;
int minRoadWall = Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT ? Math.min(ROAD_HEIGHT, WALL_HEIGHT) : ROAD_HEIGHT;
int roadY = minRoadWall - SCHEM_Y;
int worldHeight = getMaxGenHeight() - getMinGenHeight() + 1;
// SCHEM_Y should be normalised to the plot "start" height
if (schematic3 != null) {
if (schematic3.getClipboard().getDimensions().getY() == worldHeight) {
SCHEM_Y = plotY = 0;
} else if (!Settings.Schematics.PASTE_ON_TOP) {
SCHEM_Y = plotY = getMinBuildHeight() - getMinGenHeight();
}
}
if (schematic1 != null) {
if (schematic1.getClipboard().getDimensions().getY() == worldHeight) {
SCHEM_Y = roadY = getMinGenHeight();
if (schematic3 != null && schematic3.getClipboard().getDimensions().getY() != worldHeight && !Settings.Schematics.PASTE_ON_TOP) {
plotY = PLOT_HEIGHT;
}
} else if (!Settings.Schematics.PASTE_ROAD_ON_TOP) {
SCHEM_Y = roadY = getMinBuildHeight();
if (schematic3 != null && schematic3.getClipboard().getDimensions().getY() != worldHeight && !Settings.Schematics.PASTE_ON_TOP) {
plotY = PLOT_HEIGHT;
}
}
}
if (schematic3 != null) {
this.PLOT_SCHEMATIC = true;
Clipboard blockArrayClipboard3 = schematic3.getClipboard();
BlockVector3 d3 = blockArrayClipboard3.getDimensions();
short w3 = (short) d3.getX();
short l3 = (short) d3.getZ();
short h3 = (short) d3.getY();
if (w3 > PLOT_WIDTH || h3 > PLOT_WIDTH) {
this.ROAD_SCHEMATIC_ENABLED = true;
}
int centerShiftZ;
if (l3 < this.PLOT_WIDTH) {
centerShiftZ = (this.PLOT_WIDTH - l3) / 2;
} else {
centerShiftZ = (PLOT_WIDTH - l3) / 2;
}
int centerShiftX;
if (w3 < this.PLOT_WIDTH) {
centerShiftX = (this.PLOT_WIDTH - w3) / 2;
} else {
centerShiftX = (PLOT_WIDTH - w3) / 2;
}
BlockVector3 min = blockArrayClipboard3.getMinimumPoint();
for (short x = 0; x < w3; x++) {
for (short z = 0; z < l3; z++) {
for (short y = 0; y < h3; y++) {
BaseBlock id = blockArrayClipboard3.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ()));
if (!id.getBlockType().getMaterial().isAir()) {
addOverlayBlock((short) (x + shift + oddshift + centerShiftX), (short) (y + plotY), (short) (z + shift + oddshift + centerShiftZ), id, false, h3);
}
}
BiomeType biome = blockArrayClipboard3.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ()));
addOverlayBiome((short) (x + shift + oddshift + centerShiftX), (short) (z + shift + oddshift + centerShiftZ), biome);
}
}
if (Settings.DEBUG) {
LOGGER.info("- plot schematic: {}", schematic3File.getPath());
}
}
if ((schematic1 == null && schematic2 == null) || this.ROAD_WIDTH == 0) {
if (Settings.DEBUG) {
LOGGER.info("- schematic: false");
}
return;
}
this.ROAD_SCHEMATIC_ENABLED = true;
// Do not populate road if using schematic population
// TODO: What? this.ROAD_BLOCK = BlockBucket.empty(); // BlockState.getEmptyData(this.ROAD_BLOCK); // BlockUtil.get(this.ROAD_BLOCK.id, (byte) 0);
Clipboard blockArrayClipboard1 = schematic1.getClipboard();
BlockVector3 d1 = blockArrayClipboard1.getDimensions();
short w1 = (short) d1.getX();
short l1 = (short) d1.getZ();
short h1 = (short) d1.getY();
// Workaround for schematic height issue if proper calculation of road schematic height is disabled
if (!Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT) {
h1 += Math.max(ROAD_HEIGHT - WALL_HEIGHT, 0);
}
BlockVector3 min = blockArrayClipboard1.getMinimumPoint();
for (short x = 0; x < w1; x++) {
for (short z = 0; z < l1; z++) {
for (short y = 0; y < h1; y++) {
BaseBlock id = blockArrayClipboard1.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ()));
if (!id.getBlockType().getMaterial().isAir()) {
addOverlayBlock((short) (x - shift), (short) (y + roadY), (short) (z + shift + oddshift), id, false, h1);
addOverlayBlock((short) (z + shift + oddshift), (short) (y + roadY), (short) (shift - x + (oddshift - 1)), id, true, h1);
}
}
BiomeType biome = blockArrayClipboard1.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ()));
addOverlayBiome((short) (x - shift), (short) (z + shift + oddshift), biome);
addOverlayBiome((short) (z + shift + oddshift), (short) (shift - x + (oddshift - 1)), biome);
}
}
Clipboard blockArrayClipboard2 = schematic2.getClipboard();
BlockVector3 d2 = blockArrayClipboard2.getDimensions();
short w2 = (short) d2.getX();
short l2 = (short) d2.getZ();
short h2 = (short) d2.getY();
// Workaround for schematic height issue if proper calculation of road schematic height is disabled
if (!Settings.Schematics.USE_WALL_IN_ROAD_SCHEM_HEIGHT) {
h2 += Math.max(ROAD_HEIGHT - WALL_HEIGHT, 0);
}
min = blockArrayClipboard2.getMinimumPoint();
for (short x = 0; x < w2; x++) {
for (short z = 0; z < l2; z++) {
for (short y = 0; y < h2; y++) {
BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ()));
if (!id.getBlockType().getMaterial().isAir()) {
addOverlayBlock((short) (x - shift), (short) (y + roadY), (short) (z - shift), id, false, h2);
}
}
BiomeType biome = blockArrayClipboard2.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ()));
addOverlayBiome((short) (x - shift), (short) (z - shift), biome);
}
}
}
use of com.plotsquared.core.plot.schematic.Schematic in project PlotSquared by IntellectualSites.
the class Plot method claim.
/**
* Claim the plot
*
* @param player The player to set the owner to
* @param teleport If the player should be teleported
* @param schematic The schematic name to paste on the plot
* @param updateDB If the database should be updated
* @param auto If the plot is being claimed by a /plot auto
* @return success
* @since 6.1.0
*/
public boolean claim(@NonNull final PlotPlayer<?> player, boolean teleport, String schematic, boolean updateDB, boolean auto) {
this.eventDispatcher.callPlotClaimedNotify(this, auto);
if (updateDB) {
if (!this.getPlotModificationManager().create(player.getUUID(), true)) {
LOGGER.error("Player {} attempted to claim plot {}, but the database failed to update", player.getName(), this.getId().toCommaSeparatedString());
return false;
}
} else {
area.addPlot(this);
updateWorldBorder();
}
player.sendMessage(TranslatableCaption.of("working.claimed"), Template.of("plot", this.getId().toString()));
if (teleport) {
if (!auto && Settings.Teleport.ON_CLAIM) {
teleportPlayer(player, TeleportCause.COMMAND_CLAIM, result -> {
});
} else if (auto && Settings.Teleport.ON_AUTO) {
teleportPlayer(player, TeleportCause.COMMAND_AUTO, result -> {
});
}
}
PlotArea plotworld = getArea();
if (plotworld.isSchematicOnClaim()) {
Schematic sch;
try {
if (schematic == null || schematic.isEmpty()) {
sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
} else {
sch = schematicHandler.getSchematic(schematic);
if (sch == null) {
sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
}
}
} catch (SchematicHandler.UnsupportedFormatException e) {
e.printStackTrace();
return true;
}
schematicHandler.paste(sch, this, 0, getArea().getMinBuildHeight(), 0, Settings.Schematics.PASTE_ON_TOP, player, new RunnableVal<>() {
@Override
public void run(Boolean value) {
if (value) {
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
} else {
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
}
}
});
}
plotworld.getPlotManager().claimPlot(this, null);
this.getPlotModificationManager().setSign(player.getName());
return true;
}
use of com.plotsquared.core.plot.schematic.Schematic in project PlotSquared by IntellectualSites.
the class SchematicHandler method getSchematic.
public Schematic getSchematic(@NonNull InputStream is) {
try {
SpongeSchematicReader schematicReader = new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException ignored) {
try {
MCEditSchematicReader schematicReader = new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
Aggregations