From ed0ea80944c483757c24125c0b2f4c3c1795d461 Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 3 Jan 2011 17:15:09 -0800 Subject: Added LivingEntity.shootArrow(). --- src/main/java/org/bukkit/LivingEntity.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/LivingEntity.java b/src/main/java/org/bukkit/LivingEntity.java index e8e6373e..d1bd9180 100644 --- a/src/main/java/org/bukkit/LivingEntity.java +++ b/src/main/java/org/bukkit/LivingEntity.java @@ -28,4 +28,11 @@ public interface LivingEntity extends Entity { * Throws a snowball from the entity. */ public Snowball throwSnowball(); + + /** + * Shoots an arrow from the entity. + * + * @return + */ + public Arrow shootArrow(); } -- cgit v1.2.3 From 8242b1d51e6e8bc7ad26346d25f3280f4f050330 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 10:00:00 +0000 Subject: Documented + added server.matchPlayer --- src/main/java/org/bukkit/Server.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java index dd29eba3..f3556922 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java @@ -1,6 +1,7 @@ package org.bukkit; +import java.util.List; import org.bukkit.plugin.PluginManager; /** @@ -38,6 +39,18 @@ public interface Server { */ public Player getPlayer(String name); + /** + * Attempts to match any players with the given name, and returns a list + * of all possibly matches + * + * This list is not sorted in any particular order. If an exact match is found, + * the returned list will only contain a single result. + * + * @param name Name to match + * @return List of all possible players + */ + public List matchPlayer(String name); + /** * Gets the PluginManager for interfacing with plugins * -- cgit v1.2.3 From ba54c55b97dbe08f2a2b013cc68992d3afdedb51 Mon Sep 17 00:00:00 2001 From: durron597 Date: Mon, 3 Jan 2011 21:22:52 -0500 Subject: First version of item use event --- .../bukkit/event/player/PlayerItemUseEvent.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java new file mode 100644 index 00000000..12646a4d --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java @@ -0,0 +1,40 @@ +package org.bukkit.event.player; + +import org.bukkit.Block; +import org.bukkit.ItemStack; +import org.bukkit.Player; +import org.bukkit.event.Cancellable; + +/** + * + * @author durron597 + * + */ +public class PlayerItemUseEvent extends PlayerEvent implements Cancellable { + protected ItemStack item; + protected Block blockClicked; + protected boolean cancel; + + public PlayerItemUseEvent(Type type, Player who, ItemStack item, Block blockClicked) { + super(type, who); + this.item = item; + this.blockClicked = blockClicked; + cancel = false; + } + + /** + * Gets the cancellation state of this event. Set to true if you + * want to prevent buckets from placing water and so forth + * + * @return boolean cancellation state + */ + @Override + public boolean isCancelled() { + return cancel; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } +} -- cgit v1.2.3 From 038a05522d148d7d0b932061eff2818bab5e99f0 Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 7 Jan 2011 04:40:46 -0500 Subject: Convenience method to see if a material is a block --- src/main/java/org/bukkit/Material.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index d114d042..3d0d6806 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -193,10 +193,14 @@ public enum Material { return id; } + public boolean isBlock() { + return id < 256; + } + public static Material getMaterial(final int id) { return lookup.get(id); } - + static { for (Material material : values()) { lookup.put(material.getID(), material); -- cgit v1.2.3 From 3fc85a5e829d685044c6c8fb8e886b409dd60400 Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 7 Jan 2011 05:11:16 -0500 Subject: Implemented Item_Use events --- src/main/java/org/bukkit/event/Event.java | 32 ++++++++- .../bukkit/event/player/PlayerBlockItemEvent.java | 79 ++++++++++++++++++++++ .../org/bukkit/event/player/PlayerItemEvent.java | 67 ++++++++++++++++++ .../bukkit/event/player/PlayerItemUseEvent.java | 40 ----------- 4 files changed, 176 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java create mode 100644 src/main/java/org/bukkit/event/player/PlayerItemEvent.java delete mode 100644 src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 045da30e..f6bf4236 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -170,6 +170,33 @@ public abstract class Event { */ PLAYER_ANIMATION (Category.PLAYER), + /** + * Always called when a player uses an item while pointing at a block + * Sometimes, cancelling this event doesn't do anything. + * + * This is the event that is called on block placement. Cancel this + * to prevent block placement. This will ALWAYS be called, even if + * universe physics prevents the block from being placed. This allows + * you to add functionality to rightclicking with block items even + * if the universe won't allow them to get placed. Use BLOCK_CANBUILD + * to override notch's block placement rules. + * + * Example: This event is also called, for example when redstone is + * placed, when a sign is placed, when minecarts are placed on a track, + * when boats are placed (in both water and air) + */ + PLAYER_BLOCKITEM (Category.PLAYER), + + /** + * Called when a player uses an item while pointing at the air + * This can also be additionally called while pointing at the ground + * + * Example: all food will also call this event while pointing at the + * ground, bows/snowballs/eggs will all call this while pointing at + * the ground, buckets call this event. + */ + PLAYER_ITEM (Category.PLAYER), + /** * Called when a player teleports from one position to another */ @@ -185,7 +212,8 @@ public abstract class Event { BLOCK_DAMAGED (Category.BLOCK), /** - * Called when a block is undergoing a check on whether it can be built + * Called when a block is undergoing a universe physics + * check on whether it can be built * * For example, cacti cannot be built on grass unless overridden here */ @@ -210,7 +238,7 @@ public abstract class Event { * type */ BLOCK_PHYSICS (Category.BLOCK), - + /** * Called when a player is attempting to place a block */ diff --git a/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java new file mode 100644 index 00000000..2af86624 --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java @@ -0,0 +1,79 @@ +package org.bukkit.event.player; + +import org.bukkit.Block; +import org.bukkit.BlockFace; +import org.bukkit.ItemStack; +import org.bukkit.Player; +import org.bukkit.event.Cancellable; + +/** + * Represents an event that a block was clicked with an item. + * + * Note: while this is the event that is thrown on block placement, there is no + * BlockPlaced associated with this event. This is because the event is thrown + * before the block is written to the universe, so the returned block would not + * be the new placed block. In hMod, BlockPlaced worked by UNDOING the block + * placement; in Bukkit, we catch the event before it even gets written to the + * universe, so the concept of a placed block is meaningless. + * + * To get the type of block that's being placed, use the method getItem (for + * the item in your hand). + * + * @author durron597 + */ +public class PlayerBlockItemEvent extends PlayerItemEvent implements Cancellable { + protected Block blockClicked; + protected BlockFace direction; + protected boolean cancel; + + public PlayerBlockItemEvent(Type type, Player who, ItemStack item, Block blockClicked, BlockFace direction) { + super(type, who, item); + this.blockClicked = blockClicked; + cancel = false; + } + + /** + * Gets the cancellation state of this event. Set to true if you + * want to prevent buckets from placing water, from a block from being + * placed + * + * @return boolean cancellation state + */ + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Convenience method to inform the user whether this was a block placement + * event. + * + * @return boolean true if the item in hand was a block + */ + public boolean isBlock() { + if (item == null) return false; + + return item.getType().isBlock(); + } + + /** + * Returns the clicked block + * + * @return Block returns the block clicked with this item. + */ + public Block getBlockClicked() { + return blockClicked; + } + + /** + * Returns the face of the block that was clicked + * + * @return BlockFace returns the face of the block that was clicked + */ + public BlockFace getBlockFace() { + return direction; + } +} diff --git a/src/main/java/org/bukkit/event/player/PlayerItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemEvent.java new file mode 100644 index 00000000..842a0eb0 --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerItemEvent.java @@ -0,0 +1,67 @@ +package org.bukkit.event.player; + +import org.bukkit.ItemStack; +import org.bukkit.Material; +import org.bukkit.Player; +import org.bukkit.event.Cancellable; + +/** + * + * @author durron597 + * + */ +public class PlayerItemEvent extends PlayerEvent implements Cancellable { + protected ItemStack item; + protected boolean cancel; + + public PlayerItemEvent(Type type, Player who, ItemStack item) { + super(type, who); + this.item = item; + cancel = false; + } + + /** + * Gets the cancellation state of this event. Set to true if you + * want to prevent buckets from placing water and so forth + * + * @return boolean cancellation state + */ + 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 + * + * Cancelling this event will prevent use of food (player won't lose the + * food item), prevent bows/snowballs/eggs from firing, etc. (player won't + * lose the ammo) + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Returns the item in hand represented by this event + * + * @return ItemStack the item used + */ + public ItemStack getItem() { + return this.item; + } + + /** + * Convenience method. Returns the material of the item represented by this + * event + * + * @return Material the material of the item used + */ + public Material getMaterial() { + if (this.item == null) return Material.Air; + + return item.getType(); + } +} diff --git a/src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java deleted file mode 100644 index 12646a4d..00000000 --- a/src/main/java/org/bukkit/event/player/PlayerItemUseEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.bukkit.event.player; - -import org.bukkit.Block; -import org.bukkit.ItemStack; -import org.bukkit.Player; -import org.bukkit.event.Cancellable; - -/** - * - * @author durron597 - * - */ -public class PlayerItemUseEvent extends PlayerEvent implements Cancellable { - protected ItemStack item; - protected Block blockClicked; - protected boolean cancel; - - public PlayerItemUseEvent(Type type, Player who, ItemStack item, Block blockClicked) { - super(type, who); - this.item = item; - this.blockClicked = blockClicked; - cancel = false; - } - - /** - * Gets the cancellation state of this event. Set to true if you - * want to prevent buckets from placing water and so forth - * - * @return boolean cancellation state - */ - @Override - public boolean isCancelled() { - return cancel; - } - - @Override - public void setCancelled(boolean cancel) { - this.cancel = cancel; - } -} -- cgit v1.2.3 From 5d2a8ae74c73970bb94682d39d8dad8161657bfa Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 7 Jan 2011 05:38:45 -0500 Subject: Added canBuild to event --- .../bukkit/event/player/PlayerBlockItemEvent.java | 42 ++++++++++++---------- 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java index 2af86624..766296e3 100644 --- a/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java @@ -24,27 +24,12 @@ import org.bukkit.event.Cancellable; public class PlayerBlockItemEvent extends PlayerItemEvent implements Cancellable { protected Block blockClicked; protected BlockFace direction; - protected boolean cancel; + protected boolean canBuild; - public PlayerBlockItemEvent(Type type, Player who, ItemStack item, Block blockClicked, BlockFace direction) { + public PlayerBlockItemEvent(Type type, Player who, ItemStack item, Block blockClicked, BlockFace direction, boolean canBuild) { super(type, who, item); this.blockClicked = blockClicked; - cancel = false; - } - - /** - * Gets the cancellation state of this event. Set to true if you - * want to prevent buckets from placing water, from a block from being - * placed - * - * @return boolean cancellation state - */ - public boolean isCancelled() { - return cancel; - } - - public void setCancelled(boolean cancel) { - this.cancel = cancel; + this.canBuild = canBuild; } /** @@ -76,4 +61,25 @@ public class PlayerBlockItemEvent extends PlayerItemEvent implements Cancellable public BlockFace getBlockFace() { return direction; } + + /** + * Gets the value whether the player would be allowed to build here. + * Defaults to spawn if the server was going to stop them (such as, the + * player is in Spawn). Note that this is an entirely different check + * than BLOCK_CANBUILD, as this refers to a player, not universe-physics + * rule like cactus on dirt. + * + * @return boolean whether the server would allow a player to build here + */ + public boolean canBuild() { + return this.canBuild; + } + + /** + * Sets the canBuild state of this event. Set to true if you want the + * player to be able to build. + */ + public void setBuild(boolean canBuild) { + this.canBuild = canBuild; + } } -- cgit v1.2.3 From d82b900597311ded168111fe887dde9694b9f625 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 10:32:36 +0000 Subject: Some BlockFace improvements --- src/main/java/org/bukkit/Block.java | 40 ++++++++++++++++++++++++++++++++- src/main/java/org/bukkit/BlockFace.java | 10 +++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Block.java b/src/main/java/org/bukkit/Block.java index 8909de4d..63cabda8 100644 --- a/src/main/java/org/bukkit/Block.java +++ b/src/main/java/org/bukkit/Block.java @@ -12,13 +12,33 @@ public interface Block { byte getData(); /** - * Gets the block at the given face + * Gets the block at the given face
+ *
+ * This method is equal to getFace(face, 1) * * @param face Face of this block to return * @return Block at the given face + * @see Block.getFace(BlockFace face, int distance); */ Block getFace(BlockFace face); + /** + * Gets the block at the given distance of the given face
+ *
+ * For example, the following method places water at 100,102,100; two blocks + * above 100,100,100. + *
+     * Block block = world.getBlockAt(100,100,100);
+     * Block shower = block.getFace(BlockFace.Up, 2);
+     * shower.setType(Material.WATER);
+     * 
+ * + * @param face Face of this block to return + * @param distance Distance to get the block at + * @return Block at the given face + */ + Block getFace(BlockFace face, int distance); + /** * Gets the block at the given offsets * @@ -105,4 +125,22 @@ public interface Block { * @param type Type-ID to change this block to */ void setTypeID(int type); + + /** + * Gets the face relation of this block compared to the given block
+ *
+ * For example: + *
+     * Block current = world.getBlockAt(100, 100, 100);
+     * Block target = world.getBlockAt(100, 101, 100);
+     *
+     * current.getFace(target) == BlockFace.Up;
+     * 
+ *
+ * If the given block is not connected to this block, null may be returned + * + * @param block Block to compare against this block + * @return BlockFace of this block which has the requested block, or null + */ + BlockFace getFace(Block block); } diff --git a/src/main/java/org/bukkit/BlockFace.java b/src/main/java/org/bukkit/BlockFace.java index aba16cbf..12eb2c54 100644 --- a/src/main/java/org/bukkit/BlockFace.java +++ b/src/main/java/org/bukkit/BlockFace.java @@ -10,6 +10,10 @@ public enum BlockFace { West(0, 0, 1), Up(0, 1, 0), Down(0, -1, 0), + NorthEast(North, East), + NorthWest(North, West), + SouthEast(South, East), + SouthWest(South, West), Self(0, 0, 0); private final int modX; @@ -22,6 +26,12 @@ public enum BlockFace { this.modZ = modZ; } + private BlockFace(final BlockFace face1, final BlockFace face2) { + this.modX = face1.getModX() + face2.getModX(); + this.modY = face1.getModY() + face2.getModY(); + this.modZ = face1.getModZ() + face2.getModZ(); + } + /** * Get the amount of X-coordinates to modify to get the represented block * @return Amount of X-coordinates to modify -- cgit v1.2.3 From bc15bdafcc49b98dfc33706929250766d56362dd Mon Sep 17 00:00:00 2001 From: durron597 Date: Fri, 7 Jan 2011 05:44:10 -0500 Subject: Removed BlockRightClicked, as it's subsumed by PlayerBlockItemEvent --- .../java/org/bukkit/event/block/BlockListener.java | 8 ---- .../bukkit/event/block/BlockRightClickedEvent.java | 53 ---------------------- 2 files changed, 61 deletions(-) delete mode 100644 src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/block/BlockListener.java b/src/main/java/org/bukkit/event/block/BlockListener.java index 723572f9..a26c42c2 100644 --- a/src/main/java/org/bukkit/event/block/BlockListener.java +++ b/src/main/java/org/bukkit/event/block/BlockListener.java @@ -70,14 +70,6 @@ public class BlockListener implements Listener { 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 * diff --git a/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java b/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java deleted file mode 100644 index ba5b6bb3..00000000 --- a/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - */ -package org.bukkit.event.block; - -import org.bukkit.Block; -import org.bukkit.BlockFace; -import org.bukkit.ItemStack; -import org.bukkit.Player; - -/** - * @author durron597 - */ -public class BlockRightClickedEvent extends BlockEvent { - protected Player clicker; - protected BlockFace direction; - protected ItemStack clickedWith; - - /** - * @param type The type of event this is - * @param theBlock The clicked block - * @param direction The face we clicked from - * @param clicker The player who clicked a block - * @param clickedWith Item in player's hand - */ - public BlockRightClickedEvent(Type type, Block theBlock, BlockFace direction, Player clicker, ItemStack clickedWith) { - super(type, theBlock); - this.direction = direction; - this.clicker = clicker; - this.clickedWith = clickedWith; - } - - /** - * @return the clicker - */ - public Player getClicker() { - return clicker; - } - - /** - * @return the direction - */ - public BlockFace getDirection() { - return direction; - } - - /** - * @return the clickedWith - */ - public ItemStack getClickedWith() { - return clickedWith; - } -} -- cgit v1.2.3 From 6082aa143f2af2f5c4f7884e631395e423efdc10 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 13:27:09 +0000 Subject: Added Player.getDisplayName() and Player.setDisplayName(String) --- src/main/java/org/bukkit/Player.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Player.java b/src/main/java/org/bukkit/Player.java index 7d4c5ed7..3c07a5a6 100644 --- a/src/main/java/org/bukkit/Player.java +++ b/src/main/java/org/bukkit/Player.java @@ -19,4 +19,24 @@ public interface Player extends HumanEntity { * @param message Message to be displayed */ public void sendMessage(String message); + + /** + * Gets the "friendly" name to display of this player. This may include color. + * + * Note that this name will not be displayed in game, only in chat and places + * defined by plugins + * + * @return String containing a color formatted name to display for this player + */ + public String getDisplayName(); + + /** + * Sets the "friendly" name to display of this player. This may include color. + * + * Note that this name will not be displayed in game, only in chat and places + * defined by plugins + * + * @return String containing a color formatted name to display for this player + */ + public void getDisplayName(String name); } -- cgit v1.2.3 From efa95015387156451e8fbe802ee815e1173bb2f1 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 13:31:16 +0000 Subject: Added PlayerChatEvent.getFormat/setFormat --- .../java/org/bukkit/event/player/PlayerChatEvent.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/player/PlayerChatEvent.java b/src/main/java/org/bukkit/event/player/PlayerChatEvent.java index f67ebd86..b97ac5a6 100644 --- a/src/main/java/org/bukkit/event/player/PlayerChatEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerChatEvent.java @@ -10,6 +10,7 @@ import org.bukkit.event.Cancellable; public class PlayerChatEvent extends PlayerEvent implements Cancellable { private boolean cancel = false; private String message; + private String format = "<%1$s> %2$s"; public PlayerChatEvent(final Type type, final Player player, final String message) { super(type, player); @@ -63,4 +64,22 @@ public class PlayerChatEvent extends PlayerEvent implements Cancellable { public void setPlayer(final Player player) { this.player = player; } + + /** + * Gets the format to use to display this chat message + * + * @return String.Format compatible format string + */ + public String getFormat() { + return format; + } + + /** + * Sets the format to use to display this chat message + * + * @param format String.Format compatible format string + */ + public void setFormat(final String format) { + this.format = format; + } } -- cgit v1.2.3 From f71b57174ea8a5133c69ca7923ff760c7935c3c5 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 13:33:36 +0000 Subject: Set. Not get. --- src/main/java/org/bukkit/Player.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Player.java b/src/main/java/org/bukkit/Player.java index 3c07a5a6..ffa03eb8 100644 --- a/src/main/java/org/bukkit/Player.java +++ b/src/main/java/org/bukkit/Player.java @@ -38,5 +38,5 @@ public interface Player extends HumanEntity { * * @return String containing a color formatted name to display for this player */ - public void getDisplayName(String name); + public void setDisplayName(String name); } -- cgit v1.2.3 From 8563454327d96a9758f731f9db87561b40bb401f Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 14:52:28 +0000 Subject: Added Sign interface --- src/main/java/org/bukkit/block/Sign.java | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/org/bukkit/block/Sign.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/block/Sign.java b/src/main/java/org/bukkit/block/Sign.java new file mode 100644 index 00000000..595c7836 --- /dev/null +++ b/src/main/java/org/bukkit/block/Sign.java @@ -0,0 +1,39 @@ + +package org.bukkit.block; + +import org.bukkit.Block; + +/** + * Represents either a SignPost or a WallSign + */ +public interface Sign extends Block { + /** + * Gets all the lines of text currently on this sign. + * + * @return Array of Strings containing each line of text + */ + public String[] getLines(); + + /** + * Gets the line of text at the specified index. + * + * For example, getLine(0) will return the first line of text. + * + * @param index Line number to get the text from, starting at 0 + * @throws IndexOutOfBoundsException Thrown when the line does not exist + * @return Text on the given line + */ + public String getLine(int index) throws IndexOutOfBoundsException; + + /** + * Sets the line of text at the specified index. + * + * For example, setLine(0, "Line One") will set the first line of text to + * "Line One". + * + * @param index Line number to set the text at, starting from 0 + * @param line New text to set at the specified index + * @throws IndexOutOfBoundsException + */ + public void setLine(int index, String line) throws IndexOutOfBoundsException; +} -- cgit v1.2.3 From 4cdd5199630510b6d15437202e6870e6786605b8 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 16:17:54 +0000 Subject: Make a start on BlockState stuff --- src/main/java/org/bukkit/Block.java | 18 ++++- src/main/java/org/bukkit/block/BlockState.java | 108 +++++++++++++++++++++++++ src/main/java/org/bukkit/block/Sign.java | 4 +- 3 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/bukkit/block/BlockState.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Block.java b/src/main/java/org/bukkit/Block.java index 63cabda8..d2719be2 100644 --- a/src/main/java/org/bukkit/Block.java +++ b/src/main/java/org/bukkit/Block.java @@ -1,7 +1,12 @@ package org.bukkit; +import org.bukkit.block.BlockState; + /** - * Represents a block + * Represents a block. This is a live object, and only one Block may exist for + * any given location in a world. The state of the block may change concurrently + * to your own handling of it; use block.getState() to get a snapshot state of a + * block which will not be modified. */ public interface Block { /** @@ -143,4 +148,15 @@ public interface Block { * @return BlockFace of this block which has the requested block, or null */ BlockFace getFace(Block block); + + /** + * Captures the current state of this block. You may then cast that state + * into any accepted type, such as Furnace or Sign. + * + * The returned object will never be updated, and you are not guaranteed that + * (for example) a sign is still a sign after you capture its state. + * + * @return BlockState with the current state of this block. + */ + BlockState getState(); } diff --git a/src/main/java/org/bukkit/block/BlockState.java b/src/main/java/org/bukkit/block/BlockState.java new file mode 100644 index 00000000..6b8c6161 --- /dev/null +++ b/src/main/java/org/bukkit/block/BlockState.java @@ -0,0 +1,108 @@ + +package org.bukkit.block; + +import org.bukkit.Block; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; + +/** + * Represents a captured state of a block, which will not change automatically. + * + * Unlike Block, which only one object can exist per coordinate, BlockState can + * exist multiple times for any given Block. Note that another plugin may change + * the state of the block and you will not know, or they may change the block to + * another type entirely, causing your BlockState to become invalid. + */ +public interface BlockState { + /** + * Gets the block represented by this BlockState + * + * @return Block that this BlockState represents + */ + Block getBlock(); + + /** + * Gets the metadata for this block + * + * @return block specific metadata + */ + byte getData(); + + /** + * Gets the type of this block + * + * @return block type + */ + Material getType(); + + /** + * Gets the type-ID of this block + * + * @return block type-ID + */ + int getTypeID(); + + /** + * Gets the light level between 0-15 + * + * @return light level + */ + byte getLightLevel(); + + /** + * Gets the world which contains this Block + * + * @return World containing this block + */ + World getWorld(); + + /** + * Gets the x-coordinate of this block + * + * @return x-coordinate + */ + int getX(); + + /** + * Gets the y-coordinate of this block + * + * @return y-coordinate + */ + int getY(); + + /** + * Gets the z-coordinate of this block + * + * @return z-coordinate + */ + int getZ(); + + /** + * Gets the chunk which contains this block + * + * @return Containing Chunk + */ + Chunk getChunk(); + + /** + * Sets the metadata for this block + * + * @param data New block specific metadata + */ + void setData(byte data); + + /** + * Sets the type of this block + * + * @param type Material to change this block to + */ + void setType(Material type); + + /** + * Sets the type-ID of this block + * + * @param type Type-ID to change this block to + */ + void setTypeID(int type); +} diff --git a/src/main/java/org/bukkit/block/Sign.java b/src/main/java/org/bukkit/block/Sign.java index 595c7836..8731f6c2 100644 --- a/src/main/java/org/bukkit/block/Sign.java +++ b/src/main/java/org/bukkit/block/Sign.java @@ -1,12 +1,10 @@ package org.bukkit.block; -import org.bukkit.Block; - /** * Represents either a SignPost or a WallSign */ -public interface Sign extends Block { +public interface Sign extends BlockState { /** * Gets all the lines of text currently on this sign. * -- cgit v1.2.3 From af781b4317273eaf2dac3ece3822fa79ccce0c40 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Fri, 7 Jan 2011 16:53:29 +0000 Subject: Added state update() --- src/main/java/org/bukkit/block/BlockState.java | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/block/BlockState.java b/src/main/java/org/bukkit/block/BlockState.java index 6b8c6161..cb124fc7 100644 --- a/src/main/java/org/bukkit/block/BlockState.java +++ b/src/main/java/org/bukkit/block/BlockState.java @@ -105,4 +105,34 @@ public interface BlockState { * @param type Type-ID to change this block to */ void setTypeID(int type); + + /** + * Attempts to update the block represented by this state, setting it to the + * new values as defined by this state.
+ *
+ * This has the same effect as calling update(false). That is to say, + * this will not modify the state of a block if it is no longer the same + * type as it was when this state was taken. It will return false in this + * eventuality. + * + * @return true if the update was successful, otherwise false + * @see BlockState.update(boolean force) + */ + boolean update(); + + /** + * Attempts to update the block represented by this state, setting it to the + * new values as defined by this state.
+ *
+ * Unless force is true, this will not modify the state of a block if it is + * no longer the same type as it was when this state was taken. It will return + * false in this eventuality.
+ *
+ * If force is true, it will set the type of the block to match the new state, + * set the state data and then return true. + * + * @param force true to forcefully set the state + * @return true if the update was successful, otherwise false + */ + boolean update(boolean force); } -- cgit v1.2.3 From a6704ab01b07ae9ef478b8c3ed8be3b4054ef22a Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 7 Jan 2011 11:16:04 -0800 Subject: Various changes to the vehicle hooks. --- src/main/java/org/bukkit/Vehicle.java | 4 +-- .../bukkit/event/vehicle/VehicleCreateEvent.java | 38 ++++++++++++++++++++-- .../bukkit/event/vehicle/VehicleEnterEvent.java | 12 +++---- .../event/vehicle/VehicleEntityCollisionEvent.java | 30 ++++++++++++++++- 4 files changed, 73 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Vehicle.java b/src/main/java/org/bukkit/Vehicle.java index 245c671f..6fb95b8c 100644 --- a/src/main/java/org/bukkit/Vehicle.java +++ b/src/main/java/org/bukkit/Vehicle.java @@ -24,9 +24,9 @@ public interface Vehicle extends Entity { * Gets the primary passenger of a vehicle. For vehicles that could have * multiple passengers, this will only return the primary passenger. * - * @return a living entity + * @return an entity */ - public LivingEntity getPassenger(); + public Entity getPassenger(); /** * Returns true if the vehicle has no passengers. diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java index efc76094..a6279d4c 100644 --- a/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java +++ b/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java @@ -1,5 +1,6 @@ package org.bukkit.event.vehicle; +import org.bukkit.Vector; import org.bukkit.Vehicle; /** @@ -8,8 +9,41 @@ import org.bukkit.Vehicle; * @author sk89q */ public class VehicleCreateEvent extends VehicleEvent { - public VehicleCreateEvent(Type type, Vehicle vehicle) { + private boolean slowWhenEmpty; + private Vector derailedVelocityFactor; + private Vector flyingVelocityFactor; + + public VehicleCreateEvent(Type type, Vehicle vehicle, + boolean slowWhenEmpty, Vector derailedVelocityFactor, + Vector flyingVelocityFactor) { + super(type, vehicle); + this.slowWhenEmpty = slowWhenEmpty; + this.derailedVelocityFactor = derailedVelocityFactor; + this.flyingVelocityFactor = flyingVelocityFactor; + } + + public void setSlowWhenEmpty(boolean setting) { + slowWhenEmpty = setting; + } + + public boolean shouldSlowWhenEmpty() { + return slowWhenEmpty; + } + + public void setDerailedVelocityFactor(Vector setting) { + derailedVelocityFactor = setting.clone(); + } + + public Vector getDerailedVelocityFactor() { + return derailedVelocityFactor.clone(); + } + + public void setFlyingVelocityFactor(Vector setting) { + flyingVelocityFactor = setting.clone(); + } + + public Vector getFlyingVelocityFactor() { + return flyingVelocityFactor.clone(); } - } diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java index da8fc30c..5ac62428 100644 --- a/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java +++ b/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java @@ -1,30 +1,30 @@ package org.bukkit.event.vehicle; -import org.bukkit.LivingEntity; +import org.bukkit.Entity; import org.bukkit.Vehicle; import org.bukkit.event.Cancellable; /** - * Raised when a living entity enters a vehicle. + * Raised when an entity enters a vehicle. * * @author sk89q */ public class VehicleEnterEvent extends VehicleEvent implements Cancellable { private boolean cancelled; - private LivingEntity entered; + private Entity entered; - public VehicleEnterEvent(Type type, Vehicle vehicle, LivingEntity entered) { + public VehicleEnterEvent(Type type, Vehicle vehicle, Entity entered) { super(type, vehicle); this.entered = entered; } /** - * Get the living entity that entered the vehicle. + * Get the entity that entered the vehicle. * * @return */ - public LivingEntity getEntered() { + public Entity getEntered() { return entered; } diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java index fe2c3b71..514c5697 100644 --- a/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java +++ b/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java @@ -2,14 +2,18 @@ package org.bukkit.event.vehicle; import org.bukkit.Entity; import org.bukkit.Vehicle; +import org.bukkit.event.Cancellable; /** * Raised when a vehicle collides with an entity. * * @author sk89q */ -public class VehicleEntityCollisionEvent extends VehicleCollisionEvent { +public class VehicleEntityCollisionEvent extends VehicleCollisionEvent implements Cancellable { private Entity entity; + private boolean cancelled = false; + private boolean cancelledPickup = false; + private boolean cancelledCollision = false; public VehicleEntityCollisionEvent(Type type, Vehicle vehicle, Entity entity) { super(type, vehicle); @@ -19,4 +23,28 @@ public class VehicleEntityCollisionEvent extends VehicleCollisionEvent { public Entity getEntity() { return entity; } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public boolean isPickupCancelled() { + return cancelledPickup; + } + + public void setPickupCancelled(boolean cancel) { + cancelledPickup = cancel; + } + + public boolean isCollisionCancelled() { + return cancelledCollision; + } + + public void setCollisionCancelled(boolean cancel) { + cancelledCollision = cancel; + } } -- cgit v1.2.3 From 5c7aadb0b2b77a3c39699e4fbdc4cb86b3c6bbd9 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 7 Jan 2011 12:26:10 -0800 Subject: Moving some minecart flags that don't belong in the event out of the event. --- .../bukkit/event/vehicle/VehicleCreateEvent.java | 36 +--------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java index a6279d4c..9be4d55b 100644 --- a/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java +++ b/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java @@ -1,6 +1,5 @@ package org.bukkit.event.vehicle; -import org.bukkit.Vector; import org.bukkit.Vehicle; /** @@ -9,41 +8,8 @@ import org.bukkit.Vehicle; * @author sk89q */ public class VehicleCreateEvent extends VehicleEvent { - private boolean slowWhenEmpty; - private Vector derailedVelocityFactor; - private Vector flyingVelocityFactor; - - public VehicleCreateEvent(Type type, Vehicle vehicle, - boolean slowWhenEmpty, Vector derailedVelocityFactor, - Vector flyingVelocityFactor) { + public VehicleCreateEvent(Type type, Vehicle vehicle) { super(type, vehicle); - this.slowWhenEmpty = slowWhenEmpty; - this.derailedVelocityFactor = derailedVelocityFactor; - this.flyingVelocityFactor = flyingVelocityFactor; - } - - public void setSlowWhenEmpty(boolean setting) { - slowWhenEmpty = setting; - } - - public boolean shouldSlowWhenEmpty() { - return slowWhenEmpty; - } - - public void setDerailedVelocityFactor(Vector setting) { - derailedVelocityFactor = setting.clone(); - } - - public Vector getDerailedVelocityFactor() { - return derailedVelocityFactor.clone(); - } - - public void setFlyingVelocityFactor(Vector setting) { - flyingVelocityFactor = setting.clone(); - } - - public Vector getFlyingVelocityFactor() { - return flyingVelocityFactor.clone(); } } -- cgit v1.2.3 From 5e76ddc41e333bbb75b25ec6ef918f98d8584765 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 7 Jan 2011 13:01:23 -0800 Subject: Added Boat interface. --- src/main/java/org/bukkit/Boat.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/org/bukkit/Boat.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Boat.java b/src/main/java/org/bukkit/Boat.java new file mode 100644 index 00000000..33958ec0 --- /dev/null +++ b/src/main/java/org/bukkit/Boat.java @@ -0,0 +1,9 @@ +package org.bukkit; + +/** + * Represents a boat entity. + * + * @author sk89q + */ +public interface Boat extends Vehicle { +} -- cgit v1.2.3 From b671546e927e04379b8a861fe528ba434ad7013a Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 7 Jan 2011 13:59:30 -0800 Subject: Added World.spawnBoat(). --- src/main/java/org/bukkit/World.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java index e9d00810..d1deda7c 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -103,4 +103,12 @@ public interface World { * @return */ public PoweredMinecart spawnPoweredMinecart(Location loc); + + /** + * Spawn a boat. + * + * @param loc + * @return + */ + public Boat spawnBoat(Location loc); } -- cgit v1.2.3 From 39999e2c9310496ca39016824d42130c13a18c28 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 7 Jan 2011 16:25:52 -0800 Subject: Added passenger methods to Vehicle/LivingEntity. --- src/main/java/org/bukkit/LivingEntity.java | 24 ++++++++++++++++++++++++ src/main/java/org/bukkit/Vehicle.java | 15 +++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/LivingEntity.java b/src/main/java/org/bukkit/LivingEntity.java index d1bd9180..f0987ba2 100644 --- a/src/main/java/org/bukkit/LivingEntity.java +++ b/src/main/java/org/bukkit/LivingEntity.java @@ -35,4 +35,28 @@ public interface LivingEntity extends Entity { * @return */ public Arrow shootArrow(); + + /** + * Returns whether this entity is inside a vehicle. + * + * @return + */ + public boolean isInsideVehicle(); + + /** + * Leave the current vehicle. If the entity is currently in a vehicle + * (and is removed from it), true will be returned, otherwise false will + * be returned. + * + * @return + */ + public boolean leaveVehicle(); + + /** + * Get the vehicle that this player is inside. If there is no vehicle, + * null will be returned. + * + * @return + */ + public Vehicle getVehicle(); } diff --git a/src/main/java/org/bukkit/Vehicle.java b/src/main/java/org/bukkit/Vehicle.java index 6fb95b8c..76b7267b 100644 --- a/src/main/java/org/bukkit/Vehicle.java +++ b/src/main/java/org/bukkit/Vehicle.java @@ -28,10 +28,25 @@ public interface Vehicle extends Entity { */ public Entity getPassenger(); + /** + * Set the passenger of a vehicle. + * + * @param passenger + * @return false if it could not be done for whatever reason + */ + public boolean setPassenger(Entity passenger); + /** * Returns true if the vehicle has no passengers. * * @return */ public boolean isEmpty(); + + /** + * Eject any passenger. True if there was a passenger. + * + * @return + */ + public boolean eject(); } -- cgit v1.2.3 From c3a3c52e9d66c84a28f9490836355413b2a9650a Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 8 Jan 2011 02:20:29 +0000 Subject: Added Entity.teleportTo(Entity) --- src/main/java/org/bukkit/Entity.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Entity.java b/src/main/java/org/bukkit/Entity.java index 773354d0..9b4e63d0 100644 --- a/src/main/java/org/bukkit/Entity.java +++ b/src/main/java/org/bukkit/Entity.java @@ -21,11 +21,18 @@ public interface Entity { /** * Teleports this entity to the given location - * + * * @param location New location to teleport this entity to */ public void teleportTo(Location location); + /** + * Teleports this entity to the target Entity + * + * @param destination Entity to teleport this entity to + */ + public void teleportTo(Entity destination); + /** * Returns a unique ID for this entity * -- cgit v1.2.3 From 574e95926996b923d022b1983e6de7388f2f5f83 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 8 Jan 2011 02:29:42 +0000 Subject: Added World.getName and World.getId --- src/main/java/org/bukkit/World.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java index d1deda7c..42226398 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -111,4 +111,20 @@ public interface World { * @return */ public Boat spawnBoat(Location loc); + + /** + * Gets the name of this world. This is not guaranteed to be unique. + * + * @return Name of this world + */ + public String getName(); + + /** + * Gets a semi-unique identifier for this world. While it is highly unlikely + * that this may be shared with another World, it is not guaranteed to be + * unique. + * + * @return Id of this world + */ + public long getId(); } -- cgit v1.2.3 From 15329e9d584134affbfee74c64b5805be47d2f38 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 8 Jan 2011 03:34:24 +0000 Subject: Added block.getBiome() --- src/main/java/org/bukkit/Biome.java | 20 ++++++++++++++++++++ src/main/java/org/bukkit/Block.java | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/org/bukkit/Biome.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Biome.java b/src/main/java/org/bukkit/Biome.java new file mode 100644 index 00000000..265b99ce --- /dev/null +++ b/src/main/java/org/bukkit/Biome.java @@ -0,0 +1,20 @@ + +package org.bukkit; + +/** + * Holds all accepted Biomes in the default server + */ +public enum Biome { + RAINFOREST, + SWAMPLAND, + SEASONAL_FOREST, + FOREST, + SAVANNA, + SHRUBLAND, + TAIGA, + DESERT, + PLAINS, + ICE_DESERT, + TUNDRA, + HELL +} diff --git a/src/main/java/org/bukkit/Block.java b/src/main/java/org/bukkit/Block.java index d2719be2..7e8ec5d4 100644 --- a/src/main/java/org/bukkit/Block.java +++ b/src/main/java/org/bukkit/Block.java @@ -159,4 +159,11 @@ public interface Block { * @return BlockState with the current state of this block. */ BlockState getState(); + + /** + * Returns the biome that this block resides in + * + * @return Biome type containing this block + */ + Biome getBiome(); } -- cgit v1.2.3 From b43d8d60a671a7375acae9542cf42e945211aed5 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 8 Jan 2011 05:44:42 -0500 Subject: Implemented BlockInteract, BlockRightClicked and PlayerItem. Removed BlockItem as we're not doing it that way anymore. --- src/main/java/org/bukkit/event/Event.java | 34 +++------ .../org/bukkit/event/block/BlockInteractEvent.java | 69 ++++++++++++++++++ .../java/org/bukkit/event/block/BlockListener.java | 16 ++++ .../org/bukkit/event/block/BlockPlacedEvent.java | 83 +++++++++++++++++---- .../bukkit/event/block/BlockRightClickedEvent.java | 59 +++++++++++++++ .../bukkit/event/player/PlayerBlockItemEvent.java | 85 ---------------------- .../org/bukkit/event/player/PlayerItemEvent.java | 38 +++++++++- .../org/bukkit/event/player/PlayerListener.java | 8 ++ .../org/bukkit/plugin/java/JavaPluginLoader.java | 12 +++ 9 files changed, 282 insertions(+), 122 deletions(-) create mode 100644 src/main/java/org/bukkit/event/block/BlockInteractEvent.java create mode 100644 src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java delete mode 100644 src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index f6bf4236..05cd96a0 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -169,31 +169,9 @@ public abstract class Event { * Called when a player undergoes an animation, such as arm swinging */ PLAYER_ANIMATION (Category.PLAYER), - - /** - * Always called when a player uses an item while pointing at a block - * Sometimes, cancelling this event doesn't do anything. - * - * This is the event that is called on block placement. Cancel this - * to prevent block placement. This will ALWAYS be called, even if - * universe physics prevents the block from being placed. This allows - * you to add functionality to rightclicking with block items even - * if the universe won't allow them to get placed. Use BLOCK_CANBUILD - * to override notch's block placement rules. - * - * Example: This event is also called, for example when redstone is - * placed, when a sign is placed, when minecarts are placed on a track, - * when boats are placed (in both water and air) - */ - PLAYER_BLOCKITEM (Category.PLAYER), /** - * Called when a player uses an item while pointing at the air - * This can also be additionally called while pointing at the ground - * - * Example: all food will also call this event while pointing at the - * ground, bows/snowballs/eggs will all call this while pointing at - * the ground, buckets call this event. + * Called when a player uses an item */ PLAYER_ITEM (Category.PLAYER), @@ -239,11 +217,21 @@ public abstract class Event { */ BLOCK_PHYSICS (Category.BLOCK), + /** + * Called when a player is attempting to place a block + */ + BLOCK_RIGHTCLICKED (Category.BLOCK), + /** * Called when a player is attempting to place a block */ BLOCK_PLACED (Category.BLOCK), + /** + * Called when an entity interacts with a block (lever, door, pressure plate, chest, furnace) + */ + BLOCK_INTERACT (Category.BLOCK), + /** * Called when leaves are decaying naturally */ diff --git a/src/main/java/org/bukkit/event/block/BlockInteractEvent.java b/src/main/java/org/bukkit/event/block/BlockInteractEvent.java new file mode 100644 index 00000000..7587e329 --- /dev/null +++ b/src/main/java/org/bukkit/event/block/BlockInteractEvent.java @@ -0,0 +1,69 @@ +package org.bukkit.event.block; + +import org.bukkit.Block; +import org.bukkit.Entity; +import org.bukkit.Player; +import org.bukkit.event.Cancellable; + +/** + * This event is triggered whenever an entity interacts with the universe + * it's always called, on a left click or a right click, or walking on + * (as in the case of pressure plates). Use cancellable to prevent things + * from happening (doors opening, buttons, pressure plates being walked + * on, etc). Note: even though pressure plates work totally differently + * than the other interact events, it's still thrown in with this event. + * + * @author durron597 + */ +public class BlockInteractEvent extends BlockEvent implements Cancellable { + protected boolean cancel; + protected Entity theEntity; + + /** + * @param type The type of this event + * @param interactedBlock the block that was interacted with + * @param who The entity that interacted with + */ + public BlockInteractEvent(Type type, Block interactedBlock, Entity who) { + super(type, interactedBlock); + theEntity = who; + } + + /** + * 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; + } + + /** + * Returns the entity that triggered this event + * + * @return Entity the entity that triggered this event + */ + public Entity getEntity() { + return theEntity; + } + + /** + * Convenience method for seeing if this event was triggered by a player + * + * @return boolean whether this event was triggered by a player + */ + public boolean isPlayer() { + return theEntity instanceof Player; + } +} diff --git a/src/main/java/org/bukkit/event/block/BlockListener.java b/src/main/java/org/bukkit/event/block/BlockListener.java index a26c42c2..d7ee313e 100644 --- a/src/main/java/org/bukkit/event/block/BlockListener.java +++ b/src/main/java/org/bukkit/event/block/BlockListener.java @@ -59,6 +59,22 @@ public class BlockListener implements Listener { */ public void onBlockPlaced(BlockPlacedEvent event) { } + + /** + * Called when a block is interacted with + * + * @param event Relevant event details + */ + public void onBlockInteracted(BlockInteractEvent event) { + } + + /** + * Called when a player right clicks a block + * + * @param event Relevant event details + */ + public void onBlockRightClicked(BlockRightClickedEvent event) { + } /** * Called when redstone changes diff --git a/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java b/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java index 6bc18968..586f35bd 100644 --- a/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java +++ b/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java @@ -1,6 +1,7 @@ package org.bukkit.event.block; import org.bukkit.Block; +import org.bukkit.ItemStack; import org.bukkit.Player; import org.bukkit.event.Cancellable; @@ -8,23 +9,21 @@ import org.bukkit.event.Cancellable; * Not implemented yet */ public class BlockPlacedEvent extends BlockEvent implements Cancellable { - private boolean cancel; - private Player player; + protected boolean cancel; + protected boolean canBuild; + protected Block placedAgainst; + protected ItemStack itemInHand; + protected Player player; - public BlockPlacedEvent(Type type, Block theBlock) { - super(type, theBlock); + public BlockPlacedEvent(Type type, Block placedBlock, Block placedAgainst, ItemStack itemInHand, Player thePlayer, boolean canBuild) { + super(type, placedBlock); + this.placedAgainst = placedAgainst; + this.itemInHand = itemInHand; + this.player = thePlayer; + this.canBuild = canBuild; 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 @@ -45,4 +44,62 @@ public class BlockPlacedEvent extends BlockEvent implements Cancellable { this.cancel = cancel; } + /** + * Gets the player who placed this block + * + * @return Player who placed the block + */ + public Player getPlayer() { + return player; + } + + /** + * Clarity method for getting the placed block. Not really needed + * except for reasons of clarity + * + * @return Block the block that was placed + */ + public Block getBlockPlaced() { + return getBlock(); + } + + + /** + * Get the block that this block was placed against + * + * @return Block the block that the new block was placed against + */ + public Block getBlockAgainst() { + return placedAgainst; + } + + /** + * Returns the item in your hand when you placed the block + * + * @return ItemStack the item in your hand when placing the block + */ + public ItemStack getItemInHand() { + return itemInHand; + } + + /** + * Gets the value whether the player would be allowed to build here. + * Defaults to spawn if the server was going to stop them (such as, the + * player is in Spawn). Note that this is an entirely different check + * than BLOCK_CANBUILD, as this refers to a player, not universe-physics + * rule like cactus on dirt. + * + * @return boolean whether the server would allow a player to build here + */ + public boolean canBuild() { + return this.canBuild; + } + + /** + * Sets the canBuild state of this event. Set to true if you want the + * player to be able to build. + */ + public void setBuild(boolean canBuild) { + this.canBuild = canBuild; + } } diff --git a/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java b/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java new file mode 100644 index 00000000..6a11acac --- /dev/null +++ b/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java @@ -0,0 +1,59 @@ +package org.bukkit.event.block; + +import org.bukkit.Block; +import org.bukkit.BlockFace; +import org.bukkit.ItemStack; +import org.bukkit.Player; + +/** + * Not implemented yet + */ +public class BlockRightClickedEvent extends BlockEvent { + protected Block clickedBlock; + protected BlockFace direction; + protected ItemStack itemInHand; + protected Player player; + + public BlockRightClickedEvent(Type type, Block placedAgainst, BlockFace direction, ItemStack itemInHand, Player thePlayer) { + super(type, placedAgainst); + this.clickedBlock = placedAgainst; + this.direction = direction; + this.itemInHand = itemInHand; + this.player = thePlayer; + } + + /** + * Gets the player who placed this block + * + * @return Player who placed the block + */ + public Player getPlayer() { + return player; + } + + + /** + * Get the block that this block was placed against + * + * @return Block the block that the new block was placed against + */ + public Block getBlockAgainst() { + return clickedBlock; + } + + /** + * @return BlockFace the direction this block was clicked + */ + public BlockFace getDirection() { + return direction; + } + + /** + * Returns the item in your hand when you placed the block + * + * @return ItemStack the item in your hand when placing the block + */ + public ItemStack getItemInHand() { + return itemInHand; + } +} diff --git a/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java deleted file mode 100644 index 766296e3..00000000 --- a/src/main/java/org/bukkit/event/player/PlayerBlockItemEvent.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.bukkit.event.player; - -import org.bukkit.Block; -import org.bukkit.BlockFace; -import org.bukkit.ItemStack; -import org.bukkit.Player; -import org.bukkit.event.Cancellable; - -/** - * Represents an event that a block was clicked with an item. - * - * Note: while this is the event that is thrown on block placement, there is no - * BlockPlaced associated with this event. This is because the event is thrown - * before the block is written to the universe, so the returned block would not - * be the new placed block. In hMod, BlockPlaced worked by UNDOING the block - * placement; in Bukkit, we catch the event before it even gets written to the - * universe, so the concept of a placed block is meaningless. - * - * To get the type of block that's being placed, use the method getItem (for - * the item in your hand). - * - * @author durron597 - */ -public class PlayerBlockItemEvent extends PlayerItemEvent implements Cancellable { - protected Block blockClicked; - protected BlockFace direction; - protected boolean canBuild; - - public PlayerBlockItemEvent(Type type, Player who, ItemStack item, Block blockClicked, BlockFace direction, boolean canBuild) { - super(type, who, item); - this.blockClicked = blockClicked; - this.canBuild = canBuild; - } - - /** - * Convenience method to inform the user whether this was a block placement - * event. - * - * @return boolean true if the item in hand was a block - */ - public boolean isBlock() { - if (item == null) return false; - - return item.getType().isBlock(); - } - - /** - * Returns the clicked block - * - * @return Block returns the block clicked with this item. - */ - public Block getBlockClicked() { - return blockClicked; - } - - /** - * Returns the face of the block that was clicked - * - * @return BlockFace returns the face of the block that was clicked - */ - public BlockFace getBlockFace() { - return direction; - } - - /** - * Gets the value whether the player would be allowed to build here. - * Defaults to spawn if the server was going to stop them (such as, the - * player is in Spawn). Note that this is an entirely different check - * than BLOCK_CANBUILD, as this refers to a player, not universe-physics - * rule like cactus on dirt. - * - * @return boolean whether the server would allow a player to build here - */ - public boolean canBuild() { - return this.canBuild; - } - - /** - * Sets the canBuild state of this event. Set to true if you want the - * player to be able to build. - */ - public void setBuild(boolean canBuild) { - this.canBuild = canBuild; - } -} diff --git a/src/main/java/org/bukkit/event/player/PlayerItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerItemEvent.java index 842a0eb0..42bb3f59 100644 --- a/src/main/java/org/bukkit/event/player/PlayerItemEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerItemEvent.java @@ -1,5 +1,7 @@ package org.bukkit.event.player; +import org.bukkit.Block; +import org.bukkit.BlockFace; import org.bukkit.ItemStack; import org.bukkit.Material; import org.bukkit.Player; @@ -13,11 +15,15 @@ import org.bukkit.event.Cancellable; public class PlayerItemEvent extends PlayerEvent implements Cancellable { protected ItemStack item; protected boolean cancel; + protected Block blockClicked; + protected BlockFace blockFace; - public PlayerItemEvent(Type type, Player who, ItemStack item) { + public PlayerItemEvent(Type type, Player who, ItemStack item, Block blockClicked, BlockFace blockFace) { super(type, who); this.item = item; cancel = false; + this.blockClicked = blockClicked; + this.blockFace = blockFace; } /** @@ -64,4 +70,34 @@ public class PlayerItemEvent extends PlayerEvent implements Cancellable { return item.getType(); } + + /** + * Convenience method to inform the user whether this was a block placement + * event. + * + * @return boolean true if the item in hand was a block + */ + public boolean isBlock() { + if (item == null) return false; + + return item.getType().isBlock(); + } + + /** + * Returns the clicked block + * + * @return Block returns the block clicked with this item. + */ + public Block getBlockClicked() { + return blockClicked; + } + + /** + * Returns the face of the block that was clicked + * + * @return BlockFace returns the face of the block that was clicked + */ + public BlockFace getBlockFace() { + return blockFace; + } } diff --git a/src/main/java/org/bukkit/event/player/PlayerListener.java b/src/main/java/org/bukkit/event/player/PlayerListener.java index 0c6817e2..b5da4b97 100644 --- a/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/src/main/java/org/bukkit/event/player/PlayerListener.java @@ -57,6 +57,14 @@ public class PlayerListener implements Listener { */ public void onPlayerTeleport(PlayerMoveEvent event) { } + + /** + * Called when a player uses an item + * + * @param event Relevant event details + */ + public void onPlayerItem(PlayerItemEvent event) { + } /** * Called when a player attempts to log in to the server diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index f0d7d13c..fd68f0c4 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -108,6 +108,9 @@ public final class JavaPluginLoader implements PluginLoader { case PLAYER_TELEPORT: trueListener.onPlayerTeleport((PlayerMoveEvent)event); break; + case PLAYER_ITEM: + trueListener.onPlayerItem((PlayerItemEvent)event); + break; case PLAYER_LOGIN: trueListener.onPlayerLogin((PlayerLoginEvent)event); break; @@ -122,6 +125,15 @@ public final class JavaPluginLoader implements PluginLoader { case BLOCK_CANBUILD: trueListener.onBlockCanBuild((BlockCanBuildEvent)event); break; + case BLOCK_RIGHTCLICKED: + trueListener.onBlockRightClicked((BlockRightClickedEvent) event); + break; + case BLOCK_PLACED: + trueListener.onBlockPlaced((BlockPlacedEvent)event); + break; + case BLOCK_INTERACT: + trueListener.onBlockInteracted((BlockInteractEvent)event); + break; case BLOCK_FLOW: trueListener.onBlockFlow((BlockFromToEvent)event); break; -- cgit v1.2.3 From ca29aaa51960bf4e00c4b76f4b5252c0d165aca4 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sat, 8 Jan 2011 08:05:04 -0500 Subject: Should be LivingEntity --- src/main/java/org/bukkit/event/block/BlockInteractEvent.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/block/BlockInteractEvent.java b/src/main/java/org/bukkit/event/block/BlockInteractEvent.java index 7587e329..5447724b 100644 --- a/src/main/java/org/bukkit/event/block/BlockInteractEvent.java +++ b/src/main/java/org/bukkit/event/block/BlockInteractEvent.java @@ -1,7 +1,7 @@ package org.bukkit.event.block; import org.bukkit.Block; -import org.bukkit.Entity; +import org.bukkit.LivingEntity; import org.bukkit.Player; import org.bukkit.event.Cancellable; @@ -17,14 +17,14 @@ import org.bukkit.event.Cancellable; */ public class BlockInteractEvent extends BlockEvent implements Cancellable { protected boolean cancel; - protected Entity theEntity; + protected LivingEntity theEntity; /** * @param type The type of this event * @param interactedBlock the block that was interacted with * @param who The entity that interacted with */ - public BlockInteractEvent(Type type, Block interactedBlock, Entity who) { + public BlockInteractEvent(Type type, Block interactedBlock, LivingEntity who) { super(type, interactedBlock); theEntity = who; } @@ -54,7 +54,7 @@ public class BlockInteractEvent extends BlockEvent implements Cancellable { * * @return Entity the entity that triggered this event */ - public Entity getEntity() { + public LivingEntity getEntity() { return theEntity; } -- cgit v1.2.3 From 3e911e1f0d1e0a8d8a0af069614f989d702cc5c2 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 8 Jan 2011 18:47:14 +0000 Subject: Fixed VehicleListener not being able to register --- src/main/java/org/bukkit/event/vehicle/VehicleListener.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleListener.java b/src/main/java/org/bukkit/event/vehicle/VehicleListener.java index a285f681..176b30c1 100644 --- a/src/main/java/org/bukkit/event/vehicle/VehicleListener.java +++ b/src/main/java/org/bukkit/event/vehicle/VehicleListener.java @@ -1,11 +1,16 @@ package org.bukkit.event.vehicle; +import org.bukkit.event.Listener; + /** * Listener for vehicle events. * * @author sk89q */ -public class VehicleListener { +public class VehicleListener implements Listener { + public VehicleListener() { + } + /** * Called when a vehicle is created by a player. This hook will be called * for all vehicles created. -- cgit v1.2.3 From 373c958596dc5a142148637736dc751d346c6348 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 8 Jan 2011 12:24:27 -0800 Subject: Changed Block.setTypeID() to return a boolean indicating whether the block was changed (as provided by Minecraft). --- src/main/java/org/bukkit/Block.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Block.java b/src/main/java/org/bukkit/Block.java index 7e8ec5d4..90d6523d 100644 --- a/src/main/java/org/bukkit/Block.java +++ b/src/main/java/org/bukkit/Block.java @@ -128,8 +128,9 @@ public interface Block { * Sets the type-ID of this block * * @param type Type-ID to change this block to + * @return whether the block was changed */ - void setTypeID(int type); + boolean setTypeID(int type); /** * Gets the face relation of this block compared to the given block
-- cgit v1.2.3 From 3b1f74e6c5bf1d325e10f263441f54ca08ad6522 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 8 Jan 2011 12:39:54 -0800 Subject: Made Location.clone() public. --- src/main/java/org/bukkit/Location.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java index 6f19f8a5..0fffe007 100644 --- a/src/main/java/org/bukkit/Location.java +++ b/src/main/java/org/bukkit/Location.java @@ -215,7 +215,7 @@ public class Location implements Cloneable { } @Override - protected Location clone() { + public Location clone() { return new Location(world, x, y, z, yaw, pitch); } } -- cgit v1.2.3 From 327142ef52ee5c3a22a55c3439c66e90487da04a Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 8 Jan 2011 12:47:48 -0800 Subject: Added ItemDrop, world.dropItem(), and world.dropItemNaturally(). --- src/main/java/org/bukkit/ItemDrop.java | 15 +++++++++++++++ src/main/java/org/bukkit/World.java | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/org/bukkit/ItemDrop.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/ItemDrop.java b/src/main/java/org/bukkit/ItemDrop.java new file mode 100644 index 00000000..3e2fd598 --- /dev/null +++ b/src/main/java/org/bukkit/ItemDrop.java @@ -0,0 +1,15 @@ +package org.bukkit; + +/** + * Represents a dropped item. + * + * @author sk89q + */ +public interface ItemDrop extends Entity { + /** + * Gets the item stack. + * + * @return + */ + public ItemStack getItemStack(); +} diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java index 42226398..bbf31035 100644 --- a/src/main/java/org/bukkit/World.java +++ b/src/main/java/org/bukkit/World.java @@ -52,6 +52,24 @@ public interface World { */ public boolean isChunkLoaded(Chunk chunk); + /** + * Drop an item exactly at the specified location. + * + * @param loc + * @param item + * @return dropped item entity + */ + public ItemDrop dropItem(Location loc, ItemStack item); + + /** + * Drop an item as if it was mined (randomly placed). + * + * @param loc + * @param item + * @return dropped item entity + */ + public ItemDrop dropItemNaturally(Location loc, ItemStack item); + /** * Spawns an arrow. * -- cgit v1.2.3 From 154cae99a8e343018440bd8f393d1271eb6cff14 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sun, 9 Jan 2011 07:52:03 -0500 Subject: Removed unnecessary import warnings --- src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java | 1 - src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java | 1 - src/main/java/org/bukkit/event/entity/EntityEvent.java | 1 - 3 files changed, 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java index 57c36e37..631ebbf4 100644 --- a/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java @@ -1,6 +1,5 @@ package org.bukkit.event.entity; -import org.bukkit.Block; import org.bukkit.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; diff --git a/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java b/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java index c7ea7e47..65cbc388 100644 --- a/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java @@ -1,6 +1,5 @@ package org.bukkit.event.entity; -import org.bukkit.Block; import org.bukkit.Entity; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; diff --git a/src/main/java/org/bukkit/event/entity/EntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityEvent.java index 4d2f9906..dcd60372 100644 --- a/src/main/java/org/bukkit/event/entity/EntityEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityEvent.java @@ -1,7 +1,6 @@ package org.bukkit.event.entity; import org.bukkit.Entity; -import org.bukkit.LivingEntity; import org.bukkit.event.Event; /** -- cgit v1.2.3 From 7c93a16862c7d41c0765efb11e900621525c3c8a Mon Sep 17 00:00:00 2001 From: Luke GB Date: Sun, 9 Jan 2011 13:14:28 +0000 Subject: Added JavaDoc @see comments and @todo notes for those that aren't specified in the listener --- src/main/java/org/bukkit/event/Event.java | 87 +++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 05cd96a0..9524bd71 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -129,6 +129,8 @@ public abstract class Event { /** * Provides a lookup for all core events + * + * @see org.bukkit.event. */ public enum Type { /** @@ -137,46 +139,64 @@ public abstract class Event { /** * Called when a player joins a server + * + * @see org.bukkit.event.player.PlayerEvent */ PLAYER_JOIN (Category.PLAYER), /** * Called when a player is attempting to join a server + * + * @see org.bukkit.event.player.PlayerLoginEvent */ PLAYER_LOGIN (Category.PLAYER), /** * Called when a player sends a chat message + * + * @see org.bukkit.event.player.PlayerChatEvent */ PLAYER_CHAT (Category.PLAYER), /** * Called when a player attempts to use a command + * + * @see org.bukkit.event.player.PlayerChatEvent */ PLAYER_COMMAND (Category.PLAYER), /** * Called when a player leaves a server + * + * @see org.bukkit.event.player.PlayerEvent */ PLAYER_QUIT (Category.PLAYER), /** * Called when a player moves position in the world + * + * @see org.bukkit.event.player.PlayerMoveEvent */ PLAYER_MOVE (Category.PLAYER), /** * Called when a player undergoes an animation, such as arm swinging + * + * @todo: add javadoc see comment */ PLAYER_ANIMATION (Category.PLAYER), /** * Called when a player uses an item + * + * @see org.bukkit.event.player.PlayerItemEvent */ PLAYER_ITEM (Category.PLAYER), /** * Called when a player teleports from one position to another + * + * @see org.bukkit.event.player.PlayerMoveEvent */ PLAYER_TELEPORT (Category.PLAYER), @@ -186,6 +206,7 @@ public abstract class Event { /** * Called when a block is damaged (hit by a player) + * @todo: Add Javadoc see note here. */ BLOCK_DAMAGED (Category.BLOCK), @@ -194,18 +215,24 @@ public abstract class Event { * check on whether it can be built * * For example, cacti cannot be built on grass unless overridden here + * + * @see org.bukkit.event.block.BlockCanBuildEvent */ BLOCK_CANBUILD (Category.BLOCK), /** * Called when a block of water or lava attempts to flow into another * block + * + * @see org.bukkit.event.block.BlockFromToEvent */ BLOCK_FLOW (Category.BLOCK), /** * Called when a block is being set on fire from another block, such as * an adjacent block of fire attempting to set fire to wood + * + * @see org.bukkit.event.block.BlockIgniteEvent */ BLOCK_IGNITE (Category.BLOCK), @@ -214,32 +241,44 @@ public abstract class Event { * * A physics check is commonly called when an adjacent block changes * type + * + * @see org.bukkit.event.block.BlockPhysicsEvent */ BLOCK_PHYSICS (Category.BLOCK), /** * Called when a player is attempting to place a block + * + * @see org.bukkit.event.block.BlockRightClickedEvent */ BLOCK_RIGHTCLICKED (Category.BLOCK), /** * Called when a player is attempting to place a block + * + * @see org.bukkit.event.block.BlockPlacedEvent */ BLOCK_PLACED (Category.BLOCK), /** * Called when an entity interacts with a block (lever, door, pressure plate, chest, furnace) + * + * @see org.bukkit.event.block.BlockInteractEvent */ BLOCK_INTERACT (Category.BLOCK), /** * Called when leaves are decaying naturally + * + * @see org.bukkit.event.block.LeavesDecayEvent */ LEAVES_DECAY (Category.BLOCK), /** * Called when a liquid attempts to flow into a block which already * contains a "breakable" block, such as redstone wire + * + * @todo: add javadoc see comment */ LIQUID_DESTROY (Category.BLOCK), @@ -247,6 +286,8 @@ public abstract class Event { * Called when a block changes redstone current. Only triggered on blocks * that are actually capable of transmitting or carrying a redstone * current + * + * @see org.bukkit.event.block.BlockFromToEvent */ REDSTONE_CHANGE (Category.BLOCK), @@ -256,26 +297,36 @@ public abstract class Event { /** * Called when a player opens an inventory + * + * @todo: add javadoc see comment */ INVENTORY_OPEN (Category.INVENTORY), /** * Called when a player closes an inventory + * + * @todo: add javadoc see comment */ INVENTORY_CLOSE (Category.INVENTORY), /** * Called when a player clicks on an inventory slot + * + * @todo: add javadoc see comment */ INVENTORY_CLICK (Category.INVENTORY), /** * Called when an inventory slot changes values or type + * + * @todo: add javadoc see comment */ INVENTORY_CHANGE (Category.INVENTORY), /** * Called when a player is attempting to perform an inventory transaction + * + * @todo: add javadoc see comment */ INVENTORY_TRANSACTION (Category.INVENTORY), @@ -285,11 +336,15 @@ public abstract class Event { /** * Called when a plugin is enabled + * + * @see org.bukkit.event.server.PluginEvent */ PLUGIN_ENABLE (Category.SERVER), /** * Called when a plugin is disabled + * + * @see org.bukkit.event.server.PluginEvent */ PLUGIN_DISABLE (Category.SERVER), @@ -302,21 +357,29 @@ public abstract class Event { * * If a new chunk is being generated for loading, it will call * Type.CHUNK_GENERATION and then Type.CHUNK_LOADED upon completion + * + * @see org.bukkit.event.world.ChunkLoadedEvent */ CHUNK_LOADED (Category.WORLD), /** * Called when a chunk is unloaded + * + * @see org.bukkit.event.world.ChunkUnloadedEvent */ CHUNK_UNLOADED (Category.WORLD), /** * Called when a chunk needs to be generated + * + * @todo: add javadoc see comment */ CHUNK_GENERATION (Category.WORLD), /** * Called when an ItemEntity spawns in the world + * + * @todo: add javadoc see comment */ ITEM_SPAWN (Category.WORLD), @@ -327,27 +390,37 @@ public abstract class Event { /** * Called when a creature, either hostile or neutral, attempts to spawn * in the world "naturally" + * + * @todo: add javadoc see comment */ CREATURE_SPAWN (Category.LIVING_ENTITY), /** * Called when a LivingEntity is damaged by the environment (for example, * falling or lava) + * + * @see org.bukkit.event.entity.EntityDamagedByBlockEvent */ ENTITY_DAMAGEDBY_BLOCK (Category.LIVING_ENTITY), /** * Called when a LivingEntity is damaged by another LivingEntity + * + * @see org.bukkit.event.entity.EntityDamagedByEntityEvent */ ENTITY_DAMAGEDBY_ENTITY (Category.LIVING_ENTITY), /** * Called when a LivingEntity is damaged with no source. + * + * @see org.bukkit.event.entity.EntityDamagedEvent */ ENTITY_DAMAGED(Category.LIVING_ENTITY), /** * Called when a LivingEntity dies + * + * @todo: add javadoc see comment */ ENTITY_DEATH (Category.LIVING_ENTITY), @@ -357,36 +430,50 @@ public abstract class Event { /** * Called when a vehicle is placed by a player + * + * @see org.bukkit.event.vehicle.VehicleCreateEvent */ VEHICLE_CREATE (Category.VEHICLE), /** * Called when a vehicle is damaged by a LivingEntity + * + * @see org.bukkit.event.vehicle.VehicleDamageEvent */ VEHICLE_DAMAGE (Category.VEHICLE), /** * Called when a vehicle collides with an Entity + * + * @see org.bukkit.event.vehicle.VehicleCollisionEvent */ VEHICLE_COLLISION_ENTITY (Category.VEHICLE), /** * Called when a vehicle collides with a Block + * + * @see org.bukkit.event.vehicle.VehicleBlockCollisionEvent */ VEHICLE_COLLISION_BLOCK (Category.VEHICLE), /** * Called when a vehicle is entered by a LivingEntity + * + * @see org.bukkit.event.vehicle.VehicleEnterEvent */ VEHICLE_ENTER (Category.VEHICLE), /** * Called when a vehicle is exited by a LivingEntity + * + * @see org.bukkit.event.vehicle.VehicleExitEvent */ VEHICLE_EXIT (Category.VEHICLE), /** * Called when a vehicle moves position in the world + * + * @see org.bukkit.event.vehicle.VehicleMoveEvent */ VEHICLE_MOVE (Category.VEHICLE), -- cgit v1.2.3 From 5a1310148e9475e41a3c0a1ea51dc87d9a196593 Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Sun, 9 Jan 2011 18:21:31 +0100 Subject: Updated inventories to a has-a relationship. Added PlayerInventory interface with playeronly methods. Add equals to ItemStack. --- src/main/java/org/bukkit/HumanEntity.java | 32 +++++++- src/main/java/org/bukkit/Inventory.java | 114 +++++++++++++++++++++----- src/main/java/org/bukkit/ItemStack.java | 19 +++++ src/main/java/org/bukkit/PlayerInventory.java | 82 ++++++++++++++++++ src/main/java/org/bukkit/Slot.java | 22 +---- src/main/java/org/bukkit/StorageMinecart.java | 8 +- 6 files changed, 232 insertions(+), 45 deletions(-) create mode 100644 src/main/java/org/bukkit/PlayerInventory.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/HumanEntity.java b/src/main/java/org/bukkit/HumanEntity.java index 0cc7c1f5..04b391a8 100644 --- a/src/main/java/org/bukkit/HumanEntity.java +++ b/src/main/java/org/bukkit/HumanEntity.java @@ -13,10 +13,34 @@ public interface HumanEntity extends LivingEntity { public String getName(); /** - * Gets the item this entity has currently selected, which will be shown in - * their hand + * Get the player's inventory. * - * @return ItemStack containing details on the item this entity has selected + * @return The inventory of the player, this also contains the armor slots. */ - public ItemStack getSelectedItem(); + public PlayerInventory getInventory(); + + /** + * Returns the ItemStack currently in your hand, can be empty. + * + * @return The ItemStack of the item you are currently holding. + */ + public ItemStack getItemInHand(); + + + /** TODO: This probably won't work ;( + * Sets the item to the given ItemStack, this will replace whatever the + * user was holding. + * + * @param item The ItemStack which will end up in the hand + * @return + * + public void setItemInHand( ItemStack item ); + + ** + * Changes the item in hand to another of your 'action slots'. + * + * @param index The new index to use, only valid ones are 0-8. + * + public void selectItemInHand( int index ); + */ } diff --git a/src/main/java/org/bukkit/Inventory.java b/src/main/java/org/bukkit/Inventory.java index 7378903e..a3233694 100644 --- a/src/main/java/org/bukkit/Inventory.java +++ b/src/main/java/org/bukkit/Inventory.java @@ -1,6 +1,6 @@ package org.bukkit; -import java.util.Collection; +import java.util.HashMap; /** * Interface to the various inventories @@ -21,45 +21,115 @@ public interface Inventory { public String getName(); /** - * TODO Set the name of the inventory + * Get the ItemStack found in the slot at the given index * - * @param name The new name of the inventory - public void setName(String name); + * @param index The index of the Slot's ItemStack to return + * @return The ItemStack in the slot */ + public ItemStack getItem(int index); - /** TODO: Appears minecraft has different ideas for slots! - * Get the slot at a specific index of an inventory + /** + * Stores the ItemStack at the given index * - * @param index The index of the slot to get - * @return The Slot found at the index - public Slot getSlot(int index); + * @param index The index where to put the ItemStack + * @param item The ItemStack to set */ + public void setItem(int index, ItemStack item); /** - * Get the ItemStack found in the slot at the given index + * Stores the given ItemStacks in the inventory * - * @param index The index of the Slot's ItemStack to return - * @return The ItemStack in the slot + * @param items The ItemStacks to add + * @return */ - public ItemStack getItem(int index); + public HashMap addItem(ItemStack... items); /** * Get all ItemStacks from the inventory * * @return All the ItemStacks from all slots */ - public Collection getContents(); + public ItemStack[] getContents(); + + /** + * Check if the inventory contains any ItemStacks with the given materialId + * + * @param materialId The materialId to check for + * @return If any ItemStacks were found + */ + public boolean contains(int materialId); + + /** + * Check if the inventory contains any ItemStacks with the given material + * + * @param material The material to check for + * @return If any ItemStacks were found + */ + public boolean contains(Material material); + + /** + * Check if the inventory contains any ItemStacks matching the given ItemStack + * This will only match if both the type and the amount of the stack match + * + * @param item The ItemStack to match against + * @return If any matching ItemStacks were found + */ + public boolean contains(ItemStack item); + + /** + * Find all slots in the inventory containing any ItemStacks with the given materialId + * + * @param materialId The materialId to look for + * @return The Slots found. + */ + public HashMap all(int materialId); - /* - * TODO public boolean contains(int materialId); public boolean - * contains(Material material); public boolean contains(ItemStack item); + /** + * Find all slots in the inventory containing any ItemStacks with the given material * - * public Collection all(int materialId); public Collection - * all(Material material); public Collection all(ItemStack item); + * @param materialId The material to look for + * @return The Slots found. + */ + public HashMap all(Material material); + + /** + * Find all slots in the inventory containing any ItemStacks with the given ItemStack + * This will only match slots if both the type and the amount of the stack match * - * public Slot first(int materialId); public Slot first(Material material); - * public Slot first(ItemStack item); + * @param item The ItemStack to match against + * @return The Slots found. + */ + public HashMap all(ItemStack item); + + /** + * Find the first slot in the inventory containing an ItemStack with the given materialId + * + * @param materialId The materialId to look for + * @return The Slot found. + */ + public int first(int materialId); + + /** + * Find the first slot in the inventory containing an ItemStack with the given material + * + * @param materialId The material to look for + * @return The Slot found. + */ + public int first(Material material); + + /** + * Find the first slot in the inventory containing an ItemStack with the given stack + * This will only match a slot if both the type and the amount of the stack match + * + * @param item The ItemStack to match against + * @return The Slot found. + */ + public int first(ItemStack item); + + /** + * Find the first empty Slot. * - * public int firstEmptyIndex(); + * @return The first empty Slot found. */ + public int firstEmpty(); } \ No newline at end of file diff --git a/src/main/java/org/bukkit/ItemStack.java b/src/main/java/org/bukkit/ItemStack.java index f2350621..e90a5fe5 100644 --- a/src/main/java/org/bukkit/ItemStack.java +++ b/src/main/java/org/bukkit/ItemStack.java @@ -115,4 +115,23 @@ public class ItemStack { public byte getDamage() { return damage; } + + /** + * Get the maximum stacksize for the material hold in this ItemStack + * Returns -1 if it has no idea. + * + * @return The maximum you can stack this material to. + */ + public int getMaxStackSize() { + return -1; + } + + @Override + public boolean equals(Object object) { + return false; + } + + public boolean equals(ItemStack item) { + return item.getAmount() == getAmount() && item.getTypeID() == getTypeID(); + } } diff --git a/src/main/java/org/bukkit/PlayerInventory.java b/src/main/java/org/bukkit/PlayerInventory.java new file mode 100644 index 00000000..419eb07b --- /dev/null +++ b/src/main/java/org/bukkit/PlayerInventory.java @@ -0,0 +1,82 @@ +package org.bukkit; + +import java.util.ArrayList; + +/** + * Includes interface to the 4 armor slots + */ +public interface PlayerInventory extends Inventory { + /** + * Get all ItemStacks from the armor slots + * + * @return All the ItemStacks from the armor slots + */ + public ArrayList getArmorContents(); + + /** + * Return the ItemStack from the helmet slot + * + * @return The ItemStack in the helmet slot + */ + public ItemStack getHelmet(); + + /** + * Return the ItemStack from the chestplate slot + * + * @return The ItemStack in the chestplate slot + */ + public ItemStack getChestplate(); + + /** + * Return the ItemStack from the leg slot + * + * @return The ItemStack in the leg slot + */ + public ItemStack getLeggings(); + + /** + * Return the ItemStack from the boots slot + * + * @return The ItemStack in the boots slot + */ + public ItemStack getBoots(); + + /** + * Put the given ItemStack into the helmet slot + * This does not check if the ItemStack is a helmet + * + * @param helmet The ItemStack to use as helmet + */ + public void setHelmet(ItemStack helmet); + + /** + * Put the given ItemStack into the chestplate slot + * This does not check if the ItemStack is a chestplate + * + * @param chestplate The ItemStack to use as chestplate + */ + public void setChestplate(ItemStack chestplate); + + /** + * Put the given ItemStack into the leg slot + * This does not check if the ItemStack is a pair of leggings + * + * @param leggings The ItemStack to use as leggings + */ + public void setLeggings(ItemStack leggings); + + /** + * Put the given ItemStack into the boots slot + * This does not check if the ItemStack is a boots + * + * @param boots The ItemStack to use as boots + */ + public void setBoots(ItemStack boots); + + /** + * Returns the ItemStack currently hold + * + * @return The currently holded ItemStack + */ + public ItemStack getItemInHand(); +} \ No newline at end of file diff --git a/src/main/java/org/bukkit/Slot.java b/src/main/java/org/bukkit/Slot.java index 3ead0399..008c464f 100644 --- a/src/main/java/org/bukkit/Slot.java +++ b/src/main/java/org/bukkit/Slot.java @@ -3,39 +3,25 @@ package org.bukkit; /** * Represents a slot in an inventory */ -public class Slot { - private Inventory inventory; - private int index; - - public Slot(Inventory inventory, int index) { - this.inventory = inventory; - this.index = index; - } - +public interface Slot { /** * Gets the inventory this slot belongs to * * @return The inventory */ - public Inventory getInventory() { - return inventory; - } + public Inventory getInventory(); /** * Get the index this slot belongs to * * @return Index of the slot */ - public int getIndex() { - return index; - } + public int getIndex(); /** * Get the item from the slot. * * @return ItemStack in the slot. */ - public ItemStack getItem() { - return inventory.getItem(index); - } + public ItemStack getItem(); } diff --git a/src/main/java/org/bukkit/StorageMinecart.java b/src/main/java/org/bukkit/StorageMinecart.java index bd7b1b02..7ec1b5ac 100644 --- a/src/main/java/org/bukkit/StorageMinecart.java +++ b/src/main/java/org/bukkit/StorageMinecart.java @@ -5,5 +5,11 @@ package org.bukkit; * * @author sk89q */ -public interface StorageMinecart extends Minecart, Inventory { +public interface StorageMinecart extends Minecart { + /** + * Return the inventory object for this StorageMinecart. + * + * @return The inventory for this Minecart + */ + public Inventory getInventory(); } -- cgit v1.2.3 From a83e58e4625b0b5117d0d6daec2bcf43714c8980 Mon Sep 17 00:00:00 2001 From: durron597 Date: Sun, 9 Jan 2011 12:33:27 -0500 Subject: forgot to initialize cancel --- src/main/java/org/bukkit/event/block/BlockInteractEvent.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/block/BlockInteractEvent.java b/src/main/java/org/bukkit/event/block/BlockInteractEvent.java index 5447724b..37a343ad 100644 --- a/src/main/java/org/bukkit/event/block/BlockInteractEvent.java +++ b/src/main/java/org/bukkit/event/block/BlockInteractEvent.java @@ -27,6 +27,7 @@ public class BlockInteractEvent extends BlockEvent implements Cancellable { public BlockInteractEvent(Type type, Block interactedBlock, LivingEntity who) { super(type, interactedBlock); theEntity = who; + cancel = false; } /** -- cgit v1.2.3 From 68f23c547ca865db0be32402ed5ff7cc141f5183 Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Sun, 9 Jan 2011 23:40:29 +0100 Subject: Fixed getArmorContents() return value --- src/main/java/org/bukkit/ItemStack.java | 5 +++++ src/main/java/org/bukkit/PlayerInventory.java | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/ItemStack.java b/src/main/java/org/bukkit/ItemStack.java index e90a5fe5..b2a4c6f4 100644 --- a/src/main/java/org/bukkit/ItemStack.java +++ b/src/main/java/org/bukkit/ItemStack.java @@ -126,6 +126,11 @@ public class ItemStack { return -1; } + @Override + public String toString() { + return "ItemStack{"+getType().name()+" x "+getAmount()+"}"; + } + @Override public boolean equals(Object object) { return false; diff --git a/src/main/java/org/bukkit/PlayerInventory.java b/src/main/java/org/bukkit/PlayerInventory.java index 419eb07b..9dfffc6d 100644 --- a/src/main/java/org/bukkit/PlayerInventory.java +++ b/src/main/java/org/bukkit/PlayerInventory.java @@ -1,7 +1,5 @@ package org.bukkit; -import java.util.ArrayList; - /** * Includes interface to the 4 armor slots */ @@ -11,7 +9,7 @@ public interface PlayerInventory extends Inventory { * * @return All the ItemStacks from the armor slots */ - public ArrayList getArmorContents(); + public ItemStack[] getArmorContents(); /** * Return the ItemStack from the helmet slot -- cgit v1.2.3 From 9967ab16f61b2c3d5d495550d3da9f204989e216 Mon Sep 17 00:00:00 2001 From: Taylor Kelly Date: Mon, 10 Jan 2011 06:05:43 +0800 Subject: Cleaned up Fillr --- src/main/java/org/bukkit/fillr/Checker.java | 180 ++++++++-------- src/main/java/org/bukkit/fillr/Downloader.java | 285 ++++++++++++------------- src/main/java/org/bukkit/fillr/FillReader.java | 6 +- src/main/java/org/bukkit/fillr/Fillr.java | 31 +-- src/main/java/org/bukkit/fillr/Getter.java | 4 +- src/main/java/org/bukkit/fillr/Updater.java | 8 +- 6 files changed, 245 insertions(+), 269 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/fillr/Checker.java b/src/main/java/org/bukkit/fillr/Checker.java index 612957b2..8ae176bc 100644 --- a/src/main/java/org/bukkit/fillr/Checker.java +++ b/src/main/java/org/bukkit/fillr/Checker.java @@ -6,100 +6,96 @@ import org.bukkit.*; import org.bukkit.plugin.*; public class Checker { - private static String directory = Fillr.directory; + private static String DIRECTORY = Fillr.DIRECTORY; - /** - * Checks all the plugins in plugins/ for updates - * - * @param player - * The player to send info to - */ - void check(Player player) { - File folder = new File(directory); - File[] files = folder.listFiles(new PluginFilter()); - if (files.length == 0) { - player.sendMessage("No plugins to update."); - } else { - player.sendMessage("Status for " + files.length - + " plugins:"); - for (File file : files) { - PluginDescriptionFile pdfFile = Checker.getPDF(file); - if (pdfFile == null) { - continue; - } - checkForUpdate(file, player); - } - } - } + /** + * Checks all the plugins in plugins/ for updates + * + * @param player + * The player to send info to + */ + void check(Player player) { + File folder = new File(DIRECTORY); + File[] files = folder.listFiles(new PluginFilter()); + if (files.length == 0) { + player.sendMessage("No plugins to update."); + } else { + player.sendMessage("Status for " + files.length + " plugins:"); + for (File file : files) { + PluginDescriptionFile pdfFile = Checker.getPDF(file); + if (pdfFile == null) { + continue; + } + checkForUpdate(file, player); + } + } + } - /** - * Checks for an update for a given plugin - * - * @param file - * The plugin file to check for an update - * @param player - * The player to send info to - */ - private void checkForUpdate(File file, Player player) { - PluginDescriptionFile pdfFile = Checker.getPDF(file); - FillReader reader = needsUpdate(pdfFile); - if (reader != null) { - player.sendMessage(Color.RED + reader.getName() + " " - + pdfFile.getVersion() + " has an update to " - + reader.getCurrVersion()); - } else { - player.sendMessage(reader.getName() + " " + reader.getCurrVersion() - + " is up to date!"); - } - } + /** + * Checks for an update for a given plugin + * + * @param file + * The plugin file to check for an update + * @param player + * The player to send info to + */ + private void checkForUpdate(File file, Player player) { + PluginDescriptionFile pdfFile = Checker.getPDF(file); + FillReader reader = needsUpdate(pdfFile); + if (reader != null) { + player.sendMessage(Color.RED + reader.getName() + " " + pdfFile.getVersion() + " has an update to " + reader.getCurrVersion()); + } else { + player.sendMessage(pdfFile.getName() + " " + pdfFile.getVersion() + " is up to date!"); + } + } - /** - * Checks if a given plugin needs an update - * - * @param file - * The .yml file to check - * @return The FillReader for the online repo info on the plugin - */ - static FillReader needsUpdate(PluginDescriptionFile file) { - FillReader reader = new FillReader(file.getName()); - String version = file.getVersion(); - String currVersion = reader.getCurrVersion(); - String name = reader.getName(); - if (currVersion.equalsIgnoreCase(version) - && new File(directory, name + ".jar").exists()) { - return null; - } else { - return reader; - } - } + /** + * Checks if a given plugin needs an update + * + * @param file + * The .yml file to check + * @return The FillReader for the online repo info on the plugin if the plugin needs an update + * Returns null if no update is needed. + */ + static FillReader needsUpdate(PluginDescriptionFile file) { + FillReader reader = new FillReader(file.getName()); + String version = file.getVersion(); + String currVersion = reader.getCurrVersion(); + String name = reader.getName(); + if (currVersion.equalsIgnoreCase(version) && new File(DIRECTORY, name + ".jar").exists()) { + return null; + } else { + return reader; + } + } - /** - * Will grab the plugin's .yml file from the give file (hopefully a plugin). - * It'll throw it into a PluginDescriptionFile - * - * @param file - * The plugin (jar) file - * @return The PluginDescriptionFile representing the .yml - */ - static PluginDescriptionFile getPDF(File file) { - // TODO supports only jar files for now. how will yml's be stored in - // different languages? - if (file.getName().endsWith(".jar")) { - JarFile jarFile; - try { - jarFile = new JarFile(file); - JarEntry entry = jarFile.getJarEntry("plugin.yml"); - InputStream input = jarFile.getInputStream(entry); - return new PluginDescriptionFile(input); - } catch (IOException e) { - e.printStackTrace(); - return null; - } catch (InvalidDescriptionException e) { - e.printStackTrace(); - return null; - } - } else { - return null; - } - } + /** + * Will grab the plugin's .yml file from the give file (hopefully a plugin). + * It'll throw it into a PluginDescriptionFile + * + * @param file + * The plugin (jar) file + * @return The PluginDescriptionFile representing the .yml + */ + static PluginDescriptionFile getPDF(File file) { + // TODO supports only jar files for now. how will yml's be stored in + // different languages? + if (file.getName().endsWith(".jar")) { + JarFile jarFile; + try { + jarFile = new JarFile(file); + JarEntry entry = jarFile.getJarEntry("plugin.yml"); + InputStream input = jarFile.getInputStream(entry); + return new PluginDescriptionFile(input); + } catch (IOException e) { + e.printStackTrace(); + return null; + } catch (InvalidDescriptionException e) { + e.printStackTrace(); + return null; + } + } else { + return null; + } + } } diff --git a/src/main/java/org/bukkit/fillr/Downloader.java b/src/main/java/org/bukkit/fillr/Downloader.java index 8dc44c95..3b9d8e75 100644 --- a/src/main/java/org/bukkit/fillr/Downloader.java +++ b/src/main/java/org/bukkit/fillr/Downloader.java @@ -7,158 +7,135 @@ import java.io.*; import java.net.URL; public class Downloader { - private final static String directory = Fillr.directory; - private final static String downloads = directory + File.separator + "downloads"; - private final static String backup = "backup"; - - /** - * Downloads the jar from a given url. If it is a compressed archive, it - * tries to get the .jars out of it - * - * @param url - * The url to download from - */ - static void downloadJar(String url) throws Exception { - int index = url.lastIndexOf('/'); - String name = url.substring(index + 1); - - File file = new File(directory, name); - if (url.endsWith(".jar") && file.exists()) { - backupFile(file); - } - - download(new URL(url), name, directory); - file = new File("plugins", name); - /*if (name.endsWith(".zip") || name.endsWith(".tar") - || name.endsWith(".rar") || name.endsWith(".7z")) { - unzipPlugin(file); - file.delete(); - }*/ - } - - /** - * Downloads the file for a given plugin - * - * @param name - * The name of the plugin to download - * @param player - * The player to send info to - */ - void downloadFile(String name, Player player) throws Exception { - File file = new File(directory, name + ".jar"); - if (file.exists()) { - player.sendMessage("Downloading " + name + "'s file"); - PluginDescriptionFile pdfFile = Checker.getPDF(file); - FillReader reader = Checker.needsUpdate(pdfFile); - downloadFile(new URL(reader.getFile())); - player.sendMessage("Finished download"); - } else { - System.out.println("Can't find " + name); - } - } - - /** - * Downloads the file to the plugin/downloads directory - * - * @param u - * The url of the file to download - */ - private void downloadFile(URL u) throws Exception { - String name = u.getFile(); - int index = name.lastIndexOf('/'); - name = name.substring(index + 1); - download(u, name, downloads); - } - - /** - * Downloads the file to a given directory with a given name - * - * @param u - * The url of the file to download - * @param name - * The name to give the file - * @param directory - * The directory to put the file - */ - private static void download(URL u, String name, String directory) - throws Exception { - InputStream inputStream = null; - // try { - inputStream = u.openStream(); - - if (!new File(directory).exists()) { - new File(directory).mkdir(); - } - - File f = new File(directory, name); - if (f.exists()) { - f.delete(); - } - f.createNewFile(); - - copyInputStream(inputStream, new BufferedOutputStream( - new FileOutputStream(f))); - - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (IOException ioe) { - System.out.println("[UPDATR]: Error closing inputStream"); - } - // } - } - - /** - * Decompresses a file! How nice. - * - * @param f - * the file to decompress - */ - private static void unzipPlugin(File f) { - try { - System.out.println("Extracting jars out of " + f.getName()); - //ExtractorUtil.extract(f, f.getAbsolutePath()); - } catch (Exception e) { - System.out.println("[UPDATR]: Error decompressing " + f.getName()); - } - } - - /** - * Copies an InputStream to an OutputStream! - * - * @param in - * InputStream - * @param out - * OutputStream - * @throws IOException - */ - private static final void copyInputStream(InputStream in, OutputStream out) - throws IOException { - byte[] buffer = new byte[1024]; - int len; - - while ((len = in.read(buffer)) >= 0) { - out.write(buffer, 0, len); - } - - in.close(); - out.close(); - } - - /** - * Moves the file to the backup folder. - * - * @param file - * The file to backup - */ - private static void backupFile(File file) { - if (file.exists()) { - System.out.println("Backing up old file: " + file.getName()); - if (!new File(backup).exists()) { - new File(backup).mkdir(); - } - file.renameTo(new File(backup, file.getName() + ".bak")); - } - } + private final static String DIRECTORY = Fillr.DIRECTORY; + private final static String DOWNLOAD_DIR = DIRECTORY + File.separator + "downloads"; + private final static String BACKUP = DIRECTORY + File.separator + "backups"; + + /** + * Downloads the jar from a given url. If it is a compressed archive, it + * tries to get the .jars out of it + * + * @param url + * The url to download from + */ + static void downloadJar(String url) throws Exception { + int index = url.lastIndexOf('/'); + String name = url.substring(index + 1); + + File file = new File(DIRECTORY, name); + if (url.endsWith(".jar") && file.exists()) { + backupFile(file); + } + + download(new URL(url), name, DIRECTORY); + file = new File("plugins", name); + } + + /** + * Downloads the file for a given plugin + * + * @param name + * The name of the plugin to download + * @param player + * The player to send info to + */ + void downloadFile(String name, Player player) throws Exception { + File file = new File(DIRECTORY, name + ".jar"); + if (file.exists()) { + player.sendMessage("Downloading " + name + "'s file"); + PluginDescriptionFile pdfFile = Checker.getPDF(file); + FillReader reader = Checker.needsUpdate(pdfFile); + downloadFile(new URL(reader.getFile())); + player.sendMessage("Finished download"); + } else { + System.out.println("Can't find " + name); + } + } + + /** + * Downloads the file to the plugin/downloads directory + * + * @param u + * The url of the file to download + */ + private void downloadFile(URL u) throws Exception { + String name = u.getFile(); + int index = name.lastIndexOf('/'); + name = name.substring(index + 1); + download(u, name, DOWNLOAD_DIR); + } + + /** + * Downloads the file to a given directory with a given name + * + * @param u + * The url of the file to download + * @param name + * The name to give the file + * @param directory + * The directory to put the file + */ + private static void download(URL u, String name, String directory) throws Exception { + InputStream inputStream = null; + // try { + inputStream = u.openStream(); + + if (!new File(directory).exists()) { + new File(directory).mkdir(); + } + + File f = new File(directory, name); + if (f.exists()) { + f.delete(); + } + f.createNewFile(); + + copyInputStream(inputStream, new BufferedOutputStream(new FileOutputStream(f))); + + try { + if (inputStream != null) { + inputStream.close(); + } + } catch (IOException ioe) { + System.out.println("[UPDATR]: Error closing inputStream"); + } + // } + } + + /** + * Copies an InputStream to an OutputStream! + * + * @param in + * InputStream + * @param out + * OutputStream + * @throws IOException + */ + private static final void copyInputStream(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[1024]; + int len; + + while ((len = in.read(buffer)) >= 0) { + out.write(buffer, 0, len); + } + + in.close(); + out.close(); + } + + /** + * Moves the file to the backup folder. + * + * @param file + * The file to backup + */ + private static void backupFile(File file) { + if (file.exists()) { + System.out.println("Backing up old file: " + file.getName()); + if (!new File(BACKUP).exists()) { + new File(BACKUP).mkdir(); + } + file.renameTo(new File(BACKUP, file.getName() + ".bak")); + } + } } diff --git a/src/main/java/org/bukkit/fillr/FillReader.java b/src/main/java/org/bukkit/fillr/FillReader.java index ce94283a..d32e8a4e 100644 --- a/src/main/java/org/bukkit/fillr/FillReader.java +++ b/src/main/java/org/bukkit/fillr/FillReader.java @@ -13,7 +13,7 @@ import org.json.simple.parser.ParseException; */ public class FillReader { //TODO change this to what it will actually be... - private static String baseUrl = "http://taylorkelly.me/pnfo.php"; + private static final String BASE_URL = "http://taylorkelly.me/pnfo.php"; private String currVersion; private String file; private String name; @@ -24,8 +24,8 @@ public class FillReader { try { String result = ""; try { - URL url = new URL(baseUrl + "?name=" + name); - System.out.println(baseUrl + "?name=" + name); + URL url = new URL(BASE_URL + "?name=" + name); + System.out.println(BASE_URL + "?name=" + name); URLConnection conn = url.openConnection(); StringBuilder buf = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader( diff --git a/src/main/java/org/bukkit/fillr/Fillr.java b/src/main/java/org/bukkit/fillr/Fillr.java index b185fea2..4cb0654d 100644 --- a/src/main/java/org/bukkit/fillr/Fillr.java +++ b/src/main/java/org/bukkit/fillr/Fillr.java @@ -8,21 +8,24 @@ import org.bukkit.event.*; import java.io.File; public class Fillr extends JavaPlugin { - private FillrListener listener; - public static String name = "Fillr"; - public static String version = "1.0"; - public static String directory = "plugins"; + private FillrListener listener; + public static final String NAME = "Fillr"; + public static final String VERSION = "1.0"; + public static final String DIRECTORY = "plugins"; - public Fillr(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { - super(pluginLoader, instance, desc, plugin, cLoader); - registerEvents(); - } + public Fillr(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) { + super(pluginLoader, instance, desc, plugin, cLoader); + } - public void onDisable() {} - public void onEnable() {} + public void onDisable() { + } - private void registerEvents() { - listener = new FillrListener(getServer()); - getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, listener, Event.Priority.Normal, this); - } + public void onEnable() { + registerEvents(); + } + + private void registerEvents() { + listener = new FillrListener(getServer()); + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, listener, Event.Priority.Normal, this); + } } diff --git a/src/main/java/org/bukkit/fillr/Getter.java b/src/main/java/org/bukkit/fillr/Getter.java index 1bbd5b4c..c1197d48 100644 --- a/src/main/java/org/bukkit/fillr/Getter.java +++ b/src/main/java/org/bukkit/fillr/Getter.java @@ -10,7 +10,7 @@ import org.bukkit.plugin.InvalidPluginException; public class Getter { private Server server; - private static String directory = Fillr.directory; + private static String DIRECTORY = Fillr.DIRECTORY; public Getter(Server server) { this.server = server; @@ -36,7 +36,7 @@ public class Getter { private void enablePlugin(FillReader update) { final String name = update.getName(); //TODO again with the implicit jar support... - File plugin = new File(directory, name + ".jar"); + File plugin = new File(DIRECTORY, name + ".jar"); try { server.getPluginManager().loadPlugin(plugin); } catch (InvalidPluginException ex) { diff --git a/src/main/java/org/bukkit/fillr/Updater.java b/src/main/java/org/bukkit/fillr/Updater.java index 1ca26b60..3a301538 100644 --- a/src/main/java/org/bukkit/fillr/Updater.java +++ b/src/main/java/org/bukkit/fillr/Updater.java @@ -8,7 +8,7 @@ import java.util.logging.Level; import java.util.logging.Logger; public class Updater { - public static String directory = Fillr.directory; + public static String DIRECTORY = Fillr.DIRECTORY; private final Server server; Updater(Server server) { @@ -22,7 +22,7 @@ public class Updater { * The player to send info to */ void updateAll(Player player) { - File folder = new File(directory); + File folder = new File(DIRECTORY); File[] files = folder.listFiles(new PluginFilter()); if (files.length == 0) { player.sendMessage("No plugins to update."); @@ -52,7 +52,7 @@ public class Updater { */ void update(String string, Player player) { //TODO so much .jars - File file = new File(directory, string + ".jar"); + File file = new File(DIRECTORY, string + ".jar"); if (file.exists()) { PluginDescriptionFile pdfFile = Checker.getPDF(file); FillReader reader = Checker.needsUpdate(pdfFile); @@ -94,7 +94,7 @@ public class Updater { void enablePlugin(FillReader update) { final String name = update.getName(); //TODO again with the implicit jar support... - File plugin = new File(directory, name + ".jar"); + File plugin = new File(DIRECTORY, name + ".jar"); try { server.getPluginManager().loadPlugin(plugin); } catch (InvalidPluginException ex) { -- cgit v1.2.3 From 7d6400eb1df06de2f8e341d3b45d1312908f7b15 Mon Sep 17 00:00:00 2001 From: speakeasy Date: Sun, 9 Jan 2011 18:10:44 +0800 Subject: Added BlockIgniteEvent. --- .../org/bukkit/event/block/BlockIgniteEvent.java | 91 ++++++++++++++++++++-- .../org/bukkit/plugin/java/JavaPluginLoader.java | 3 + 2 files changed, 88 insertions(+), 6 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java b/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java index 62745b34..c43a6a2b 100644 --- a/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java +++ b/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java @@ -1,19 +1,98 @@ package org.bukkit.event.block; +import org.bukkit.Block; +import org.bukkit.Player; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; /** - * @author durron597 + * @author SpeaKeasY * + * Represents a block ignite event. */ -public class BlockIgniteEvent extends Event { +public class BlockIgniteEvent extends BlockEvent implements Cancellable { + + private IgniteCause cause; + private boolean cancel; + private Player thePlayer; + private Block theBlock; + + /** + * @param Block, IgniteCause, Player or null. + */ + public BlockIgniteEvent(Block theBlock, IgniteCause cause, Player thePlayer) { + super(Event.Type.BLOCK_IGNITE, theBlock); + this.cause = cause; + this.theBlock = theBlock; + this.thePlayer = thePlayer; + this.cancel = false; + } + + /** + * Gets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins. + * + * If an ignite event is cancelled, the block will not be ignited. + * This will not fire an event. + * + * @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. + * + * If an ignite event is cancelled, the block will not be ignited. + * This will not fire an event. + * + * @param cancel true if you wish to cancel this event + */ + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } + + /** + * Gets the cause of block ignite. + * @return An IgniteCause value detailing the cause of block ignition. + */ + public IgniteCause getCause() + { + return cause; + } /** - * @param type + * Gets the player who ignited this block + * + * @return Player who placed the block, if not ignited by player returns null. */ - public BlockIgniteEvent(Type type) { - super(type); - // TODO Auto-generated constructor stub + public Player getPlayer() { + return thePlayer; + } + + /** + * An enum to specify the cause of the ignite + */ + public enum IgniteCause { + /** + * Block ignition caused by lava. + */ + LAVA, + /** + * Block ignition caused by player using flint-and-steel. + */ + FLINT_AND_STEEL, + /** + * Block ignition caused by dynamic spreading of fire. + */ + SPREAD, + /** + * Block ignition caused by VERY SLOW dynamic spreading of fire. + */ + SLOW_SPREAD + } } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index fd68f0c4..346429d5 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -140,6 +140,9 @@ public final class JavaPluginLoader implements PluginLoader { case LEAVES_DECAY: trueListener.onLeavesDecay((LeavesDecayEvent)event); break; + case BLOCK_IGNITE: + trueListener.onBlockIgnite((BlockIgniteEvent)event); + break; } } else if(listener instanceof ServerListener) { ServerListener trueListener = (ServerListener)listener; -- cgit v1.2.3 From 219c0772fd48e9facb0d2f8cde5920d88bfd0ce6 Mon Sep 17 00:00:00 2001 From: Taylor Kelly Date: Mon, 10 Jan 2011 06:51:10 +0800 Subject: EntityCombustEvent --- src/main/java/org/bukkit/event/Event.java | 7 ++++++ .../bukkit/event/entity/EntityCombustEvent.java | 27 ++++++++++++++++++++++ .../org/bukkit/event/entity/EntityListener.java | 3 +++ .../org/bukkit/plugin/java/JavaPluginLoader.java | 4 ++++ 4 files changed, 41 insertions(+) create mode 100644 src/main/java/org/bukkit/event/entity/EntityCombustEvent.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/event/Event.java b/src/main/java/org/bukkit/event/Event.java index 9524bd71..61bebb4e 100644 --- a/src/main/java/org/bukkit/event/Event.java +++ b/src/main/java/org/bukkit/event/Event.java @@ -423,6 +423,13 @@ public abstract class Event { * @todo: add javadoc see comment */ ENTITY_DEATH (Category.LIVING_ENTITY), + + /** + * Called when a Skeleton or Zombie catch fire due to the sun + * + * @todo: add javadoc see comment + */ + ENTITY_COMBUST (Category.LIVING_ENTITY), /** * VEHICLE EVENTS diff --git a/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java b/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java new file mode 100644 index 00000000..e1e54217 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java @@ -0,0 +1,27 @@ +package org.bukkit.event.entity; + +import org.bukkit.Entity; +import org.bukkit.event.Cancellable; + +/** + * The event when a skeleton or zombie catch on fire due to the sun. + * If the event is cancelled, the fire is stopped. + */ +public class EntityCombustEvent extends EntityEvent implements Cancellable { + private boolean cancel; + + public EntityCombustEvent(Type type, Entity what) { + super(type, what); + this.cancel = false; + } + + @Override + public boolean isCancelled() { + return cancel; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } +} diff --git a/src/main/java/org/bukkit/event/entity/EntityListener.java b/src/main/java/org/bukkit/event/entity/EntityListener.java index 60808f52..f7e4de5c 100644 --- a/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -14,4 +14,7 @@ public class EntityListener implements Listener { public void onEntityDamagedByEntity(EntityDamagedByEntityEvent event) { } + + public void onEntityCombust(EntityCombustEvent event) { + } } diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 346429d5..75d4d91c 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -16,6 +16,7 @@ import org.bukkit.event.CustomEventListener; import org.bukkit.event.Event; import org.bukkit.event.Listener; import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamagedByBlockEvent; import org.bukkit.event.entity.EntityDamagedByEntityEvent; import org.bukkit.event.entity.EntityListener; @@ -179,6 +180,9 @@ public final class JavaPluginLoader implements PluginLoader { case ENTITY_DEATH: // TODO: ENTITY_DEATH hook break; + case ENTITY_COMBUST: + trueListener.onEntityCombust((EntityCombustEvent)event); + break; } } else if (listener instanceof VehicleListener) { VehicleListener trueListener = (VehicleListener)listener; -- cgit v1.2.3 From a213311a1d2e6ee2bc36713d5da37d915e80d99e Mon Sep 17 00:00:00 2001 From: Taylor Kelly Date: Mon, 10 Jan 2011 06:34:59 +0800 Subject: BlockDamagedEvent --- src/main/java/org/bukkit/BlockDamageLevel.java | 15 +++++++ .../org/bukkit/event/block/BlockBrokenEvent.java | 19 --------- .../org/bukkit/event/block/BlockDamagedEvent.java | 48 ++++++++++++++++++++++ .../java/org/bukkit/event/block/BlockListener.java | 4 +- .../org/bukkit/plugin/java/JavaPluginLoader.java | 3 ++ 5 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 src/main/java/org/bukkit/BlockDamageLevel.java delete mode 100644 src/main/java/org/bukkit/event/block/BlockBrokenEvent.java create mode 100644 src/main/java/org/bukkit/event/block/BlockDamagedEvent.java (limited to 'src/main') diff --git a/src/main/java/org/bukkit/BlockDamageLevel.java b/src/main/java/org/bukkit/BlockDamageLevel.java new file mode 100644 index 00000000..bb8e4b23 --- /dev/null +++ b/src/main/java/org/bukkit/BlockDamageLevel.java @@ -0,0 +1,15 @@ +package org.bukkit; + +public enum BlockDamageLevel { + STARTED(0), DIGGING(1), BROKEN(3), STOPPED(2); + + private int level; + + private BlockDamageLevel(final int level) { + this.level = level; + } + + public int getLevel() { + return level; + } +} diff --git a/src/main/java/org/bukkit/event/block/BlockBrokenEvent.java b/src/main/java/org/bukkit/event/block/BlockBrokenEvent.java deleted file mode 100644 index ec064865..00000000 --- a/src/main/java/org/bukkit/event/block/BlockBrokenEvent.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.bukkit.event.block; - -import org.bukkit.Block; -import org.bukkit.Player; - -/** - * Not implemented yet - */ -public class BlockBrokenEvent extends BlockEvent { - private Player player; - - public BlockBrokenEvent(Type type, Block block ) { - super(type, block); - } - - public Player getPlayer() { - return player; - } -} diff --git a/src/main/java/org/bukkit/event/block/BlockDamagedEvent.java b/src/main/java/org/bukkit/event/block/BlockDamagedEvent.java new file mode 100644 index 00000000..5586f846 --- /dev/null +++ b/src/main/java/org/bukkit/event/block/BlockDamagedEvent.java @@ -0,0 +1,48 @@ +package org.bukkit.event.block; + +import org.bukkit.Block; +import org.bukkit.BlockDamageLevel; +import org.bukkit.Player; +import org.bukkit.event.Cancellable; + +/** + * @author tkelly + */ +public class BlockDamagedEvent extends BlockEvent implements Cancellable { + private Player player; + private BlockDamageLevel damageLevel; + private boolean cancel; + + public BlockDamagedEvent(Type type, Block block, BlockDamageLevel level, Player player) { + super(type, block); + this.damageLevel = level; + this.player = player; + this.cancel = false; + } + + /** + * Returns the player doing the damage + * + * @return + */ + public Player getPlayer() { + return player; + } + + /** + * Returns the level of damage to the block + * + * @return + */ + public BlockDamageLevel getDamageLevel() { + return damageLevel; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = cancel; + } +} diff --git a/src/main/java/org/bukkit/event/block/BlockListener.java b/src/main/java/org/bukkit/event/block/BlockListener.java index d7ee313e..f7ef3738 100644 --- a/src/main/java/org/bukkit/event/block/BlockListener.java +++ b/src/main/java/org/bukkit/event/block/BlockListener.java @@ -15,11 +15,11 @@ public class BlockListener implements Listener { } /** - * Called when a block is broken (or destroyed) + * Called when a block is damaged (or broken) * * @param event Relevant event details */ - public void onBlockBroken(BlockBrokenEvent event) { + public void onBlockDamaged(BlockDamagedEvent event) { } /** diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 75d4d91c..1a5b9210 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -132,6 +132,9 @@ public final class JavaPluginLoader implements PluginLoader { case BLOCK_PLACED: trueListener.onBlockPlaced((BlockPlacedEvent)event); break; + case BLOCK_DAMAGED: + trueListener.onBlockDamaged((BlockDamagedEvent)event); + break; case BLOCK_INTERACT: trueListener.onBlockInteracted((BlockInteractEvent)event); break; -- cgit v1.2.3