Fixes some nullpointerexceptions in PlayerEventsListener's onPlayerMove

This commit is contained in:
Kristian Knarvik 2021-02-22 20:23:12 +01:00
parent d26196b8aa
commit 279ea9d8f0

View File

@ -100,19 +100,23 @@ public class PlayerEventsListener implements Listener {
*/
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (event.isCancelled()) {
if (event.isCancelled() || event.getTo() == null) {
return;
}
//Check to see if the player moved to another block
BlockLocation fromLocation = (BlockLocation) event.getFrom();
BlockLocation toLocation = (BlockLocation) event.getTo();
if (toLocation == null || fromLocation.equals(toLocation)) {
BlockLocation fromLocation = new BlockLocation(event.getFrom().getBlock());
BlockLocation toLocation = new BlockLocation(event.getTo().getBlock());
if (fromLocation.equals(toLocation)) {
return;
}
Player player = event.getPlayer();
Portal entrancePortal = PortalHandler.getByEntrance(toLocation);
if (entrancePortal == null) {
return;
}
Portal destination = entrancePortal.getDestination(player);
//Decide if the anything stops the player from teleport