Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Entity Teleport event. #6530

Merged
15 changes: 15 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
import org.bukkit.event.entity.FireworkExplodeEvent;
Expand Down Expand Up @@ -616,6 +617,20 @@ public Entity get(final EntityTameEvent e) {
}
}, 0);

// EntityTeleportEvent
EventValues.registerEventValue(EntityTeleportEvent.class, Location.class, new Getter<Location, EntityTeleportEvent>() {
@Override
public @Nullable Location get(EntityTeleportEvent event) {
return event.getFrom();
}
}, EventValues.TIME_PAST);
EventValues.registerEventValue(EntityTeleportEvent.class, Location.class, new Getter<Location, EntityTeleportEvent>() {
@Override
public @Nullable Location get(EntityTeleportEvent event) {
return event.getTo();
}
}, EventValues.TIME_FUTURE);
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved

// EntityChangeBlockEvent
EventValues.registerEventValue(EntityChangeBlockEvent.class, Block.class, new Getter<Block, EntityChangeBlockEvent>() {
@Override
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/ch/njol/skript/events/EvtEntityTeleport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.events;

import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.entity.EntityType;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityTeleportEvent;

import javax.annotation.Nullable;

public class EvtEntityTeleport extends SkriptEvent {
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved

static {
Skript.registerEvent("Entity Teleport", EvtEntityTeleport.class, EntityTeleportEvent.class, "[any] entity teleport[ing] [of %entitytypes%]")
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
.description("Called whenever a non-player entity is teleported, this event may also be called due to a result of natural causes, such as an Enderman or Shulker teleporting, or Wolfs teleporting to players.")
.examples("on entity teleport:", "on entity teleport of creeper:")
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
.since("VERSION");
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
}

@SuppressWarnings("unchecked")
private Expression<EntityType> entities;;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Expression<EntityType> entities;;
private Expression<EntityType> entities;


@Override
public boolean init(Literal<?>[] args, int matchedPattern, SkriptParser.ParseResult parseResult) {
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
if (args.length > 0 && args[0] != null) {
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
entities = (Expression<EntityType>) args[0];
}
return true;
}


@Override
public boolean check(Event e) {
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
if (e instanceof EntityTeleportEvent) {
EntityTeleportEvent event = (EntityTeleportEvent) e;
Entity entity = event.getEntity();
if (entities != null) {
for (EntityType entType : entities.getArray(e)) {
if (entType.isInstance(entity)) {
return true;
}
}
} else {
return true;
}
}
return false;
}


@Override
public String toString(@Nullable Event e, boolean debug) {
return "on any entity teleport";
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
}
}
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
Loading