use of org.bukkit.event.player.PlayerTeleportEvent in project Towny by ElgarL.
the class TownyPlayerListener method onPlayerMove.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
if (plugin.isError()) {
event.setCancelled(true);
return;
}
/*
* Abort if we havn't really moved
*/
if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ() && event.getFrom().getBlockY() == event.getTo().getBlockY()) {
return;
}
Player player = event.getPlayer();
Location to = event.getTo();
Location from;
PlayerCache cache = plugin.getCache(player);
try {
from = cache.getLastLocation();
} catch (NullPointerException e) {
from = event.getFrom();
}
// Prevent fly/double jump cheats
if (!(event instanceof PlayerTeleportEvent)) {
if (TownySettings.isUsingCheatProtection() && (player.getGameMode() != GameMode.CREATIVE) && !TownyUniverse.getPermissionSource().has(player, PermissionNodes.CHEAT_BYPASS.getNode())) {
try {
if (TownyUniverse.getDataSource().getWorld(player.getWorld().getName()).isUsingTowny())
if ((from.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) && (player.getFallDistance() == 0) && (player.getVelocity().getY() <= -0.6) && (player.getLocation().getY() > 0)) {
// plugin.sendErrorMsg(player, "Cheat Detected!");
Location blockLocation = from;
// find the first non air block below us
while ((blockLocation.getBlock().getType() == Material.AIR) && (blockLocation.getY() > 0)) blockLocation.setY(blockLocation.getY() - 1);
// set to 1 block up so we are not sunk in the
// ground
blockLocation.setY(blockLocation.getY() + 1);
// Update the cache for this location (same
// WorldCoord).
cache.setLastLocation(blockLocation);
player.teleport(blockLocation);
return;
}
} catch (NotRegisteredException e1) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured"));
return;
}
}
}
try {
TownyWorld fromWorld = TownyUniverse.getDataSource().getWorld(from.getWorld().getName());
WorldCoord fromCoord = new WorldCoord(fromWorld.getName(), Coord.parseCoord(from));
TownyWorld toWorld = TownyUniverse.getDataSource().getWorld(to.getWorld().getName());
WorldCoord toCoord = new WorldCoord(toWorld.getName(), Coord.parseCoord(to));
if (!fromCoord.equals(toCoord))
onPlayerMoveChunk(player, fromCoord, toCoord, from, to, event);
else {
// plugin.sendDebugMsg(" From: " + fromCoord);
// plugin.sendDebugMsg(" To: " + toCoord);
// plugin.sendDebugMsg(" " + from.toString());
// plugin.sendDebugMsg(" " + to.toString());
}
} catch (NotRegisteredException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage());
}
// Update the cached players current location
cache.setLastLocation(to);
// plugin.updateCache(player);
// plugin.sendDebugMsg("onBlockMove: " + player.getName() + ": ");
// plugin.sendDebugMsg(" " + from.toString());
// plugin.sendDebugMsg(" " + to.toString());
}
use of org.bukkit.event.player.PlayerTeleportEvent in project Denizen-For-Bukkit by DenizenScript.
the class TeleportCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
dLocation location = (dLocation) scriptEntry.getObject("location");
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
// Report to dB
dB.report(scriptEntry, getName(), aH.debugObj("location", location) + aH.debugObj("entities", entities.toString()));
for (dEntity entity : entities) {
// world event and other plugins
if (entity.isSpawned()) {
if (entity.getBukkitEntityType() != EntityType.PLAYER) {
Bukkit.getPluginManager().callEvent(new EntityTeleportEvent(entity.getBukkitEntity(), entity.getLocation(), location));
} else {
Bukkit.getPluginManager().callEvent(new PlayerTeleportEvent((Player) entity.getBukkitEntity(), entity.getLocation(), location));
}
}
entity.spawnAt(location);
}
}
Aggregations