From 5901415d13ce6eb92dafe61a9d41864f6c2a04b2 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 14:08:29 +0000 Subject: [PATCH 1/6] Added Chunk.getWorld() By: Dinnerbone --- paper-api/src/main/java/org/bukkit/Chunk.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/Chunk.java b/paper-api/src/main/java/org/bukkit/Chunk.java index 4bb9431fff..3f158f5b72 100644 --- a/paper-api/src/main/java/org/bukkit/Chunk.java +++ b/paper-api/src/main/java/org/bukkit/Chunk.java @@ -20,4 +20,10 @@ public interface Chunk { */ int getZ(); + /** + * Gets the world containing this chunk + * + * @return Parent World + */ + World getWorld(); } From 950ed1a52ac116ca9a1b0656e9b22ae6d63a8207 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 14:08:56 +0000 Subject: [PATCH 2/6] Added Chunk events in new World category By: Dinnerbone --- .../bukkit/event/world/ChunkLoadedEvent.java | 26 ++++++++++++++++++ .../event/world/ChunkUnloadedEvent.java | 25 +++++++++++++++++ .../org/bukkit/event/world/WorldEvent.java | 27 +++++++++++++++++++ .../org/bukkit/event/world/WorldListener.java | 25 +++++++++++++++++ .../bukkit/plugin/java/JavaPluginLoader.java | 14 ++++++++++ 5 files changed, 117 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/WorldListener.java diff --git a/paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java b/paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java new file mode 100644 index 0000000000..f91b7aebe6 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/ChunkLoadedEvent.java @@ -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; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java b/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java new file mode 100644 index 0000000000..3aa8922149 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java @@ -0,0 +1,25 @@ + +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); + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java b/paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java new file mode 100644 index 0000000000..d877758a99 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/WorldEvent.java @@ -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; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/WorldListener.java b/paper-api/src/main/java/org/bukkit/event/world/WorldListener.java new file mode 100644 index 0000000000..fc8f5799f3 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/WorldListener.java @@ -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) { + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index ba220c3e64..7cbccbe8be 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -23,6 +23,9 @@ import org.bukkit.event.player.*; import org.bukkit.event.server.PluginEvent; import org.bukkit.event.server.ServerListener; 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.*; /** @@ -136,6 +139,17 @@ public final class JavaPluginLoader implements PluginLoader { trueListener.onPluginDisabled((PluginEvent)event); 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) { EntityListener trueListener = (EntityListener) listener; switch(event.getType()) From 6a7187055549ad2c9f6e88ad8327298e491b2b9d Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 19:54:41 +0000 Subject: [PATCH 3/6] ItemStack.setDamage and ItemStack.getDamage By: Dinnerbone --- .../src/main/java/org/bukkit/ItemStack.java | 189 ++++++++++-------- 1 file changed, 108 insertions(+), 81 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/ItemStack.java b/paper-api/src/main/java/org/bukkit/ItemStack.java index 2ca42274ab..a724717815 100644 --- a/paper-api/src/main/java/org/bukkit/ItemStack.java +++ b/paper-api/src/main/java/org/bukkit/ItemStack.java @@ -1,81 +1,108 @@ - -package org.bukkit; - -/** - * Represents a stack of items - */ -public class ItemStack { - private int type; - private int amount = 0; - - public ItemStack(final int type) { - this.type = type; - } - - public ItemStack(final Material type) { - this(type.getID()); - } - - public ItemStack(final int type, final int amount) { - this.type = type; - this.amount = amount; - } - - public ItemStack(final Material type, final int amount) { - this(type.getID(), amount); - } - - /** - * Gets the type of this item - * - * @return Type of the items in this stack - */ - public Material getType() { - return Material.getMaterial(type); - } - - /** - * Sets the type of this item - * - * @param type New type to set the items in this stack to - */ - public void setType(Material type) { - this.type = type.getID(); - } - - /** - * Gets the type ID of this item - * - * @return Type ID of the items in this stack - */ - public int getTypeID() { - return type; - } - - /** - * Sets the type ID of this item - * - * @param type New type ID to set the items in this stack to - */ - public void setTypeID(int type) { - this.type = type; - } - - /** - * Gets the amount of items in this stack - * - * @return Amount of items in this stick - */ - public int getAmount() { - return amount; - } - - /** - * Sets the amount of items in this stack - * - * @param amount New amount of items in this stack - */ - public void setAmount(int amount) { - this.amount = amount; - } -} + +package org.bukkit; + +/** + * Represents a stack of items + */ +public class ItemStack { + private int type; + private int amount = 0; + private byte damage = 0; + + public ItemStack(final int type) { + this.type = type; + } + + public ItemStack(final Material type) { + this(type.getID()); + } + + public ItemStack(final int type, final int amount) { + this.type = type; + this.amount = amount; + } + + public ItemStack(final Material type, final int amount) { + this(type.getID(), amount); + } + + /** + * Gets the type of this item + * + * @return Type of the items in this stack + */ + public Material getType() { + return Material.getMaterial(type); + } + + /** + * Sets the type of this item + * + * @param type New type to set the items in this stack to + */ + public void setType(Material type) { + this.type = type.getID(); + } + + /** + * Gets the type ID of this item + * + * @return Type ID of the items in this stack + */ + public int getTypeID() { + return type; + } + + /** + * Sets the type ID of this item + * + * @param type New type ID to set the items in this stack to + */ + public void setTypeID(int type) { + this.type = type; + } + + /** + * Gets the amount of items in this stack + * + * @return Amount of items in this stick + */ + public int getAmount() { + return amount; + } + + /** + * Sets the amount of items in this stack + * + * @param amount New amount of items in this stack + */ + public void setAmount(int amount) { + this.amount = amount; + } + + /** + * Sets the damage of this item

+ * + * 0x00 represents an item which cannot be damaged
+ * 0x01 represents an item at maximum health
+ * 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

+ * + * 0x00 represents an item which cannot be damaged
+ * 0x01 represents an item at maximum health
+ * 0x32 represents an item with no health left + * + * @return Damage of this item + */ + public byte getDamage() { + return damage; + } +} From fa8b3da89b2d836e20a5cc315a6000f6864fffe1 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 19:56:19 +0000 Subject: [PATCH 4/6] Constructors for damage on itemstack By: Dinnerbone --- paper-api/src/main/java/org/bukkit/ItemStack.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/ItemStack.java b/paper-api/src/main/java/org/bukkit/ItemStack.java index a724717815..af17669835 100644 --- a/paper-api/src/main/java/org/bukkit/ItemStack.java +++ b/paper-api/src/main/java/org/bukkit/ItemStack.java @@ -26,6 +26,16 @@ public class ItemStack { 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 * From 7f944f0a0decf65a1d7154af120736aa7c619a2b Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 22:03:15 +0000 Subject: [PATCH 5/6] Removed onBlockSent, added onLeavesDecay By: Dinnerbone --- .../src/main/java/org/bukkit/event/Event.java | 4 +- .../org/bukkit/event/block/BlockListener.java | 170 +++++++++--------- .../bukkit/event/block/LeavesDecayEvent.java | 36 ++++ .../bukkit/plugin/java/JavaPluginLoader.java | 3 + 4 files changed, 130 insertions(+), 83 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/block/LeavesDecayEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index fe1d69207a..045da30edb 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -217,9 +217,9 @@ public abstract class Event { 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 diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java b/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java index c760758849..723572f99f 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java @@ -1,81 +1,89 @@ -package org.bukkit.event.block; - -import org.bukkit.event.Listener; - -/** - * Handles all events thrown in relation to Blocks - * - * @author durron597 - */ -public class BlockListener implements Listener { - /** - * Default Constructor - */ - public BlockListener() { - } - - /** - * Called when a block is broken (or destroyed) - * - * @param event Relevant event details - */ - 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(BlockFromToEvent event) { - } - - /** - * Called when a block gets ignited - * - * @param event Relevant event details - */ - public void onBlockIgnite(BlockIgniteEvent event) { - } - - /** - * Called when block physics occurs - * - * @param event Relevant event details - */ - public void onBlockPhysics(BlockPhysicsEvent event) { - } - - /** - * Called when a player places a block - * - * @param event Relevant event details - */ - public void onBlockPlaced(BlockPlacedEvent event) { - } - - /** - * Called when redstone changes - * From: the source of the redstone change - * To: The redstone dust that changed - * - * @param event Relevant event details - */ - public void onBlockRedstoneChange(BlockFromToEvent event) { - } - - /** - * Called when a player right clicks a block - * - * @param event Relevant event details - */ - public void onBlockRightClicked(BlockRightClickedEvent event) { - } - -} +package org.bukkit.event.block; + +import org.bukkit.event.Listener; + +/** + * Handles all events thrown in relation to Blocks + * + * @author durron597 + */ +public class BlockListener implements Listener { + /** + * Default Constructor + */ + public BlockListener() { + } + + /** + * Called when a block is broken (or destroyed) + * + * @param event Relevant event details + */ + 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(BlockFromToEvent event) { + } + + /** + * Called when a block gets ignited + * + * @param event Relevant event details + */ + public void onBlockIgnite(BlockIgniteEvent event) { + } + + /** + * Called when block physics occurs + * + * @param event Relevant event details + */ + public void onBlockPhysics(BlockPhysicsEvent event) { + } + + /** + * Called when a player places a block + * + * @param event Relevant event details + */ + public void onBlockPlaced(BlockPlacedEvent event) { + } + + /** + * Called when redstone changes + * From: the source of the redstone change + * To: The redstone dust that changed + * + * @param event Relevant event details + */ + public void onBlockRedstoneChange(BlockFromToEvent event) { + } + + /** + * Called when a player right clicks a block + * + * @param event Relevant event details + */ + public void onBlockRightClicked(BlockRightClickedEvent event) { + } + + /** + * Called when leaves are decaying naturally + * + * @param event Relevant event details + */ + public void onLeavesDecay(LeavesDecayEvent event) { + } + +} diff --git a/paper-api/src/main/java/org/bukkit/event/block/LeavesDecayEvent.java b/paper-api/src/main/java/org/bukkit/event/block/LeavesDecayEvent.java new file mode 100644 index 0000000000..1ee2f4039c --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/LeavesDecayEvent.java @@ -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; + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 7cbccbe8be..2c9b507810 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -127,6 +127,9 @@ public final class JavaPluginLoader implements PluginLoader { case BLOCK_FLOW: trueListener.onBlockFlow((BlockFromToEvent)event); break; + case LEAVES_DECAY: + trueListener.onLeavesDecay((LeavesDecayEvent)event); + break; } } else if(listener instanceof ServerListener) { ServerListener trueListener = (ServerListener)listener; From 740077970e6bab257d9f1374ee3a8fda9325be39 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 4 Jan 2011 22:05:53 +0000 Subject: [PATCH 6/6] Javadoc By: Dinnerbone --- .../bukkit/event/block/BlockPlacedEvent.java | 24 ++++++++++++++----- .../event/world/ChunkUnloadedEvent.java | 13 +++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java index 030a2dd92a..6bc1896877 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java @@ -11,24 +11,36 @@ public class BlockPlacedEvent extends BlockEvent implements Cancellable { private boolean cancel; private Player player; - /** - * @param type - * @param theBlock - */ public BlockPlacedEvent(Type type, Block theBlock) { super(type, theBlock); cancel = false; } - + + /** + * Gets the player who placed this block + * + * @return Player who placed the block + */ public Player getPlayer() { 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() { - // TODO Auto-generated method stub 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; } diff --git a/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java b/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java index 3aa8922149..fc9d57b1de 100644 --- a/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/world/ChunkUnloadedEvent.java @@ -14,12 +14,23 @@ public class ChunkUnloadedEvent extends ChunkLoadedEvent implements Cancellable 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; } - }