mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 11:15:24 +01:00
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:
parent
6e3e3561c1
commit
6cd8c70bd4
@ -94,7 +94,7 @@ public class BlueprintPaster {
|
||||
* @param island - island related to this paste
|
||||
* @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;
|
||||
// Offset due to bedrock
|
||||
Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0);
|
||||
|
@ -15,7 +15,9 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.blueprints.Blueprint;
|
||||
import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||
@ -197,15 +199,24 @@ public class PortalTeleportationListener implements Listener {
|
||||
* @param env - NETHER or THE_END
|
||||
*/
|
||||
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
|
||||
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon
|
||||
-> new BlueprintPaster(plugin, plugin.getBlueprintsManager().getBlueprints(addon).get(name),
|
||||
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()));
|
||||
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
|
||||
// Get the default bundle's nether or end blueprint
|
||||
BlueprintBundle bb = plugin.getBlueprintsManager().getDefaultBlueprintBundle(addon);
|
||||
if (bb != null) {
|
||||
Blueprint bp = plugin.getBlueprintsManager().getBlueprints(addon).get(bb.getBlueprint(env));
|
||||
if (bp != null) {
|
||||
new BlueprintPaster(plugin, bp,
|
||||
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?");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +142,19 @@ public class BlueprintsManager {
|
||||
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}.
|
||||
*
|
||||
|
@ -166,7 +166,7 @@ public class PortalTeleportationListenerTest {
|
||||
@Test
|
||||
public void testOnEndIslandPortalNoEndWorldGenerated() {
|
||||
Location from = mock(Location.class);
|
||||
// Teleport from world to nether
|
||||
// Teleport from world to end
|
||||
when(from.getWorld()).thenReturn(world);
|
||||
when(from.toVector()).thenReturn(new Vector(1,2,3));
|
||||
// No end world
|
||||
|
Loading…
Reference in New Issue
Block a user