
This metadata implementation has the following features: - All metadata is lazy. Metadata values are not actually computed until another plugin requests them. Memory and CPU are conserved by not computing and storing unnecessary metadata values. - All metadata is cached. Once a metadata value is computed its value is cached in the metadata store to prevent further unnecessary computation. An invalidation mechanism is provided to flush the cache and force recompilation of metadata values. - All metadata is stored in basic data types. Convenience methods in the MetadataValue class allow for the conversion of metadata data types when possible. Restricting metadata to basic data types prevents the accidental linking of large object graphs into metadata. Metadata is persistent across the lifetime of the application and adding large object graphs would damage garbage collector performance. - Metadata access is thread safe. Care has been taken to protect the internal data structures and access them in a thread safe manner. - Metadata is exposed for all objects that descend from Entity, Block, and World. All Entity and World metadata is stored at the Server level and all Block metadata is stored at the World level. - Metadata is NOT keyed on references to original objects - instead metadata is keyed off of unique fields within those objects. Doing this allows metadata to exist for blocks that are in chunks not currently in memory. Additionally, Player objects are keyed off of player name so that Player metadata remains consistent between logins. - Metadata convenience methods have been added to all Entities, Players, Blocks, BlockStates, and World allowing direct access to an individual instance's metadata. - Players and OfflinePlayers share a single metadata store, allowing player metadata to be manipulated regardless of the player's current online status.
153 lines
3.6 KiB
Java
153 lines
3.6 KiB
Java
package org.bukkit.block;
|
|
|
|
import org.bukkit.Chunk;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.World;
|
|
import org.bukkit.material.MaterialData;
|
|
import org.bukkit.metadata.Metadatable;
|
|
|
|
/**
|
|
* Represents a captured state of a block, which will not change automatically.
|
|
* <p />
|
|
* 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 extends Metadatable {
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
MaterialData 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 location of this block
|
|
*
|
|
* @return location
|
|
*/
|
|
Location getLocation();
|
|
|
|
/**
|
|
* 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(MaterialData 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
|
|
* @return Whether it worked?
|
|
*/
|
|
boolean setTypeId(int type);
|
|
|
|
/**
|
|
* Attempts to update the block represented by this state, setting it to the
|
|
* new values as defined by this state.
|
|
* <p />
|
|
* 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 #update(boolean)
|
|
*/
|
|
boolean update();
|
|
|
|
/**
|
|
* Attempts to update the block represented by this state, setting it to the
|
|
* new values as defined by this state.
|
|
* <p />
|
|
* 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.
|
|
* <p />
|
|
* 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);
|
|
|
|
public byte getRawData();
|
|
|
|
public void setRawData(byte data);
|
|
}
|