Skip to content

Commit

Permalink
Fixed #13 unsafe spawn location bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTuxn committed Sep 24, 2021
1 parent ea6ea65 commit e8f0883
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public static Location getPlotSpawnPoint(Plot plot) {
(double) (PlotManager.getPlotSize(plot) / 2) + 0.5,
-90,
90);
// Set spawn point 3 blocks above the highest center point
spawnLocation.setY(plot.getPlotWorld().getHighestBlockYAt((int) spawnLocation.getX(), (int) spawnLocation.getZ()));
// Set spawn point 1 block above the highest center point
spawnLocation.setY(plot.getPlotWorld().getHighestBlockYAt((int) spawnLocation.getX(), (int) spawnLocation.getZ()) + 1);
return spawnLocation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public AbstractPlotGenerator(@NotNull Plot plot, @NotNull Builder builder) {
this.plot = plot;
this.builder = builder;

CompletableFuture<Boolean> a = configureWorldGeneration(), b = generateWorld(), c = configureWorld(worldManager.getMVWorld(plot.getPlotWorld())),
d = generateOutlines(plot.getOutlinesSchematic()), e = createProtection();
CompletableFuture<Boolean> a = configureWorldGeneration(), b = generateWorld(), c = generateOutlines(plot.getOutlinesSchematic()),
d = configureWorld(worldManager.getMVWorld(plot.getPlotWorld())), e = createProtection();

// TODO: Improve exceptions
CompletableFuture<Void> plotGen = CompletableFuture.allOf(a, b, c, d, e);
Expand Down Expand Up @@ -116,6 +116,35 @@ protected CompletableFuture<Boolean> generateWorld() {
return CompletableFuture.completedFuture(true);
}

/**
* Generates plot schematic and outlines
* @param plotSchematic - schematic file
* @return - true if generation was successful
*/
protected CompletableFuture<Boolean> generateOutlines(File plotSchematic) {
try {
if (plotSchematic != null) {
Vector buildingOutlinesCoordinates = PlotManager.getPlotCenter(plot);

com.sk89q.worldedit.world.World weWorld = new BukkitWorld(plot.getPlotWorld());
Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(plotSchematic)).read(weWorld.getWorldData());
clipboard.setOrigin(clipboard.getOrigin().setY(clipboard.getMinimumPoint().getY())); // Set origin point to the center bottom of the schematic

ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, weWorld.getWorldData());
EditSession editSession = PlotSystem.DependencyManager.getWorldEdit().getEditSessionFactory().getEditSession(weWorld, -1);

Operation operation = clipboardHolder.createPaste(editSession, weWorld.getWorldData()).to(buildingOutlinesCoordinates).ignoreAirBlocks(false).build();
Operations.complete(operation);
editSession.flushQueue();

return CompletableFuture.completedFuture(true);
}
} catch (IOException | WorldEditException ex) {
return CompletableFuture.completedFuture(false);
}
return CompletableFuture.completedFuture(false);
}

/**
* Configures plot world
* @param mvWorld - plot world
Expand All @@ -142,39 +171,11 @@ protected CompletableFuture<Boolean> configureWorld(@NotNull MultiverseWorld mvW
mvWorld.setAllowMonsterSpawn(false);
mvWorld.setAutoLoad(false);
mvWorld.setKeepSpawnInMemory(false);
mvWorld.setSpawnLocation(PlotHandler.getPlotSpawnPoint(getPlot()));

return CompletableFuture.completedFuture(true);
}

/**
* Generates plot schematic and outlines
* @param plotSchematic - schematic file
* @return - true if generation was successful
*/
protected CompletableFuture<Boolean> generateOutlines(File plotSchematic) {
try {
if (plotSchematic != null) {
Vector buildingOutlinesCoordinates = PlotManager.getPlotCenter(plot);

com.sk89q.worldedit.world.World weWorld = new BukkitWorld(plot.getPlotWorld());
Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(new FileInputStream(plotSchematic)).read(weWorld.getWorldData());
clipboard.setOrigin(clipboard.getOrigin().setY(clipboard.getMinimumPoint().getY())); // Set origin point to the center bottom of the schematic

ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, weWorld.getWorldData());
EditSession editSession = PlotSystem.DependencyManager.getWorldEdit().getEditSessionFactory().getEditSession(weWorld, -1);

Operation operation = clipboardHolder.createPaste(editSession, weWorld.getWorldData()).to(buildingOutlinesCoordinates).ignoreAirBlocks(false).build();
Operations.complete(operation);
editSession.flushQueue();

return CompletableFuture.completedFuture(true);
}
} catch (IOException | WorldEditException ex) {
return CompletableFuture.completedFuture(false);
}
return CompletableFuture.completedFuture(false);
}

/**
* Creates plot protection
* @return - true if protection was created successful
Expand Down

0 comments on commit e8f0883

Please sign in to comment.