0.9.0.5 - Adds three new options to disable features of vehicle teleportation with more granularity #9
Some checks failed
EpicKnarvik97/Stargate/pipeline/head There was a failure building this commit
Some checks failed
EpicKnarvik97/Stargate/pipeline/head There was a failure building this commit
This commit is contained in:
@ -13,6 +13,9 @@ public final class StargateGateConfig {
|
||||
private int maxGatesEachNetwork = 0;
|
||||
private boolean rememberDestination = false;
|
||||
private boolean handleVehicles = true;
|
||||
private boolean handleEmptyVehicles = true;
|
||||
private boolean handleCreatureTransportation = true;
|
||||
private boolean handleNonPlayerVehicles = true;
|
||||
private boolean handleLeashedCreatures = true;
|
||||
private boolean sortNetworkDestinations = false;
|
||||
private boolean protectEntrance = false;
|
||||
@ -77,6 +80,47 @@ public final class StargateGateConfig {
|
||||
return handleVehicles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether vehicles with no passengers should be handled
|
||||
*
|
||||
* <p>The handle vehicles option overrides this option if disabled. This option allows empty passenger
|
||||
* minecarts/boats, but also chest/tnt/hopper/furnace minecarts to teleport through stargates.</p>
|
||||
*
|
||||
* @return <p>Whether vehicles without passengers should be handled</p>
|
||||
*/
|
||||
public boolean handleEmptyVehicles() {
|
||||
return handleEmptyVehicles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether vehicles containing creatures should be handled
|
||||
*
|
||||
* <p>The handle vehicles option overrides this option if disabled. This option allows creatures (pigs, pandas,
|
||||
* zombies, etc.) to teleport through stargates if in a vehicle.</p>
|
||||
*
|
||||
* @return <p>Whether vehicles with creatures should be handled</p>
|
||||
*/
|
||||
public boolean handleCreatureTransportation() {
|
||||
return handleCreatureTransportation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether vehicles containing a creature, but not a player should be handled
|
||||
*
|
||||
* <p>The handle vehicles option, and the handle creature transportation option, override this option if disabled.
|
||||
* This option allows creatures (pigs, pandas, zombies, etc.) to teleport through stargates if in a vehicle, even
|
||||
* if no player is in the vehicle.
|
||||
* As it is not possible to check if a creature is allowed through a stargate, they will be able to go through
|
||||
* regardless of whether the initiating player is allowed to enter the stargate. Enabling this is necessary to
|
||||
* teleport creatures using minecarts, but only handleCreatureTransportation is required to teleport creatures
|
||||
* using a boat manned by a player.</p>
|
||||
*
|
||||
* @return <p>Whether non-empty vehicles without a player should be handled</p>
|
||||
*/
|
||||
public boolean handleNonPlayerVehicles() {
|
||||
return handleNonPlayerVehicles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether leashed creatures should be teleported with a teleporting player
|
||||
*
|
||||
@ -152,6 +196,9 @@ public final class StargateGateConfig {
|
||||
|
||||
//Functionality
|
||||
handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles");
|
||||
handleEmptyVehicles = newConfig.getBoolean("gates.functionality.handleEmptyVehicles");
|
||||
handleCreatureTransportation = newConfig.getBoolean("gates.functionality.handleCreatureTransportation");
|
||||
handleNonPlayerVehicles = newConfig.getBoolean("gates.functionality.handleNonPlayerVehicles");
|
||||
handleLeashedCreatures = newConfig.getBoolean("gates.functionality.handleLeashedCreatures");
|
||||
enableBungee = newConfig.getBoolean("gates.functionality.enableBungee");
|
||||
|
||||
|
@ -90,7 +90,8 @@ public class PlayerEventListener implements Listener {
|
||||
|
||||
Entity playerVehicle = player.getVehicle();
|
||||
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player
|
||||
if (playerVehicle == null || Stargate.getGateConfig().handleVehicles()) {
|
||||
if (playerVehicle == null || (playerVehicle instanceof LivingEntity &&
|
||||
Stargate.getGateConfig().handleVehicles())) {
|
||||
teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
|
||||
}
|
||||
}
|
||||
|
@ -115,9 +115,12 @@ public class VehicleEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||
new VehicleTeleporter(destinationPortal, vehicle).teleport(entrancePortal);
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
//Teleport the vehicle and inform the user if the vehicle was teleported
|
||||
boolean teleported = new VehicleTeleporter(destinationPortal, vehicle).teleport(entrancePortal);
|
||||
if (teleported) {
|
||||
Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("teleportMsg"));
|
||||
entrancePortal.getPortalOpener().closePortal(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,8 +26,9 @@ public class EntityTeleporter extends Teleporter {
|
||||
* Teleports an entity to this teleporter's portal
|
||||
*
|
||||
* @param origin <p>The portal the entity is teleporting from</p>
|
||||
* @return <p>True if the entity was teleported. False otherwise</p>
|
||||
*/
|
||||
public void teleport(Portal origin) {
|
||||
public boolean teleport(Portal origin) {
|
||||
Location traveller = teleportingEntity.getLocation();
|
||||
Location exit = getExit(teleportingEntity, traveller);
|
||||
|
||||
@ -38,7 +39,7 @@ public class EntityTeleporter extends Teleporter {
|
||||
if (!origin.equals(portal)) {
|
||||
exit = triggerEntityPortalEvent(origin, exit);
|
||||
if (exit == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +47,7 @@ public class EntityTeleporter extends Teleporter {
|
||||
loadChunks();
|
||||
|
||||
teleportingEntity.teleport(exit);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.knarcraft.stargate.portal;
|
||||
|
||||
import net.knarcraft.stargate.Stargate;
|
||||
import net.knarcraft.stargate.config.StargateGateConfig;
|
||||
import net.knarcraft.stargate.utility.DirectionHelper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -37,9 +38,10 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
* calling this method.</p>
|
||||
*
|
||||
* @param origin <p>The portal the vehicle is teleporting from</p>
|
||||
* @return <p>True if the vehicle was teleported. False otherwise</p>
|
||||
*/
|
||||
@Override
|
||||
public void teleport(Portal origin) {
|
||||
public boolean teleport(Portal origin) {
|
||||
Location traveller = teleportingVehicle.getLocation();
|
||||
Location exit = getExit(teleportingVehicle, traveller);
|
||||
|
||||
@ -59,12 +61,12 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
if (!origin.equals(portal)) {
|
||||
exit = triggerEntityPortalEvent(origin, exit);
|
||||
if (exit == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Teleport the vehicle
|
||||
teleportVehicle(exit, newVelocity, origin);
|
||||
return teleportVehicle(exit, newVelocity, origin);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,13 +75,19 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
* @param exit <p>The location the vehicle should be teleported to</p>
|
||||
* @param newVelocity <p>The velocity to give the vehicle right after teleportation</p>
|
||||
* @param origin <p>The portal the vehicle teleported from</p>
|
||||
* @return <p>True if the vehicle was teleported. False otherwise</p>
|
||||
*/
|
||||
private void teleportVehicle(Location exit, Vector newVelocity, Portal origin) {
|
||||
private boolean teleportVehicle(Location exit, Vector newVelocity, Portal origin) {
|
||||
//Load chunks to make sure not to teleport to the void
|
||||
loadChunks();
|
||||
|
||||
List<Entity> passengers = teleportingVehicle.getPassengers();
|
||||
if (!passengers.isEmpty()) {
|
||||
//Check if the passengers are allowed according to current config settings
|
||||
if (!vehiclePassengersAllowed(passengers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(teleportingVehicle instanceof LivingEntity)) {
|
||||
//Teleport a normal vehicle with passengers (minecart or boat)
|
||||
putPassengersInNewVehicle(passengers, exit, newVelocity, origin);
|
||||
@ -88,11 +96,62 @@ public class VehicleTeleporter extends EntityTeleporter {
|
||||
teleportLivingVehicle(exit, passengers, origin);
|
||||
}
|
||||
} else {
|
||||
//Check if teleportation of empty vehicles is enabled
|
||||
if (!Stargate.getGateConfig().handleEmptyVehicles()) {
|
||||
return false;
|
||||
}
|
||||
//Teleport an empty vehicle
|
||||
teleportingVehicle.teleport(exit);
|
||||
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(),
|
||||
() -> teleportingVehicle.setVelocity(newVelocity), 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether current config values allow the teleportation of the given passengers
|
||||
*
|
||||
* @param passengers <p>The passengers to teleport</p>
|
||||
* @return <p>True if the passengers are allowed to teleport</p>
|
||||
*/
|
||||
private boolean vehiclePassengersAllowed(List<Entity> passengers) {
|
||||
StargateGateConfig config = Stargate.getGateConfig();
|
||||
//Don't teleport if the vehicle contains a creature and creature transportation is disabled
|
||||
if (containsNonPlayer(passengers) && !config.handleCreatureTransportation()) {
|
||||
return false;
|
||||
}
|
||||
//Don't teleport if the player does not contain a player and non-player vehicles is disabled
|
||||
return containsPlayer(passengers) || config.handleNonPlayerVehicles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a list of entities contains any non-players
|
||||
*
|
||||
* @param entities <p>The list of entities to check</p>
|
||||
* @return <p>True if at least one entity is not a player</p>
|
||||
*/
|
||||
private boolean containsNonPlayer(List<Entity> entities) {
|
||||
for (Entity entity : entities) {
|
||||
if (!(entity instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a list of entities contains at least one player
|
||||
*
|
||||
* @param entities <p>The list of entities to check</p>
|
||||
* @return <p>True if at least one player is present among the passengers</p>
|
||||
*/
|
||||
private boolean containsPlayer(List<Entity> entities) {
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof Player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user