Splits the preventExitSuffocation method and improves some more comments

This commit is contained in:
Kristian Knarvik 2021-10-29 15:08:44 +02:00
parent 945798916b
commit f52ba79ae9
3 changed files with 40 additions and 20 deletions

View File

@ -223,28 +223,29 @@ public class PortalCreator {
* @return <p>True if the portal is completely valid</p>
*/
private boolean checkIfNewPortalIsValid(int cost, String portalName) {
// Name & Network can be changed in the event, so do these checks here.
//Check if the portal name can fit on the sign with padding (>name<)
if (portal.getName().length() < 1 || portal.getName().length() > 11) {
Stargate.debug("createPortal", "Name length error");
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createNameLength"));
return false;
}
//Don't do network checks for bungee portals
if (portal.getOptions().isBungee()) {
//Check if the bungee portal's name has been duplicated
if (PortalHandler.getBungeePortals().get(portal.getName().toLowerCase()) != null) {
Stargate.debug("createPortal::Bungee", "Gate name duplicate");
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createExists"));
return false;
}
} else {
//Check if the portal name has been duplicated on the network
if (PortalHandler.getByName(portal.getName(), portal.getNetwork()) != null) {
Stargate.debug("createPortal", "Gate name duplicate");
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("createExists"));
return false;
}
//Check if there are too many gates in this network
//Check if the number of portals in the network has been surpassed
List<String> networkList = PortalHandler.getAllPortalNetworks().get(portal.getNetwork().toLowerCase());
int maxGates = Stargate.getGateConfig().maxGatesEachNetwork();
if (maxGates > 0 && networkList != null && networkList.size() >= maxGates) {
@ -254,6 +255,7 @@ public class PortalCreator {
}
if (cost > 0) {
//Deduct the required fee from the player
if (!Stargate.getEconomyConfig().chargePlayerIfNecessary(player, cost)) {
EconomyHelper.sendInsufficientFundsMessage(portalName, player, cost);
Stargate.debug("createPortal", "Insufficient Funds");

View File

@ -267,8 +267,8 @@ public class PortalRegistry {
if (!allPortalNetworks.get(networkName).contains(portalName)) {
allPortalNetworks.get(networkName).add(portalName);
} else {
Stargate.logSevere(String.format("Portal %s was registered twice. Check your portal database for " +
"duplicates.", portal));
Stargate.logSevere(String.format("Portal %s on network %s was registered twice. Check your portal " +
"database for duplicates.", portal.getName(), portal.getNetwork()));
}
}

View File

@ -62,10 +62,11 @@ public abstract class Teleporter {
*/
public Location getExit(Entity entity, Location traveller) {
Location exitLocation = null;
// Check if the gate has an exit block
RelativeBlockVector relativeExit = portal.getGate().getLayout().getExit();
if (relativeExit != null) {
BlockLocation exit = portal.getBlockAt(relativeExit);
//Move one block out to prevent exiting inside the portal
float portalYaw = portal.getYaw();
if (portal.getOptions().isBackwards()) {
portalYaw += 180;
@ -74,6 +75,7 @@ public abstract class Teleporter {
if (entity != null) {
double entitySize = EntityHelper.getEntityMaxSize(entity);
//Prevent exit suffocation for players riding horses or similar
if (entitySize > 1) {
exitLocation = preventExitSuffocation(relativeExit, exitLocation, entity);
}
@ -83,6 +85,7 @@ public abstract class Teleporter {
portal.getGate().getFilename()));
}
//Adjust pitch and height
return adjustExitLocation(traveller, exitLocation);
}
@ -112,25 +115,34 @@ public abstract class Teleporter {
}
exitLocation = DirectionHelper.moveLocation(exitLocation, newOffset, 0, 0, portal.getYaw());
//Move large entities further from the portal, especially if this teleporter's portal will teleport them at once
//Move large entities further from the portal
return moveExitLocationOutwards(exitLocation, entity);
}
/**
* Moves the exit location out from the portal to prevent the entity from entering a teleportation loop
*
* @param exitLocation <p>The current exit location to adjust</p>
* @param entity <p>The entity to adjust the exit location for</p>
* @return <p>The adjusted exit location</p>
*/
private Location moveExitLocationOutwards(Location exitLocation, Entity entity) {
double entitySize = EntityHelper.getEntityMaxSize(entity);
int entityBoxSize = EntityHelper.getEntityMaxSizeInt(entity);
if (entitySize > 1) {
double entityOffset;
if (portal.getOptions().isAlwaysOn()) {
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, (entityBoxSize / 2D),
portal.getYaw());
entityOffset = entityBoxSize / 2D;
} else {
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0,
(entitySize / 2D) - 1, portal.getYaw());
entityOffset = (entitySize / 2D) - 1;
}
//If a horse has a player riding it, the player will spawn inside the roof of a standard portal unless it's
// moved one block out.
if (entity instanceof AbstractHorse) {
entityOffset += 1;
}
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, entityOffset, portal.getYaw());
}
//If a horse has a player riding it, the player will spawn inside the roof of a standard portal unless it's
//moved one block out.
if (entity instanceof AbstractHorse) {
exitLocation = DirectionHelper.moveLocation(exitLocation, 0, 0, 1, portal.getYaw());
}
return exitLocation;
}
@ -143,6 +155,7 @@ public abstract class Teleporter {
*/
private RelativeBlockVector getPortalExitEdge(RelativeBlockVector relativeExit, int direction) {
RelativeBlockVector openingEdge = relativeExit;
do {
RelativeBlockVector possibleOpening = new RelativeBlockVector(openingEdge.getRight() + direction,
openingEdge.getDown(), openingEdge.getOut());
@ -152,11 +165,16 @@ public abstract class Teleporter {
break;
}
} while (true);
return openingEdge;
}
/**
* Adjusts an exit location with rotation and slab height incrementation
* Adjusts an exit location by setting pitch and adjusting height
*
* <p>If the exit location is a slab or water, the exit location will be changed to arrive one block above. The
* slab check is necessary to prevent the player from clipping through the slab and spawning beneath it. The water
* check is necessary when teleporting boats to prevent it from becoming a submarine.</p>
*
* @param traveller <p>The location of the travelling entity</p>
* @param exitLocation <p>The exit location generated</p>
@ -180,8 +198,8 @@ public abstract class Teleporter {
return exitLocation;
} else {
Stargate.logWarning("Unable to generate exit location");
return traveller;
}
return traveller;
}
/**