Added an EntityCreatePortalEvent

By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2012-01-15 11:58:03 +00:00
parent cff0c0ecc5
commit 77c577bdf8
5 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package org.bukkit;
/**
* Represents various types of portals that can be made in a world.
*/
public enum PortalType {
/**
* This is a Nether portal, made of obsidian.
*/
NETHER,
/**
* This is an Ender portal.
*/
ENDER,
/**
* This is a custom Plugin portal.
*/
CUSTOM;
}

View File

@ -745,6 +745,12 @@ public abstract class Event implements Serializable {
* @see org.bukkit.event.entity.FoodLevelChangeEvent
*/
FOOD_LEVEL_CHANGE(Category.LIVING_ENTITY),
/**
* Called when an entity creates a portal in a world
*
* @see org.bukkit.event.entity.EntityCreatePortalEvent
*/
ENTITY_CREATE_PORTAL(Category.LIVING_ENTITY),
/**
* WEATHER EVENTS

View File

@ -0,0 +1,49 @@
package org.bukkit.event.entity;
import java.util.List;
import org.bukkit.PortalType;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.event.Cancellable;
/**
* Thrown when a Living Entity creates a portal in a world.
*/
public class EntityCreatePortalEvent extends EntityEvent implements Cancellable {
private List<BlockState> blocks;
private boolean cancelled = false;
private PortalType type = PortalType.CUSTOM;
public EntityCreatePortalEvent(Entity what, List<BlockState> blocks, PortalType type) {
super(Type.ENTITY_CREATE_PORTAL, what);
this.blocks = blocks;
this.type = type;
}
/**
* Gets a list of all blocks associated with the portal.
*
* @return List of blocks that will be changed.
*/
public List<BlockState> getBlocks() {
return blocks;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
this.cancelled = true;
}
/**
* Gets the type of portal that is trying to be created.
*
* @return Type of portal.
*/
public PortalType getPortalType() {
return type;
}
}

View File

@ -169,4 +169,11 @@ public class EntityListener implements Listener {
* @param event Relevant event details
*/
public void onItemDespawn(ItemDespawnEvent event) {}
/**
* Called when an entity creates a portal.
*
* @param event Relevant event details
*/
public void onEntityCreatePortalEvent(EntityCreatePortalEvent event) {}
}

View File

@ -763,6 +763,13 @@ public class JavaPluginLoader implements PluginLoader {
}
};
case ENTITY_CREATE_PORTAL:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((EntityListener) listener).onEntityCreatePortalEvent((EntityCreatePortalEvent) event);
}
};
case CREATURE_SPAWN:
return new EventExecutor() {
public void execute(Listener listener, Event event) {