Pastes default nether or end blueprints if island doesn't exist

Fixes issue where the nether-island or end-island named blueprints were
deleted.

https://github.com/BentoBoxWorld/BentoBox/issues/943
This commit is contained in:
tastybento 2019-09-15 14:10:52 -07:00
parent 6e3e3561c1
commit 6cd8c70bd4
4 changed files with 35 additions and 11 deletions

View File

@ -94,7 +94,7 @@ public class BlueprintPaster {
* @param island - island related to this paste * @param island - island related to this paste
* @param task - task to run after pasting * @param task - task to run after pasting
*/ */
public BlueprintPaster(@NonNull BentoBox plugin, Blueprint bp, World world, Island island, Runnable task) { public BlueprintPaster(@NonNull BentoBox plugin, @NonNull Blueprint bp, World world, Island island, Runnable task) {
this.plugin = plugin; this.plugin = plugin;
// Offset due to bedrock // Offset due to bedrock
Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0); Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0);

View File

@ -15,7 +15,9 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.blueprints.Blueprint;
import world.bentobox.bentobox.blueprints.BlueprintPaster; import world.bentobox.bentobox.blueprints.BlueprintPaster;
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport; import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
@ -197,15 +199,24 @@ public class PortalTeleportationListener implements Listener {
* @param env - NETHER or THE_END * @param env - NETHER or THE_END
*/ */
private void pasteNewIsland(Player player, Location to, Island island, Environment env) { private void pasteNewIsland(Player player, Location to, Island island, Environment env) {
String name = env.equals(Environment.NETHER) ? "nether-island" : "end-island";
// Paste then teleport player // Paste then teleport player
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
-> new BlueprintPaster(plugin, plugin.getBlueprintsManager().getBlueprints(addon).get(name), // Get the default bundle's nether or end blueprint
to.getWorld(), BlueprintBundle bb = plugin.getBlueprintsManager().getDefaultBlueprintBundle(addon);
island, () -> new SafeSpotTeleport.Builder(plugin) if (bb != null) {
.entity(player) Blueprint bp = plugin.getBlueprintsManager().getBlueprints(addon).get(bb.getBlueprint(env));
.location(island.getSpawnPoint(env) == null ? to : island.getSpawnPoint(env)) if (bp != null) {
// No need to use portal because there will be no portal on the other end new BlueprintPaster(plugin, bp,
.build())); to.getWorld(),
island, () -> new SafeSpotTeleport.Builder(plugin)
.entity(player)
.location(island.getSpawnPoint(env) == null ? to : island.getSpawnPoint(env))
// No need to use portal because there will be no portal on the other end
.build());
} else {
plugin.logError("Could not paste default island in nether or end. Is there a nether-island or end-island blueprint?");
}
}
});
} }
} }

View File

@ -142,6 +142,19 @@ public class BlueprintsManager {
return blueprintBundles.get(addon).stream().collect(Collectors.toMap(BlueprintBundle::getUniqueId, b -> b)); return blueprintBundles.get(addon).stream().collect(Collectors.toMap(BlueprintBundle::getUniqueId, b -> b));
} }
/**
* Get the default blueprint bundle for game mode
* @param addon - game mode addon
* @return the default blueprint bundle or null if none
* @since 1.8.0
*/
public BlueprintBundle getDefaultBlueprintBundle(@NonNull GameModeAddon addon) {
if (blueprintBundles.containsKey(addon)) {
return blueprintBundles.get(addon).stream().filter(bb -> bb.getUniqueId().equals(DEFAULT_BUNDLE_NAME)).findFirst().orElse(null);
}
return null;
}
/** /**
* Returns a {@link File} instance of the blueprints folder of this {@link GameModeAddon}. * Returns a {@link File} instance of the blueprints folder of this {@link GameModeAddon}.
* *

View File

@ -166,7 +166,7 @@ public class PortalTeleportationListenerTest {
@Test @Test
public void testOnEndIslandPortalNoEndWorldGenerated() { public void testOnEndIslandPortalNoEndWorldGenerated() {
Location from = mock(Location.class); Location from = mock(Location.class);
// Teleport from world to nether // Teleport from world to end
when(from.getWorld()).thenReturn(world); when(from.getWorld()).thenReturn(world);
when(from.toVector()).thenReturn(new Vector(1,2,3)); when(from.toVector()).thenReturn(new Vector(1,2,3));
// No end world // No end world