mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-29 12:37:37 +01:00
WIP - still need to fix bedrock saving in schem
This commit is contained in:
parent
c430d910b2
commit
35247965fa
@ -179,6 +179,10 @@ public class Clipboard {
|
||||
maxZ = Math.max(maxZ, z);
|
||||
count ++;
|
||||
}
|
||||
if (block.getType().equals(Material.BEDROCK)) {
|
||||
plugin.log("DEBUG: setting bedrock to " + x + "," + y + "," + z);
|
||||
blockConfig.set("bedrock", x + "," + y + "," + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,7 +201,17 @@ public class Clipboard {
|
||||
* @param task - task to run after pasting
|
||||
*/
|
||||
public void paste(World world, Island island, Runnable task) {
|
||||
blockConfig.getConfigurationSection(BLOCK).getKeys(false).forEach(b -> pasteBlock(world, island, island.getCenter(), blockConfig.getConfigurationSection(BLOCK + "." + b)));
|
||||
// Offset due to bedrock
|
||||
Vector off = new Vector(0,0,0);
|
||||
if (blockConfig.contains("bedrock")) {
|
||||
String[] offset = blockConfig.getString("bedrock").split(",");
|
||||
off = new Vector(Integer.valueOf(offset[0]), Integer.valueOf(offset[1]), Integer.valueOf(offset[2]));
|
||||
}
|
||||
// Calculate location for pasting
|
||||
Location loc = island.getCenter().toVector().subtract(off).toLocation(world);
|
||||
// Paste
|
||||
blockConfig.getConfigurationSection(BLOCK).getKeys(false).forEach(b -> pasteBlock(world, island, loc, blockConfig.getConfigurationSection(BLOCK + "." + b)));
|
||||
// Run follow on task if it exists
|
||||
if (task != null) {
|
||||
Bukkit.getScheduler().runTaskLater(plugin, task, 2L);
|
||||
}
|
||||
@ -226,7 +240,13 @@ public class Clipboard {
|
||||
}
|
||||
// Sub in player's name
|
||||
for (int i = 0 ; i < lines.size(); i++) {
|
||||
sign.setLine(i, lines.get(i).replace(TextVariables.NAME, plugin.getPlayers().getName(island.getOwner())));
|
||||
sign.setLine(i, lines
|
||||
.get(i)
|
||||
.replace(TextVariables.NAME,
|
||||
plugin
|
||||
.getPlayers()
|
||||
.getName(island
|
||||
.getOwner())));
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
package us.tastybento.bskyblock.island.builders;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
|
||||
/**
|
||||
* Generates islands
|
||||
*
|
||||
* @author tastybento
|
||||
* @since 1.0
|
||||
*/
|
||||
public class IslandBuilder {
|
||||
|
||||
private Island island;
|
||||
private World world;
|
||||
private Environment type = Environment.NORMAL;
|
||||
private BSkyBlock plugin;
|
||||
private Runnable task;
|
||||
|
||||
public IslandBuilder(BSkyBlock plugin, Island island) {
|
||||
this.plugin = plugin;
|
||||
this.island = island;
|
||||
world = island.getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public IslandBuilder setType(Environment type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The task to run when the island is built
|
||||
* @param task
|
||||
* @return IslandBuilder
|
||||
*/
|
||||
public IslandBuilder run(Runnable task) {
|
||||
this.task = task;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
plugin.log("Pasting island to " + type);
|
||||
// Switch on island type
|
||||
switch (type) {
|
||||
case NETHER:
|
||||
world = Bukkit.getWorld(island.getWorld().getName() + "_nether");
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case THE_END:
|
||||
world = Bukkit.getWorld(island.getWorld().getName() + "_the_end");
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
plugin.getSchemsManager().paste(world, island, task);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -28,18 +28,17 @@ public class SchemsManager {
|
||||
}
|
||||
|
||||
private void copySchems(File schems, World world, String name) {
|
||||
if (!schems.exists()) {
|
||||
if (!schems.mkdirs()) {
|
||||
plugin.logError("Could not make schems folder!");
|
||||
} else {
|
||||
Optional<Addon> addon = plugin.getIWM().getAddon(world);
|
||||
addon.ifPresent(a -> a.saveResource("schems/" + name, false));
|
||||
if (!addon.isPresent()) {
|
||||
plugin.saveResource("schems/" + name, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!schems.exists() && !schems.mkdirs()) {
|
||||
plugin.logError("Could not make schems folder!");
|
||||
return;
|
||||
|
||||
}
|
||||
Optional<Addon> addon = plugin.getIWM().getAddon(world);
|
||||
if (addon.isPresent()) {
|
||||
addon.get().saveResource("schems/" + name + ".schem", false);
|
||||
} else {
|
||||
plugin.saveResource("schems/" + name + ".schem", false);
|
||||
}
|
||||
}
|
||||
|
||||
public Clipboard get(World world) {
|
||||
@ -102,4 +101,14 @@ public class SchemsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste the schem to world for island
|
||||
* @param world
|
||||
* @param island
|
||||
*/
|
||||
public void paste(World world, Island island) {
|
||||
paste(world, island, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.island.builders.IslandBuilder;
|
||||
|
||||
/**
|
||||
* Create and paste a new island
|
||||
@ -122,24 +121,23 @@ public class NewIsland {
|
||||
return;
|
||||
}
|
||||
// Create island
|
||||
new IslandBuilder(plugin, island).setType(Environment.NORMAL).run(() -> {
|
||||
plugin.getSchemsManager().paste(world, island, () -> {
|
||||
// Set initial spawn point if one exists
|
||||
if (island.getSpawnPoint(Environment.NORMAL) != null) {
|
||||
plugin.log("DEBUG: spawn point = " + island.getSpawnPoint(Environment.NORMAL));
|
||||
plugin.getPlayers().setHomeLocation(user, island.getSpawnPoint(Environment.NORMAL), 1);
|
||||
}
|
||||
// Teleport player after this island is built
|
||||
plugin.getIslands().homeTeleport(world, user.getPlayer(), true);
|
||||
}).build();
|
||||
});
|
||||
|
||||
// Make nether island
|
||||
if (plugin.getSettings().isNetherGenerate() && plugin.getSettings().isNetherIslands() && plugin.getIWM().getNetherWorld() != null) {
|
||||
new IslandBuilder(plugin, island).setType(Environment.NETHER).build();
|
||||
plugin.getSchemsManager().paste(plugin.getIWM().getNetherWorld(world), island);
|
||||
}
|
||||
|
||||
// Make end island
|
||||
if (plugin.getSettings().isEndGenerate() && plugin.getSettings().isEndIslands() && plugin.getIWM().getEndWorld() != null) {
|
||||
new IslandBuilder(plugin, island).setType(Environment.THE_END).build();
|
||||
plugin.getSchemsManager().paste(plugin.getIWM().getEndWorld(world), island);
|
||||
}
|
||||
|
||||
// Fire exit event
|
||||
|
Loading…
Reference in New Issue
Block a user