Merge branch 'master' of github.com:Dinnerbone/Bukkit

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2011-01-01 06:59:52 +00:00
commit d520767525
14 changed files with 112 additions and 99 deletions

View file

@ -3,6 +3,7 @@ package com.dinnerbone.bukkit.sample;
import org.bukkit.Block;
import org.bukkit.BlockFace;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
@ -28,4 +29,13 @@ public class SampleBlockListener extends BlockListener {
}
}
}
@Override
public void onBlockCanBuild(BlockCanBuildEvent event) {
Block block = event.getBlock();
if (block.getType() == 81) {
event.setCancelled(false);
}
}
}

View file

@ -0,0 +1,6 @@
package org.bukkit.event;
public interface Cancellable {
public boolean isCancelled();
public void setCancelled(boolean cancel);
}

View file

@ -76,7 +76,8 @@ public abstract class Event {
/**
* Block Events
*/
BLOCK_DAMAGED (Category.BLOCK),
BLOCK_BROKEN (Category.BLOCK),
BLOCK_CANBUILD (Category.BLOCK),
BLOCK_FLOW (Category.BLOCK),
BLOCK_IGNITE (Category.BLOCK),
BLOCK_PHYSICS (Category.BLOCK),

View file

@ -1,7 +1,8 @@
package org.bukkit.event;
public class EventException extends Exception {
private final Throwable cause;
private static final long serialVersionUID = 3532808232324183999L;
private final Throwable cause;
/**
* Constructs a new EventException based on the given Exception

View file

@ -0,0 +1,39 @@
/**
*
*/
package org.bukkit.event.block;
import org.bukkit.Block;
import org.bukkit.event.Cancellable;
/**
* @author durron597
*/
public class BlockCanBuildEvent extends BlockEvent implements Cancellable {
protected boolean cancel;
public BlockCanBuildEvent(Type type, Block block, boolean canBuild) {
super(type, block);
cancel = canBuild;
}
/**
* Returns whether or not the block can be built here. By default, returns
* Minecraft's answer on whether the block can be built
*
* @return boolean whether or not the block can be built
*/
@Override
public boolean isCancelled() {
return cancel;
}
/**
* Set whether the block can be built here.
*/
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
}

View file

@ -1,85 +0,0 @@
package org.bukkit.event.block;
import java.util.HashSet;
import java.util.List;
import org.bukkit.Block;
import org.bukkit.BlockFace;
import org.bukkit.event.Event;
/**
* Holds information for events with a source block and a destination block
*/
public class BlockFlowEvent extends BlockEvent {
protected final HashSet<BlockFlow> faceList;
public BlockFlowEvent(final Event.Type type, final Block block, BlockFace... faces) {
super(type, block);
this.faceList = new HashSet<BlockFlow>();
if (faces != null && faces.length > 0) {
for (BlockFace theFace : faces) {
faceList.add(new BlockFlow(theFace));
}
}
}
public BlockFlowEvent(final Event.Type type, final Block block, List<BlockFace> faces) {
super(type, block);
this.faceList = new HashSet<BlockFlow>();
if (faces != null && faces.size() > 0) {
for (BlockFace theFace : faces) {
faceList.add(new BlockFlow(theFace));
}
}
}
/**
* We don't want plugins changing the eligible flowing faces
* therefore give them a new HashSet instance
*
* @return Block the block is event originated from
*/
public HashSet<BlockFlow> getFaces() {
return new HashSet<BlockFlow>(faceList);
}
/**
* Class that represents a flow direction and whether it's cancelled
*/
public class BlockFlow {
private final BlockFace flowDirection;
private boolean cancelled;
public BlockFlow(BlockFace flowDirection) {
this.flowDirection = flowDirection;
cancelled = false;
}
public BlockFace getFlowDirection() {
return flowDirection;
}
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof BlockFlow)) return false;
return equals((BlockFlow) o);
}
public boolean equals(BlockFlow flow) {
return flowDirection.equals(flow.flowDirection);
}
@Override
public int hashCode() {
return flowDirection.hashCode();
}
}
}

View file

@ -2,19 +2,22 @@ package org.bukkit.event.block;
import org.bukkit.Block;
import org.bukkit.BlockFace;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
/**
* Holds information for events with a source block and a destination block
*/
public class BlockFromToEvent extends BlockEvent {
public class BlockFromToEvent extends BlockEvent implements Cancellable {
protected Block from;
protected BlockFace face;
protected boolean cancel;
public BlockFromToEvent(final Event.Type type, final Block block, final BlockFace face) {
super(type, block);
this.face = face;
this.from = block.getRelative(face.getModX(), face.getModY(), face.getModZ());
this.cancel = false;
}
/**
@ -34,4 +37,14 @@ public class BlockFromToEvent extends BlockEvent {
public Block getFromBlock() {
return from;
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
}

View file

@ -22,12 +22,18 @@ public class BlockListener implements Listener {
public void onBlockBroken(BlockBrokenEvent event) {
}
/**
* Called when we try to place a block, to see if we can build it
*/
public void onBlockCanBuild(BlockCanBuildEvent event) {
}
/**
* Called when a block flows (water/lava)
*
* @param event Relevant event details
*/
public void onBlockFlow(BlockFlowEvent event) {
public void onBlockFlow(BlockFromToEvent event) {
}
/**

View file

@ -1,19 +1,32 @@
package org.bukkit.event.block;
import org.bukkit.Block;
import org.bukkit.event.Cancellable;
/**
* Not implemented yet
*/
public class BlockPlacedEvent extends BlockEvent {
public class BlockPlacedEvent extends BlockEvent implements Cancellable {
private boolean cancel;
/**
* @param type
* @param theBlock
*/
public BlockPlacedEvent(Type type, Block theBlock) {
super(type, theBlock);
// TODO Auto-generated constructor stub
cancel = false;
}
@Override
public boolean isCancelled() {
// TODO Auto-generated method stub
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
}

View file

@ -2,11 +2,12 @@
package org.bukkit.event.player;
import org.bukkit.Player;
import org.bukkit.event.Cancellable;
/**
* Holds information for player chat and commands
*/
public class PlayerChatEvent extends PlayerEvent {
public class PlayerChatEvent extends PlayerEvent implements Cancellable {
private boolean cancel = false;
private String message;

View file

@ -3,12 +3,13 @@ package org.bukkit.event.player;
import org.bukkit.Location;
import org.bukkit.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
/**
* Holds information for player movement and teleportation events
*/
public class PlayerMoveEvent extends PlayerEvent {
public class PlayerMoveEvent extends PlayerEvent implements Cancellable {
private boolean cancel = false;
private Location from;
private Location to;

View file

@ -5,7 +5,8 @@ package org.bukkit.plugin;
* Thrown when attempting to load an invalid PluginDescriptionFile
*/
public class InvalidDescriptionException extends Exception {
private final Throwable cause;
private static final long serialVersionUID = 5721389122281775894L;
private final Throwable cause;
/**
* Constructs a new InvalidDescriptionException based on the given Exception

View file

@ -5,7 +5,8 @@ package org.bukkit.plugin;
* Thrown when attempting to load an invalid Plugin file
*/
public class InvalidPluginException extends Exception {
private final Throwable cause;
private static final long serialVersionUID = -8242141640709409542L;
private final Throwable cause;
/**
* Constructs a new InvalidPluginException based on the given Exception

View file

@ -14,8 +14,7 @@ import java.util.regex.Pattern;
import org.bukkit.Server;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.*;
import org.bukkit.event.player.*;
import org.bukkit.plugin.*;
@ -112,6 +111,12 @@ public final class JavaPluginLoader implements PluginLoader {
case BLOCK_PHYSICS:
trueListener.onBlockPhysics((BlockPhysicsEvent)event);
break;
case BLOCK_CANBUILD:
trueListener.onBlockCanBuild((BlockCanBuildEvent)event);
break;
case BLOCK_FLOW:
trueListener.onBlockFlow((BlockFromToEvent)event);
break;
}
}
}