diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 05b5f0e..04116a0 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -32,6 +32,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.event.vehicle.VehicleMoveEvent; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -50,6 +51,7 @@ public class Plugin extends JavaPlugin { private PermissionController permissionController = new PermissionController(); private PlayerMoveListener moveListener; + private VehicleMoveListener vehicleListener; private PlayerTeleportListener teleportListener = new PlayerTeleportListener(); private PlayerRespawnListener respawnListener = new PlayerRespawnListener(); private PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener(); @@ -59,6 +61,7 @@ public class Plugin extends JavaPlugin { public Plugin() { instance = this; moveListener = new PlayerMoveListener(this); + vehicleListener = new VehicleMoveListener(this); } public static Plugin getPlugin() { @@ -159,6 +162,7 @@ public class Plugin extends JavaPlugin { pm.registerEvents(this.respawnListener, this); pm.registerEvents(this.worldChangeListener, this); pm.registerEvents(this.joinListener, this); + pm.registerEvents(this.vehicleListener, this); if (getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) { pm.registerEvents(this.blockBreakListener, this); diff --git a/src/de/craftinc/gates/controllers/TeleportController.java b/src/de/craftinc/gates/controllers/TeleportController.java index 13dbb9c..7b015a7 100644 --- a/src/de/craftinc/gates/controllers/TeleportController.java +++ b/src/de/craftinc/gates/controllers/TeleportController.java @@ -47,16 +47,16 @@ public class TeleportController { if (vehicle != null && !gate.getAllowsVehicles()) { messageUtil.sendVehicleForbiddenMessage(player); + Plugin.log("no vehicle transport"); return; } final Location destination = calculateDestination(player, gate); + player.teleport(destination); if (vehicle != null) { vehicle.teleport(destination, PlayerTeleportEvent.TeleportCause.PLUGIN); vehicle.setPassenger(player); - } else { - player.teleport(destination); } messageUtil.sendTeleportMessage(player); diff --git a/src/de/craftinc/gates/listeners/VehicleMoveListener.java b/src/de/craftinc/gates/listeners/VehicleMoveListener.java new file mode 100644 index 0000000..3c23cee --- /dev/null +++ b/src/de/craftinc/gates/listeners/VehicleMoveListener.java @@ -0,0 +1,27 @@ +package de.craftinc.gates.listeners; + +import de.craftinc.gates.Plugin; +import de.craftinc.gates.controllers.TeleportController; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.vehicle.VehicleMoveEvent; + +public class VehicleMoveListener implements Listener { + private TeleportController teleportController; + + public VehicleMoveListener(Plugin plugin) { + this.teleportController = new TeleportController(plugin); + } + + @EventHandler(priority = EventPriority.NORMAL) + public void onVehicleMove(VehicleMoveEvent event) { + Entity passenger = event.getVehicle().getPassenger(); + + if (passenger instanceof Player) { + teleportController.teleport((Player)passenger, event.getTo()); + } + } +}