diff --git a/paper-api/src/main/java/org/bukkit/Biome.java b/paper-api/src/main/java/org/bukkit/Biome.java new file mode 100644 index 0000000000..265b99ce15 --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/Block.java b/paper-api/src/main/java/org/bukkit/Block.java index 8909de4d9d..90d6523d76 100644 --- a/paper-api/src/main/java/org/bukkit/Block.java +++ b/paper-api/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 { /** @@ -12,13 +17,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 * @@ -103,6 +128,43 @@ 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
+ *
+ * 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); + + /** + * 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(); + + /** + * Returns the biome that this block resides in + * + * @return Biome type containing this block + */ + Biome getBiome(); } diff --git a/paper-api/src/main/java/org/bukkit/BlockDamageLevel.java b/paper-api/src/main/java/org/bukkit/BlockDamageLevel.java new file mode 100644 index 0000000000..bb8e4b231a --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/BlockFace.java b/paper-api/src/main/java/org/bukkit/BlockFace.java index aba16cbf6f..12eb2c54d3 100644 --- a/paper-api/src/main/java/org/bukkit/BlockFace.java +++ b/paper-api/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 diff --git a/paper-api/src/main/java/org/bukkit/Boat.java b/paper-api/src/main/java/org/bukkit/Boat.java new file mode 100644 index 0000000000..33958ec039 --- /dev/null +++ b/paper-api/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 { +} diff --git a/paper-api/src/main/java/org/bukkit/Entity.java b/paper-api/src/main/java/org/bukkit/Entity.java index 773354d070..9b4e63d0b2 100644 --- a/paper-api/src/main/java/org/bukkit/Entity.java +++ b/paper-api/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 * diff --git a/paper-api/src/main/java/org/bukkit/HumanEntity.java b/paper-api/src/main/java/org/bukkit/HumanEntity.java index 0cc7c1f51c..04b391a8dc 100644 --- a/paper-api/src/main/java/org/bukkit/HumanEntity.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/Inventory.java b/paper-api/src/main/java/org/bukkit/Inventory.java index 7378903e57..a3233694df 100644 --- a/paper-api/src/main/java/org/bukkit/Inventory.java +++ b/paper-api/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 @@ -20,21 +20,6 @@ public interface Inventory { */ public String getName(); - /** - * TODO Set the name of the inventory - * - * @param name The new name of the inventory - public void setName(String name); - */ - - /** TODO: Appears minecraft has different ideas for slots! - * Get the slot at a specific index of an inventory - * - * @param index The index of the slot to get - * @return The Slot found at the index - public Slot getSlot(int index); - */ - /** * Get the ItemStack found in the slot at the given index * @@ -43,23 +28,108 @@ public interface Inventory { */ public ItemStack getItem(int index); + /** + * Stores the ItemStack at the given index + * + * @param index The index where to put the ItemStack + * @param item The ItemStack to set + */ + public void setItem(int index, ItemStack item); + + /** + * Stores the given ItemStacks in the inventory + * + * @param items The ItemStacks to add + * @return + */ + public HashMap addItem(ItemStack... items); + /** * Get all ItemStacks from the inventory * * @return All the ItemStacks from all slots */ - public Collection getContents(); + public ItemStack[] getContents(); - /* - * TODO public boolean contains(int materialId); public boolean - * contains(Material material); public boolean contains(ItemStack item); + /** + * Check if the inventory contains any ItemStacks with the given materialId * - * public Collection all(int materialId); public Collection - * all(Material material); public Collection all(ItemStack item); - * - * public Slot first(int materialId); public Slot first(Material material); - * public Slot first(ItemStack item); - * - * public int firstEmptyIndex(); + * @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); + + /** + * Find all slots in the inventory containing any ItemStacks with the given material + * + * @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 + * + * @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. + * + * @return The first empty Slot found. + */ + public int firstEmpty(); } \ No newline at end of file diff --git a/paper-api/src/main/java/org/bukkit/ItemDrop.java b/paper-api/src/main/java/org/bukkit/ItemDrop.java new file mode 100644 index 0000000000..3e2fd59881 --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/ItemStack.java b/paper-api/src/main/java/org/bukkit/ItemStack.java index f235062134..b2a4c6f4bb 100644 --- a/paper-api/src/main/java/org/bukkit/ItemStack.java +++ b/paper-api/src/main/java/org/bukkit/ItemStack.java @@ -115,4 +115,28 @@ 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 String toString() { + return "ItemStack{"+getType().name()+" x "+getAmount()+"}"; + } + + @Override + public boolean equals(Object object) { + return false; + } + + public boolean equals(ItemStack item) { + return item.getAmount() == getAmount() && item.getTypeID() == getTypeID(); + } } diff --git a/paper-api/src/main/java/org/bukkit/LivingEntity.java b/paper-api/src/main/java/org/bukkit/LivingEntity.java index e8e6373ef6..f0987ba28a 100644 --- a/paper-api/src/main/java/org/bukkit/LivingEntity.java +++ b/paper-api/src/main/java/org/bukkit/LivingEntity.java @@ -28,4 +28,35 @@ public interface LivingEntity extends Entity { * Throws a snowball from the entity. */ public Snowball throwSnowball(); + + /** + * Shoots an arrow from the 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/paper-api/src/main/java/org/bukkit/Location.java b/paper-api/src/main/java/org/bukkit/Location.java index 6f19f8a5c3..0fffe00779 100644 --- a/paper-api/src/main/java/org/bukkit/Location.java +++ b/paper-api/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); } } diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index f420a5bbe7..ae08dcbf06 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -194,6 +194,10 @@ public enum Material { return id; } + public boolean isBlock() { + return id < 256; + } + public static Material getMaterial(final int id) { return lookupId.get(id); } @@ -201,7 +205,7 @@ public enum Material { public static Material getMaterial(final String name) { return lookupName.get(name); } - + static { for (Material material : values()) { lookupId.put(material.getID(), material); diff --git a/paper-api/src/main/java/org/bukkit/Player.java b/paper-api/src/main/java/org/bukkit/Player.java index b20aad20ba..3d3f4d3abe 100644 --- a/paper-api/src/main/java/org/bukkit/Player.java +++ b/paper-api/src/main/java/org/bukkit/Player.java @@ -21,6 +21,26 @@ 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 setDisplayName(String name); /** * Gets the socket address of this player diff --git a/paper-api/src/main/java/org/bukkit/PlayerInventory.java b/paper-api/src/main/java/org/bukkit/PlayerInventory.java new file mode 100644 index 0000000000..9dfffc6d68 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/PlayerInventory.java @@ -0,0 +1,80 @@ +package org.bukkit; + +/** + * 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 ItemStack[] 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/paper-api/src/main/java/org/bukkit/Server.java b/paper-api/src/main/java/org/bukkit/Server.java index dd29eba38d..f355692239 100644 --- a/paper-api/src/main/java/org/bukkit/Server.java +++ b/paper-api/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 * diff --git a/paper-api/src/main/java/org/bukkit/Slot.java b/paper-api/src/main/java/org/bukkit/Slot.java index 3ead03998f..008c464fcc 100644 --- a/paper-api/src/main/java/org/bukkit/Slot.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/StorageMinecart.java b/paper-api/src/main/java/org/bukkit/StorageMinecart.java index bd7b1b02e0..7ec1b5ac62 100644 --- a/paper-api/src/main/java/org/bukkit/StorageMinecart.java +++ b/paper-api/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(); } diff --git a/paper-api/src/main/java/org/bukkit/Vehicle.java b/paper-api/src/main/java/org/bukkit/Vehicle.java index 245c671fa7..76b7267be4 100644 --- a/paper-api/src/main/java/org/bukkit/Vehicle.java +++ b/paper-api/src/main/java/org/bukkit/Vehicle.java @@ -24,9 +24,17 @@ 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(); + + /** + * 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. @@ -34,4 +42,11 @@ public interface Vehicle extends Entity { * @return */ public boolean isEmpty(); + + /** + * Eject any passenger. True if there was a passenger. + * + * @return + */ + public boolean eject(); } diff --git a/paper-api/src/main/java/org/bukkit/World.java b/paper-api/src/main/java/org/bukkit/World.java index e9d008104b..bbf31035ca 100644 --- a/paper-api/src/main/java/org/bukkit/World.java +++ b/paper-api/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. * @@ -103,4 +121,28 @@ public interface World { * @return */ public PoweredMinecart spawnPoweredMinecart(Location loc); + + /** + * Spawn a boat. + * + * @param loc + * @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(); } diff --git a/paper-api/src/main/java/org/bukkit/block/BlockState.java b/paper-api/src/main/java/org/bukkit/block/BlockState.java new file mode 100644 index 0000000000..cb124fc790 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/block/BlockState.java @@ -0,0 +1,138 @@ + +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); + + /** + * 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); +} diff --git a/paper-api/src/main/java/org/bukkit/block/Sign.java b/paper-api/src/main/java/org/bukkit/block/Sign.java new file mode 100644 index 0000000000..8731f6c279 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/block/Sign.java @@ -0,0 +1,37 @@ + +package org.bukkit.block; + +/** + * Represents either a SignPost or a WallSign + */ +public interface Sign extends BlockState { + /** + * 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; +} diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index 045da30edb..61bebb4e4e 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/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,41 +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), @@ -181,25 +206,33 @@ public abstract class Event { /** * Called when a block is damaged (hit by a player) + * @todo: Add Javadoc see note here. */ 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 + * + * @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), @@ -208,22 +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), @@ -231,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), @@ -240,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), @@ -269,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), @@ -286,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), @@ -311,29 +390,46 @@ 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), + + /** + * Called when a Skeleton or Zombie catch fire due to the sun + * + * @todo: add javadoc see comment + */ + ENTITY_COMBUST (Category.LIVING_ENTITY), /** * VEHICLE EVENTS @@ -341,36 +437,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), diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockBrokenEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockBrokenEvent.java deleted file mode 100644 index ec06486589..0000000000 --- a/paper-api/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/paper-api/src/main/java/org/bukkit/event/block/BlockDamagedEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockDamagedEvent.java new file mode 100644 index 0000000000..5586f8462b --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java index 62745b3442..c43a6a2b7b 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockIgniteEvent.java +++ b/paper-api/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 type + * @param Block, IgniteCause, Player or null. */ - public BlockIgniteEvent(Type type) { - super(type); - // TODO Auto-generated constructor stub + 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; + } + + /** + * Gets the player who ignited this block + * + * @return Player who placed the block, if not ignited by player returns null. + */ + 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/paper-api/src/main/java/org/bukkit/event/block/BlockInteractEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockInteractEvent.java new file mode 100644 index 0000000000..37a343ad55 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockInteractEvent.java @@ -0,0 +1,70 @@ +package org.bukkit.event.block; + +import org.bukkit.Block; +import org.bukkit.LivingEntity; +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 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, LivingEntity who) { + super(type, interactedBlock); + theEntity = who; + 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 + * + * @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 LivingEntity 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/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java b/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java index 723572f99f..f7ef373834 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java @@ -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) { } /** @@ -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 @@ -70,14 +86,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/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java index 6bc1896877..586f35bd70 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockPlacedEvent.java @@ -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/paper-api/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java index ba5b6bb3c3..6a11acaccf 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockRightClickedEvent.java @@ -1,6 +1,3 @@ -/** - * - */ package org.bukkit.event.block; import org.bukkit.Block; @@ -9,45 +6,54 @@ import org.bukkit.ItemStack; import org.bukkit.Player; /** - * @author durron597 + * Not implemented yet */ -public class BlockRightClickedEvent extends BlockEvent { - protected Player clicker; +public class BlockRightClickedEvent extends BlockEvent { + protected Block clickedBlock; protected BlockFace direction; - protected ItemStack clickedWith; + protected ItemStack itemInHand; + protected Player player; - /** - * @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); + public BlockRightClickedEvent(Type type, Block placedAgainst, BlockFace direction, ItemStack itemInHand, Player thePlayer) { + super(type, placedAgainst); + this.clickedBlock = placedAgainst; this.direction = direction; - this.clicker = clicker; - this.clickedWith = clickedWith; + this.itemInHand = itemInHand; + this.player = thePlayer; } /** - * @return the clicker + * Gets the player who placed this block + * + * @return Player who placed the block */ - public Player getClicker() { - return clicker; + public Player getPlayer() { + return player; } + /** - * @return the direction + * 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; } /** - * @return the clickedWith + * Returns the item in your hand when you placed the block + * + * @return ItemStack the item in your hand when placing the block */ - public ItemStack getClickedWith() { - return clickedWith; + public ItemStack getItemInHand() { + return itemInHand; } } diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java new file mode 100644 index 0000000000..e1e54217e3 --- /dev/null +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java index 57c36e3717..631ebbf471 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedByEntityEvent.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java index c7ea7e47c0..65cbc388c6 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityDamagedEvent.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/entity/EntityEvent.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityEvent.java index 4d2f990664..dcd60372b0 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityEvent.java +++ b/paper-api/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; /** diff --git a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java b/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java index 60808f5260..f7e4de5c26 100644 --- a/paper-api/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java index f67ebd8627..b97ac5a6a9 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerChatEvent.java +++ b/paper-api/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; + } } diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerItemEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerItemEvent.java new file mode 100644 index 0000000000..42bb3f59f4 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerItemEvent.java @@ -0,0 +1,103 @@ +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; +import org.bukkit.event.Cancellable; + +/** + * + * @author durron597 + * + */ +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, Block blockClicked, BlockFace blockFace) { + super(type, who); + this.item = item; + cancel = false; + this.blockClicked = blockClicked; + this.blockFace = blockFace; + } + + /** + * 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(); + } + + /** + * 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/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java index 0c6817e238..b5da4b97e6 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java index efc7609447..9be4d55b9a 100644 --- a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleCreateEvent.java @@ -9,7 +9,7 @@ import org.bukkit.Vehicle; */ public class VehicleCreateEvent extends VehicleEvent { public VehicleCreateEvent(Type type, Vehicle vehicle) { + super(type, vehicle); } - } diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java index da8fc30c3c..5ac6242822 100644 --- a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEnterEvent.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java index fe2c3b71c6..514c569767 100644 --- a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleEntityCollisionEvent.java +++ b/paper-api/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; + } } diff --git a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleListener.java b/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleListener.java index a285f681ec..176b30c189 100644 --- a/paper-api/src/main/java/org/bukkit/event/vehicle/VehicleListener.java +++ b/paper-api/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. diff --git a/paper-api/src/main/java/org/bukkit/fillr/Checker.java b/paper-api/src/main/java/org/bukkit/fillr/Checker.java index 612957b2c1..8ae176bcfc 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Checker.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/fillr/Downloader.java b/paper-api/src/main/java/org/bukkit/fillr/Downloader.java index 8dc44c9543..3b9d8e7573 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Downloader.java +++ b/paper-api/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"; + 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); + /** + * 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); - } + 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(); - }*/ - } + 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 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 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(); + /** + * 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(); - } + if (!new File(directory).exists()) { + new File(directory).mkdir(); + } - File f = new File(directory, name); - if (f.exists()) { - f.delete(); - } - f.createNewFile(); + File f = new File(directory, name); + if (f.exists()) { + f.delete(); + } + f.createNewFile(); - copyInputStream(inputStream, new BufferedOutputStream( - new FileOutputStream(f))); + copyInputStream(inputStream, new BufferedOutputStream(new FileOutputStream(f))); - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (IOException ioe) { - System.out.println("[UPDATR]: Error closing inputStream"); - } - // } - } + 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; - /** - * 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); + } - while ((len = in.read(buffer)) >= 0) { - out.write(buffer, 0, len); - } + in.close(); + out.close(); + } - 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")); - } - } + /** + * 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/paper-api/src/main/java/org/bukkit/fillr/FillReader.java b/paper-api/src/main/java/org/bukkit/fillr/FillReader.java index ce94283a72..d32e8a4e50 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/FillReader.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/fillr/Fillr.java b/paper-api/src/main/java/org/bukkit/fillr/Fillr.java index b185fea24a..4cb0654d92 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Fillr.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/fillr/Getter.java b/paper-api/src/main/java/org/bukkit/fillr/Getter.java index 1bbd5b4c27..c1197d483a 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Getter.java +++ b/paper-api/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/paper-api/src/main/java/org/bukkit/fillr/Updater.java b/paper-api/src/main/java/org/bukkit/fillr/Updater.java index 1ca26b60a2..3a301538a4 100644 --- a/paper-api/src/main/java/org/bukkit/fillr/Updater.java +++ b/paper-api/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) { diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index f0d7d13c2a..1a5b9210f4 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -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; @@ -108,6 +109,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,12 +126,27 @@ 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_DAMAGED: + trueListener.onBlockDamaged((BlockDamagedEvent)event); + break; + case BLOCK_INTERACT: + trueListener.onBlockInteracted((BlockInteractEvent)event); + break; case BLOCK_FLOW: trueListener.onBlockFlow((BlockFromToEvent)event); break; 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; @@ -164,6 +183,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;