/**
* Fire a CoarsePlayerMoveEvent that wraps the given event, only if it crosses
* a block boundary, or the PoseFlags change.
* @param event The movement event to potentially wrap
* @return True if the original event was not cancelled, and a coarse event was fired,
* and that coarse event was cancelled. In this case, the wrapped event won't
* actually be cancelled, but callers should treat it like it is.
*/
private boolean callCoarsePlayerMove(final PlayerMoveEvent event) {
// Don't fire coarse events for teleports that are not "in-game"
// e.g. /jumpto command
if(event instanceof PlayerTeleportEvent) {
PlayerTeleportEvent teleportEvent = (PlayerTeleportEvent) event;
if(teleportEvent.getCause() != TeleportCause.ENDER_PEARL &&
teleportEvent.getCause() != TeleportCause.UNKNOWN) {
return false;
}
}
// If the movement does not cross a block boundary, and no PoseFlags changed, we don't care about it
final EntityLocation from = event.getEntityFrom();
final EntityLocation to = event.getEntityTo();
if(from.position().coarseEquals(to.position()) && from.poseFlags().equals(to.poseFlags())) {
return false;
}
// Remember whether the original event was already cancelled
boolean wasCancelled = event.isCancelled();
CoarsePlayerMoveEvent generalEvent = new CoarsePlayerMoveEvent(event, event.getPlayer(), from, to);
this.eventBus.callEvent(generalEvent);
if(!wasCancelled && generalEvent.isCancelled()) {
// When a coarse event is cancelled, we have our own logic for resetting the
// player's position, so we un-cancel the event and instead modify its
// to location to put the player where we want them.
resetPosition(event);
return true;
} else {
return false;
}
}
PlayerMovementListener.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:ProjectAres
作者:
评论列表
文章目录