Skip to content

Commit

Permalink
Fire EntityTeleportEvent (fixes part of #922) (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg023 authored and mastercoms committed Jun 7, 2018
1 parent 8058aa7 commit 9554ea6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main/java/net/glowstone/entity/GlowEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.EntityPortalExitEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
Expand Down Expand Up @@ -453,6 +454,15 @@ public Vector getGravityAccel() {
// Internals
@Override
public boolean teleport(Location location) {
if (!(this instanceof GlowPlayer)) {
// TODO: Properly test when Enderman teleportation is implemented.
EntityTeleportEvent event = EventFactory.getInstance().callEvent(
new EntityTeleportEvent(this, getLocation(), location));
if (event.isCancelled()) {
return false;
}
location = event.getTo();
}
checkNotNull(location, "location cannot be null");
checkNotNull(location.getWorld(), "location's world cannot be null");
worldLock.writeLock().lock();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/glowstone/entity/GlowEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public void setUp() throws Exception {
.thenAnswer(RETURN_FIRST_ARG);
oldEventFactory = EventFactory.getInstance();
EventFactory.setInstance(eventFactory);
when(eventFactory.callEvent(any(Event.class))).thenAnswer(RETURN_FIRST_ARG);
if (createEntityInSuperSetUp()) {
entity = entityCreator.apply(location);
}
when(eventFactory.callEvent(any(Event.class))).thenAnswer(RETURN_FIRST_ARG);
when(eventFactory.onEntityDamage(any(EntityDamageEvent.class))).thenAnswer(
RETURN_FIRST_ARG);
inventory = new GlowPlayerInventory(player);
Expand Down

0 comments on commit 9554ea6

Please sign in to comment.