Fix teleporting players riding a vehicle.

This commit is contained in:
Tobias Ottenweller 2017-01-01 11:34:33 +01:00
parent 790fd5bccd
commit ed32b23823
3 changed files with 33 additions and 2 deletions

View File

@ -32,6 +32,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -50,6 +51,7 @@ public class Plugin extends JavaPlugin {
private PermissionController permissionController = new PermissionController(); private PermissionController permissionController = new PermissionController();
private PlayerMoveListener moveListener; private PlayerMoveListener moveListener;
private VehicleMoveListener vehicleListener;
private PlayerTeleportListener teleportListener = new PlayerTeleportListener(); private PlayerTeleportListener teleportListener = new PlayerTeleportListener();
private PlayerRespawnListener respawnListener = new PlayerRespawnListener(); private PlayerRespawnListener respawnListener = new PlayerRespawnListener();
private PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener(); private PlayerChangedWorldListener worldChangeListener = new PlayerChangedWorldListener();
@ -59,6 +61,7 @@ public class Plugin extends JavaPlugin {
public Plugin() { public Plugin() {
instance = this; instance = this;
moveListener = new PlayerMoveListener(this); moveListener = new PlayerMoveListener(this);
vehicleListener = new VehicleMoveListener(this);
} }
public static Plugin getPlugin() { public static Plugin getPlugin() {
@ -159,6 +162,7 @@ public class Plugin extends JavaPlugin {
pm.registerEvents(this.respawnListener, this); pm.registerEvents(this.respawnListener, this);
pm.registerEvents(this.worldChangeListener, this); pm.registerEvents(this.worldChangeListener, this);
pm.registerEvents(this.joinListener, this); pm.registerEvents(this.joinListener, this);
pm.registerEvents(this.vehicleListener, this);
if (getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) { if (getConfig().getBoolean(ConfigurationUtil.confCheckForBrokenGateFramesKey)) {
pm.registerEvents(this.blockBreakListener, this); pm.registerEvents(this.blockBreakListener, this);

View File

@ -47,16 +47,16 @@ public class TeleportController {
if (vehicle != null && !gate.getAllowsVehicles()) { if (vehicle != null && !gate.getAllowsVehicles()) {
messageUtil.sendVehicleForbiddenMessage(player); messageUtil.sendVehicleForbiddenMessage(player);
Plugin.log("no vehicle transport");
return; return;
} }
final Location destination = calculateDestination(player, gate); final Location destination = calculateDestination(player, gate);
player.teleport(destination);
if (vehicle != null) { if (vehicle != null) {
vehicle.teleport(destination, PlayerTeleportEvent.TeleportCause.PLUGIN); vehicle.teleport(destination, PlayerTeleportEvent.TeleportCause.PLUGIN);
vehicle.setPassenger(player); vehicle.setPassenger(player);
} else {
player.teleport(destination);
} }
messageUtil.sendTeleportMessage(player); messageUtil.sendTeleportMessage(player);

View File

@ -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());
}
}
}