use of pl.themolka.arcade.session.PlayerMoveEvent in project Arcade2 by ShootGame.
the class GeneralListeners method onPlayerMove.
//
// Custom Events
//
/**
* Bukkit's {@link PlayerMoveEvent} is not what we need. We can simply
* cancel the last player movement using the setCanceled(...) method in
* {@link PlayerMoveEvent}.
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerMove(org.bukkit.event.player.PlayerMoveEvent event) {
Game game = this.plugin.getGames().getCurrentGame();
if (game == null) {
return;
}
World fromWorld = event.getFrom().getWorld();
World toWorld = event.getTo().getWorld();
if (fromWorld == null || !fromWorld.equals(toWorld) || !fromWorld.equals(game.getWorld())) {
// We are not interested in such events.
return;
}
GamePlayer player = game.getPlayer(event.getPlayer());
if (player == null) {
return;
}
PlayerMoveEvent wrapper = new PlayerMoveEvent(this.plugin, player, event);
this.plugin.getEventBus().publish(wrapper);
if (wrapper.isCanceled()) {
Location to = event.getFrom().clone();
to.setX(to.getBlockX() + 0.5);
to.setZ(to.getBlockZ() + 0.5);
event.setTo(to);
}
}
Aggregations