Prevent teleporting while riding a vehicle
The TeleportEvent has been updated to prevent players from teleporting while riding or seated in a vehicle. Instead of dismounting the player and adjusting the destination's coordinates, the request is now simply cancelled and a message is sent to the player, explaining why the teleportation was not completed. This change improves the clarity of the situation for the player and fixed the glitch that lets players teleport into places they shouldn't be.
This commit is contained in:
parent
ef99403c2e
commit
94ec002810
|
|
@ -1,6 +1,5 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
|
@ -15,13 +14,11 @@ public class TeleportEvent implements Listener {
|
|||
* @param event the PlayerTeleportEvent being triggered
|
||||
*/
|
||||
@EventHandler()
|
||||
public void modifyTeleportForMountedPlayers(PlayerTeleportEvent event) {
|
||||
public void preventTeleportForMountedPlayers(PlayerTeleportEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getVehicle() == null)
|
||||
return;
|
||||
player.getVehicle().removePassenger(player);
|
||||
Location eventTo = event.getTo();
|
||||
eventTo.setY(eventTo.getBlockY() + 1);
|
||||
event.setTo(eventTo);
|
||||
event.setCancelled(true);
|
||||
player.sendRichMessage("<red>Teleporting was cancelled. You can not be sitting, or mounted while teleporting.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user