Fixes some things regarding vehicle teleportation
Adds extra space between the portal and the vehicle if the destination portal is always on Fixes a bug causing vehicles not being detected soon enough Fixes boats facing into the portal rather than out from the portal Fixes boats spawning inside water rather than on top of it if water is in front of a portal
This commit is contained in:
parent
ba64572254
commit
da32cf11d1
@ -30,7 +30,7 @@ public class EntityEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if (PortalHandler.getByAdjacentEntrance(event.getFrom(), (int) EntityHelper.getEntityMaxSize(entity)) != null) {
|
if (PortalHandler.getByAdjacentEntrance(event.getFrom(), EntityHelper.getEntityMaxSizeInt(entity)) != null) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,8 @@ public class PlayerEventsListener implements Listener {
|
|||||||
!(playerVehicle instanceof Boat)) {
|
!(playerVehicle instanceof Boat)) {
|
||||||
Portal destinationPortal = portal.getDestination();
|
Portal destinationPortal = portal.getDestination();
|
||||||
if (destinationPortal != null) {
|
if (destinationPortal != null) {
|
||||||
VehicleEventListener.teleportVehicleAfterPlayer((Vehicle) playerVehicle, destinationPortal, event.getPlayer());
|
VehicleEventListener.teleportVehicleAfterPlayer((Vehicle) playerVehicle, destinationPortal,
|
||||||
|
event.getPlayer(), portal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,10 @@ public class VehicleEventListener implements Listener {
|
|||||||
* @param vehicle <p>The vehicle to teleport</p>
|
* @param vehicle <p>The vehicle to teleport</p>
|
||||||
* @param destinationPortal <p>The portal the player teleported to</p>
|
* @param destinationPortal <p>The portal the player teleported to</p>
|
||||||
* @param player <p>The player who teleported</p>
|
* @param player <p>The player who teleported</p>
|
||||||
|
* @param origin <p>The portal the player entered</p>
|
||||||
*/
|
*/
|
||||||
public static void teleportVehicleAfterPlayer(Vehicle vehicle, Portal destinationPortal, Player player) {
|
public static void teleportVehicleAfterPlayer(Vehicle vehicle, Portal destinationPortal, Player player, Portal origin) {
|
||||||
destinationPortal.teleport(vehicle);
|
destinationPortal.teleport(vehicle, origin);
|
||||||
Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, () -> vehicle.addPassenger(player), 6);
|
Stargate.server.getScheduler().scheduleSyncDelayedTask(Stargate.stargate, () -> vehicle.addPassenger(player), 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ public class VehicleEventListener implements Listener {
|
|||||||
Vehicle vehicle = event.getVehicle();
|
Vehicle vehicle = event.getVehicle();
|
||||||
|
|
||||||
Portal entrancePortal;
|
Portal entrancePortal;
|
||||||
int entitySize = (int) EntityHelper.getEntityMaxSize(vehicle);
|
int entitySize = EntityHelper.getEntityMaxSizeInt(vehicle);
|
||||||
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
|
||||||
entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
|
||||||
} else {
|
} else {
|
||||||
@ -79,7 +80,7 @@ public class VehicleEventListener implements Listener {
|
|||||||
Stargate.log.warning(Stargate.getString("prefox") + "Unable to find portal destination");
|
Stargate.log.warning(Stargate.getString("prefox") + "Unable to find portal destination");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
destinationPortal.teleport(vehicle);
|
destinationPortal.teleport(vehicle, entrancePortal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +119,7 @@ public class VehicleEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
||||||
destinationPortal.teleport(vehicle);
|
destinationPortal.teleport(vehicle, entrancePortal);
|
||||||
entrancePortal.close(false);
|
entrancePortal.close(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -692,11 +692,14 @@ public class Portal {
|
|||||||
* Teleports a vehicle to this portal
|
* Teleports a vehicle to this portal
|
||||||
*
|
*
|
||||||
* @param vehicle <p>The vehicle to teleport</p>
|
* @param vehicle <p>The vehicle to teleport</p>
|
||||||
|
* @param origin <p>The portal the vehicle entered</p>
|
||||||
*/
|
*/
|
||||||
public void teleport(final Vehicle vehicle) {
|
public void teleport(final Vehicle vehicle, Portal origin) {
|
||||||
Location traveller = vehicle.getLocation();
|
Location traveller = vehicle.getLocation();
|
||||||
Location exit = getExit(vehicle, traveller);
|
Location exit = getExit(vehicle, traveller);
|
||||||
|
|
||||||
|
adjustRotation(traveller, exit, origin);
|
||||||
|
|
||||||
double velocity = vehicle.getVelocity().length();
|
double velocity = vehicle.getVelocity().length();
|
||||||
|
|
||||||
// Stop and teleport
|
// Stop and teleport
|
||||||
@ -793,13 +796,12 @@ public class Portal {
|
|||||||
|
|
||||||
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
||||||
if (entitySize > 1) {
|
if (entitySize > 1) {
|
||||||
exitLocation = preventExitSuffocation(relativeExit, exitLocation, entitySize);
|
exitLocation = preventExitSuffocation(relativeExit, exitLocation, entity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Stargate.log.log(Level.WARNING, Stargate.getString("prefix") + "Missing destination point in .gate file " + gate.getFilename());
|
Stargate.log.log(Level.WARNING, Stargate.getString("prefix") + "Missing destination point in .gate file " + gate.getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return adjustExitLocation(traveller, exitLocation);
|
return adjustExitLocation(traveller, exitLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,10 +810,10 @@ public class Portal {
|
|||||||
*
|
*
|
||||||
* @param relativeExit <p>The relative exit defined as the portal's exit</p>
|
* @param relativeExit <p>The relative exit defined as the portal's exit</p>
|
||||||
* @param exitLocation <p>The currently calculated portal exit</p>
|
* @param exitLocation <p>The currently calculated portal exit</p>
|
||||||
* @param entitySize <p>The size of the travelling entity</p>
|
* @param entity <p>The travelling entity</p>
|
||||||
* @return <p>A location which won't suffocate the entity inside the portal</p>
|
* @return <p>A location which won't suffocate the entity inside the portal</p>
|
||||||
*/
|
*/
|
||||||
private Location preventExitSuffocation(RelativeBlockVector relativeExit, Location exitLocation, double entitySize) {
|
private Location preventExitSuffocation(RelativeBlockVector relativeExit, Location exitLocation, Entity entity) {
|
||||||
//Go left to find start of opening
|
//Go left to find start of opening
|
||||||
RelativeBlockVector openingLeft = getPortalExitEdge(relativeExit, -1);
|
RelativeBlockVector openingLeft = getPortalExitEdge(relativeExit, -1);
|
||||||
|
|
||||||
@ -828,8 +830,16 @@ public class Portal {
|
|||||||
newOffset -= 0.5;
|
newOffset -= 0.5;
|
||||||
}
|
}
|
||||||
exitLocation = DirectionHelper.adjustLocation(exitLocation, newOffset, 0, 0, modX, modZ);
|
exitLocation = DirectionHelper.adjustLocation(exitLocation, newOffset, 0, 0, modX, modZ);
|
||||||
if (entitySize > openingWidth) {
|
|
||||||
exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, (entitySize / 2D), modX, modZ);
|
//Move large entities further from the portal, especially if this portal will teleport them at once
|
||||||
|
double entitySize = EntityHelper.getEntityMaxSize(entity);
|
||||||
|
int entityBoxSize = EntityHelper.getEntityMaxSizeInt(entity);
|
||||||
|
if (entitySize > 1) {
|
||||||
|
if (isAlwaysOn()) {
|
||||||
|
exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, (entityBoxSize / 2D), modX, modZ);
|
||||||
|
} else {
|
||||||
|
exitLocation = DirectionHelper.adjustLocation(exitLocation, 0, 0, (entitySize / 2D) - 1, modX, modZ);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return exitLocation;
|
return exitLocation;
|
||||||
@ -869,6 +879,8 @@ public class Portal {
|
|||||||
BlockData blockData = getWorld().getBlockAt(exitLocation).getBlockData();
|
BlockData blockData = getWorld().getBlockAt(exitLocation).getBlockData();
|
||||||
if (blockData instanceof Bisected && ((Bisected) blockData).getHalf() == Bisected.Half.BOTTOM) {
|
if (blockData instanceof Bisected && ((Bisected) blockData).getHalf() == Bisected.Half.BOTTOM) {
|
||||||
exitLocation.add(0, 0.5, 0);
|
exitLocation.add(0, 0.5, 0);
|
||||||
|
} else if (blockData.getMaterial() == Material.WATER) {
|
||||||
|
exitLocation.add(0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
exitLocation.setPitch(traveller.getPitch());
|
exitLocation.setPitch(traveller.getPitch());
|
||||||
|
@ -7,7 +7,11 @@ import org.bukkit.Location;
|
|||||||
/**
|
/**
|
||||||
* This class helps with direction-dependent (modX, modZ) calculations
|
* This class helps with direction-dependent (modX, modZ) calculations
|
||||||
*/
|
*/
|
||||||
public class DirectionHelper {
|
public final class DirectionHelper {
|
||||||
|
|
||||||
|
private DirectionHelper() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the block at a relative block vector location
|
* Gets the block at a relative block vector location
|
||||||
|
@ -18,10 +18,20 @@ public final class EntityHelper {
|
|||||||
* contain the entity.</p>
|
* contain the entity.</p>
|
||||||
*
|
*
|
||||||
* @param entity <p>The entity to get max size for</p>
|
* @param entity <p>The entity to get max size for</p>
|
||||||
* @return <p></p>
|
* @return <p>The max size of the entity</p>
|
||||||
|
*/
|
||||||
|
public static int getEntityMaxSizeInt(Entity entity) {
|
||||||
|
return (int) Math.ceil((float) getEntityMaxSize(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the max size of an entity along its x and z axis
|
||||||
|
*
|
||||||
|
* @param entity <p>The entity to get max size for</p>
|
||||||
|
* @return <p>The max size of the entity</p>
|
||||||
*/
|
*/
|
||||||
public static double getEntityMaxSize(Entity entity) {
|
public static double getEntityMaxSize(Entity entity) {
|
||||||
return Math.ceil((float) Math.max(entity.getBoundingBox().getWidthX(), entity.getBoundingBox().getWidthZ()));
|
return Math.max(entity.getBoundingBox().getWidthX(), entity.getBoundingBox().getWidthZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user