diff --git a/README.md b/README.md
index 9be727a..2c36786 100644
--- a/README.md
+++ b/README.md
@@ -302,6 +302,9 @@ gates:
functionality:
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.
+ 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.
economy:
useEconomy - Whether or not to enable Economy using Vault (must have the Vault plugin)
@@ -369,6 +372,14 @@ bungeeSign=Teleport to
# 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
- Adds teleportation of leashed creatures. By default, any creature connected to a player by a lead will be teleported
diff --git a/pom.xml b/pom.xml
index f10ab1c..ab6bb5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
net.knarcraft
Stargate
- 0.9.0.4
+ 0.9.0.5
diff --git a/src/main/java/net/knarcraft/stargate/config/StargateGateConfig.java b/src/main/java/net/knarcraft/stargate/config/StargateGateConfig.java
index f8da09e..be13cdc 100644
--- a/src/main/java/net/knarcraft/stargate/config/StargateGateConfig.java
+++ b/src/main/java/net/knarcraft/stargate/config/StargateGateConfig.java
@@ -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
+ *
+ * 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.
+ *
+ * @return Whether vehicles without passengers should be handled
+ */
+ public boolean handleEmptyVehicles() {
+ return handleEmptyVehicles;
+ }
+
+ /**
+ * Gets whether vehicles containing creatures should be handled
+ *
+ * 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.
+ *
+ * @return Whether vehicles with creatures should be handled
+ */
+ public boolean handleCreatureTransportation() {
+ return handleCreatureTransportation;
+ }
+
+ /**
+ * Gets whether vehicles containing a creature, but not a player should be handled
+ *
+ * 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.
+ *
+ * @return Whether non-empty vehicles without a player should be handled
+ */
+ 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");
diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java
index f428ac2..42bb9ee 100644
--- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java
+++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java
@@ -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);
}
}
diff --git a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java
index 43e7f38..5fb2f3f 100644
--- a/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java
+++ b/src/main/java/net/knarcraft/stargate/listener/VehicleEventListener.java
@@ -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);
+ }
}
/**
diff --git a/src/main/java/net/knarcraft/stargate/portal/EntityTeleporter.java b/src/main/java/net/knarcraft/stargate/portal/EntityTeleporter.java
index c14bce4..ba067a8 100644
--- a/src/main/java/net/knarcraft/stargate/portal/EntityTeleporter.java
+++ b/src/main/java/net/knarcraft/stargate/portal/EntityTeleporter.java
@@ -26,8 +26,9 @@ public class EntityTeleporter extends Teleporter {
* Teleports an entity to this teleporter's portal
*
* @param origin The portal the entity is teleporting from
+ * @return True if the entity was teleported. False otherwise
*/
- 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;
}
/**
diff --git a/src/main/java/net/knarcraft/stargate/portal/VehicleTeleporter.java b/src/main/java/net/knarcraft/stargate/portal/VehicleTeleporter.java
index aee44fc..07ad185 100644
--- a/src/main/java/net/knarcraft/stargate/portal/VehicleTeleporter.java
+++ b/src/main/java/net/knarcraft/stargate/portal/VehicleTeleporter.java
@@ -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.
*
* @param origin The portal the vehicle is teleporting from
+ * @return True if the vehicle was teleported. False otherwise
*/
@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 The location the vehicle should be teleported to
* @param newVelocity The velocity to give the vehicle right after teleportation
* @param origin The portal the vehicle teleported from
+ * @return True if the vehicle was teleported. False otherwise
*/
- 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 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 The passengers to teleport
+ * @return True if the passengers are allowed to teleport
+ */
+ private boolean vehiclePassengersAllowed(List 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 The list of entities to check
+ * @return True if at least one entity is not a player
+ */
+ private boolean containsNonPlayer(List 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 The list of entities to check
+ * @return True if at least one player is present among the passengers
+ */
+ private boolean containsPlayer(List entities) {
+ for (Entity entity : entities) {
+ if (entity instanceof Player) {
+ return true;
+ }
+ }
+ return false;
}
/**
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index c67aa5a..aa6aec7 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -8,7 +8,10 @@
# maxGatesEachNetwork - The maximum number of gates allowed on a network - 0 for unlimited
# language - The language file to load for messages
# 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
# 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)
@@ -50,6 +53,9 @@ gates:
functionality:
enableBungee: false
handleVehicles: true
+ handleEmptyVehicles: true
+ handleCreatureTransportation: true
+ handleNonPlayerVehicles: true
handleLeashedCreatures: true
economy:
useEconomy: false
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 6867590..f4c8259 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
name: Stargate
main: net.knarcraft.stargate.Stargate
-version: 0.9.0.4
+version: 0.9.0.5
description: Stargate mod for Bukkit Revived
author: EpicKnarvik97
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]