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

This commit is contained in:
Kristian Knarvik 2021-11-03 15:55:56 +01:00
parent cab99e11b0
commit e5c1ad1f3a
9 changed files with 142 additions and 13 deletions

View File

@ -302,6 +302,9 @@ gates:
functionality: functionality:
enableBungee - Enable this for BungeeCord support. This allows portals across Bungee servers. enableBungee - Enable this for BungeeCord support. This allows portals across Bungee servers.
handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates. handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates.
handleEmptyVehicles - Whether or not to handle empty vehicles going through gates (chest/hopper/tnt/furnace minecarts included).
handleCreatureTransportation - Whether or not to handle players that transport creatures by sending vehicles (minecarts, boats) through gates.
handleNonPlayerVehicles - Whether or not to handle vehicles with a passenger which is not a player going through gates (pigs, horses, villagers, creepers, etc.). handleCreatureTransportation must be enabled.
handleLeashedCreatures - Whether or not to handle creatures leashed by a player going through gates. Set to false to disallow leashed creatures going through gates. handleLeashedCreatures - Whether or not to handle creatures leashed by a player going through gates. Set to false to disallow leashed creatures going through gates.
economy: economy:
useEconomy - Whether or not to enable Economy using Vault (must have the Vault plugin) useEconomy - Whether or not to enable Economy using Vault (must have the Vault plugin)
@ -369,6 +372,14 @@ bungeeSign=Teleport to
# Changes # Changes
#### \[Version 0.9.0.5] EpicKnarvik97 fork
- Adds an option to stargate functionality to disable all teleportation of creatures
- Adds an option to stargate functionality to disable all teleportation of empty minecarts
- Adds an option to stargate functionality to disable teleportation of creatures if no player is present in the vehicle
- Prevents a player in a vehicle from teleporting without the vehicle if vehicle teleportation is disabled
- Prevents an infinite number of teleportation messages if vehicle teleportation is detected but denied
#### \[Version 0.9.0.4] EpicKnarvik97 fork #### \[Version 0.9.0.4] EpicKnarvik97 fork
- Adds teleportation of leashed creatures. By default, any creature connected to a player by a lead will be teleported - Adds teleportation of leashed creatures. By default, any creature connected to a player by a lead will be teleported

View File

@ -4,7 +4,7 @@
<groupId>net.knarcraft</groupId> <groupId>net.knarcraft</groupId>
<artifactId>Stargate</artifactId> <artifactId>Stargate</artifactId>
<version>0.9.0.4</version> <version>0.9.0.5</version>
<licenses> <licenses>
<license> <license>

View File

@ -13,6 +13,9 @@ public final class StargateGateConfig {
private int maxGatesEachNetwork = 0; private int maxGatesEachNetwork = 0;
private boolean rememberDestination = false; private boolean rememberDestination = false;
private boolean handleVehicles = true; private boolean handleVehicles = true;
private boolean handleEmptyVehicles = true;
private boolean handleCreatureTransportation = true;
private boolean handleNonPlayerVehicles = true;
private boolean handleLeashedCreatures = true; private boolean handleLeashedCreatures = true;
private boolean sortNetworkDestinations = false; private boolean sortNetworkDestinations = false;
private boolean protectEntrance = false; private boolean protectEntrance = false;
@ -77,6 +80,47 @@ public final class StargateGateConfig {
return handleVehicles; 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 * Gets whether leashed creatures should be teleported with a teleporting player
* *
@ -152,6 +196,9 @@ public final class StargateGateConfig {
//Functionality //Functionality
handleVehicles = newConfig.getBoolean("gates.functionality.handleVehicles"); 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"); handleLeashedCreatures = newConfig.getBoolean("gates.functionality.handleLeashedCreatures");
enableBungee = newConfig.getBoolean("gates.functionality.enableBungee"); enableBungee = newConfig.getBoolean("gates.functionality.enableBungee");

View File

@ -90,7 +90,8 @@ public class PlayerEventListener implements Listener {
Entity playerVehicle = player.getVehicle(); Entity playerVehicle = player.getVehicle();
//If the player is in a vehicle, but vehicle handling is disabled, just ignore the player //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); teleportPlayer(playerVehicle, player, entrancePortal, destination, event);
} }
} }

View File

@ -115,10 +115,13 @@ public class VehicleEventListener implements Listener {
} }
} }
//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")); Stargate.getMessageSender().sendSuccessMessage(player, Stargate.getString("teleportMsg"));
new VehicleTeleporter(destinationPortal, vehicle).teleport(entrancePortal);
entrancePortal.getPortalOpener().closePortal(false); entrancePortal.getPortalOpener().closePortal(false);
} }
}
/** /**
* Takes payment from all player passengers * Takes payment from all player passengers

View File

@ -26,8 +26,9 @@ public class EntityTeleporter extends Teleporter {
* Teleports an entity to this teleporter's portal * Teleports an entity to this teleporter's portal
* *
* @param origin <p>The portal the entity is teleporting from</p> * @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 traveller = teleportingEntity.getLocation();
Location exit = getExit(teleportingEntity, traveller); Location exit = getExit(teleportingEntity, traveller);
@ -38,7 +39,7 @@ public class EntityTeleporter extends Teleporter {
if (!origin.equals(portal)) { if (!origin.equals(portal)) {
exit = triggerEntityPortalEvent(origin, exit); exit = triggerEntityPortalEvent(origin, exit);
if (exit == null) { if (exit == null) {
return; return false;
} }
} }
@ -46,6 +47,7 @@ public class EntityTeleporter extends Teleporter {
loadChunks(); loadChunks();
teleportingEntity.teleport(exit); teleportingEntity.teleport(exit);
return true;
} }
/** /**

View File

@ -1,6 +1,7 @@
package net.knarcraft.stargate.portal; package net.knarcraft.stargate.portal;
import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.config.StargateGateConfig;
import net.knarcraft.stargate.utility.DirectionHelper; import net.knarcraft.stargate.utility.DirectionHelper;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -37,9 +38,10 @@ public class VehicleTeleporter extends EntityTeleporter {
* calling this method.</p> * calling this method.</p>
* *
* @param origin <p>The portal the vehicle is teleporting from</p> * @param origin <p>The portal the vehicle is teleporting from</p>
* @return <p>True if the vehicle was teleported. False otherwise</p>
*/ */
@Override @Override
public void teleport(Portal origin) { public boolean teleport(Portal origin) {
Location traveller = teleportingVehicle.getLocation(); Location traveller = teleportingVehicle.getLocation();
Location exit = getExit(teleportingVehicle, traveller); Location exit = getExit(teleportingVehicle, traveller);
@ -59,12 +61,12 @@ public class VehicleTeleporter extends EntityTeleporter {
if (!origin.equals(portal)) { if (!origin.equals(portal)) {
exit = triggerEntityPortalEvent(origin, exit); exit = triggerEntityPortalEvent(origin, exit);
if (exit == null) { if (exit == null) {
return; return false;
} }
} }
//Teleport the vehicle //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 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 newVelocity <p>The velocity to give the vehicle right after teleportation</p>
* @param origin <p>The portal the vehicle teleported from</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 //Load chunks to make sure not to teleport to the void
loadChunks(); loadChunks();
List<Entity> passengers = teleportingVehicle.getPassengers(); List<Entity> passengers = teleportingVehicle.getPassengers();
if (!passengers.isEmpty()) { if (!passengers.isEmpty()) {
//Check if the passengers are allowed according to current config settings
if (!vehiclePassengersAllowed(passengers)) {
return false;
}
if (!(teleportingVehicle instanceof LivingEntity)) { if (!(teleportingVehicle instanceof LivingEntity)) {
//Teleport a normal vehicle with passengers (minecart or boat) //Teleport a normal vehicle with passengers (minecart or boat)
putPassengersInNewVehicle(passengers, exit, newVelocity, origin); putPassengersInNewVehicle(passengers, exit, newVelocity, origin);
@ -88,11 +96,62 @@ public class VehicleTeleporter extends EntityTeleporter {
teleportLivingVehicle(exit, passengers, origin); teleportLivingVehicle(exit, passengers, origin);
} }
} else { } else {
//Check if teleportation of empty vehicles is enabled
if (!Stargate.getGateConfig().handleEmptyVehicles()) {
return false;
}
//Teleport an empty vehicle //Teleport an empty vehicle
teleportingVehicle.teleport(exit); teleportingVehicle.teleport(exit);
scheduler.scheduleSyncDelayedTask(Stargate.getInstance(), scheduler.scheduleSyncDelayedTask(Stargate.getInstance(),
() -> teleportingVehicle.setVelocity(newVelocity), 1); () -> 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;
} }
/** /**

View File

@ -8,7 +8,10 @@
# maxGatesEachNetwork - The maximum number of gates allowed on a network - 0 for unlimited # maxGatesEachNetwork - The maximum number of gates allowed on a network - 0 for unlimited
# language - The language file to load for messages # language - The language file to load for messages
# rememberDestination - Whether to remember the cursor location between uses # rememberDestination - Whether to remember the cursor location between uses
# handleVehicles - Whether to allow vehicles through gates # handleVehicles - Whether to allow vehicles through gates. This overrides other vehicle settings
# handleEmptyVehicles - Whether to allow empty vehicles through gates (chest/hopper/tnt/furnace minecarts included)
# handleCreatureTransportation - Whether to allow players to transport creatures by sending vehicles (minecarts, boats) through gates
# handleNonPlayerVehicles - Whether to allow vehicles with a passenger which is not a player through gates. handleCreatureTransportation must be enabled
# handleLeashedCreatures - Whether to allow creatures lead by a player to teleport with the player # handleLeashedCreatures - Whether to allow creatures lead by a player to teleport with the player
# sortNetworkDestinations - Whether to sort network lists alphabetically # sortNetworkDestinations - Whether to sort network lists alphabetically
# protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material) # protectEntrance - Whether to protect gate entrance material (More resource intensive. Only enable if using destroyable open/closed material)
@ -50,6 +53,9 @@ gates:
functionality: functionality:
enableBungee: false enableBungee: false
handleVehicles: true handleVehicles: true
handleEmptyVehicles: true
handleCreatureTransportation: true
handleNonPlayerVehicles: true
handleLeashedCreatures: true handleLeashedCreatures: true
economy: economy:
useEconomy: false useEconomy: false

View File

@ -1,6 +1,6 @@
name: Stargate name: Stargate
main: net.knarcraft.stargate.Stargate main: net.knarcraft.stargate.Stargate
version: 0.9.0.4 version: 0.9.0.5
description: Stargate mod for Bukkit Revived description: Stargate mod for Bukkit Revived
author: EpicKnarvik97 author: EpicKnarvik97
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ] authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]