mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Merge branch 'master' of github.com:Bukkit/Bukkit
By: stevenh <steven.hartland@multiplay.co.uk>
This commit is contained in:
commit
f7d795843a
11 changed files with 400 additions and 170 deletions
|
@ -20,4 +20,10 @@ public interface Chunk {
|
||||||
*/
|
*/
|
||||||
int getZ();
|
int getZ();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the world containing this chunk
|
||||||
|
*
|
||||||
|
* @return Parent World
|
||||||
|
*/
|
||||||
|
World getWorld();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,81 +1,118 @@
|
||||||
|
|
||||||
package org.bukkit;
|
package org.bukkit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a stack of items
|
* Represents a stack of items
|
||||||
*/
|
*/
|
||||||
public class ItemStack {
|
public class ItemStack {
|
||||||
private int type;
|
private int type;
|
||||||
private int amount = 0;
|
private int amount = 0;
|
||||||
|
private byte damage = 0;
|
||||||
public ItemStack(final int type) {
|
|
||||||
this.type = type;
|
public ItemStack(final int type) {
|
||||||
}
|
this.type = type;
|
||||||
|
}
|
||||||
public ItemStack(final Material type) {
|
|
||||||
this(type.getID());
|
public ItemStack(final Material type) {
|
||||||
}
|
this(type.getID());
|
||||||
|
}
|
||||||
public ItemStack(final int type, final int amount) {
|
|
||||||
this.type = type;
|
public ItemStack(final int type, final int amount) {
|
||||||
this.amount = amount;
|
this.type = type;
|
||||||
}
|
this.amount = amount;
|
||||||
|
}
|
||||||
public ItemStack(final Material type, final int amount) {
|
|
||||||
this(type.getID(), amount);
|
public ItemStack(final Material type, final int amount) {
|
||||||
}
|
this(type.getID(), amount);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Gets the type of this item
|
public ItemStack(final int type, final int amount, final byte damage) {
|
||||||
*
|
this.type = type;
|
||||||
* @return Type of the items in this stack
|
this.amount = amount;
|
||||||
*/
|
this.damage = damage;
|
||||||
public Material getType() {
|
}
|
||||||
return Material.getMaterial(type);
|
|
||||||
}
|
public ItemStack(final Material type, final int amount, final byte damage) {
|
||||||
|
this(type.getID(), amount, damage);
|
||||||
/**
|
}
|
||||||
* Sets the type of this item
|
|
||||||
*
|
/**
|
||||||
* @param type New type to set the items in this stack to
|
* Gets the type of this item
|
||||||
*/
|
*
|
||||||
public void setType(Material type) {
|
* @return Type of the items in this stack
|
||||||
this.type = type.getID();
|
*/
|
||||||
}
|
public Material getType() {
|
||||||
|
return Material.getMaterial(type);
|
||||||
/**
|
}
|
||||||
* Gets the type ID of this item
|
|
||||||
*
|
/**
|
||||||
* @return Type ID of the items in this stack
|
* Sets the type of this item
|
||||||
*/
|
*
|
||||||
public int getTypeID() {
|
* @param type New type to set the items in this stack to
|
||||||
return type;
|
*/
|
||||||
}
|
public void setType(Material type) {
|
||||||
|
this.type = type.getID();
|
||||||
/**
|
}
|
||||||
* Sets the type ID of this item
|
|
||||||
*
|
/**
|
||||||
* @param type New type ID to set the items in this stack to
|
* Gets the type ID of this item
|
||||||
*/
|
*
|
||||||
public void setTypeID(int type) {
|
* @return Type ID of the items in this stack
|
||||||
this.type = type;
|
*/
|
||||||
}
|
public int getTypeID() {
|
||||||
|
return type;
|
||||||
/**
|
}
|
||||||
* Gets the amount of items in this stack
|
|
||||||
*
|
/**
|
||||||
* @return Amount of items in this stick
|
* Sets the type ID of this item
|
||||||
*/
|
*
|
||||||
public int getAmount() {
|
* @param type New type ID to set the items in this stack to
|
||||||
return amount;
|
*/
|
||||||
}
|
public void setTypeID(int type) {
|
||||||
|
this.type = type;
|
||||||
/**
|
}
|
||||||
* Sets the amount of items in this stack
|
|
||||||
*
|
/**
|
||||||
* @param amount New amount of items in this stack
|
* Gets the amount of items in this stack
|
||||||
*/
|
*
|
||||||
public void setAmount(int amount) {
|
* @return Amount of items in this stick
|
||||||
this.amount = amount;
|
*/
|
||||||
}
|
public int getAmount() {
|
||||||
}
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the amount of items in this stack
|
||||||
|
*
|
||||||
|
* @param amount New amount of items in this stack
|
||||||
|
*/
|
||||||
|
public void setAmount(int amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the damage of this item<br /><br />
|
||||||
|
*
|
||||||
|
* 0x00 represents an item which cannot be damaged<br />
|
||||||
|
* 0x01 represents an item at maximum health<br />
|
||||||
|
* 0x32 represents an item with no health left
|
||||||
|
*
|
||||||
|
* @param damage Damage of this item
|
||||||
|
*/
|
||||||
|
public void setDamage(final byte damage) {
|
||||||
|
this.damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the damage of this item<br /><br />
|
||||||
|
*
|
||||||
|
* 0x00 represents an item which cannot be damaged<br />
|
||||||
|
* 0x01 represents an item at maximum health<br />
|
||||||
|
* 0x32 represents an item with no health left
|
||||||
|
*
|
||||||
|
* @return Damage of this item
|
||||||
|
*/
|
||||||
|
public byte getDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -217,9 +217,9 @@ public abstract class Event {
|
||||||
BLOCK_PLACED (Category.BLOCK),
|
BLOCK_PLACED (Category.BLOCK),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a specific block is being sent to a player
|
* Called when leaves are decaying naturally
|
||||||
*/
|
*/
|
||||||
BLOCK_SENT (Category.BLOCK),
|
LEAVES_DECAY (Category.BLOCK),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a liquid attempts to flow into a block which already
|
* Called when a liquid attempts to flow into a block which already
|
||||||
|
|
|
@ -1,81 +1,89 @@
|
||||||
package org.bukkit.event.block;
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles all events thrown in relation to Blocks
|
* Handles all events thrown in relation to Blocks
|
||||||
*
|
*
|
||||||
* @author durron597
|
* @author durron597
|
||||||
*/
|
*/
|
||||||
public class BlockListener implements Listener {
|
public class BlockListener implements Listener {
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*/
|
*/
|
||||||
public BlockListener() {
|
public BlockListener() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a block is broken (or destroyed)
|
* Called when a block is broken (or destroyed)
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockBroken(BlockBrokenEvent event) {
|
public void onBlockBroken(BlockBrokenEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when we try to place a block, to see if we can build it
|
* Called when we try to place a block, to see if we can build it
|
||||||
*/
|
*/
|
||||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a block flows (water/lava)
|
* Called when a block flows (water/lava)
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockFlow(BlockFromToEvent event) {
|
public void onBlockFlow(BlockFromToEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a block gets ignited
|
* Called when a block gets ignited
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when block physics occurs
|
* Called when block physics occurs
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockPhysics(BlockPhysicsEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player places a block
|
* Called when a player places a block
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockPlaced(BlockPlacedEvent event) {
|
public void onBlockPlaced(BlockPlacedEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when redstone changes
|
* Called when redstone changes
|
||||||
* From: the source of the redstone change
|
* From: the source of the redstone change
|
||||||
* To: The redstone dust that changed
|
* To: The redstone dust that changed
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
public void onBlockRedstoneChange(BlockFromToEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player right clicks a block
|
* Called when a player right clicks a block
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
public void onBlockRightClicked(BlockRightClickedEvent event) {
|
public void onBlockRightClicked(BlockRightClickedEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Called when leaves are decaying naturally
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -11,24 +11,36 @@ public class BlockPlacedEvent extends BlockEvent implements Cancellable {
|
||||||
private boolean cancel;
|
private boolean cancel;
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param type
|
|
||||||
* @param theBlock
|
|
||||||
*/
|
|
||||||
public BlockPlacedEvent(Type type, Block theBlock) {
|
public BlockPlacedEvent(Type type, Block theBlock) {
|
||||||
super(type, theBlock);
|
super(type, theBlock);
|
||||||
cancel = false;
|
cancel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player who placed this block
|
||||||
|
*
|
||||||
|
* @return Player who placed the block
|
||||||
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @return true if this event is cancelled
|
||||||
|
*/
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancel = cancel;
|
this.cancel = cancel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
package org.bukkit.event.block;
|
||||||
|
|
||||||
|
import org.bukkit.Block;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on leaves decaying
|
||||||
|
*/
|
||||||
|
public class LeavesDecayEvent extends BlockEvent implements Cancellable {
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
|
public LeavesDecayEvent(final Type type, final Block block) {
|
||||||
|
super(type, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @return true if this event is cancelled
|
||||||
|
*/
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
package org.bukkit.event.world;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a chunk is loaded
|
||||||
|
*/
|
||||||
|
public class ChunkLoadedEvent extends WorldEvent {
|
||||||
|
private final Chunk chunk;
|
||||||
|
|
||||||
|
public ChunkLoadedEvent(final Type type, final Chunk chunk) {
|
||||||
|
super(type, chunk.getWorld());
|
||||||
|
|
||||||
|
this.chunk = chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the chunk being loaded/unloaded
|
||||||
|
*
|
||||||
|
* @return Chunk that triggered this event
|
||||||
|
*/
|
||||||
|
public Chunk getChunk() {
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
package org.bukkit.event.world;
|
||||||
|
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a chunk is unloaded
|
||||||
|
*/
|
||||||
|
public class ChunkUnloadedEvent extends ChunkLoadedEvent implements Cancellable {
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
|
public ChunkUnloadedEvent(final Type type, final Chunk chunk) {
|
||||||
|
super(type, chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @return true if this event is cancelled
|
||||||
|
*/
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
|
||||||
|
package org.bukkit.event.world;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents events within a world
|
||||||
|
*/
|
||||||
|
public class WorldEvent extends Event {
|
||||||
|
private final World world;
|
||||||
|
|
||||||
|
public WorldEvent(final Type type, final World world) {
|
||||||
|
super(type);
|
||||||
|
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the world primarily involved with this event
|
||||||
|
*
|
||||||
|
* @return World which caused this event
|
||||||
|
*/
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
package org.bukkit.event.world;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all World related events
|
||||||
|
*/
|
||||||
|
public class WorldListener implements Listener {
|
||||||
|
/**
|
||||||
|
* Called when a chunk is loaded
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
public void onChunkLoaded(ChunkLoadedEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a chunk is unloaded
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
public void onChunkUnloaded(ChunkUnloadedEvent event) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,9 @@ import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.server.PluginEvent;
|
import org.bukkit.event.server.PluginEvent;
|
||||||
import org.bukkit.event.server.ServerListener;
|
import org.bukkit.event.server.ServerListener;
|
||||||
import org.bukkit.event.vehicle.*;
|
import org.bukkit.event.vehicle.*;
|
||||||
|
import org.bukkit.event.world.ChunkLoadedEvent;
|
||||||
|
import org.bukkit.event.world.ChunkUnloadedEvent;
|
||||||
|
import org.bukkit.event.world.WorldListener;
|
||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,6 +127,9 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
case BLOCK_FLOW:
|
case BLOCK_FLOW:
|
||||||
trueListener.onBlockFlow((BlockFromToEvent)event);
|
trueListener.onBlockFlow((BlockFromToEvent)event);
|
||||||
break;
|
break;
|
||||||
|
case LEAVES_DECAY:
|
||||||
|
trueListener.onLeavesDecay((LeavesDecayEvent)event);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if(listener instanceof ServerListener) {
|
} else if(listener instanceof ServerListener) {
|
||||||
ServerListener trueListener = (ServerListener)listener;
|
ServerListener trueListener = (ServerListener)listener;
|
||||||
|
@ -136,6 +142,17 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
trueListener.onPluginDisabled((PluginEvent)event);
|
trueListener.onPluginDisabled((PluginEvent)event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if(listener instanceof WorldListener) {
|
||||||
|
WorldListener trueListener = (WorldListener)listener;
|
||||||
|
|
||||||
|
switch (event.getType()) {
|
||||||
|
case CHUNK_LOADED:
|
||||||
|
trueListener.onChunkLoaded((ChunkLoadedEvent)event);
|
||||||
|
break;
|
||||||
|
case CHUNK_UNLOADED:
|
||||||
|
trueListener.onChunkUnloaded((ChunkUnloadedEvent)event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if(listener instanceof EntityListener) {
|
} else if(listener instanceof EntityListener) {
|
||||||
EntityListener trueListener = (EntityListener) listener;
|
EntityListener trueListener = (EntityListener) listener;
|
||||||
switch(event.getType())
|
switch(event.getType())
|
||||||
|
|
Loading…
Reference in a new issue