Fixes boats sometimes not detecting the portal before the player detects the portal
This commit is contained in:
		@@ -3,6 +3,7 @@ package net.knarcraft.stargate.listener;
 | 
				
			|||||||
import net.knarcraft.stargate.portal.Portal;
 | 
					import net.knarcraft.stargate.portal.Portal;
 | 
				
			||||||
import net.knarcraft.stargate.portal.PortalHandler;
 | 
					import net.knarcraft.stargate.portal.PortalHandler;
 | 
				
			||||||
import net.knarcraft.stargate.Stargate;
 | 
					import net.knarcraft.stargate.Stargate;
 | 
				
			||||||
 | 
					import net.knarcraft.stargate.utility.EntityHelper;
 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
@@ -29,9 +30,7 @@ public class EntityEventListener implements Listener {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Entity entity = event.getEntity();
 | 
					        Entity entity = event.getEntity();
 | 
				
			||||||
        int entitySize = (int) Math.ceil((float) Math.max(entity.getBoundingBox().getWidthX(),
 | 
					        if (PortalHandler.getByAdjacentEntrance(event.getFrom(), (int) EntityHelper.getEntityMaxSize(entity)) != null) {
 | 
				
			||||||
                entity.getBoundingBox().getWidthZ()));
 | 
					 | 
				
			||||||
        if (PortalHandler.getByAdjacentEntrance(event.getFrom(), entitySize) != null) {
 | 
					 | 
				
			||||||
            event.setCancelled(true);
 | 
					            event.setCancelled(true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ import net.knarcraft.stargate.portal.Portal;
 | 
				
			|||||||
import net.knarcraft.stargate.portal.PortalHandler;
 | 
					import net.knarcraft.stargate.portal.PortalHandler;
 | 
				
			||||||
import net.knarcraft.stargate.Stargate;
 | 
					import net.knarcraft.stargate.Stargate;
 | 
				
			||||||
import net.knarcraft.stargate.utility.EconomyHelper;
 | 
					import net.knarcraft.stargate.utility.EconomyHelper;
 | 
				
			||||||
 | 
					import net.knarcraft.stargate.utility.EntityHelper;
 | 
				
			||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.entity.Vehicle;
 | 
					import org.bukkit.entity.Vehicle;
 | 
				
			||||||
@@ -44,7 +45,13 @@ public class VehicleEventListener implements Listener {
 | 
				
			|||||||
        List<Entity> passengers = event.getVehicle().getPassengers();
 | 
					        List<Entity> passengers = event.getVehicle().getPassengers();
 | 
				
			||||||
        Vehicle vehicle = event.getVehicle();
 | 
					        Vehicle vehicle = event.getVehicle();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Portal entrancePortal = PortalHandler.getByEntrance(event.getTo());
 | 
					        Portal entrancePortal;
 | 
				
			||||||
 | 
					        int entitySize = (int) EntityHelper.getEntityMaxSize(vehicle);
 | 
				
			||||||
 | 
					        if (EntityHelper.getEntityMaxSize(vehicle) > 1) {
 | 
				
			||||||
 | 
					            entrancePortal = PortalHandler.getByAdjacentEntrance(event.getTo(), entitySize - 1);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            entrancePortal = PortalHandler.getByEntrance(event.getTo());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Return if the portal cannot be teleported through
 | 
					        //Return if the portal cannot be teleported through
 | 
				
			||||||
        if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.isBungee()) {
 | 
					        if (entrancePortal == null || !entrancePortal.isOpen() || entrancePortal.isBungee()) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@ import net.knarcraft.stargate.event.StargateCloseEvent;
 | 
				
			|||||||
import net.knarcraft.stargate.event.StargateDeactivateEvent;
 | 
					import net.knarcraft.stargate.event.StargateDeactivateEvent;
 | 
				
			||||||
import net.knarcraft.stargate.event.StargateOpenEvent;
 | 
					import net.knarcraft.stargate.event.StargateOpenEvent;
 | 
				
			||||||
import net.knarcraft.stargate.event.StargatePortalEvent;
 | 
					import net.knarcraft.stargate.event.StargatePortalEvent;
 | 
				
			||||||
 | 
					import net.knarcraft.stargate.utility.EntityHelper;
 | 
				
			||||||
import org.bukkit.Axis;
 | 
					import org.bukkit.Axis;
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.Location;
 | 
					import org.bukkit.Location;
 | 
				
			||||||
@@ -595,8 +596,10 @@ public class Portal {
 | 
				
			|||||||
        if (gate.getLayout().getExit() != null) {
 | 
					        if (gate.getLayout().getExit() != null) {
 | 
				
			||||||
            BlockLocation exit = getBlockAt(gate.getLayout().getExit());
 | 
					            BlockLocation exit = getBlockAt(gate.getLayout().getExit());
 | 
				
			||||||
            int back = (isBackwards()) ? -1 : 1;
 | 
					            int back = (isBackwards()) ? -1 : 1;
 | 
				
			||||||
            double entitySize = Math.ceil((float) Math.max(entity.getBoundingBox().getWidthX(), entity.getBoundingBox().getWidthZ()));
 | 
					            //TODO: Improve positioning to place the entity just far enough from the portal not to suffocate
 | 
				
			||||||
            exitLocation = exit.modRelativeLoc(0D, 0D, entitySize, traveller.getYaw(), traveller.getPitch(), modX * back, 1, modZ * back);
 | 
					            double entitySize = EntityHelper.getEntityMaxSize(entity);
 | 
				
			||||||
 | 
					            exitLocation = exit.modRelativeLoc(0D, 0D, entitySize, traveller.getYaw(),
 | 
				
			||||||
 | 
					                    traveller.getPitch(), modX * back, 1, modZ * back);
 | 
				
			||||||
        } 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());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -588,7 +588,6 @@ public class PortalHandler {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (BlockLocation adjacentPosition : adjacentPositions) {
 | 
					        for (BlockLocation adjacentPosition : adjacentPositions) {
 | 
				
			||||||
            Stargate.debug("getByAdjacentEntrance", "Testing" + adjacentPosition);
 | 
					 | 
				
			||||||
            Portal portal = lookupEntrances.get(adjacentPosition);
 | 
					            Portal portal = lookupEntrances.get(adjacentPosition);
 | 
				
			||||||
            if (portal != null) {
 | 
					            if (portal != null) {
 | 
				
			||||||
                return portal;
 | 
					                return portal;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,7 @@ import java.util.Iterator;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
public class StarGateThread implements Runnable {
 | 
					public class StarGateThread implements Runnable {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
    public void run() {
 | 
					    public void run() {
 | 
				
			||||||
        long time = System.currentTimeMillis() / 1000;
 | 
					        long time = System.currentTimeMillis() / 1000;
 | 
				
			||||||
        // Close open portals
 | 
					        // Close open portals
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					package net.knarcraft.stargate.utility;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This helper class helps with entity properties not immediately available
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public final class EntityHelper {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private EntityHelper() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Gets the max size of an entity along its x and z axis
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * <p>This function gets the ceiling of the max size of an entity, thus calculating the smallest square needed to
 | 
				
			||||||
 | 
					     * contain the entity.</p>
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param entity <p>The entity to get max size for</p>
 | 
				
			||||||
 | 
					     * @return <p></p>
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static double getEntityMaxSize(Entity entity) {
 | 
				
			||||||
 | 
					        return Math.ceil((float) Math.max(entity.getBoundingBox().getWidthX(), entity.getBoundingBox().getWidthZ()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user