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

By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
Bukkit/Spigot 2011-01-04 23:32:38 +00:00
commit f7d795843a
11 changed files with 400 additions and 170 deletions

View file

@ -20,4 +20,10 @@ public interface Chunk {
*/ */
int getZ(); int getZ();
/**
* Gets the world containing this chunk
*
* @return Parent World
*/
World getWorld();
} }

View file

@ -7,6 +7,7 @@ package org.bukkit;
public class ItemStack { public class ItemStack {
private int type; private int type;
private int amount = 0; private int amount = 0;
private byte damage = 0;
public ItemStack(final int type) { public ItemStack(final int type) {
this.type = type; this.type = type;
@ -25,6 +26,16 @@ public class ItemStack {
this(type.getID(), amount); this(type.getID(), amount);
} }
public ItemStack(final int type, final int amount, final byte damage) {
this.type = type;
this.amount = amount;
this.damage = damage;
}
public ItemStack(final Material type, final int amount, final byte damage) {
this(type.getID(), amount, damage);
}
/** /**
* Gets the type of this item * Gets the type of this item
* *
@ -78,4 +89,30 @@ public class ItemStack {
public void setAmount(int amount) { public void setAmount(int amount) {
this.amount = amount; this.amount = amount;
} }
/**
* Sets the damage of this item<br /><br />
*
* 0x00 represents an item which cannot be damaged<br />
* 0x01 represents an item at maximum health<br />
* 0x32 represents an item with no health left
*
* @param damage Damage of this item
*/
public void setDamage(final byte damage) {
this.damage = damage;
}
/**
* Gets the damage of this item<br /><br />
*
* 0x00 represents an item which cannot be damaged<br />
* 0x01 represents an item at maximum health<br />
* 0x32 represents an item with no health left
*
* @return Damage of this item
*/
public byte getDamage() {
return damage;
}
} }

View file

@ -217,9 +217,9 @@ public abstract class Event {
BLOCK_PLACED (Category.BLOCK), BLOCK_PLACED (Category.BLOCK),
/** /**
* Called when a specific block is being sent to a player * Called when leaves are decaying naturally
*/ */
BLOCK_SENT (Category.BLOCK), LEAVES_DECAY (Category.BLOCK),
/** /**
* Called when a liquid attempts to flow into a block which already * Called when a liquid attempts to flow into a block which already

View file

@ -78,4 +78,12 @@ public class BlockListener implements Listener {
public void onBlockRightClicked(BlockRightClickedEvent event) { public void onBlockRightClicked(BlockRightClickedEvent event) {
} }
/**
* Called when leaves are decaying naturally
*
* @param event Relevant event details
*/
public void onLeavesDecay(LeavesDecayEvent event) {
}
} }

View file

@ -11,24 +11,36 @@ public class BlockPlacedEvent extends BlockEvent implements Cancellable {
private boolean cancel; private boolean cancel;
private Player player; private Player player;
/**
* @param type
* @param theBlock
*/
public BlockPlacedEvent(Type type, Block theBlock) { public BlockPlacedEvent(Type type, Block theBlock) {
super(type, theBlock); super(type, theBlock);
cancel = false; cancel = false;
} }
/**
* Gets the player who placed this block
*
* @return Player who placed the block
*/
public Player getPlayer() { public Player getPlayer() {
return player; return player;
} }
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() { public boolean isCancelled() {
// TODO Auto-generated method stub
return cancel; return cancel;
} }
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) { public void setCancelled(boolean cancel) {
this.cancel = cancel; this.cancel = cancel;
} }

View file

@ -0,0 +1,36 @@
package org.bukkit.event.block;
import org.bukkit.Block;
import org.bukkit.event.Cancellable;
/**
* Called on leaves decaying
*/
public class LeavesDecayEvent extends BlockEvent implements Cancellable {
private boolean cancel = false;
public LeavesDecayEvent(final Type type, final Block block) {
super(type, block);
}
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() {
return cancel;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
}

View file

@ -0,0 +1,26 @@
package org.bukkit.event.world;
import org.bukkit.Chunk;
/**
* Called when a chunk is loaded
*/
public class ChunkLoadedEvent extends WorldEvent {
private final Chunk chunk;
public ChunkLoadedEvent(final Type type, final Chunk chunk) {
super(type, chunk.getWorld());
this.chunk = chunk;
}
/**
* Gets the chunk being loaded/unloaded
*
* @return Chunk that triggered this event
*/
public Chunk getChunk() {
return chunk;
}
}

View file

@ -0,0 +1,36 @@
package org.bukkit.event.world;
import org.bukkit.Chunk;
import org.bukkit.event.Cancellable;
/**
* Called when a chunk is unloaded
*/
public class ChunkUnloadedEvent extends ChunkLoadedEvent implements Cancellable {
private boolean cancel = false;
public ChunkUnloadedEvent(final Type type, final Chunk chunk) {
super(type, chunk);
}
/**
* Gets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @return true if this event is cancelled
*/
public boolean isCancelled() {
return cancel;
}
/**
* Sets the cancellation state of this event. A cancelled event will not
* be executed in the server, but will still pass to other plugins
*
* @param cancel true if you wish to cancel this event
*/
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
}

View file

@ -0,0 +1,27 @@
package org.bukkit.event.world;
import org.bukkit.World;
import org.bukkit.event.Event;
/**
* Represents events within a world
*/
public class WorldEvent extends Event {
private final World world;
public WorldEvent(final Type type, final World world) {
super(type);
this.world = world;
}
/**
* Gets the world primarily involved with this event
*
* @return World which caused this event
*/
public World getWorld() {
return world;
}
}

View file

@ -0,0 +1,25 @@
package org.bukkit.event.world;
import org.bukkit.event.Listener;
/**
* Handles all World related events
*/
public class WorldListener implements Listener {
/**
* Called when a chunk is loaded
*
* @param event Relevant event details
*/
public void onChunkLoaded(ChunkLoadedEvent event) {
}
/**
* Called when a chunk is unloaded
*
* @param event Relevant event details
*/
public void onChunkUnloaded(ChunkUnloadedEvent event) {
}
}

View file

@ -23,6 +23,9 @@ import org.bukkit.event.player.*;
import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.PluginEvent;
import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.ServerListener;
import org.bukkit.event.vehicle.*; import org.bukkit.event.vehicle.*;
import org.bukkit.event.world.ChunkLoadedEvent;
import org.bukkit.event.world.ChunkUnloadedEvent;
import org.bukkit.event.world.WorldListener;
import org.bukkit.plugin.*; import org.bukkit.plugin.*;
/** /**
@ -124,6 +127,9 @@ public final class JavaPluginLoader implements PluginLoader {
case BLOCK_FLOW: case BLOCK_FLOW:
trueListener.onBlockFlow((BlockFromToEvent)event); trueListener.onBlockFlow((BlockFromToEvent)event);
break; break;
case LEAVES_DECAY:
trueListener.onLeavesDecay((LeavesDecayEvent)event);
break;
} }
} else if(listener instanceof ServerListener) { } else if(listener instanceof ServerListener) {
ServerListener trueListener = (ServerListener)listener; ServerListener trueListener = (ServerListener)listener;
@ -136,6 +142,17 @@ public final class JavaPluginLoader implements PluginLoader {
trueListener.onPluginDisabled((PluginEvent)event); trueListener.onPluginDisabled((PluginEvent)event);
break; break;
} }
} else if(listener instanceof WorldListener) {
WorldListener trueListener = (WorldListener)listener;
switch (event.getType()) {
case CHUNK_LOADED:
trueListener.onChunkLoaded((ChunkLoadedEvent)event);
break;
case CHUNK_UNLOADED:
trueListener.onChunkUnloaded((ChunkUnloadedEvent)event);
break;
}
} else if(listener instanceof EntityListener) { } else if(listener instanceof EntityListener) {
EntityListener trueListener = (EntityListener) listener; EntityListener trueListener = (EntityListener) listener;
switch(event.getType()) switch(event.getType())