Archiviert
13
0

Indicate when a teleport event was triggered by ender pearls or unknown internal teleports

Dieser Commit ist enthalten in:
Nathan Adams 2011-12-04 11:04:14 +00:00
Ursprung 645079be08
Commit 55a532c251
4 geänderte Dateien mit 40 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,8 @@ package net.minecraft.server;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
public class EntityEnderPearl extends EntityProjectile {
public EntityEnderPearl(World world) {
@ -28,23 +30,36 @@ public class EntityEnderPearl extends EntityProjectile {
if (!this.world.isStatic) {
// CraftBukkit start - dupe fix + damage event
boolean damage = false;
boolean teleport = false;
PlayerTeleportEvent teleEvent = null;
if (this.shooter != null) {
if (this.shooter instanceof EntityPlayer) {
damage = ((CraftPlayer)this.shooter.bukkitEntity).isOnline();
CraftPlayer player = (CraftPlayer)this.shooter.bukkitEntity;
teleport = player.isOnline();
if (teleport) {
teleEvent = new PlayerTeleportEvent(player, player.getLocation(), getBukkitEntity().getLocation(), PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
Bukkit.getPluginManager().callEvent(teleEvent);
teleport = !teleEvent.isCancelled();
}
} else {
damage = true;
teleport = true;
}
}
if (damage) {
if (teleport) {
if (this.shooter instanceof EntityPlayer) {
((EntityPlayer)this.shooter).netServerHandler.teleport(teleEvent.getTo());
} else {
this.shooter.a_(this.locX, this.locY, this.locZ);
}
this.shooter.fallDistance = 0.0F;
EntityDamageEvent event = new EntityDamageEvent(getBukkitEntity(), EntityDamageEvent.DamageCause.FALL, 5);
Bukkit.getPluginManager().callEvent(event);
EntityDamageEvent damageEvent = new EntityDamageEvent(getBukkitEntity(), EntityDamageEvent.DamageCause.FALL, 5);
Bukkit.getPluginManager().callEvent(damageEvent);
if (!event.isCancelled()) {
this.shooter.damageEntity(DamageSource.FALL, event.getDamage());
if (!damageEvent.isCancelled()) {
this.shooter.damageEntity(DamageSource.FALL, damageEvent.getDamage());
}
}
// CraftBukkit end

Datei anzeigen

@ -190,7 +190,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
We only do this if the Event was not cancelled. */
if (!to.equals(event.getTo()) && !event.isCancelled()) {
this.player.getBukkitEntity().teleport(event.getTo());
this.player.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
return;
}
@ -204,7 +204,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
}
if (Double.isNaN(packet10flying.x) || Double.isNaN(packet10flying.y) || Double.isNaN(packet10flying.z) || Double.isNaN(packet10flying.stance)) {
player.teleport(player.getWorld().getSpawnLocation());
player.teleport(player.getWorld().getSpawnLocation(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
System.err.println(player.getName() + " was caught trying to crash the server with an invalid position.");
player.kickPlayer("Nope!");
return;
@ -386,7 +386,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
Player player = this.getPlayer();
Location from = player.getLocation();
Location to = new Location(this.getPlayer().getWorld(), d0, d1, d2, f, f1);
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to, PlayerTeleportEvent.TeleportCause.UNKNOWN);
this.server.getPluginManager().callEvent(event);
from = event.getFrom();

Datei anzeigen

@ -15,6 +15,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public abstract class CraftEntity implements org.bukkit.entity.Entity {
private static final Map<String, CraftPlayer> players = new MapMaker().softValues().makeMap();
@ -152,6 +153,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
public boolean teleport(Location location) {
return teleport(this, TeleportCause.PLUGIN);
}
public boolean teleport(Location location, TeleportCause cause) {
entity.world = ((CraftWorld) location.getWorld()).getHandle();
entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
// entity.setLocation() throws no event, and so cannot be cancelled
@ -162,6 +167,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return teleport(destination.getLocation());
}
public boolean teleport(org.bukkit.entity.Entity destination, TeleportCause cause) {
return teleport(destination.getLocation(), cause);
}
public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
@SuppressWarnings("unchecked")
List<Entity> notchEntityList = entity.world.b(entity, entity.boundingBox.b(x, y, z));

Datei anzeigen

@ -86,10 +86,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
@Override
public double getEyeHeight() {
return getEyeHeight(false);
}
@Override
public double getEyeHeight(boolean ignoreSneaking) {
if (ignoreSneaking) {
return 1.62D;
@ -274,7 +276,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
@Override
public boolean teleport(Location location) {
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
if (getHandle().netServerHandler == null) return false;
// From = Players current Location
@ -282,7 +284,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// To = Players new Location if Teleport is Successful
Location to = location;
// Create & Call the Teleport Event.
PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to);
PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to, cause);
server.getPluginManager().callEvent(event);
// Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
if (event.isCancelled() == true) {