Added painting events (thanks verrier and tanelsuurhans)

By: Stephen <stephen@jazer.com>
This commit is contained in:
Bukkit/Spigot 2011-04-11 23:06:34 -04:00
parent 314c53177e
commit 08decac14e
8 changed files with 232 additions and 2 deletions

View File

@ -91,7 +91,12 @@ public abstract class Event implements Serializable {
* @see Category.LIVING_ENTITY * @see Category.LIVING_ENTITY
*/ */
PLAYER, PLAYER,
/**
* Represents Entity-based events
*/
ENTITY,
/** /**
* Represents Block-based events * Represents Block-based events
*/ */
@ -500,6 +505,24 @@ public abstract class Event implements Serializable {
*/ */
WORLD_LOAD (Category.WORLD), WORLD_LOAD (Category.WORLD),
/**
* ENTITY EVENTS
*/
/**
* Called when a painting is placed by player
*
* @see org.bukkit.event.painting.PaintingCreateEvent
*/
PAINTING_PLACE (Category.ENTITY),
/**
* Called when a painting is removed
*
* @see org.bukkit.event.painting.PaintingRemoveEvent
*/
PAINTING_BREAK (Category.ENTITY),
/** /**
* LIVING_ENTITY EVENTS * LIVING_ENTITY EVENTS
*/ */

View File

@ -1,6 +1,8 @@
package org.bukkit.event.entity; package org.bukkit.event.entity;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.event.painting.PaintingBreakEvent;
/** /**
* Handles all events fired in relation to entities * Handles all events fired in relation to entities
@ -29,7 +31,13 @@ public class EntityListener implements Listener {
public void onEntityTarget(EntityTargetEvent event) { public void onEntityTarget(EntityTargetEvent event) {
} }
public void onEntityInteract(EntityInteractEvent event) { public void onEntityInteract(EntityInteractEvent event) {
} }
public void onPaintingPlace(PaintingPlaceEvent event){
}
public void onPaintingBreak(PaintingBreakEvent event){
}
} }

View File

@ -0,0 +1,23 @@
package org.bukkit.event.painting;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Painting;
/**
* Triggered when a painting is removed by an entity
*
* @author Tanel Suurhans
*/
public class PaintingBreakByEntityEvent extends PaintingBreakEvent {
private Entity remover;
public PaintingBreakByEntityEvent(final Painting painting, final Entity remover) {
super(painting, RemoveCause.ENTITY);
this.remover = remover;
}
public Entity getRemover() {
return remover;
}
}

View File

@ -0,0 +1,15 @@
package org.bukkit.event.painting;
import org.bukkit.entity.Painting;
/**
* Triggered when a painting is removed by the world (water flowing over it, block damaged behind it)
*
* @author Tanel Suurhans
*/
public class PaintingBreakByWorldEvent extends PaintingBreakEvent{
public PaintingBreakByWorldEvent(final Painting painting) {
super(painting, RemoveCause.WORLD);
}
}

View File

@ -0,0 +1,52 @@
package org.bukkit.event.painting;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Painting;
import org.bukkit.event.Cancellable;
/**
* Triggered when a painting is removed
*
* @author Tanel Suurhans
*/
public class PaintingBreakEvent extends PaintingEvent implements Cancellable {
private boolean cancelled;
private RemoveCause cause;
public PaintingBreakEvent(final Painting painting, RemoveCause cause) {
super(Type.PAINTING_BREAK, painting);
this.cause = cause;
}
public RemoveCause getCause(){
return cause;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
/**
* An enum to specify the cause of the removal
*/
public enum RemoveCause {
/**
* Removed by an entity
*/
ENTITY,
/**
* Removed by the world - block destroyed behind, water flowing over etc
*/
WORLD
}
}

View File

@ -0,0 +1,29 @@
package org.bukkit.event.painting;
import org.bukkit.entity.Painting;
import org.bukkit.event.Event;
/**
* Represents a painting-related event.
*
* @author Tanel Suurhans
*/
public class PaintingEvent extends Event {
protected Painting painting;
protected PaintingEvent(final Type type, final Painting painting) {
super(type);
this.painting = painting;
}
/**
* Get the painting.
*
* @return the painting
*/
public Painting getPainting() {
return painting;
}
}

View File

@ -0,0 +1,65 @@
package org.bukkit.event.painting;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
/**
* Triggered when a painting is created in the world
*
* @author Tanel Suurhans
*/
public class PaintingPlaceEvent extends PaintingEvent implements Cancellable {
private boolean cancelled;
private Player player;
private Block block;
private BlockFace blockFace;
public PaintingPlaceEvent(final Painting painting, final Player player, Block block, BlockFace blockFace) {
super(Event.Type.PAINTING_PLACE, painting);
this.player = player;
this.block = block;
this.blockFace = blockFace;
}
/**
* Returns the player placing the painting
*
* @return Entity returns the player placing the painting
*/
public Player getPlayer() {
return player;
}
/**
* Returns the block painting placed on
*
* @return Block returns the block painting placed on
*/
public Block getBlock() {
return block;
}
/**
* Returns the face of the block that the painting was placed on
*
* @return BlockFace returns the face of the block the painting was placed on
*/
public BlockFace getBlockFace() {
return blockFace;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

View File

@ -19,6 +19,7 @@ import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.*; import org.bukkit.event.block.*;
import org.bukkit.event.painting.*;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import org.bukkit.event.server.*; import org.bukkit.event.server.*;
@ -451,6 +452,20 @@ public final class JavaPluginLoader implements PluginLoader {
} }
}; };
//Painting Events
case PAINTING_PLACE:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((EntityListener) listener).onPaintingPlace((PaintingPlaceEvent) event);
}
};
case PAINTING_BREAK:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((EntityListener) listener).onPaintingBreak((PaintingBreakEvent) event);
}
};
// Entity Events // Entity Events
case ENTITY_DAMAGE: case ENTITY_DAMAGE:
return new EventExecutor() { return new EventExecutor() {