use of org.bukkit.event.entity.EntityPortalEnterEvent in project Glowstone by GlowstoneMC.
the class GlowEntity method pulse.
/**
* Called every game cycle. Subclasses should implement this to implement periodic functionality
* e.g. mob AI.
*/
public void pulse() {
if (!isTicking()) {
return;
}
ticksLived++;
if (fireTicks > 0) {
--fireTicks;
}
metadata.setBit(MetadataIndex.STATUS, StatusFlags.ON_FIRE, fireTicks > 0);
// to dislocate.
if (ticksLived % (30 * 20) == 0) {
if (!(this instanceof GlowItemFrame || this instanceof GlowPainting)) {
teleported = true;
}
}
if (this instanceof GlowLivingEntity && !isDead() && ((GlowLivingEntity) this).hasAI()) {
GlowLivingEntity entity = (GlowLivingEntity) this;
entity.getTaskManager().pulse();
}
followLead();
pulsePhysics();
if (hasMoved()) {
Block currentBlock = location.getBlock();
if (currentBlock.getType() == Material.END_PORTAL) {
EventFactory.getInstance().callEvent(new EntityPortalEnterEvent(this, currentBlock.getLocation()));
if (server.getAllowEnd()) {
Location previousLocation = location.clone();
boolean success;
if (getWorld().getEnvironment() == Environment.THE_END) {
success = teleportToSpawn();
} else {
success = teleportToEnd();
}
if (success) {
EntityPortalExitEvent e = EventFactory.getInstance().callEvent(new EntityPortalExitEvent(this, previousLocation, location.clone(), velocity.clone(), new Vector()));
if (!e.getAfter().equals(velocity)) {
setVelocity(e.getAfter());
}
}
}
}
}
if (leashHolderUniqueId != null && ticksLived < 2) {
Optional<GlowEntity> any = world.getEntityManager().getAll().stream().filter(e -> leashHolderUniqueId.equals(e.getUniqueId())).findAny();
if (!any.isPresent()) {
world.dropItemNaturally(location, new ItemStack(Material.LEAD));
}
setLeashHolder(any.orElse(null));
leashHolderUniqueId = null;
}
}
use of org.bukkit.event.entity.EntityPortalEnterEvent in project BKCommonLib by bergerhealer.
the class PortalHandler_1_8 method enable.
@Override
public void enable(CommonPlugin plugin) {
// Cleans up players ignored for a single tick. If something broke, this
// prevents a memory leak.
_ignorePortalEventPlayersCleanup = RunOnceTask.create(plugin, () -> _ignorePortalEventPlayers.clear());
// Listener to disable player portal events pre-emptively while players are viewing credits
// This is required, otherwise other plugins get very confused and teleport players out of the
// credits screen.
plugin.register(new Listener() {
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityPortalEnter(EntityPortalEnterEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (EntityPlayerHandle.fromBukkit(player).isViewingCredits()) {
_ignorePortalEventPlayers.add(player);
_ignorePortalEventPlayersCleanup.start();
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPortalEvent(PlayerPortalEvent event) {
if (_ignorePortalEventPlayers.remove(event.getPlayer())) {
event.setCancelled(true);
}
}
});
}
Aggregations