mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 13:15:28 +01:00
Creating end/nether islands on first join to dimension
Substitutes for PR #713 because the code did not work. https://github.com/BentoBoxWorld/BentoBox/pull/713 Pastes and teleports to preferred spawn location.
This commit is contained in:
parent
ca8b453e4b
commit
db5bb8ed8b
@ -1,8 +1,11 @@
|
|||||||
package world.bentobox.bentobox.listeners;
|
package world.bentobox.bentobox.listeners;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -15,6 +18,7 @@ import world.bentobox.bentobox.BentoBox;
|
|||||||
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;
|
||||||
import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles teleportation via the Nether/End portals to the Nether and End dimensions of the worlds added by the GameModeAddons.
|
* Handles teleportation via the Nether/End portals to the Nether and End dimensions of the worlds added by the GameModeAddons.
|
||||||
@ -94,32 +98,25 @@ public class PortalTeleportationListener implements Listener {
|
|||||||
|
|
||||||
World endWorld = plugin.getIWM().getEndWorld(overWorld);
|
World endWorld = plugin.getIWM().getEndWorld(overWorld);
|
||||||
// If this is to island End, then go to the same vector, otherwise try spawn
|
// If this is to island End, then go to the same vector, otherwise try spawn
|
||||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
Optional<Island> optionalIsland = plugin.getIslands().getIslandAt(e.getFrom());
|
||||||
|
Location to = optionalIsland.map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
// Check if there is a missing end island
|
||||||
if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld) && plugin.getIWM().getEndWorld(overWorld) != null) {
|
if (plugin.getIWM().isEndGenerate(overWorld)
|
||||||
if (!plugin.getIslands().getIslandAt(e.getFrom()).hasEndIsland()) {
|
&& plugin.getIWM().isEndIslands(overWorld)
|
||||||
//To do, paste the schem/blueprint
|
&& plugin.getIWM().getEndWorld(overWorld) != null
|
||||||
Runnable task = () -> {
|
&& !optionalIsland.map(Island::hasEndIsland).orElse(true)) {
|
||||||
new SafeSpotTeleport.Builder(plugin)
|
// No end island present so paste the default one
|
||||||
.entity(e.getPlayer())
|
pasteNewIsland(e.getPlayer(), to, optionalIsland.get(), Environment.THE_END);
|
||||||
.location(to)
|
return true;
|
||||||
.portal()
|
|
||||||
.build();
|
|
||||||
};
|
|
||||||
plugin.getIWM().getAddon(overWorld).ifPresent(addon
|
|
||||||
-> new BlueprintPaster(plugin, plugin.getBlueprintsManager().getBlueprints(addon).get("end-island"), addon.getEndWorld(), plugin.getIslands().getIslandAt(e.getFrom()).get(), task));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else other worlds teleport to the nether
|
// Else other worlds teleport to the nether
|
||||||
new SafeSpotTeleport.Builder(plugin)
|
new SafeSpotTeleport.Builder(plugin)
|
||||||
.entity(e.getPlayer())
|
.entity(e.getPlayer())
|
||||||
.location(to)
|
.location(to)
|
||||||
.portal()
|
.portal()
|
||||||
.build();
|
.build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +141,6 @@ public class PortalTeleportationListener implements Listener {
|
|||||||
if (fromWorld.getEnvironment() != Environment.NETHER) {
|
if (fromWorld.getEnvironment() != Environment.NETHER) {
|
||||||
// To Standard Nether
|
// To Standard Nether
|
||||||
e.setTo(plugin.getIWM().getNetherWorld(overWorld).getSpawnLocation());
|
e.setTo(plugin.getIWM().getNetherWorld(overWorld).getSpawnLocation());
|
||||||
// e.useTravelAgent(true); - No longer available in 1.14
|
|
||||||
}
|
}
|
||||||
// From standard nether
|
// From standard nether
|
||||||
else {
|
else {
|
||||||
@ -169,34 +165,47 @@ public class PortalTeleportationListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// TO NETHER
|
// TO NETHER
|
||||||
|
|
||||||
World nether = plugin.getIWM().getNetherWorld(overWorld);
|
World nether = plugin.getIWM().getNetherWorld(overWorld);
|
||||||
// If this is to island nether, then go to the same vector, otherwise try spawn
|
// If this is to island nether, then go to the same vector, otherwise try spawn
|
||||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NETHER)).orElse(e.getFrom().toVector().toLocation(nether));
|
Optional<Island> optionalIsland = plugin.getIslands().getIslandAt(e.getFrom());
|
||||||
|
Location to = optionalIsland.map(i -> i.getSpawnPoint(Environment.NETHER)).orElse(e.getFrom().toVector().toLocation(nether));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
// Check if there is an island there or not
|
||||||
if (plugin.getIWM().isNetherGenerate(overWorld) && plugin.getIWM().isNetherIslands(overWorld) && plugin.getIWM().getNetherWorld(overWorld) != null) {
|
if (plugin.getIWM().isNetherGenerate(overWorld)
|
||||||
if (!plugin.getIslands().getIslandAt(e.getFrom()).hasNetherIsland()) {
|
&& plugin.getIWM().isNetherIslands(overWorld)
|
||||||
//To do, paste the schem/blueprint
|
&& plugin.getIWM().getNetherWorld(overWorld) != null
|
||||||
Runnable task = () -> {
|
&& !optionalIsland.map(Island::hasNetherIsland).orElse(true)) {
|
||||||
new SafeSpotTeleport.Builder(plugin)
|
// No nether island present so paste the default one
|
||||||
.entity(e.getPlayer())
|
pasteNewIsland(e.getPlayer(), to, optionalIsland.get(), Environment.NETHER);
|
||||||
.location(to)
|
return true;
|
||||||
.portal()
|
}
|
||||||
.build();
|
|
||||||
};
|
|
||||||
plugin.getIWM().getAddon(overWorld).ifPresent(addon
|
|
||||||
-> new BlueprintPaster(plugin, plugin.getBlueprintsManager().getBlueprints(addon).get("nether-island"), addon.getNetherWorld(), plugin.getIslands().getIslandAt(e.getFrom()).get(), task));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Else other worlds teleport to the nether
|
// Else other worlds teleport to the nether
|
||||||
new SafeSpotTeleport.Builder(plugin)
|
new SafeSpotTeleport.Builder(plugin)
|
||||||
.entity(e.getPlayer())
|
.entity(e.getPlayer())
|
||||||
.location(to)
|
.location(to)
|
||||||
.portal()
|
.portal()
|
||||||
.build();
|
.build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pastes the default nether or end island and teleports the player to the island's spawn point
|
||||||
|
* @param player - player to teleport after pasting
|
||||||
|
* @param to - the fallback location if a spawn point is not part of the blueprint
|
||||||
|
* @param island - the island
|
||||||
|
* @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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user