mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-18 08:45:19 +01:00
Players will teleport faster
Players will teleport to a spawn point if it is safe and marked. https://github.com/tastybento/bskyblock/projects/3#card-11060603
This commit is contained in:
parent
9021df099a
commit
a663395a13
@ -36,7 +36,7 @@ public class NetherPortals implements Listener {
|
||||
/**
|
||||
* Function to check proximity to nether or end spawn location.
|
||||
* Used when playing with the standard nether or end.
|
||||
*
|
||||
*
|
||||
* @param location - the location
|
||||
* @return true if in the spawn area, false if not
|
||||
*/
|
||||
@ -45,7 +45,7 @@ public class NetherPortals implements Listener {
|
||||
Vector spawn = location.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1));
|
||||
int radiusSquared = plugin.getIWM().getNetherSpawnRadius(location.getWorld()) ^ 2;
|
||||
return (spawn.distanceSquared(p) < radiusSquared);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the player is not in the standard nether or standard end or op, do nothing.
|
||||
@ -66,7 +66,7 @@ public class NetherPortals implements Listener {
|
||||
|
||||
/**
|
||||
* Prevents blocks from being broken
|
||||
*
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@ -110,17 +110,18 @@ public class NetherPortals implements Listener {
|
||||
if (plugin.getIslands().hasIsland(overWorld, e.getPlayer().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
plugin.getIslands().homeTeleport(overWorld, e.getPlayer());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Going to the end, then go to the same location in the end world
|
||||
if (plugin.getIWM().isEndGenerate(overWorld) && plugin.getIWM().isEndIslands(overWorld)) {
|
||||
World endWorld = plugin.getIWM().getEndWorld(overWorld);
|
||||
// End exists and end islands are being used
|
||||
Location to = plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.THE_END)).orElse(e.getFrom().toVector().toLocation(endWorld));
|
||||
e.setCancelled(true);
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(e.getFrom().toVector().toLocation(endWorld))
|
||||
.location(to)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -128,7 +129,7 @@ public class NetherPortals implements Listener {
|
||||
/**
|
||||
* This handles non-player portal use
|
||||
* Currently disables portal use by entities
|
||||
*
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@ -141,13 +142,13 @@ public class NetherPortals implements Listener {
|
||||
|
||||
/**
|
||||
* Prevent standard nether or end spawns from being blown up
|
||||
*
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public boolean onExplosion(EntityExplodeEvent e) {
|
||||
if (!plugin.getIWM().inWorld(e.getLocation())
|
||||
|| plugin.getIWM().isIslandNether(e.getLocation().getWorld())
|
||||
|| plugin.getIWM().isIslandNether(e.getLocation().getWorld())
|
||||
|| plugin.getIWM().isIslandEnd(e.getLocation().getWorld())) {
|
||||
// Not used in island worlds
|
||||
return false;
|
||||
@ -173,38 +174,39 @@ public class NetherPortals implements Listener {
|
||||
// Get the overworld, which may be the same world
|
||||
World overWorld = Util.getWorld(e.getFrom().getWorld());
|
||||
// If entering a portal in the nether, teleport to portal in overworld if there is one
|
||||
if (e.getFrom().getWorld().getEnvironment().equals(Environment.NETHER)) {
|
||||
if (e.getFrom().getWorld().getEnvironment().equals(Environment.NETHER)) {
|
||||
// If this is from the island nether, then go to the same vector, otherwise try island home location
|
||||
Location to = plugin.getIWM().isNetherIslands(overWorld)
|
||||
? e.getFrom().toVector().toLocation(overWorld)
|
||||
Location to = plugin.getIWM().isNetherIslands(overWorld)
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NORMAL)).orElse(e.getFrom().toVector().toLocation(overWorld))
|
||||
: plugin.getIslands().getIslandLocation(overWorld, e.getPlayer().getUniqueId());
|
||||
e.setCancelled(true);
|
||||
// Else other worlds teleport to the nether
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(to)
|
||||
.portal()
|
||||
.build();
|
||||
return true;
|
||||
|
||||
e.setCancelled(true);
|
||||
// Else other worlds teleport to the nether
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(to)
|
||||
.portal()
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
World nether = plugin.getIWM().getNetherWorld(overWorld);
|
||||
// If this is to island nether, then go to the same vector, otherwise try spawn
|
||||
Location to = (plugin.getIWM().isNetherIslands(overWorld) && plugin.getIWM().isNetherGenerate(overWorld))
|
||||
? e.getFrom().toVector().toLocation(nether)
|
||||
Location to = (plugin.getIWM().isNetherIslands(overWorld) && plugin.getIWM().isNetherGenerate(overWorld))
|
||||
? plugin.getIslands().getIslandAt(e.getFrom()).map(i -> i.getSpawnPoint(Environment.NETHER)).orElse(e.getFrom().toVector().toLocation(nether))
|
||||
: nether.getSpawnLocation();
|
||||
e.setCancelled(true);
|
||||
// Else other worlds teleport to the nether
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(to)
|
||||
.portal()
|
||||
.build();
|
||||
return true;
|
||||
e.setCancelled(true);
|
||||
// Else other worlds teleport to the nether
|
||||
new SafeTeleportBuilder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(to)
|
||||
.portal()
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents placing of blocks at standard nether or end spawns
|
||||
*
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@ -220,7 +222,7 @@ public class NetherPortals implements Listener {
|
||||
|
||||
/**
|
||||
* Converts trees to gravel and glowstone
|
||||
*
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
|
@ -69,6 +69,19 @@ public class SafeSpotTeleport {
|
||||
((Player)entity).setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
// If there is no portal scan required, try the desired location immediately
|
||||
if (plugin.getIslands().isSafeLocation(location)) {
|
||||
if (portal) {
|
||||
// If the desired location is safe, then that's where you'll go if there's no portal
|
||||
bestSpot = location;
|
||||
} else {
|
||||
// If this is not a portal teleport, then go to the safe location immediately
|
||||
entity.teleport(location);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get chunks to scan
|
||||
chunksToScan = getChunksToScan();
|
||||
|
||||
@ -213,8 +226,8 @@ public class SafeSpotTeleport {
|
||||
task.cancel();
|
||||
// Return to main thread and teleport the player
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!portal && entity instanceof Player) {
|
||||
// Set home
|
||||
if (!portal && entity instanceof Player && homeNumber > 0) {
|
||||
// Set home if so marked
|
||||
plugin.getPlayers().setHomeLocation(User.getInstance(entity), loc, homeNumber);
|
||||
}
|
||||
Vector velocity = entity.getVelocity();
|
||||
|
Loading…
Reference in New Issue
Block a user