summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua999
-rw-r--r--MCServer/Plugins/APIDump/WebWorldThreads.html64
-rw-r--r--MCServer/Plugins/APIDump/main.css5
-rw-r--r--MCServer/Plugins/APIDump/main.lua231
m---------MCServer/Plugins/Core0
-rw-r--r--MCServer/Plugins/MagicCarpet/coremessaging.lua19
-rw-r--r--MCServer/Plugins/MagicCarpet/plugin.lua15
m---------MCServer/Plugins/ProtectionAreas0
m---------MCServer/Plugins/TransAPI6
9 files changed, 1095 insertions, 244 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 444d697fa..dc04d3e81 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -157,10 +157,13 @@ g_APIDesc =
SetBlockMeta = { Params = "BlockX, BlockY, BlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified absolute coords" },
SetBlockSkyLight = { Params = "BlockX, BlockY, BlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified absolute coords" },
SetBlockType = { Params = "BlockX, BlockY, BlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified absolute coords" },
+ SetBlockTypeMeta = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified absolute coords" },
+ SetOrigin = { Params = "OriginX, OriginY, OriginZ", Return = "", Notes = "Resets the origin for the absolute coords. Only affects how absolute coords are translated into relative coords." },
SetRelBlockLight = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockLight", Return = "", Notes = "Sets the blocklight at the specified relative coords" },
SetRelBlockMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified relative coords" },
SetRelBlockSkyLight = { Params = "RelBlockX, RelBlockY, RelBlockZ, SkyLight", Return = "", Notes = "Sets the skylight at the specified relative coords" },
SetRelBlockType = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType", Return = "", Notes = "Sets the block type at the specified relative coords" },
+ SetRelBlockTypeMeta = { Params = "RelBlockX, RelBlockY, RelBlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block type and meta at the specified relative coords" },
Write = { Params = "World, MinX, MinY, MinZ, DataTypes", Return = "bool", Notes = "Writes the area into World at the specified coords, returns true if successful" },
},
Constants =
@@ -311,8 +314,41 @@ g_APIDesc =
cBoundingBox =
{
- Desc = "",
- Functions = {},
+ Desc = [[
+ Represents two sets of coordinates, minimum and maximum for each direction; thus defining an
+ axis-aligned cuboid with floating-point boundaries. It supports operations changing the size and
+ position of the box, as well as querying whether a point or another BoundingBox is inside the box.</p>
+ <p>
+ All the points within the coordinate limits (inclusive the edges) are considered "inside" the box.
+ However, for intersection purposes, if the intersection is "sharp" in any coord (min1 == max2, i. e.
+ zero volume), the boxes are considered non-intersecting.</p>
+ ]],
+ Functions =
+ {
+ constructor =
+ {
+ { Params = "MinX, MaxX, MinY, MaxY, MinZ, MaxZ", Return = "cBoundingBox", Notes = "Creates a new bounding box with the specified edges" },
+ { Params = "{{Vector3d|Min}}, {{Vector3d|Max}}", Return = "cBoundingBox", Notes = "Creates a new bounding box with the coords specified as two vectors" },
+ { Params = "{{Vector3d|Pos}}, Radius, Height", Return = "cBoundingBox", Notes = "Creates a new bounding box from the position given and radius (X/Z) and height. Radius is added from X/Z to calculate the maximum coords and subtracted from X/Z to get the minimum; minimum Y is set to Pos.y and maxumim Y to Pos.y plus Height. This corresponds with how {{cEntity|entities}} are represented in Minecraft." },
+ { Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Creates a new copy of the given bounding box. Same result can be achieved by using a simple assignment." },
+ },
+ CalcLineIntersection = { Params = "{{Vector3d|LineStart}}, {{Vector3d|LinePt2}}", Return = "DoesIntersect, LineCoeff, Face", Notes = "Calculates the intersection of a ray (half-line), given by two of its points, with the bounding box. Returns false if the line doesn't intersect the bounding box, or true, together with coefficient of the intersection (how much of the difference between the two ray points is needed to reach the intersection), and the face of the box which is intersected.<br /><b>TODO</b>: Lua binding for this function is wrong atm." },
+ DoesIntersect = { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if the two bounding boxes have an intersection of nonzero volume." },
+ Expand = { Params = "ExpandX, ExpandY, ExpandZ", Return = "", Notes = "Expands this bounding box by the specified amount in each direction (so the box becomes larger by 2 * Expand in each axis)." },
+ IsInside =
+ {
+ { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." },
+ { Params = "PointX, PointY, PointZ", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." },
+ { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if OtherBoundingBox is inside of this box." },
+ { Params = "{{Vector3d|OtherBoxMin}}, {{Vector3d|OtherBoxMax}}", Return = "bool", Notes = "Returns true if the other bounding box, specified by its 2 corners, is inside of this box." },
+ },
+ Move =
+ {
+ { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Moves the bounding box by the specified offset in each axis" },
+ { Params = "{{Vector3d|Offset}}", Return = "", Notes = "Moves the bounding box by the specified offset in each axis" },
+ },
+ Union = { Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Returns the smallest bounding box that contains both OtherBoundingBox and this bounding box. Note that unlike the strict geometrical meaning of \"union\", this operation actually returns a cBoundingBox." },
+ },
Constants = {},
},
@@ -340,17 +376,46 @@ g_APIDesc =
Desc = [[
A chest entity is a {{cBlockEntityWithItems|cBlockEntityWithItems}} descendant that represents a chest
in the world. Note that doublechests consist of two separate cChestEntity objects, they do not collaborate
- in any way.
+ in any way.</p>
+ <p>
+ The chest entity can be created by the plugins only in the {{OnChunkGenerating}} and
+ {{OnChunkGenerated}} hooks, as part of the new chunk being generated. Plugins may generate chests
+ with contents in this way.</p>
+ <p>
+ To manipulate a chest already in the game, you need to use {{cWorld}}'s callback mechanism with
+ either DoWithChestAt() or ForEachChestInChunk() function. See the code example below
]],
Inherits = "cBlockEntityWithItems",
Functions =
{
+ constructor = { Params = "BlockX, BlockY, BlockZ", Return = "cChestEntity", Notes = "Creates a new cChestEntity object. To be used only in the chunk generating hooks {{OnChunkGenerating}} and {{OnChunkGenerated}}." },
},
Constants =
{
+ ContentsHeight = { Notes = "Height of the contents' {{cItemGrid|ItemGrid}}, as required by the parent class, {{cBlockEntityWithItems}}" },
+ ContentsWidth = { Notes = "Width of the contents' {{cItemGrid|ItemGrid}}, as required by the parent class, {{cBlockEntityWithItems}}" },
},
+ AdditionalInfo =
+ {
+ {
+ Header = "Code example",
+ Contents = [[
+ The following example code sets the top-left item of each chest in the same chunk as Player to
+ 64 * diamond:
+<pre class="prettyprint lang-lua">
+-- Player is a {{cPlayer}} object instance
+local World = Player:GetWorld();
+World:ForEachChestInChunk(Player:GetChunkX(), Player:GetChunkZ(),
+ function (ChestEntity)
+ ChestEntity:SetSlot(0, 0, cItem(E_ITEM_DIAMOND, 64));
+ end
+);
+</pre>
+ ]],
+ },
+ }, -- AdditionalInfo
},
cChunkDesc =
@@ -365,17 +430,40 @@ g_APIDesc =
Functions =
{
FillBlocks = { Params = "BlockType, BlockMeta", Return = "", Notes = "Fills the entire chunk with the specified blocks" },
+ FillRelCuboid =
+ {
+ { Params = "{{cCuboid|RelCuboid}}, BlockType, BlockMeta", Return = "", Notes = "Fills the cuboid, specified in relative coords, by the specified block type and block meta. The cuboid may reach outside of the chunk, only the part intersecting with this chunk is filled." },
+ { Params = "MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ, BlockType, BlockMeta", Return = "", Notes = "Fills the cuboid, specified in relative coords, by the specified block type and block meta. The cuboid may reach outside of the chunk, only the part intersecting with this chunk is filled." },
+ },
+ FloorRelCuboid =
+ {
+ { Params = "{{cCuboid|RelCuboid}}, BlockType, BlockMeta", Return = "", Notes = "Fills those blocks of the cuboid (specified in relative coords) that are considered non-floor (air, water) with the specified block type and meta. Cuboid may reach outside the chunk, only the part intersecting with this chunk is filled." },
+ { Params = "MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ, BlockType, BlockMeta", Return = "", Notes = "Fills those blocks of the cuboid (specified in relative coords) that are considered non-floor (air, water) with the specified block type and meta. Cuboid may reach outside the chunk, only the part intersecting with this chunk is filled." },
+ },
GetBiome = { Params = "RelX, RelZ", Return = "EMCSBiome", Notes = "Returns the biome at the specified relative coords" },
GetBlockMeta = { Params = "RelX, RelY, RelZ", Return = "NIBBLETYPE", Notes = "Returns the block meta at the specified relative coords" },
GetBlockType = { Params = "RelX, RelY, RelZ", Return = "BLOCKTYPE", Notes = "Returns the block type at the specified relative coords" },
GetBlockTypeMeta = { Params = "RelX, RelY, RelZ", Return = "BLOCKTYPE, NIBBLETYPE", Notes = "Returns the block type and meta at the specified relative coords" },
+ GetChunkX = { Params = "", Return = "number", Notes = "Returns the X coord of the chunk contained." },
+ GetChunkZ = { Params = "", Return = "number", Notes = "Returns the Z coord of the chunk contained." },
GetHeight = { Params = "RelX, RelZ", Return = "number", Notes = "Returns the height at the specified relative coords" },
+ GetMaxHeight = { Params = "", Return = "number", Notes = "Returns the maximum height contained in the heightmap." },
IsUsingDefaultBiomes = { Params = "", Return = "bool", Notes = "Returns true if the chunk is set to use default biome generator" },
IsUsingDefaultComposition = { Params = "", Return = "bool", Notes = "Returns true if the chunk is set to use default composition generator" },
IsUsingDefaultFinish = { Params = "", Return = "bool", Notes = "Returns true if the chunk is set to use default finishers" },
IsUsingDefaultHeight = { Params = "", Return = "bool", Notes = "Returns true if the chunk is set to use default height generator" },
IsUsingDefaultStructures = { Params = "", Return = "bool", Notes = "Returns true if the chunk is set to use default structures" },
- ReadBlockArea = { Params = "BlockArea, MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ", Return = "", Notes = "Reads data from the chunk into the block area object" },
+ RandomFillRelCuboid =
+ {
+ { Params = "{{cCuboid|RelCuboid}}, BlockType, BlockMeta, RandomSeed, ChanceOutOf10k", Return = "", Notes = "Fills the specified relative cuboid with block type and meta in random locations. RandomSeed is used for the random number genertion (same seed produces same results); ChanceOutOf10k specifies the density (how many out of every 10000 blocks should be filled). Cuboid may reach outside the chunk, only the part intersecting with this chunk is filled." },
+ { Params = "MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ, BlockType, BlockMeta, RandomSeed, ChanceOutOf10k", Return = "", Notes = "Fills the specified relative cuboid with block type and meta in random locations. RandomSeed is used for the random number genertion (same seed produces same results); ChanceOutOf10k specifies the density (how many out of every 10000 blocks should be filled). Cuboid may reach outside the chunk, only the part intersecting with this chunk is filled." },
+ },
+ ReadBlockArea = { Params = "{{cBlockArea|BlockArea}}, MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ", Return = "", Notes = "Reads data from the chunk into the block area object. Block types and metas are processed." },
+ ReplaceRelCuboid =
+ {
+ { Params = "{{cCuboid|RelCuboid}}, SrcType, SrcMeta, DstType, DstMeta", Return = "", Notes = "Replaces all SrcType+SrcMeta blocks in the cuboid (specified in relative coords) with DstType+DstMeta blocks. Cuboid may reach outside the chunk, only the part intersecting with this chunk is filled." },
+ { Params = "MinRelX, MaxRelX, MinRelY, MaxRelY, MinRelZ, MaxRelZ, SrcType, SrcMeta, DstType, DstMeta", Return = "", Notes = "Replaces all SrcType+SrcMeta blocks in the cuboid (specified in relative coords) with DstType+DstMeta blocks. Cuboid may reach outside the chunk, only the part intersecting with this chunk is filled." },
+ },
SetBiome = { Params = "RelX, RelZ, EMCSBiome", Return = "", Notes = "Sets the biome at the specified relative coords" },
SetBlockMeta = { Params = "RelX, RelY, RelZ, BlockMeta", Return = "", Notes = "Sets the block meta at the specified relative coords" },
SetBlockType = { Params = "RelX, RelY, RelZ, BlockType", Return = "", Notes = "Sets the block type at the specified relative coords" },
@@ -386,7 +474,7 @@ g_APIDesc =
SetUseDefaultFinish = { Params = "bool", Return = "", Notes = "Sets the chunk to use default finishers or not" },
SetUseDefaultHeight = { Params = "bool", Return = "", Notes = "Sets the chunk to use default height generator or not" },
SetUseDefaultStructures = { Params = "bool", Return = "", Notes = "Sets the chunk to use default structures or not" },
- WriteBlockArea = { Params = "BlockArea, MinRelX, MinRelY, MinRelZ", Return = "", Notes = "Writes data from the block area into the chunk" },
+ WriteBlockArea = { Params = "{{cBlockArea|BlockArea}}, MinRelX, MinRelY, MinRelZ", Return = "", Notes = "Writes data from the block area into the chunk" },
},
Constants =
{
@@ -396,41 +484,48 @@ g_APIDesc =
cClientHandle =
{
Desc = [[
- A cClientHandle represents technical aspect of a connected player - their game client connection.
+ A cClientHandle represents the technical aspect of a connected player - their game client
+ connection. Internally, it handles all the incoming and outgoing packets, the chunks that are to be
+ sent to the client, ping times etc.
]],
Functions =
{
GetPing = { Params = "", Return = "number", Notes = "Returns the ping time, in ms" },
- GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client" },
+ GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." },
GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" },
GetUsername = { Params = "", Return = "string", Notes = "Returns the username that the client has provided" },
GetViewDistance = { Params = "", Return = "number", Notes = "Returns the viewdistance (number of chunks loaded for the player in each direction)" },
Kick = { Params = "Reason", Return = "", Notes = "Kicks the user with the specified reason" },
SetUsername = { Params = "Name", Return = "", Notes = "Sets the username" },
SetViewDistance = { Params = "ViewDistance", Return = "", Notes = "Sets the viewdistance (number of chunks loaded for the player in each direction)" },
- SendBlockChange = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sends a block to the client. This can be used to create fake blocks." },
+ SendBlockChange = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sends a BlockChange packet to the client. This can be used to create fake blocks only for that player." },
},
Constants =
{
- MAX = { Notes = "10" },
- MIN = { Notes = "4" },
+ MAX_VIEW_DISTANCE = { Notes = "The maximum value of the view distance" },
+ MIN_VIEW_DISTANCE = { Notes = "The minimum value of the view distance" },
},
},
cCraftingGrid =
{
Desc = [[
- cCraftingGrid represents the player's crafting grid. It is used only in
+ cCraftingGrid represents the player's crafting grid. It is used in
{{OnCraftingNoRecipe|OnCraftingNoRecipe}}, {{OnPostCrafting|OnPostCrafting}} and
{{OnPreCrafting|OnPreCrafting}} hooks. Plugins may use it to inspect the items the player placed
- on their crafting grid.
+ on their crafting grid.</p>
+ <p>
+ Also, an object of this type is used in {{cCraftingRecipe}}'s ConsumeIngredients() function for
+ specifying the exact number of ingredients to consume in that recipe; plugins may use this to
+ apply the crafting recipe.</p>
]],
Functions =
{
+ constructor = { Params = "Width, Height", Return = "cCraftingGrid", Notes = "Creates a new CraftingGrid object. This new crafting grid is not related to any player, but may be needed for {{cCraftingRecipe}}'s ConsumeIngredients function." },
Clear = { Params = "", Return = "", Notes = "Clears the entire grid" },
- ConsumeGrid = { Params = "{{cCraftingGrid|CraftingGrid}}", Return = "", Notes = "Consumes items specified in CraftingGrid from the current contents" },
+ ConsumeGrid = { Params = "{{cCraftingGrid|CraftingGrid}}", Return = "", Notes = "Consumes items specified in CraftingGrid from the current contents. Used internally by {{cCraftingRecipe}}'s ConsumeIngredients() function, but available to plugins, too." },
Dump = { Params = "", Return = "", Notes = "DEBUG build: Dumps the contents of the grid to the log. RELEASE build: no action" },
GetHeight = { Params = "", Return = "number", Notes = "Returns the height of the grid" },
GetItem = { Params = "x, y", Return = "{{cItem|cItem}}", Notes = "Returns the item at the specified coords" },
@@ -481,15 +576,37 @@ g_APIDesc =
cCuboid =
{
Desc = [[
- cCuboid offers some native support for integral-boundary cuboids. A cuboid simply consists of two
- {{vector3i}}-s. It offers some extra functions for sorting and checking if a point is inside the
- cuboid.
+ cCuboid offers some native support for integral-boundary cuboids. A cuboid internally consists of
+ two {{Vector3i}}s. By default the cuboid doesn't make any assumptions about the defining points,
+ but for most of the operations in the cCuboid class, the p1 member variable is expected to be the
+ minima and the p2 variable the maxima. The Sort() function guarantees this condition.</p>
+ <p>
+ The Cuboid considers both its edges inclusive.</p>
]],
Functions =
{
- Sort = { Notes = "void" },
- IsInside = { Notes = "bool" },
- IsInside = { Notes = "bool" },
+ constructor =
+ {
+ { Params = "OtheCuboid", Return = "cCuboid", Notes = "Creates a new Cuboid object as a copy of OtherCuboid" },
+ { Params = "{{Vector3i|Point1}}, {{Vector3i|Point2}}", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." },
+ { Params = "X, Y, Z", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified point as both its corners (the cuboid has a size of 1 in each direction)." },
+ { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "cCuboid", Notes = "Creates a new Cuboid object with the specified points as its corners." },
+ },
+ Assign = { Params = "X1, Y1, Z1, X2, Y2, Z2", Return = "", Notes = "Assigns all the coords stored in the cuboid. Sort-state is ignored." },
+ DifX = { Params = "", Return = "number", Notes = "Returns the difference between the two X coords (X-size minus 1). Assumes sorted." },
+ DifY = { Params = "", Return = "number", Notes = "Returns the difference between the two Y coords (Y-size minus 1). Assumes sorted." },
+ DifZ = { Params = "", Return = "number", Notes = "Returns the difference between the two Z coords (Z-size minus 1). Assumes sorted." },
+ DoesIntersect = { Params = "OtherCuboid", Return = "bool", Notes = "Returns true if this cuboid has at least one voxel in common with OtherCuboid. Note that edges are considered inclusive. Assumes both sorted." },
+ IsCompletelyInside = { Params = "OuterCuboid", Return = "bool", Notes = "Returns true if this cuboid is completely inside (in all directions) in OuterCuboid. Assumes both sorted." },
+ IsInside =
+ {
+ { Params = "X, Y, Z", Return = "bool", Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted." },
+ { Params = "{{Vector3i|Point}}", Return = "bool", Notes = "Returns true if the specified point (integral coords) is inside this cuboid. Assumes sorted." },
+ { Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point (floating-point coords) is inside this cuboid. Assumes sorted." },
+ },
+ IsSorted = { Params = "", Return = "bool", Notes = "Returns true if this cuboid is sorted" },
+ Move = { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Adds the specified offsets to each respective coord, effectively moving the Cuboid. Sort-state is ignored." },
+ Sort = { Params = "", Return = "" , Notes = "Sorts the internal representation so that p1 contains the lesser coords and p2 contains the greater coords." },
},
Variables =
{
@@ -542,8 +659,8 @@ g_APIDesc =
},
Constants =
{
- ContentsWidth = { Notes = "Width (X) of the cItemGrid representing the contents" },
- ContentsHeight = { Notes = "Height (Y) of the cItemGrid representing the contents" },
+ ContentsWidth = { Notes = "Width (X) of the {{cItemGrid}} representing the contents" },
+ ContentsHeight = { Notes = "Height (Y) of the {{cItemGrid}} representing the contents" },
},
Inherits = "cBlockEntity";
@@ -557,8 +674,12 @@ g_APIDesc =
]],
Functions =
{
- constructor = { Params = "", Return = "cEnchantments", Notes = "Creates a new empty cEnchantments object" },
- constructor = { Params = "StringSpec", Return = "cEnchantments", Notes = "Creates a new cEnchantments object filled with enchantments based on the string description" },
+ constructor =
+ {
+ { Params = "", Return = "cEnchantments", Notes = "Creates a new empty cEnchantments object" },
+ { Params = "StringSpec", Return = "cEnchantments", Notes = "Creates a new cEnchantments object filled with enchantments based on the string description" },
+ },
+ operator_eq = { Params = "OtherEnchantments", Return = "bool", Notes = "Returns true if this enchantments object has the same enchantments as OtherEnchantments." },
AddFromString = { Params = "StringSpec", Return = "", Notes = "Adds the enchantments in the string description into the object. If a specified enchantment already existed, it is overwritten." },
Clear = { Params = "", Return = "", Notes = "Removes all enchantments" },
GetLevel = { Params = "EnchantmentNumID", Return = "number", Notes = "Returns the level of the specified enchantment stored in this object; 0 if not stored" },
@@ -574,68 +695,174 @@ g_APIDesc =
cEntity =
{
- Desc = [[A cEntity object represents an object in the world, it has a position and orientation. cEntity is an abstract class, and can not be instantiated directly, instead, all entities are implemented as subclasses. The cEntity class works as the common interface for the operations that all (most) entities support.
-</p>
- <p>All cEntity objects have an Entity Type so it can be determined what kind of entity it is efficiently. Entities also have a class inheritance awareness, they know their class name, their parent class' name and can decide if there is a class within their inheritance chain. Since these functions operate on strings, they are slightly slower than checking the entity type directly, on the other hand, they are more specific (compare etMob vs "cSpider" class name).
-</p>
- <p>Note that you should not store a cEntity object between two hooks' calls, because MCServer may remove that entity in between the calls. If you need to refer to an entity later, use its UniqueID and {{cWorld|cWorld}}'s entity manipulation functions to access the entity.
-]],
+ Desc = [[
+ A cEntity object represents an object in the world, it has a position and orientation. cEntity is an
+ abstract class, and can not be instantiated directly, instead, all entities are implemented as
+ subclasses. The cEntity class works as the common interface for the operations that all (most)
+ entities support.</p>
+ <p>
+ All cEntity objects have an Entity Type so it can be determined what kind of entity it is
+ efficiently. Entities also have a class inheritance awareness, they know their class name,
+ their parent class' name and can decide if there is a class within their inheritance chain.
+ Since these functions operate on strings, they are slightly slower than checking the entity type
+ directly, on the other hand, they are more specific directly. To check if the entity is a spider,
+ you need to call IsMob(), then cast the object to {{cMonster}} and finally compare
+ {{cMonster}}:GetMonsterType() to mtSpider. GetClass(), on the other hand, returns "cSpider"
+ directly.</p>
+ <p>
+ Note that you should not store a cEntity object between two hooks' calls, because MCServer may
+ despawn / remove that entity in between the calls. If you need to refer to an entity later, use its
+ UniqueID and {{cWorld|cWorld}}'s entity manipulation functions DoWithEntityByID(), ForEachEntity()
+ or ForEachEntityInChunk() to access the entity again.</p>
+ ]],
Functions =
{
+ AddPosition =
+ {
+ { Params = "OffsetX, OffsetY, OffsetZ", Return = "", Notes = "Moves the entity by the specified amount in each axis direction" },
+ { Params = "{{Vector3d|Offset}}", Return = "", Notes = "Moves the entity by the specified amount in each direction" },
+ },
+ AddPosX = { Params = "OffsetX", Return = "", Notes = "Moves the entity by the specified amount in the X axis direction" },
+ AddPosY = { Params = "OffsetY", Return = "", Notes = "Moves the entity by the specified amount in the Y axis direction" },
+ AddPosZ = { Params = "OffsetZ", Return = "", Notes = "Moves the entity by the specified amount in the Z axis direction" },
+ AddSpeed =
+ {
+ { Params = "AddX, AddY, AddZ", Return = "", Notes = "Adds the specified amount of speed in each axis direction." },
+ { Params = "{{Vector3d|Add}}", Return = "", Notes = "Adds the specified amount of speed in each axis direction." },
+ },
+ AddSpeedX = { Params = "AddX", Return = "", Notes = "Adds the specified amount of speed in the X axis direction." },
+ AddSpeedY = { Params = "AddY", Return = "", Notes = "Adds the specified amount of speed in the Y axis direction." },
+ AddSpeedZ = { Params = "AddZ", Return = "", Notes = "Adds the specified amount of speed in the Z axis direction." },
Destroy = { Params = "", Return = "", Notes = "Schedules the entity to be destroyed" },
+ GetArmorCoverAgainst = { Params = "AttackerEntity, DamageType, RawDamage", Return = "number", Notes = "Returns the number of hitpoints out of RawDamage that the currently equipped armor would cover. See {{TakeDamageInfo}} for more information on attack damage." },
GetChunkX = { Params = "", Return = "number", Notes = "Returns the X-coord of the chunk in which the entity is placed" },
- GetChunkY = { Params = "", Return = "number", Notes = "Returns the Y-coord of the chunk in which the entity is placed" },
GetChunkZ = { Params = "", Return = "number", Notes = "Returns the Z-coord of the chunk in which the entity is placed" },
- GetClass = { Params = "", Return = "string", Notes = "Returns the classname of the entity, such as \"spider\" or \"pickup\"" },
+ GetClass = { Params = "", Return = "string", Notes = "Returns the classname of the entity, such as \"cSpider\" or \"cPickup\"" },
GetClassStatic = { Params = "", Return = "string", Notes = "Returns the entity classname that this class implements. Each descendant overrides this function. Is static" },
- GetEntityType = { Params = "", Return = "cEntity.eEntityType", Notes = "Returns the type of the entity, one of the etXXX constants" },
+ GetEntityType = { Params = "", Return = "eEntityType", Notes = "Returns the type of the entity, one of the etXXX constants. Note that to check specific entity type, you should use one of the IsXXX functions instead of comparing the value returned by this call." },
+ GetEquippedBoots = { Params = "", Return = "{{cItem}}", Notes = "Returns the boots that the entity has equipped. Returns an empty cItem if no boots equipped or not applicable." },
+ GetEquippedChestplate = { Params = "", Return = "{{cItem}}", Notes = "Returns the chestplate that the entity has equipped. Returns an empty cItem if no chestplate equipped or not applicable." },
+ GetEquippedHelmet = { Params = "", Return = "{{cItem}}", Notes = "Returns the helmet that the entity has equipped. Returns an empty cItem if no helmet equipped or not applicable." },
+ GetEquippedLeggings = { Params = "", Return = "{{cItem}}", Notes = "Returns the leggings that the entity has equipped. Returns an empty cItem if no leggings equipped or not applicable." },
+ GetEquippedWeapon = { Params = "", Return = "{{cItem}}", Notes = "Returns the weapon that the entity has equipped. Returns an empty cItem if no weapon equipped or not applicable." },
+ GetGravity = { Params = "", Return = "number", Notes = "Returns the number that is used as the gravity for physics simulation. 1G (9.78) by default." },
+ GetHeadYaw = { Params = "", Return = "number", Notes = "Returns the pitch of the entity's head (FIXME: Rename to GetHeadPitch() )." },
+ GetHealth = { Params = "", Return = "number", Notes = "Returns the current health of the entity." },
+ GetHeight = { Params = "", Return = "number", Notes = "Returns the height (Y size) of the entity" },
+ GetKnockbackAmountAgainst = { Params = "ReceiverEntity", Return = "number", Notes = "Returns the amount of knockback that the currently equipped items would cause when attacking the ReceiverEntity." },
GetLookVector = { Params = "", Return = "Vector3f", Notes = "Returns the vector that defines the direction in which the entity is looking" },
+ GetMass = { Params = "", Return = "number", Notes = "Returns the mass of the entity. Currently unused." },
+ GetMaxHealth = { Params = "", Return = "number", Notes = "Returns the maximum number of hitpoints this entity is allowed to have." },
GetParentClass = { Params = "", Return = "string", Notes = "Returns the name of the direct parent class for this entity" },
GetPitch = { Params = "", Return = "number", Notes = "Returns the pitch (nose-down rotation) of the entity" },
+ GetPosition = { Params = "", Return = "Vector3d", Notes = "Returns the entity's pivot position as a 3D vector" },
GetPosX = { Params = "", Return = "number", Notes = "Returns the X-coord of the entity's pivot" },
GetPosY = { Params = "", Return = "number", Notes = "Returns the Y-coord of the entity's pivot" },
GetPosZ = { Params = "", Return = "number", Notes = "Returns the Z-coord of the entity's pivot" },
- GetPosition = { Params = "", Return = "Vector3d", Notes = "Returns the entity's pivot position as a 3D vector" },
- GetRoll = { Params = "", Return = "number", Notes = "Returns the roll (sideways rotation) of the entity" },
- GetRot = { Params = "", Return = "Vector3f", Notes = "Returns the entire rotation vector (Rotation, Pitch, Roll)" },
- GetRotation = { Params = "", Return = "number", Notes = "Returns the rotation (direction) of the entity" },
+ GetRawDamageAgainst = { Params = "ReceiverEntity", Return = "number", Notes = "Returns the raw damage that this entity's equipment would cause when attacking the ReceiverEntity. This includes this entity's weapon {{cEnchantments|enchantments}}, but excludes the receiver's armor or potion effects. See {{TakeDamageInfo}} for more information on attack damage." },
+ GetRoll = { Params = "", Return = "number", Notes = "Returns the roll (sideways rotation) of the entity. Currently unused." },
+ GetRot = { Params = "", Return = "{{Vector3f}}", Notes = "Returns the entire rotation vector (Yaw, Pitch, Roll)" },
+ GetRotation = { Params = "", Return = "number", Notes = "Returns the yaw (direction) of the entity. FIXME: Rename to GetYaw()." },
GetSpeed = { Params = "", Return = "Vector3d", Notes = "Returns the complete speed vector of the entity" },
GetSpeedX = { Params = "", Return = "number", Notes = "Returns the X-part of the speed vector" },
GetSpeedY = { Params = "", Return = "number", Notes = "Returns the Y-part of the speed vector" },
GetSpeedZ = { Params = "", Return = "number", Notes = "Returns the Z-part of the speed vector" },
- GetUniqueID = { Params = "", Return = "number", Notes = "Returns the ID that uniquely identifies the entity" },
+ GetUniqueID = { Params = "", Return = "number", Notes = "Returns the ID that uniquely identifies the entity within the running server. Note that this ID is not persisted to the data files." },
+ GetWidth = { Params = "", Return = "number", Notes = "Returns the width (X and Z size) of the entity." },
GetWorld = { Params = "", Return = "{{cWorld|cWorld}}", Notes = "Returns the world where the entity resides" },
+ Heal = { Params = "Hitpoints", Return = "", Notes = "Heals the specified number of hitpoints. Hitpoints is expected to be a positive number." },
IsA = { Params = "ClassName", Return = "bool", Notes = "Returns true if the entity class is a descendant of the specified class name, or the specified class itself" },
- IsCrouched = { Params = "", Return = "bool", Notes = "Returns true if the entity is crouched. False for entities that don't support crouching" },
- IsDestroyed = { Params = "", Return = "bool", Notes = "Returns true if the entity has been destroyed and is awaiting removal from the internal structures" },
- IsMinecart = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a minecart" },
- IsMob = { Params = "", Return = "bool", Notes = "Returns true if the entity represents any mob" },
+ IsBoat = { Params = "", Return = "bool", Notes = "Returns true if the entity is a {{cBoat|boat}}." },
+ IsCrouched = { Params = "", Return = "bool", Notes = "Returns true if the entity is crouched. Always false for entities that don't support crouching." },
+ IsDestroyed = { Params = "", Return = "bool", Notes = "Returns true if the entity has been destroyed and is awaiting removal from the internal structures." },
+ IsMinecart = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cMinecart|minecart}}" },
+ IsMob = { Params = "", Return = "bool", Notes = "Returns true if the entity represents any {{cMonster|mob}}." },
IsOnFire = { Params = "", Return = "bool", Notes = "Returns true if the entity is on fire" },
- IsPickup = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a pickup" },
- IsPlayer = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a player" },
- IsTNT = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a TNT entity" },
+ IsPickup = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cPickup|pickup}}." },
+ IsPlayer = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cPlayer|player}}" },
IsRclking = { Params = "", Return = "bool", Notes = "Currently unimplemented" },
- IsSprinting = { Params = "", Return = "bool", Notes = "Returns true if the entity is sprinting. ENtities that cannot sprint return always false" },
+ IsRiding = { Params = "", Return = "bool", Notes = "Returns true if the entity is attached to (riding) another entity." },
+ IsSprinting = { Params = "", Return = "bool", Notes = "Returns true if the entity is sprinting. Entities that cannot sprint return always false" },
+ IsTNT = { Params = "", Return = "bool", Notes = "Returns true if the entity represents a {{cTNTEntity|TNT entity}}" },
+ KilledBy = { Notes = "FIXME: Remove this from API" },
+ SetGravity = { Params = "Gravity", Return = "", Notes = "Sets the number that is used as the gravity for physics simulation. 1G (9.78) by default." },
+ SetHeadYaw = { Params = "HeadPitch", Return = "", Notes = "Sets the head pitch (FIXME: Rename to SetHeadPitch() )." },
+ SetHealth = { Params = "Hitpoints", Return = "", Notes = "Sets the entity's health to the specified amount of hitpoints. Doesn't broadcast any hurt animation. Doesn't kill the entity if health drops below zero. Use the TakeDamage() function instead for taking damage." },
+ SetHeight = { Params = "", Return = "", Notes = "FIXME: Remove this from API" },
+ SetMass = { Params = "Mass", Return = "", Notes = "Sets the mass of the entity. Currently unused." },
+ SetMaxHealth = { Params = "MaxHitpoints", Return = "", Notes = "Sets the maximum hitpoints of the entity. If current health is above MaxHitpoints, it is capped to MaxHitpoints." },
SetPitch = { Params = "number", Return = "", Notes = "Sets the pitch (nose-down rotation) of the entity" },
+ SetPitchFromSpeed = { Params = "", Return = "", Notes = "Sets the entity pitch to match its speed (entity looking forwards as it moves)" },
+ SetPosition =
+ {
+ { Params = "PosX, PosY, PosZ", Return = "", Notes = "Sets all three coords of the entity's pivot" },
+ { Params = "{{Vector3d|Vector3d}}", Return = "", Notes = "Sets all three coords of the entity's pivot" },
+ },
SetPosX = { Params = "number", Return = "", Notes = "Sets the X-coord of the entity's pivot" },
SetPosY = { Params = "number", Return = "", Notes = "Sets the Y-coord of the entity's pivot" },
SetPosZ = { Params = "number", Return = "", Notes = "Sets the Z-coord of the entity's pivot" },
- SetPosition = { Params = "X, Y, Z", Return = "", Notes = "Sets all three coords of the entity's pivot" },
- SetPosition = { Params = "{{Vector3d|Vector3d}}", Return = "", Notes = ":::" },
- SetRoll = { Params = "number", Return = "", Notes = "Sets the roll (sideways rotation) of the entity" },
- SetRot = { Params = "{{Vector3f|Vector3f}}", Return = "", Notes = "Sets the entire rotation vector (Rotation, Pitch, Roll)" },
- SetRotation = { Params = "number", Return = "", Notes = "Sets the rotation (direction) of the entity" },
+ SetRoll = { Params = "number", Return = "", Notes = "Sets the roll (sideways rotation) of the entity. Currently unused." },
+ SetRot = { Params = "{{Vector3f|Rotation}}", Return = "", Notes = "Sets the entire rotation vector (Yaw, Pitch, Roll)" },
+ SetRotation = { Params = "number", Return = "", Notes = "Sets the yaw (direction) of the entity. FIXME: Rename to SetYaw()." },
+ SetRotationFromSpeed = { Params = "", Return = "", Notes = "Sets the entity's yaw to match its current speed (entity looking forwards as it moves). (FIXME: Rename to SetYawFromSpeed)" },
+ SetSpeed =
+ {
+ { Params = "SpeedX, SpeedY, SpeedZ", Return = "", Notes = "Sets the current speed of the entity" },
+ { Params = "{{Vector3d|Speed}}", Return = "", Notes = "Sets the current speed of the entity" },
+ },
+ SetSpeedX = { Params = "SpeedX", Return = "", Notes = "Sets the X component of the entity speed" },
+ SetSpeedY = { Params = "SpeedY", Return = "", Notes = "Sets the Y component of the entity speed" },
+ SetSpeedZ = { Params = "SpeedZ", Return = "", Notes = "Sets the Z component of the entity speed" },
+ SetWidth = { Params = "", Return = "", Notes = "FIXME: Remove this from API" },
+ StartBurning = { Params = "NumTicks", Return = "", Notes = "Sets the entity on fire for the specified number of ticks. If entity is on fire already, makes it burn for either NumTicks or the number of ticks left from the previous fire, whichever is larger." },
+ SteerVehicle = { Params = "ForwardAmount, SidewaysAmount", Return = "", Notes = "Applies the specified steering to the vehicle this entity is attached to. Ignored if not attached to any entity." },
+ StopBurning = { Params = "", Return = "", Notes = "Extinguishes the entity fire, cancels all fire timers." },
+ TakeDamage =
+ {
+ { Params = "AttackerEntity", Return = "", Notes = "Causes this entity to take damage that AttackerEntity would inflict. Includes their weapon and this entity's armor." },
+ { Params = "DamageType, AttackerEntity, RawDamage, KnockbackAmount", Return = "", Notes = "Causes this entity to take damage of the specified type, from the specified attacker (may be nil). The final damage is calculated from RawDamage using the currently equipped armor." },
+ { Params = "DamageType, ArrackerEntity, RawDamage, FinalDamage, KnockbackAmount", Return = "", Notes = "Causes this entity to take damage of the specified type, from the specified attacker (may be nil). The values are wrapped into a {{TakeDamageInfo}} structure and applied directly." },
+ },
+ TeleportToCoords = { Params = "PosX, PosY, PosZ", Return = "", Notes = "Teleports the entity to the specified coords." },
+ TeleportToEntity = { Params = "DestEntity", Return = "", Notes = "Teleports this entity to the specified destination entity." },
},
Constants =
{
- etEntity = { Notes = "N" },
- etPlayer = { Notes = "{{cPlayer|cPlayer" },
- etPickup = { Notes = "{{cPickup|cPickup" },
- etMob = { Notes = "{{cMonster|cMonster}} and descendan" },
- etFallingBlock = { Notes = "{{cFallingBlock|cFallingBlock" },
- etMinecart = { Notes = "{{cMinecart|cMinecart" },
- etTNT = { Notes = "{{cTNTEntity|cTNTEntity" },
+ etBoat = { Notes = "The entity is a {{cBoat}}" },
+ etEntity = { Notes = "No further specialization available" },
+ etFallingBlock = { Notes = "The entity is a {{cFallingBlock}}" },
+ etMob = { Notes = "The entity is a {{cMonster}} descendant" },
+ etMonster = { Notes = "The entity is a {{cMonster}} descendant" },
+ etMinecart = { Notes = "The entity is a {{cMinecart}} descendant" },
+ etPlayer = { Notes = "The entity is a {{cPlayer}}" },
+ etPickup = { Notes = "The entity is a {{cPickup}}" },
+ etProjectile = { Notes = "The entity is a {{cProjectile}} descendant" },
+ etTNT = { Notes = "The entity is a {{cTNTEntity}}" },
+ },
+ },
+
+ cFile =
+ {
+ Desc = [[
+ Provides helper functions for manipulating and querying the filesystem. Most functions are called
+ directly on the cFile class itself:
+<pre class="prettyprint lang-lua">
+cFile:Delete("/usr/bin/virus.exe");
+</pre></p>
+ ]],
+
+ Functions =
+ {
+ Copy = { Params = "SrcFileName, DstFileName", Return = "bool", Notes = "Copies a single file to a new destination. Returns true if successful. Fails if the destination already exists." },
+ CreateFolder = { Params = "FolderName", Return = "bool", Notes = "Creates a new folder. Returns true if successful." },
+ Delete = { Params = "FileName", Return = "bool", Notes = "Deletes the specified file. Returns true if successful." },
+ Exists = { Params = "FileName", Return = "bool", Notes = "Returns true if the specified file exists." },
+ GetSize = { Params = "FileName", Return = "number", Notes = "Returns the size of the file, or -1 on failure." },
+ IsFile = { Params = "Path", Return = "bool", Notes = "Returns true if the specified path points to an existing file." },
+ IsFolder = { Params = "Path", Return = "bool", Notes = "Returns true if the specified path points to an existing folder." },
+ Rename = { Params = "OrigPath, NewPath", Return = "bool", Notes = "Renames a file or a folder. Returns true if successful. Undefined result if NewPath already exists." },
},
+
},
cFireChargeEntity =
@@ -680,6 +907,7 @@ g_APIDesc =
Desc = "",
Functions = {},
Constants = {},
+ Inherits = "cProjectileEntity",
} ,
cGroup =
@@ -688,14 +916,14 @@ g_APIDesc =
]],
Functions =
{
- SetName = { Notes = "void" },
- GetName = { Notes = "String" },
- SetColor = { Notes = "void" },
- GetColor = { Notes = "String" },
- AddCommand = { Notes = "void" },
- HasCommand = { Notes = "bool" },
- AddPermission = { Notes = "void" },
- InheritFrom = { Notes = "void" },
+ SetName = { Return = "" },
+ GetName = { Return = "string" },
+ SetColor = { Return = "" },
+ GetColor = { Return = "string" },
+ AddCommand = { Return = "" },
+ HasCommand = { Return = "bool" },
+ AddPermission = { Return = "" },
+ InheritFrom = { Return = "" },
},
Constants =
{
@@ -709,16 +937,16 @@ g_APIDesc =
Functions =
{
constructor = { Return = "{{cIniFile|cIniFile}}" },
- CaseSensitive = { Notes = "void" },
- CaseInsensitive = { Notes = "void" },
- Path = { Notes = "void" },
- Path = { Notes = "String" },
- SetPath = { Notes = "void" },
- ReadFile = { Notes = "bool" },
- WriteFile = { Notes = "bool" },
- Erase = { Notes = "void" },
- Clear = { Notes = "void" },
- Reset = { Notes = "void" },
+ CaseSensitive = { Return = "" },
+ CaseInsensitive = { Return = "" },
+ Path = { Return = "" },
+ Path = { Return = "string" },
+ SetPath = { Return = "" },
+ ReadFile = { Return = "bool" },
+ WriteFile = { Return = "bool" },
+ Erase = { Return = "" },
+ Clear = { Return = "" },
+ Reset = { Return = "" },
FindKey = { Notes = "long i" },
FindValue = { Notes = "long i" },
NumKeys = { Notes = "unsigned i" },
@@ -743,29 +971,29 @@ g_APIDesc =
GetValueSetI = { Notes = "i" },
GetValueSetB = { Notes = "bo" },
GetValueSetF = { Notes = "doub" },
- SetValue = { Notes = "bool" },
- SetValue = { Notes = "bool" },
- SetValueI = { Notes = "bool" },
- SetValueB = { Notes = "bool" },
- SetValueF = { Notes = "bool" },
- DeleteValueByID = { Notes = "bool" },
- DeleteValue = { Notes = "bool" },
- DeleteKey = { Notes = "bool" },
+ SetValue = { Return = "bool" },
+ SetValue = { Return = "bool" },
+ SetValueI = { Return = "bool" },
+ SetValueB = { Return = "bool" },
+ SetValueF = { Return = "bool" },
+ DeleteValueByID = { Return = "bool" },
+ DeleteValue = { Return = "bool" },
+ DeleteKey = { Return = "bool" },
NumHeaderComments = { Notes = "unsigned int" },
- HeaderComment = { Notes = "void" },
+ HeaderComment = { Return = "" },
HeaderComment = { Notes = "Stri" },
- DeleteHeaderComment = { Notes = "bool" },
- DeleteHeaderComments = { Notes = "void" },
+ DeleteHeaderComment = { Return = "bool" },
+ DeleteHeaderComments = { Return = "" },
NumKeyComments = { Notes = "unsigned i" },
NumKeyComments = { Notes = "unsigned i" },
- KeyComment = { Notes = "bool" },
- KeyComment = { Notes = "bool" },
+ KeyComment = { Return = "bool" },
+ KeyComment = { Return = "bool" },
KeyComment = { Notes = "Stri" },
KeyComment = { Notes = "Stri" },
- DeleteKeyComment = { Notes = "bool" },
- DeleteKeyComment = { Notes = "bool" },
- DeleteKeyComments = { Notes = "bool" },
- DeleteKeyComments = { Notes = "bool" },
+ DeleteKeyComment = { Return = "bool" },
+ DeleteKeyComment = { Return = "bool" },
+ DeleteKeyComments = { Return = "bool" },
+ DeleteKeyComments = { Return = "bool" },
},
Constants =
{
@@ -830,27 +1058,29 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
{
Desc = [[
cItem is what defines an item or stack of items in the game, it contains the item ID, damage,
- quantity and enchantments. Each slot in a {{cInventory|cInventory}} class or a
- {{cItemGrid|cItemGrid}} class is a cItem and each cPickup contains a cItem. The enchantments
- are contained in a {{cEnchantments|cEnchantments}} class
+ quantity and enchantments. Each slot in a {{cInventory}} class or a {{cItemGrid}} class is a cItem
+ and each {{cPickup}} contains a cItem. The enchantments are contained in a separate
+ {{cEnchantments}} class and are accessible through the m_Enchantments variable.
]],
Functions =
{
constructor =
{
- { Params = "", Return = "cItem", Notes = "Creates a new empty cItem obje" },
+ { Params = "", Return = "cItem", Notes = "Creates a new empty cItem object" },
{ Params = "ItemType, Count, Damage, EnchantmentString", Return = "cItem", Notes = "Creates a new cItem object of the specified type, count (1 by default), damage (0 by default) and enchantments (non-enchanted by default)" },
{ Params = "cItem", Return = "cItem", Notes = "Creates an exact copy of the cItem object in the parameter" },
} ,
+ AddCount = { Params = "AmountToAdd", Return = "cItem", Notes = "Adds the specified amount to the item count. Returns self (useful for chaining)." },
Clear = { Params = "", Return = "", Notes = "Resets the instance to an empty item" },
CopyOne = { Params = "", Return = "cItem", Notes = "Creates a copy of this object, with its count set to 1" },
DamageItem = { Params = "[Amount]", Return = "bool", Notes = "Adds the specified damage. Returns true when damage reaches max value and the item should be destroyed (but doesn't destroy the item)" },
Empty = { Params = "", Return = "", Notes = "Resets the instance to an empty item" },
GetMaxDamage = { Params = "", Return = "number", Notes = "Returns the maximum value for damage that this item can get before breaking; zero if damage is not accounted for for this item type" },
IsDamageable = { Params = "", Return = "bool", Notes = "Returns true if this item does account for its damage" },
- IsEnchantable = { Params = "ItemType", Return = "bool", Notes = "(static) Returns true if the specified ItemType is an enchantable item, as defined by the 1.2.5 network protocol (deprecated)" },
+ IsEmpty = { Params = "", Return = "bool", Notes = "Returns true if this object represents an empty item (zero count or invalid ID)" },
IsEqual = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is the same as the one stored in the object (type, damage and enchantments)" },
+ IsFullStack = { Params = "", Return = "bool", Notes = "Returns true if the item is stacked up to its maximum stacking" },
IsSameType = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is of the same ItemType as the one stored in the object" },
IsStackableWith = { Params = "cItem", Return = "bool", Notes = "Returns true if the item in the parameter is stackable with the one stored in the object" },
},
@@ -864,10 +1094,10 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
Desc = [[This class represents a 2D array of items. It is used as the underlying storage and API for all cases that use a grid of items:
<li>Chest contents</li>
<li>(TODO) Chest minecart contents</li>
-<li>Dispenser contents</li>
-<li>Dropper contents</li>
-<li>(TODO) Furnace contents (?)</li>
-<li>(TODO) Hopper contents</li>
+<li>{{cDispenserEntity|Dispenser|| contents</li>
+<li>{{cDropperEntity|Dropper}} contents</li>
+<li>{{cFurnaceEntity|Furnace}} contents (?)</li>
+<li>{{cHopperEntity|Hopper}} contents</li>
<li>(TODO) Hopper minecart contents</li>
<li>Player Inventory areas</li>
<li>(TODO) Trapped chest contents</li>
@@ -878,33 +1108,54 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
{
AddItem = { Params = "{{cItem|cItem}}, [AllowNewStacks]", Return = "number", Notes = "Adds an item to the storage; if AllowNewStacks is true (default), will also create new stacks in empty slots. Returns the number of items added" },
AddItems = { Params = "{{cItems|cItems}}, [AllowNewStacks]", Return = "number", Notes = "Same as AddItem, but for several items at once" },
- ChangeSlotCount = { Params = "SlotNum, AddToCount", Return = "number", Notes = "Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid SlotNum" },
- ChangeSlotCount = { Params = "X, Y, AddToCount", Return = "number", Notes = "Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid slot coords" },
+ ChangeSlotCount =
+ {
+ { Params = "SlotNum, AddToCount", Return = "number", Notes = "Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid SlotNum" },
+ { Params = "X, Y, AddToCount", Return = "number", Notes = "Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid slot coords" },
+ },
Clear = { Params = "", Return = "", Notes = "Empties all slots" },
CopyToItems = { Params = "{{cItems|cItems}}", Return = "", Notes = "Copies all non-empty slots into the cItems object provided; original cItems contents are preserved" },
- DamageItem = { Params = "SlotNum, [DamageAmount]", Return = "bool", Notes = "Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed" },
- DamageItem = { Params = "X, Y, [DamageAmount]", Return = "bool", Notes = "Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed" },
- EmptySlot = { Params = "SlotNum", Return = "", Notes = "Destroys the item in the specified slot" },
- EmptySlot = { Params = "X, Y", Return = "", Notes = "Destroys the item in the specified slot" },
+ DamageItem =
+ {
+ { Params = "SlotNum, [DamageAmount]", Return = "bool", Notes = "Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed" },
+ { Params = "X, Y, [DamageAmount]", Return = "bool", Notes = "Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed" },
+ },
+ EmptySlot =
+ {
+ { Params = "SlotNum", Return = "", Notes = "Destroys the item in the specified slot" },
+ { Params = "X, Y", Return = "", Notes = "Destroys the item in the specified slot" },
+ },
GetFirstEmptySlot = { Params = "", Return = "number", Notes = "Returns the SlotNumber of the first empty slot, -1 if all slots are full" },
GetHeight = { Params = "", Return = "number", Notes = "Returns the Y dimension of the grid" },
GetLastEmptySlot = { Params = "", Return = "number", Notes = "Returns the SlotNumber of the last empty slot, -1 if all slots are full" },
GetNextEmptySlot = { Params = "StartFrom", Return = "number", Notes = "Returns the SlotNumber of the first empty slot following StartFrom, -1 if all the following slots are full" },
GetNumSlots = { Params = "", Return = "number", Notes = "Returns the total number of slots in the grid (Width * Height)" },
- GetSlot = { Params = "SlotNumber", Return = "{{cItem|cItem}}", Notes = "Returns the item in the specified slot. Note that the item is read-only" },
- GetSlot = { Params = "X, Y", Return = "{{cItem|cItem}}", Notes = "Returns the item in the specified slot. Note that the item is read-only" },
+ GetSlot =
+ {
+ { Params = "SlotNumber", Return = "{{cItem|cItem}}", Notes = "Returns the item in the specified slot. Note that the item is read-only" },
+ { Params = "X, Y", Return = "{{cItem|cItem}}", Notes = "Returns the item in the specified slot. Note that the item is read-only" },
+ },
GetSlotCoords = { Params = "SlotNum", Return = "number, number", Notes = "Returns the X and Y coords for the specified SlotNumber. Returns \"-1, -1\" on invalid SlotNumber" },
GetSlotNum = { Params = "X, Y", Return = "number", Notes = "Returns the SlotNumber for the specified slot coords. Returns -1 on invalid coords" },
GetWidth = { Params = "", Return = "number", Notes = "Returns the X dimension of the grid" },
HasItems = { Params = "{{cItem|cItem}}", Return = "bool", Notes = "Returns true if there are at least as many items of the specified type as in the parameter" },
HowManyCanFit = { Params = "{{cItem|cItem}}", Return = "number", Notes = "Returns the number of the specified items that can fit in the storage, including empty slots" },
HowManyItems = { Params = "{{cItem|cItem}}", Return = "number", Notes = "Returns the number of the specified items that are currently stored" },
- IsSlotEmpty = { Params = "SlotNum", Return = "bool", Notes = "Returns true if the specified slot is empty, or an invalid slot is specified" },
- IsSlotEmpty = { Params = "X, Y", Return = "bool", Notes = "Returns true if the specified slot is empty, or an invalid slot is specified" },
- RemoveOneItem = { Params = "SlotNum", Return = "{{cItem|cItem}}", Notes = "Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned" },
- RemoveOneItem = { Params = "X, Y", Return = "{{cItem|cItem}}", Notes = "Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned" },
- SetSlot = { Params = "SlotNum, {{cItem|cItem}}", Return = "", Notes = "Sets the specified slot to the specified item" },
- SetSlot = { Params = "X, Y, {{cItem|cItem}}", Return = "", Notes = "Sets the specified slot to the specified item" },
+ IsSlotEmpty =
+ {
+ { Params = "SlotNum", Return = "bool", Notes = "Returns true if the specified slot is empty, or an invalid slot is specified" },
+ { Params = "X, Y", Return = "bool", Notes = "Returns true if the specified slot is empty, or an invalid slot is specified" },
+ },
+ RemoveOneItem =
+ {
+ { Params = "SlotNum", Return = "{{cItem|cItem}}", Notes = "Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned" },
+ { Params = "X, Y", Return = "{{cItem|cItem}}", Notes = "Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned" },
+ },
+ SetSlot =
+ {
+ { Params = "SlotNum, {{cItem|cItem}}", Return = "", Notes = "Sets the specified slot to the specified item" },
+ { Params = "X, Y, {{cItem|cItem}}", Return = "", Notes = "Sets the specified slot to the specified item" },
+ },
},
Constants =
{
@@ -921,13 +1172,19 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
Functions =
{
constructor = { Params = "", Return = "cItems", Notes = "Creates a new cItems object" },
- Add = { Params = "Index, {{cItem|cItem}}", Return = "", Notes = "Adds a new item to the end of the collection" },
- Add = { Params = "Index, ItemType, ItemCount, ItemDamage", Return = "", Notes = "Adds a new item to the end of the collection" },
+ Add =
+ {
+ { Params = "{{cItem|cItem}}", Return = "", Notes = "Adds a new item to the end of the collection" },
+ { Params = "ItemType, ItemCount, ItemDamage", Return = "", Notes = "Adds a new item to the end of the collection" },
+ },
Clear = { Params = "", Return = "", Notes = "Removes all items from the collection" },
Delete = { Params = "Index", Return = "", Notes = "Deletes item at the specified index" },
Get = { Params = "Index", Return = "{{cItem|cItem}}", Notes = "Returns the item at the specified index" },
- Set = { Params = "Index, {{cItem|cItem}}", Return = "", Notes = "Sets the item at the specified index to the specified item" },
- Set = { Params = "Index, ItemType, ItemCount, ItemDamage", Return = "", Notes = "Sets the item at the specified index to the specified item" },
+ Set =
+ {
+ { Params = "Index, {{cItem|cItem}}", Return = "", Notes = "Sets the item at the specified index to the specified item" },
+ { Params = "Index, ItemType, ItemCount, ItemDamage", Return = "", Notes = "Sets the item at the specified index to the specified item" },
+ },
Size = { Params = "", Return = "number", Notes = "Returns the number of items in the collection" },
},
Constants =
@@ -937,10 +1194,92 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
cLineBlockTracer =
{
- Desc = "",
- Functions = {},
- Constants = {},
- },
+ Desc = [[Objects of this class provide an easy-to-use interface to tracing lines through individual
+blocks in the world. It will call the provided callbacks according to what events it encounters along the
+way.</p>
+<p>
+For the Lua API, there's only one function exported that takes all the parameters necessary to do the
+tracing. The Callbacks parameter is a table containing all the functions that will be called upon the
+various events. See below for further information.
+ ]],
+ Functions =
+ {
+ Trace = { Params = "{{cWorld}}, Callbacks, StartX, StartY, StartZ, EndX, EndY, EndZ", Return = "bool", Notes = "(STATIC) Performs the trace on the specified line. Returns true if the entire trace was processed (no callback returned true)" },
+ },
+
+ AdditionalInfo =
+ {
+ {
+ Header = "Callbacks",
+ Contents = [[
+The Callbacks in the Trace() function is a table that contains named functions. MCServer will call
+individual functions from that table for the events that occur on the line - hitting a block, going out of
+valid world data etc. The following table lists all the available callbacks. If the callback function is
+not defined, MCServer skips it. Each function can return a bool value, if it returns true, the tracing is
+aborted and Trace() returns false.</p>
+<p>
+<table><tr><th>Name</th><th>Parameters</th><th>Notes</th></tr>
+<tr><td>OnNextBlock</td><td>BlockX, BlockY, BlockZ, BlockType, BlockMeta, EntryFace</td>
+ <td>Called when the ray hits a new valid block. The block type and meta is given. EntryFace is one of the
+ BLOCK_FACE_ constants indicating which "side" of the block got hit by the ray.</td></tr>
+<tr><td>OnNextBlockNoData</td><td>BlockX, BlockY, BlockZ, EntryFace</td>
+ <td>Called when the ray hits a new block, but the block is in an unloaded chunk - no valid data is
+ available. Only the coords and the entry face are given.</td></tr>
+<tr><td>OnOutOfWorld</td><td>X, Y, Z</td>
+ <td>Called when the ray goes outside of the world (Y-wise); the coords specify the exact exit point. Note
+ that for other paths than lines (considered for future implementations) the path may leave the world and
+ go back in again later, in such a case this callback is followed by OnIntoWorld() and further
+ OnNextBlock() calls.</td></tr>
+<tr><td>OnIntoWorld</td><td>X, Y, Z</td>
+ <td>Called when the ray enters the world (Y-wise); the coords specify the exact entry point.</td></tr>
+<tr><td>OnNoMoreHits</td><td>&nbsp;</td>
+ <td>Called when the path is sure not to hit any more blocks. This is the final callback, no more
+ callbacks are called after this function. Unlike the other callbacks, this function doesn't have a return
+ value.</td></tr>
+<tr><td>OnNoChunk</td><td>&nbsp;</td>
+ <td>Called when the ray enters a chunk that is not loaded. This usually means that the tracing is aborted.
+ Unlike the other callbacks, this function doesn't have a return value.</td></tr>
+</table>
+ ]],
+ },
+ {
+ Header = "Example",
+ Contents = [[
+<p>The following example is taken from the Debuggers plugin. It is a command handler function for the
+"/spidey" command that creates a line of cobweb blocks from the player's eyes up to 50 blocks away in
+the direction they're looking, but only through the air.
+<pre class="prettyprint lang-lua">
+function HandleSpideyCmd(a_Split, a_Player)
+ local World = a_Player:GetWorld();
+
+ local Callbacks = {
+ OnNextBlock = function(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta)
+ if (a_BlockType ~= E_BLOCK_AIR) then
+ -- abort the trace
+ return true;
+ end
+ World:SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_COBWEB, 0);
+ end
+ };
+
+ local EyePos = a_Player:GetEyePosition();
+ local LookVector = a_Player:GetLookVector();
+ LookVector:Normalize(); -- Make the vector 1 m long
+
+ -- Start cca 2 blocks away from the eyes
+ local Start = EyePos + LookVector + LookVector;
+ local End = EyePos + LookVector * 50;
+
+ cLineBlockTracer.Trace(World, Callbacks, Start.x, Start.y, Start.z, End.x, End.y, End.z);
+
+ return true;
+end
+</pre>
+</p>
+ ]],
+ },
+ }, -- AdditionalInfo
+ }, -- cLineBlockTracer
cLuaWindow =
{
@@ -976,7 +1315,7 @@ These ItemGrids are available in the API and can be manipulated by the plugins,
Header = "OnClosing Callback",
Contents = [[
This callback, settable via the SetOnClosing() function, will be called when the player tries to close the window, or the window is closed for any other reason (such as a player disconnecting).</p>
-<pre>
+<pre class="prettyprint lang-lua">
function OnWindowClosing(a_Window, a_Player, a_CanRefuse)
</pre>
<p>
@@ -987,7 +1326,7 @@ function OnWindowClosing(a_Window, a_Player, a_CanRefuse)
Header = "OnSlotChanged Callback",
Contents = [[
This callback, settable via the SetOnSlotChanged() function, will be called whenever the contents of any slot in the window's contents (i. e. NOT in the player inventory!) changes.</p>
-<pre>
+<pre class="prettyprint lang-lua">
function OnWindowSlotChanged(a_Window, a_SlotNum)
</pre>
<p>The a_Window parameter is the cLuaWindow object representing the window, a_SlotNum is the slot number. There is no reference to a {{cPlayer}}, because the slot change needn't originate from the player action. To get or set the slot, you'll need to retrieve a cPlayer object, for example by calling {{cWorld|cWorld}}:DoWithPlayer().
@@ -999,7 +1338,7 @@ function OnWindowSlotChanged(a_Window, a_SlotNum)
Header = "Example",
Contents = [[
This example is taken from the Debuggers plugin, used to test the API functionality. It opens a window and refuse to close it 3 times. It also logs slot changes to the server console.
-<pre>
+<pre class="prettyprint lang-lua">
-- Callback that refuses to close the window twice, then allows:
local Attempt = 1;
local OnClosing = function(Window, Player, CanRefuse)
@@ -1026,6 +1365,7 @@ a_Player:OpenWindow(Window);
]],
},
}, -- AdditionalInfo
+ Inherits = "cWindow",
}, -- cLuaWindow
cMonster =
@@ -1042,12 +1382,12 @@ a_Player:OpenWindow(Window);
]],
Functions =
{
- TeleportToEntity = { Notes = "void" },
- TeleportTo = { Notes = "void" },
- Heal = { Notes = "void" },
- TakeDamage = { Notes = "void" },
- KilledBy = { Notes = "void" },
- GetHealth = { Notes = "int" },
+ TeleportToEntity = { Return = "" },
+ TeleportTo = { Return = "" },
+ Heal = { Return = "" },
+ TakeDamage = { Return = "" },
+ KilledBy = { Return = "" },
+ GetHealth = { Return = "number" },
},
Constants =
{
@@ -1063,7 +1403,7 @@ a_Player:OpenWindow(Window);
{
cPickup = { Notes = "[[cPickup}}" },
GetItem = { Notes = "{{cItem|cItem}}" },
- CollectedBy = { Notes = "bool" },
+ CollectedBy = { Return = "bool" },
},
Constants =
{
@@ -1077,40 +1417,35 @@ a_Player:OpenWindow(Window);
]],
Functions =
{
- GetEyeHeight = { Notes = "double" },
- GetEyePosition = { Notes = "{{Vector3d|Vector3d}}" },
- GetFlying = { Notes = "bool" },
- GetStance = { Notes = "double" },
- GetInventory = { Notes = "{{cInventory|cInventory}}" },
- TeleportTo = { Notes = "void" },
- GetGameMode = { Notes = "{{eGameMode|eGameMode}}" },
- GetIP = { Notes = "String" },
- GetLastBlockActionTime = { Notes = "float" },
- GetLastBlockActionCnt = { Notes = "int" },
- SetLastBlockActionCnt = { Notes = "void" },
- SetLastBlockActionTime = { Notes = "void" },
- SetGameMode = { Notes = "void" },
- MoveTo = { Notes = "void" },
- GetClientHandle = { Notes = "{{cClientHandle|cClientHandle}}" },
- SendMessage = { Notes = "void" },
- GetName = { Notes = "String" },
- SetName = { Notes = "void" },
- AddToGroup = { Notes = "void" },
- CanUseCommand = { Notes = "bool" },
- HasPermission = { Notes = "bool" },
- IsInGroup = { Notes = "bool" },
- GetColor = { Notes = "String" },
- TossItem = { Notes = "void" },
- Heal = { Notes = "void" },
- TakeDamage = { Notes = "void" },
- KilledBy = { Notes = "void" },
- Respawn = { Notes = "void" },
- SetVisible = { Notes = "void" },
- IsVisible = { Notes = "bool" },
- MoveToWorld = { Notes = "bool" },
- LoadPermissionsFromDisk = { Notes = "void" },
- GetGroups = { Notes = "list<{{cGroup|cGroup}}>" },
- GetResolvedPermissions = { Notes = "String" },
+ GetEyeHeight = { Return = "number" },
+ GetEyePosition = { Return = "{{Vector3d|EyePositionVector}}" },
+ GetFlying = { Return = "bool" },
+ GetStance = { Return = "number" },
+ GetInventory = { Return = "{{cInventory|Inventory}}" },
+ GetGameMode = { Return = "{{eGameMode|GameMode}}", Notes = "Returns the player's gamemode. The player may have their gamemode unassigned, in which case they inherit the gamemode from the current {{cWorld|world}}.<br /> <b>NOTE:</b> Instead of comparing the value returned by this function to the gmXXX constants, use the IsGameModeXXX() functions. These functions handle the gamemode inheritance automatically."},
+ GetIP = { Return = "string" },
+ SetGameMode = { Return = "" },
+ MoveTo = { Return = "" },
+ GetClientHandle = { Return = "{{cClientHandle|ClientHandle}}" },
+ SendMessage = { Return = "" },
+ GetName = { Return = "String" },
+ SetName = { Return = "" },
+ AddToGroup = { Return = "" },
+ CanUseCommand = { Return = "bool" },
+ HasPermission = { Return = "bool" },
+ IsInGroup = { Return = "bool" },
+ GetColor = { Return = "string" },
+ TossItem = { Return = "" },
+ Heal = { Return = "" },
+ TakeDamage = { Return = "" },
+ KilledBy = { Return = "" },
+ Respawn = { Return = "" },
+ SetVisible = { Return = "" },
+ IsVisible = { Return = "bool" },
+ MoveToWorld = { Return = "bool" },
+ LoadPermissionsFromDisk = { Return = "" },
+ GetGroups = { Return = "list<{{cGroup|cGroup}}>" },
+ GetResolvedPermissions = { Return = "string" },
},
Constants =
{
@@ -1120,15 +1455,19 @@ a_Player:OpenWindow(Window);
cPlugin =
{
- Desc = [[cPlugin describes a Lua plugin. This page is dedicated to new-style plugins and contain their functions.
+ Desc = [[cPlugin describes a Lua plugin. This page is dedicated to new-style plugins and contain their functions. Each plugin has its own Plugin object.
]],
Functions =
{
- GetName = { Notes = "String" },
- SetName = { Notes = "void" },
- GetVersion = { Notes = "int" },
- SetVersion = { Notes = "void" },
- GetFileName = { Notes = "String" },
+ Call = { Params = "Function name, [All the parameters divided with commas]", Notes = "This function allows you to call a function from another plugin. It can only use pass: integers, booleans, strings and usertypes (cPlayer, cEntity, cCuboid, etc.)." },
+ GetDirectory = { Return = "string", Notes = "Returns the name of the folder where the plugin's files are. (APIDump)" },
+ GetLocalDirectory = { Notes = "OBSOLETE use GetLocalFolder instead." },
+ GetLocalFolder = { Return = "string", Notes = "Returns the path where the plugin's files are. (Plugins/APIDump)" },
+ GetName = { Return = "string", Notes = "Returns the name of the plugin." },
+ SetName = { Params = "string", Notes = "Sets the name of the Plugin." },
+ GetVersion = { Return = "number", Notes = "Returns the version of the plugin." },
+ SetVersion = { Params = "number", Notes = "Sets the version of the plugin." },
+ GetFileName = { Return = "string" },
CreateWebPlugin = { Notes = "{{cWebPlugin|cWebPlugin}}" },
},
Constants =
@@ -1146,34 +1485,106 @@ a_Player:OpenWindow(Window);
cPluginManager =
{
- Desc = [[This class is used for generic plugin-related functionality. The plugin manager has a list of all plugins, can enable or disable plugins, manages hook and in-game console commands.
-</p>
- <p>There is one instance of cPluginManager in MCServer, to get it, call either {{GetPluginManager|GetPluginManager}}() or cPluginManager:Get() function.
+ Desc = [[
+ This class is used for generic plugin-related functionality. The plugin manager has a list of all
+ plugins, can enable or disable plugins, manages hooks and in-game console commands.</p>
+ <p>
+ There is one instance of cPluginManager in MCServer, to get it, call either
+ {{cRoot|cRoot}}:Get():GetPluginManager() or cPluginManager:Get() function.</p>
+ <p>
+ Note that some functions are "static", that means that they are called using a dot operator instead
+ of the colon operator. For example:
+<pre class="prettyprint lang-lua">
+cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
+</pre></p>
]],
Functions =
{
- AddHook = { Params = "{{cPlugin|Plugin}}, HookType", Return = "", Notes = "Adds processing of the specified hook" },
- BindCommand = { Params = "Command, Permission, Callback, HelpString", Return = "", Notes = "Binds an in-game command with the specified callback function, permission and help string" },
- BindConsoleCommand = { Params = "Command, Callback, HelpString", Return = "", Notes = "Binds a console command with the specified callback function and help string" },
- DisablePlugin = { Params = "PluginName", Return = "", Notes = "Disables a plugin specified by its name" },
- ExecuteCommand = { Params = "Player, Command", Return = "bool", Notes = "Executes the command as if given by the specified Player. Checks permissions. Returns true if executed" },
- ExecuteConsoleCommand = { Params = "Command", Return = "bool", Notes = "Executes the command as if given on the server console. Returns true if executed." },
+ AddHook =
+ {
+ { Params = "HookType, [HookFunction]", Return = "", Notes = "(STATIC) Informs the plugin manager that it should call the specified function when the specified hook event occurs. If a function is not specified, a default function name is looked up, based on the hook type" },
+ { Params = "{{cPlugin|Plugin}}, HookType, [HookFunction]", Return = "", Notes = "(STATIC, <b>DEPRECATED</b>) Informs the plugin manager that it should call the specified function when the specified hook event occurs. If a function is not specified, a default function name is looked up, based on the hook type. NOTE: This format is deprecated and the server outputs a warning if it is used!" },
+ },
+ BindCommand =
+ {
+ { Params = "Command, Permission, Callback, HelpString", Return = "", Notes = "(STATIC) Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display." },
+ { Params = "Command, Permission, Callback, HelpString", Return = "", Notes = "Binds an in-game command with the specified callback function, permission and help string. By common convention, providing an empty string for HelpString will hide the command from the /help display." },
+ },
+ BindConsoleCommand =
+ {
+ { Params = "Command, Callback, HelpString", Return = "", Notes = "(STATIC) Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command." },
+ { Params = "Command, Callback, HelpString", Return = "", Notes = "Binds a console command with the specified callback function and help string. By common convention, providing an empty string for HelpString will hide the command from the \"help\" console command." },
+ },
+ DisablePlugin = { Params = "PluginName", Return = "bool", Notes = "Disables a plugin specified by its name. Returns true if the plugin was disabled, false if it wasn't found or wasn't active." },
+ ExecuteCommand = { Params = "{{cPlayer|Player}}, CommandStr", Return = "bool", Notes = "Executes the command as if given by the specified Player. Checks permissions. Returns true if executed." },
+ ExecuteConsoleCommand = { Params = "CommandStr", Return = "bool", Notes = "Executes the command as if given on the server console. Returns true if executed." },
FindPlugins = { Params = "", Return = "", Notes = "Refreshes the list of plugins to include all folders inside the Plugins folder (potentially new disabled plugins)" },
- ForceExecuteCommand = { Params = "Player, Command", Return = "bool", Notes = "Same as ExecuteCommand, but doesn't check permissions" },
- ForEachCommand = { Params = "Callback", Return = "", Notes = "Calls the Callback function for each command that has been bound using BindCommand()" },
- ForEachConsoleCommand = { Params = "Callback", Return = "", Notes = "Calls the Callback function for each command that has been bound using BindConsoleCommand()" },
+ ForceExecuteCommand = { Params = "{{cPlayer|Player}}, CommandStr", Return = "bool", Notes = "Same as ExecuteCommand, but doesn't check permissions" },
+ ForEachCommand = { Params = "CallbackFn", Return = "bool", Notes = "Calls the CallbackFn function for each command that has been bound using BindCommand(). The CallbackFn has the following signature: <pre class=\"prettyprint lang-lua\">function(Command, Permission, HelpString)</pre>. If the callback returns true, the enumeration is aborted and this API function returns false; if it returns false or no value, the enumeration continues with the next command, and the API function returns true." },
+ ForEachConsoleCommand = { Params = "CallbackFn", Return = "bool", Notes = "Calls the CallbackFn function for each command that has been bound using BindConsoleCommand(). The CallbackFn has the following signature: <pre class=\"prettyprint lang-lua\">function (Command, HelpString)</pre>. If the callback returns true, the enumeration is aborted and this API function returns false; if it returns false or no value, the enumeration continues with the next command, and the API function returns true." },
Get = { Params = "", Return = "cPluginManager", Notes = "Returns the single instance of the plugin manager" },
- GetAllPlugins = { Params = "", Return = "PluginTable", Notes = "Returns a table of all plugins, [name => cPlugin] pairs" },
+ GetAllPlugins = { Params = "", Return = "table", Notes = "Returns a table (dictionary) of all plugins, [name => {{cPlugin}}] pairing." },
GetCommandPermission = { Params = "Command", Return = "Permission", Notes = "Returns the permission needed for executing the specified command" },
GetNumPlugins = { Params = "", Return = "number", Notes = "Returns the number of plugins, including the disabled ones" },
GetPlugin = { Params = "PluginName", Return = "{{cPlugin|cPlugin}}", Notes = "Returns a plugin handle of the specified plugin" },
- IsCommandBound = { Params = "Command", Return = "boolean", Notes = "Returns true if in-game Command is already bound (by any plugin)" },
- IsConsoleCommandBound = { Params = "Command", Return = "boolean", Notes = "Returns true if console Command is already bound (by any plugin)" },
- LoadPlugin = { Params = "PluginFolder", Return = "", Notes = "Loads a plugin from the specified folder" },
+ IsCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if in-game Command is already bound (by any plugin)" },
+ IsConsoleCommandBound = { Params = "Command", Return = "bool", Notes = "Returns true if console Command is already bound (by any plugin)" },
+ LoadPlugin = { Params = "PluginFolder", Return = "", Notes = "(<b>DEPRECATED</b>) Loads a plugin from the specified folder. NOTE: Loading plugins may be an unsafe operation and may result in a deadlock or a crash. This API is deprecated and might be removed." },
ReloadPlugins = { Params = "", Return = "", Notes = "Reloads all active plugins" },
},
Constants =
{
+ HOOK_BLOCK_TO_PICKUPS = { Notes = "Called when a block has been dug and is being converted to pickups. The server has provided the default pickups and the plugins may modify them." },
+ HOOK_CHAT = { Notes = "Called when a client sends a chat message that is not a command. The plugin may modify the chat message" },
+ HOOK_CHUNK_AVAILABLE = { Notes = "Called when a chunk is loaded or generated and becomes available in the {{cWorld|world}}." },
+ HOOK_CHUNK_GENERATED = { Notes = "Called after a chunk is generated. A plugin may do last modifications on the generated chunk before it is handed of to the {{cWorld|world}}." },
+ HOOK_CHUNK_GENERATING = { Notes = "Called before a chunk is generated. A plugin may override some parts of the generation algorithm." },
+ HOOK_CHUNK_UNLOADED = { Notes = "Called after a chunk has been unloaded from a {{cWorld|world}}." },
+ HOOK_CHUNK_UNLOADING = { Notes = "Called before a chunk is unloaded from a {{cWorld|world}}. The chunk has already been saved." },
+ HOOK_COLLECTING_PICKUP = { Notes = "Called when a player is about to collect a pickup." },
+ HOOK_CRAFTING_NO_RECIPE = { Notes = "Called when a player has items in the crafting slots and the server cannot locate any recipe. Plugin may provide a recipe." },
+ HOOK_DISCONNECT = { Notes = "Called after the player has disconnected." },
+ HOOK_EXECUTE_COMMAND = { Notes = "Called when a client sends a chat message that is recognized as a command, before handing that command to the regular command handler. A plugin may stop the command from being handled. This hook is called even when the player doesn't have permissions for the command." },
+ HOOK_EXPLODED = { Notes = "Called after an explosion has been processed in a {{cWorld|world}}." },
+ HOOK_EXPLODING = { Notes = "Called before an explosion is processed in a {{cWorld|world}}. A plugin may alter the explosion parameters or cancel the explosion altogether." },
+ HOOK_HANDSHAKE = { Notes = "Called when a Handshake packet is received from a client." },
+ HOOK_HOPPER_PULLING_ITEM = { Notes = "Called when a hopper is pulling an item from the container above it." },
+ HOOK_HOPPER_PUSHING_ITEM = { Notes = "Called when a hopper is pushing an item into the container it is aimed at." },
+ HOOK_KILLING = { Notes = "Called when an entity has just been killed. A plugin may resurrect the entity by setting its health to above zero." },
+ HOOK_LOGIN = { Notes = "Called when a Login packet is sent to the client, before the client is queued for authentication." },
+ HOOK_MAX = { Notes = "The maximum TypeID of a hook. Used internally by MCS to check hook type for validity." },
+ HOOK_NUM_HOOKS = { Notes = "Total number of hook types MCS supports. Used internally by MCS to check hook type for validity." },
+ HOOK_PLAYER_ANIMATION = { Notes = "Called when a client send the Animation packet." },
+ HOOK_PLAYER_BREAKING_BLOCK = { Notes = "Called when a player is about to break a block. A plugin may cancel the event." },
+ HOOK_PLAYER_BROKEN_BLOCK = { Notes = "Called after a player has broken a block." },
+ HOOK_PLAYER_EATING = { Notes = "Called when the player starts eating a held item. Plugins may abort the eating." },
+ HOOK_PLAYER_JOINED = { Notes = "Called when the player entity has been created. It has not yet been fully initialized." },
+ HOOK_PLAYER_LEFT_CLICK = { Notes = "Called when the client sends the LeftClick packet." },
+ HOOK_PLAYER_MOVING = { Notes = "Called when the player has moved and the movement is now being applied." },
+ HOOK_PLAYER_PLACED_BLOCK = { Notes = "Called when the player has just placed a block" },
+ HOOK_PLAYER_PLACING_BLOCK = { Notes = "Called when the player is about to place a block. A plugin may cancel the event." },
+ HOOK_PLAYER_RIGHT_CLICK = { Notes = "Called when the client sends the RightClick packet." },
+ HOOK_PLAYER_RIGHT_CLICKING_ENTITY = { Notes = "Called when the client sends the UseEntity packet." },
+ HOOK_PLAYER_SHOOTING = { Notes = "Called when the player releases the mouse button to fire their bow." },
+ HOOK_PLAYER_SPAWNED = { Notes = "Called after the player entity has been created. The entity is fully initialized and is spawning in the {{cWorld|world}}." },
+ HOOK_PLAYER_TOSSING_ITEM = { Notes = "Called when the player is tossing the held item (keypress Q)" },
+ HOOK_PLAYER_USED_BLOCK = { Notes = "Called after the player has right-clicked a block" },
+ HOOK_PLAYER_USED_ITEM = { Notes = "Called after the player has right-clicked with a usable item in their hand." },
+ HOOK_PLAYER_USING_BLOCK = { Notes = "Called when the player is about to use (right-click) a block" },
+ HOOK_PLAYER_USING_ITEM = { Notes = "Called when the player is about to right-click with a usable item in their hand." },
+ HOOK_POST_CRAFTING = { Notes = "Called after a valid recipe has been chosen for the current contents of the crafting grid. Plugins may modify the recipe." },
+ HOOK_PRE_CRAFTING = { Notes = "Called before a recipe is searched for the current contents of the crafting grid. Plugins may provide a recipe and cancel the built-in search." },
+ HOOK_SPAWNED_ENTITY = { Notes = "Called after an entity is spawned in a {{cWorld|world}}. The entity is already part of the world." },
+ HOOK_SPAWNED_MONSTER = { Notes = "Called after a mob is spawned in a {{cWorld|world}}. The mob is already part of the world." },
+ HOOK_SPAWNING_ENTITY = { Notes = "Called just before an entity is spawned in a {{cWorld|world}}." },
+ HOOK_SPAWNING_MONSTER = { Notes = "Called just before a mob is spawned in a {{cWorld|world}}." },
+ HOOK_TAKE_DAMAGE = { Notes = "Called when an entity is taking any kind of damage. Plugins may modify the damage value, effects, source or cancel the damage." },
+ HOOK_TICK = { Notes = "Called when the main server thread ticks - 20 times a second." },
+ HOOK_UPDATED_SIGN = { Notes = "Called after a {{cSignEntity|sign}} text has been updated, either by a player or by any external means." },
+ HOOK_UPDATING_SIGN = { Notes = "Called before a {{cSignEntity|sign}} text is updated, either by a player or by any external means." },
+ HOOK_WEATHER_CHANGED = { Notes = "Called after the weather has changed." },
+ HOOK_WEATHER_CHANGING = { Notes = "Called just before the weather changes" },
+ HOOK_WORLD_TICK = { Notes = "Called in each world's tick thread when the game logic is about to tick (20 times a second)." },
},
},
@@ -1191,6 +1602,25 @@ a_Player:OpenWindow(Window);
]],
Functions =
{
+ Get = { Params = "", Return = "Root object", Notes = "This function returns the cRoot object." },
+ BroadcastChat = { Params = "Message", Return = "", Notes = "Broadcasts a message to every player in the server." },
+ FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for the given player." },
+ ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|cPlayer}})</pre>" },
+ ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cWorld|cWorld}})</pre>" },
+ GetCraftingRecipes = { Params = "", Return = "{{cCraftingRecipe|cCraftingRecipe}}", Notes = "Returns the CraftingRecipes object" },
+ GetDefaultWorld = { Params = "", Return = "{{cWorld|cWorld}}", Notes = "Returns the world object from the default world." },
+ GetFurnaceRecipe = { Params = "", Return = "{{cFurnaceRecipe|cFurnaceRecipe}}", Notes = "Returns the cFurnaceRecipes object." },
+ GetGroupManager = { Params = "", Return = "{{cGroupManager|cGroupManager}}", Notes = "Returns the cGroupManager object." },
+ GetPluginManager = { Params = "", Return = "{{cPluginManager|cPluginManager}}", Notes = "Returns the cPluginManager object." },
+ GetPrimaryServerVersion = { Params = "", Return = "number", Notes = "Returns the servers primary server version." },
+ GetProtocolVersionTextFromInt = { Params = "Protocol Version", Return = "string", Notes = "Returns the Minecraft version from the given Protocol. If there is no version found, it returns 'Unknown protocol(Parameter)'" },
+ GetServer = { Params = "", Return = "{{cServer|cServer}}", Notes = "Returns the cServer object." },
+ GetTotalChunkCount = { Params = "", Return = "number", Notes = "Returns the amount of loaded chunks." },
+ GetWebAdmin = { Params = "", Return = "{{cWebAdmin|cWebAdmin}}", Notes = "Returns the cWebAdmin object." },
+ GetWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Returns the cWorld object of the given world. It returns nil if there is no world with the given name." },
+ QueueExecuteConsoleCommand = { Params = "Message", Return = "", Notes = "Queues a console command for execution through the cServer class. The command will be executed in the tick thread The command's output will be sent to console " .. '"stop" and "restart" commands have special handling.' },
+ SaveAllChunks = { Params = "", Return = "", Notes = "Saves all the chunks in all the worlds." },
+ SetPrimaryServerVersion = { Params = "Protocol Version", Return = "", Notes = "Sets the servers PrimaryServerVersion to the given protocol number." }
},
Constants =
{
@@ -1199,10 +1629,15 @@ a_Player:OpenWindow(Window);
cServer =
{
- Desc = [[cServer is typically only used by plugins to broadcast a chat message to all players in the server. Natively however, cServer accepts connections from clients and adds those clients to the game.
+ Desc = [[cServer is typically only used by plugins to broadcast a chat message(Now replaced by the {{cRoot|cRoot}} BroadcastChat function) to all players in the server. Natively however, cServer accepts connections from clients and adds those clients to the game.
]],
Functions =
{
+ GetDescription = { Return = "string", Notes = "Returns the server description set in the settings.ini." },
+ GetMaxPlayers = { Return = "number", Notes = "Returns the max amount of players who can join the server." },
+ SetMaxPlayers = { Params = "number", Notes = "Sets the max amount of players who can join." },
+ GetNumPlayers = { Return = "number", Notes = "Returns the amount of players online." },
+ GetServerID = { Return = "string", Notes = "Returns the ID of the server?" },
},
Constants =
{
@@ -1365,24 +1800,24 @@ Sign entities are saved and loaded from disk when the chunk they reside in is sa
CreateProjectile = { Params = "X, Y, Z, {{cProjectile|ProjectileKind}}, {{cEntity|Creator}}, [{{Vector3d|Speed}}]", Return = "", Notes = "Creates a new projectile of the specified kind at the specified coords. The projectile's creator is set to Creator (may be nil). Optional speed indicates the initial speed for the projectile." },
DigBlock = { Params = "X, Y, Z", Return = "", Notes = "Replaces the specified block with air, without dropping the usual pickups for the block. Wakes up the simulators for the block and its neighbors." },
DoExplosionAt = { Params = "Force, X, Y, Z, CanCauseFire, Source, SourceData", Return = "", Notes = "Creates an explosion of the specified relative force in the specified position. If CanCauseFire is set, the explosion will set blocks on fire, too. The Source parameter specifies the source of the explosion, one of the esXXX constants. The SourceData parameter is specific to each source type, usually it provides more info about the source." },
- DoWithChestAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a chest at the specified coords, calls the CallbackFunction with the {{cChestEntity}} parameter representing the chest. The CallbackFunction has the following signature: <pre>function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The function returns false if there is no chest, or if there is, it returns the bool value that the callback has returned." },
- DoWithDispenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dispenser at the specified coords, calls the CallbackFunction with the {{cDispenserEntity}} parameter representing the dispenser. The CallbackFunction has the following signature: <pre>function Callback({{cDispenserEntity|DispenserEntity}}, [CallbackData])</pre> The function returns false if there is no dispenser, or if there is, it returns the bool value that the callback has returned." },
- DoWithDropSpenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature: <pre>function Callback({{cDropSpenserEntity|DropSpenserEntity}}, [CallbackData])</pre> Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." },
- DoWithDropperAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature: <pre>function Callback({{cDropperEntity|DropperEntity}}, [CallbackData])</pre> The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." },
- DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature: <pre>function Callback({{cEntity|Entity}}, [CallbackData])</pre> The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." },
- DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature: <pre>function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." },
- DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre>function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
+ DoWithChestAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a chest at the specified coords, calls the CallbackFunction with the {{cChestEntity}} parameter representing the chest. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The function returns false if there is no chest, or if there is, it returns the bool value that the callback has returned." },
+ DoWithDispenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dispenser at the specified coords, calls the CallbackFunction with the {{cDispenserEntity}} parameter representing the dispenser. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDispenserEntity|DispenserEntity}}, [CallbackData])</pre> The function returns false if there is no dispenser, or if there is, it returns the bool value that the callback has returned." },
+ DoWithDropSpenserAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper or a dispenser at the specified coords, calls the CallbackFunction with the {{cDropSpenserEntity}} parameter representing the dropper or dispenser. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDropSpenserEntity|DropSpenserEntity}}, [CallbackData])</pre> Note that this can be used to access both dispensers and droppers in a similar way. The function returns false if there is neither dispenser nor dropper, or if there is, it returns the bool value that the callback has returned." },
+ DoWithDropperAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a dropper at the specified coords, calls the CallbackFunction with the {{cDropperEntity}} parameter representing the dropper. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cDropperEntity|DropperEntity}}, [CallbackData])</pre> The function returns false if there is no dropper, or if there is, it returns the bool value that the callback has returned." },
+ DoWithEntityByID = { Params = "EntityID, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If an entity with the specified ID exists, calls the callback with the {{cEntity}} parameter representing the entity. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The function returns false if the entity was not found, and it returns the same bool value that the callback has returned if the entity was found." },
+ DoWithFurnaceAt = { Params = "X, Y, Z, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a furnace at the specified coords, calls the CallbackFunction with the {{cFurnaceEntity}} parameter representing the furnace. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The function returns false if there is no furnace, or if there is, it returns the bool value that the callback has returned." },
+ DoWithPlayer = { Params = "PlayerName, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of the specified name (exact match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." },
FastSetBlock =
{
{ Params = "X, Y, Z, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" },
{ Params = "{{Vector3i|BlockCoords}}, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" },
},
- FindAndDoWithPlayer = { Params = "PlayerNameHint, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of a name similar to the specified name (weighted-match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre>function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found. Note that the name matching is very loose, so it is a good idea to check the player name in the callback function." },
- ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre>function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next chest, or true to abort the enumeration." },
- ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre>function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
- ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre>function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
- ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre>function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." },
- ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre>function Callback({{cPlayer|Player}}, [CallbackData])</pre> The callback should return false or no value to continue with the next player, or true to abort the enumeration." },
+ FindAndDoWithPlayer = { Params = "PlayerNameHint, CallbackFunction, [CallbackData]", Return = "bool", Notes = "If there is a player of a name similar to the specified name (weighted-match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The function returns false if the player was not found, or whatever bool value the callback returned if the player was found. Note that the name matching is very loose, so it is a good idea to check the player name in the callback function." },
+ ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cChestEntity|ChestEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next chest, or true to abort the enumeration." },
+ ForEachEntity = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
+ ForEachEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each entity in the specified chunk. Returns true if all the entities have been processed (including when there are zero entities), or false if the chunk is not loaded or the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cEntity|Entity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next entity, or true to abort the enumeration." },
+ ForEachFurnaceInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each furnace in the chunk. Returns true if all furnaces in the chunk have been processed (including when there are zero furnaces), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cFurnaceEntity|FurnaceEntity}}, [CallbackData])</pre> The callback should return false or no value to continue with the next furnace, or true to abort the enumeration." },
+ ForEachPlayer = { Params = "CallbackFunction, [CallbackData]", Return = "bool", Notes = "Calls the specified callback for each player in the loaded world. Returns true if all the players have been processed (including when there are zero players), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature: <pre class=\"prettyprint lang-lua\">function Callback({{cPlayer|Player}}, [CallbackData])</pre> The callback should return false or no value to continue with the next player, or true to abort the enumeration." },
GenerateChunk = { Params = "ChunkX, ChunkZ", Return = "", Notes = "Queues the specified chunk in the chunk generator. Ignored if the chunk is already generated (use RegenerateChunk() to force chunk re-generation)." },
GetBiomeAt = { Params = "BlockX, BlockZ", Return = "eBiome", Notes = "Returns the biome at the specified coords. Reads the biome from the chunk, if it is loaded, otherwise it uses the chunk generator to provide the biome value." },
GetBlock =
@@ -1418,7 +1853,7 @@ Sign entities are saved and loaded from disk when the chunk they reside in is sa
GetStorageSaveQueueLength = { Params = "", Return = "number", Notes = "Returns the number of chunks queued up for saving" },
GetTicksUntilWeatherChange = { Params = "", Return = "number", Notes = "Returns the number of ticks that will pass before the weather is changed" },
GetTimeOfDay = { Params = "", Return = "number", Notes = "Returns the number of ticks that have passed from the sunrise, 0 .. 24000." },
- GetWeather = { Params = "", Return = "eWeather", Notes = "Returns the current weather in the world (wSunny, wRain, wStorm)." },
+ GetWeather = { Params = "", Return = "eWeather", Notes = "Returns the current weather in the world (wSunny, wRain, wStorm). To check for weather, use IsWeatherXXX() functions instead." },
GetWorldAge = { Params = "", Return = "number", Notes = "Returns the total age of the world, in ticks. The age always grows, cannot be set by plugins and is unrelated to TimeOfDay." },
GrowCactus = { Params = "BlockX, BlockY, BlockZ, NumBlocksToGrow", Return = "", Notes = "Grows a cactus block at the specified coords, by up to the specified number of blocks. Adheres to the world's maximum cactus growth (GetMaxCactusHeight())." },
GrowMelonPumpkin = { Params = "BlockX, BlockY, BlockZ, StemType", Return = "", Notes = "Grows a melon or pumpkin, based on the stem type specified (assumed to be in the coords provided). Checks for normal melon / pumpkin growth conditions - stem not having another produce next to it and suitable ground below." },
@@ -1433,6 +1868,10 @@ Sign entities are saved and loaded from disk when the chunk they reside in is sa
IsGameModeCreative = { Params = "", Return = "bool", Notes = "Returns true if the current gamemode is gmCreative." },
IsGameModeSurvival = { Params = "", Return = "bool", Notes = "Returns true if the current gamemode is gmSurvival." },
IsPVPEnabled = { Params = "", Return = "bool", Notes = "Returns whether PVP is enabled in the world settings." },
+ IsWeatherRain = { Params = "", Return = "bool", Notes = "Returns true if the current weather is rain." },
+ IsWeatherStorm = { Params = "", Return = "bool", Notes = "Returns true if the current weather is a storm." },
+ IsWeatherSunny = { Params = "", Return = "bool", Notes = "Returns true if the current weather is sunny." },
+ IsWeatherWet = { Params = "", Return = "bool", Notes = "Returns true if the current weather has any precipitation (rain or storm)." },
QueueBlockForTick = { Params = "BlockX, BlockY, BlockZ, TicksToWait", Return = "", Notes = "Queues the specified block to be ticked after the specified number of gameticks." },
QueueSaveAllChunks = { Params = "", Return = "", Notes = "Queues all chunks to be saved in the world storage thread" },
QueueSetBlock = { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta, TickDelay", Return = "", Notes = "Queues the block to be set to the specified blocktype and meta after the specified amount of game ticks. Uses SetBlock() for the actual setting, so simulators are woken up and block entities are handled correctly." },
@@ -1485,7 +1924,7 @@ Sign entities are saved and loaded from disk when the chunk they reside in is sa
The following code examples show how to use the callbacks</p>
<p>
This code teleports player Player to another player named ToName in the same world:
-<pre>
+<pre class="prettyprint lang-lua">
-- Player is a cPlayer object
-- ToName is a string
-- World is a cWorld object
@@ -1498,7 +1937,7 @@ World:ForEachPlayer(
</pre></p>
<p>
This code fills each furnace in the chunk with 64 coals:
-<pre>
+<pre class="prettyprint lang-lua">
-- Player is a cPlayer object
-- World is a cWorld object
World:ForEachFurnaceInChunk(Player:GetChunkX(), Player:GetChunkZ(),
@@ -1509,7 +1948,7 @@ World:ForEachFurnaceInChunk(Player:GetChunkX(), Player:GetChunkZ(),
</pre></p>
<p>
This code teleports all spiders up by 100 blocks:
-<pre>
+<pre class="prettyprint lang-lua">
-- World is a cWorld object
World:ForEachEntity(
function (a_Entity)
@@ -1576,9 +2015,142 @@ World:ForEachEntity(
{
},
},
+ Globals =
+ {
+ Desc = [[These functions are available directly, without a class instance. Any plugin cal call them at any time.]],
+ Functions =
+ {
+ AddFaceDirection = {Params = "BlockX, BlockY, BlockZ, BlockFace, Inverse", Return = "BlockX, BlockY, BlockZ", Notes = "Returns the coords of a block adjacent to the specified block through the specified face"},
+ BlockStringToType = {Params = "BlockTypeString", Return = "BLOCKTYPE", Notes = "Returns the block type parsed from the given string"},
+ ClickActionToString = {Params = "ClickAction", Return = "string", Notes = "Returns a string description of the ClickAction enumerated value"},
+ DamageTypeToString = {Params = "{{TakeDamageInfo|eDamageType}}", Return = "string", Notes = "Converts a damage type enumerated value to a string representation "},
+ EscapeString = {Params = "string", Return = "string", Notes = "Returns a copy of the string with all quotes and backslashes escaped by a backslash"},
+ GetChar = {Params = "String, Pos", Return = "string", Notes = "Returns one character from the string, specified by position "},
+ GetTime = {Return = "number", Notes = "Returns the current OS time, as a unix time stamp (number of seconds since Jan 1, 1970)"},
+ IsValidBlock = {Params = "BlockType", Return = "bool", Notes = "Returns true if BlockType is a known block type"},
+ IsValidItem = {Params = "ItemType", Return = "bool", Notes = "Returns true if ItemType is a known item type"},
+ ItemToFullString = {Params = "{{cItem|cItem}}", Return = "string", Notes = "Returns the string representation of the item, in the format “ItemTypeText:ItemDamage * Count”"},
+ ItemToString = {Params = "{{cItem|cItem}}", Return = "string", Notes = "Returns the string representation of the item type"},
+ ItemTypeToString = {Params = "ItemType", Return = "string", Notes = "Returns the string representation of ItemType "},
+ LOG = {Params = "string", Notes = "Logs a text into the server console using “normal” severity (gray text) "},
+ LOGERROR = {Params = "string", Notes = "Logs a text into the server console using “error” severity (black text on red background)"},
+ LOGINFO = {Params = "string", Notes = "Logs a text into the server console using “info” severity (yellow text)"},
+ LOGWARN = {Params = "string", Notes = "Logs a text into the server console using “warning” severity (red text); OBSOLETE"},
+ LOGWARNING = {Params = "string", Notes = "Logs a text into the server console using “warning” severity (red text)"},
+ NoCaseCompare = {Params = "string, string", Return = "number", Notes = "Case-insensitive string comparison; returns 0 if the strings are the same"},
+ ReplaceString = {Params = "full-string, to-be-replaced-string, to-replace-string", Notes = "Replaces *each* occurence of to-be-replaced-string in full-string with to-replace-string"},
+ StringSplit = {Params = "string, Seperator", Return = "list", Notes = "Seperates string into multiple by splitting every time Seperator is encountered."},
+ StringToBiome = {Params = "string", Return = "EMCSBiome", Notes = "Converts a string representation to a biome enumerated value"},
+ StringToDamageType = {Params = "string", Return = "{{TakeDamageInfo|eDamageType}}", Notes = "Converts a string representation to an {{TakeDamageInfo|eDamageType}} enumerated value "},
+ StringToDimension = {Params = "string", Return = "eDimension", Notes = "Converts a string representation to an eDimension enumerated value"},
+ StringToItem = {Params = "string, {{cItem|cItem}}", Return = "bool", Notes = "Parses the given string and sets the item; returns true if successful"},
+ StringToMobType = {Params = "string", Return = "number", Notes = "Converts a string representation to a mob enumerated value"},
+ StripColorCodes = {Params = "string", Return = "string", Notes = "Removes all control codes used by MC for colors and styles"},
+ TrimString = {Params = "string", Return = "string", Notes = "Trime whitespace at both ends of the string"},
+ md5 = {Params = "string", Return = "string", Notes = "converts a string to an md5 hash"},
+ },
+ Constants =
+ {
+ },
+ },
},
+ Hooks =
+ {
+ HOOK_BLOCK_TO_PICKUPS =
+ {
+ CalledWhen = "A block is about to be dug ({{cPlayer|player}}, {{cEntity|entity}} or natural reason), plugins may override what pickups that will produce.",
+ DefaultFnName = "OnBlockToPickups", -- also used as pagename
+ Desc = [[
+ This callback gets called whenever a block is about to be dug. This includes {{cPlayer|players}}
+ digging blocks, entities causing blocks to disappear ({{cTNTEntity|TNT}}, Endermen) and natural
+ causes (water washing away a block). Plugins may override the amount and kinds of pickups this
+ action produces.
+ ]],
+ Params =
+ {
+ { Name = "World", Type = "{{cWorld}}", Notes = "The world in which the block resides" },
+ { Name = "Digger", Type = "{{cEntity}} descendant", Notes = "The entitycausing the digging. May be a {{cPlayer}}, {{cTNTEntity}} or even nil (natural causes)" },
+ { Name = "BlockX", Type = "number", Notes = "X-coord of the block" },
+ { Name = "BlockY", Type = "number", Notes = "Y-coord of the block" },
+ { Name = "BlockZ", Type = "number", Notes = "Z-coord of the block" },
+ { Name = "BlockType", Type = "BLOCKTYPE", Notes = "Block type of the block" },
+ { Name = "BlockMeta", Type = "NIBBLETYPE", Notes = "Block meta of the block" },
+ { Name = "Pickups", Type = "{{cItems}}", Notes = "Items that will be spawned as pickups" },
+ },
+ Returns = [[
+ If the function returns false or no value, the next callback in the hook chain will be called. If
+ the function returns true, no other callbacks in the chain will be called.</p>
+ <p>
+ Either way, the server will then spawn pickups specified in the Pickups parameter, so to disable
+ pickups, you need to Clear the object first, then return true.
+ ]],
+ CodeExamples =
+ {
+ {
+ Title = "Modify pickups",
+ Desc = "This example callback function makes tall grass drop diamonds when digged by natural causes (washed away by water).",
+ Code = [[
+function OnBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups)
+ if (a_Digger ~= nil) then
+ -- Not a natural cause
+ return false;
+ end
+ if (a_BlockType ~= E_BLOCK_TALL_GRASS) then
+ -- Not a tall grass being washed away
+ return false;
+ end
+
+ -- Remove all pickups suggested by MCServer:
+ a_Pickups:Clear();
+
+ -- Drop a diamond:
+ a_Pickups:Add(cItem(E_ITEM_DIAMOND));
+ return true;
+end;
+ ]],
+ },
+ } , -- CodeExamples
+ }, -- HOOK_BLOCK_TO_PICKUPS
+
+ HOOK_CHAT =
+ {
+ CalledWhen = "Player sends a chat message",
+ DefaultFnName = "OnChat", -- also used as pagename
+ Desc = [[
+ A plugin may implement an OnChat() function and register it as a Hook to process chat messages from
+ the players. The function is then called for every in-game message sent from any player. Note that
+ commands are handled separately using a command framework API.
+ ]],
+ Params = {
+ { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who sent the message" },
+ { Name = "Message", Type = "string", Notes = "The message" },
+ },
+ Returns = [[
+ The plugin may return 2 values. The first is a boolean specifying whether the hook handling is to be
+ stopped or not. If it is false, the message is broadcast to all players in the world. If it is true,
+ no message is broadcast and no further action is taken.</p>
+ <p>
+ The second value is specifies the message to broadcast. This way, plugins may modify the message. If
+ the second value is not provided, the original message is used.
+ ]],
+ }, -- HOOK_CHAT
+ }, -- Hooks[]
+
+
+ IgnoreClasses =
+ {
+ "coroutine",
+ "debug",
+ "io",
+ "math",
+ "package",
+ "os",
+ "string",
+ "table",
+ },
+
IgnoreFunctions =
{
"Globals.assert",
@@ -1591,13 +2163,22 @@ World:ForEachEntity(
"%a+.delete", -- AnyClass.delete
-- Functions global in the APIDump plugin:
- "Initialize",
- "DumpAPITxt",
"CreateAPITables",
"DumpAPIHtml",
+ "DumpAPITxt",
+ "Initialize",
+ "LinkifyString",
"ReadDescriptions",
+ "ReadHooks",
"WriteHtmlClass",
+ "WriteHtmlHook",
},
+
+ ExtraPages =
+ {
+ -- No sorting is provided for these, they will be output in the same order as defined here
+ { FileName = "WebWorldThreads.html", Title = "Webserver vs World threads" },
+ }
} ;
diff --git a/MCServer/Plugins/APIDump/WebWorldThreads.html b/MCServer/Plugins/APIDump/WebWorldThreads.html
new file mode 100644
index 000000000..a77209b0b
--- /dev/null
+++ b/MCServer/Plugins/APIDump/WebWorldThreads.html
@@ -0,0 +1,64 @@
+<html>
+<head>
+<title>MCServer - Webserver vs World threads</title>
+<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
+<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/lang-lua.js"></script>
+</head>
+<body>
+
+<h1>Webserver vs World threads</h1>
+<p>
+This article will explain the threading issues that arise between the webserver and world threads are of concern to plugin authors.</p>
+<p>
+Generally, plugins that provide webadmin pages should be quite careful about their interactions. Most operations on MCServer objects requires synchronization, that MCServer provides automatically and transparently to plugins - when a block is written, the chunkmap is locked, or when an entity is being manipulated, the entity list is locked. Each plugin also has a mutex lock, so that only one thread at a time may be executing plugin code.</p>
+<p>
+This locking can be a source of deadlocks for plugins that are not written carefully.</p>
+
+<h2>Example scenario</h2>
+<p>Consider the following example. A plugin provides a webadmin page that allows the admin to kick players off the server. When the admin presses the "Kick" button, the plugin calls cWorld:DoWithPlayer() with a callback to kick the player. Everything seems to be working fine now.</p>
+<p>
+A new feature is developed in the plugin, now the plugin adds a new in-game command so that the admins can kick players while they're playing the game. The plugin registers a command callback with cPluginManager.AddCommand(). Now there are problems bound to happen.</p>
+<p>
+Suppose that two admins are in, one is using the webadmin and the other is in-game. Both try to kick a player at the same time. The webadmin locks the plugin, so that it can execute the plugin code, but right at this moment the OS switches threads. The world thread locks the world so that it can access the list of in-game commands, receives the in-game command, it tries to lock the plugin. The plugin is already locked, so the world thread is put on hold. After a while, the webadmin thread is woken up again and continues processing. It tries to lock the world so that it can traverse the playerlist, but the lock is already held by the world thread. Now both threads are holding one lock each and trying to grab the other lock, and are therefore deadlocked.</p>
+
+<h2>How to avoid the deadlock</h2>
+<p>
+There are two main ways to avoid such a deadlock. The first approach is using tasks: Everytime you need to execute a task inside a world, instead of executing it, queue it, using <a href="cWorld.html">cWorld</a>:QueueTask(). This handy utility can will call the given function inside the world's TickThread, thus eliminating the deadlock, because now there's only one thread. However, this approach will not let you get data back. You cannot query the player list, or the entities, or anything - because when the task runs, the webadmin page has already been served to the browser.</p>
+<p>
+To accommodate this, you'll need to use the second approach - preparing and caching data in the tick thread, possibly using callbacks. This means that the plugin will have global variables that will store the data, and update those variables when the data changes; then the webserver thread will only read those variables, instead of calling the world functions. For example, if a webpage was to display the list of currently connected players, the plugin should maintain a global variable, g_WorldPlayers, which would be a table of worlds, each item being a list of currently connected players. The webadmin handler would read this variable and create the page from it; the plugin would use HOOK_PLAYER_JOINED and HOOK_DISCONNECT to update the variable.</p>
+
+<h2>What to avoid</h2>
+<p>
+Now that we know what the danger is and how to avoid it, how do we know if our code is susceptible?</p>
+<p>
+The general rule of thumb is to avoid calling any functions that read or write lists of things in the webserver thread. This means most ForEach() and DoWith() functions. Only <a href="cRoot.html">cRoot</a>:ForEachWorld() is safe - because the list of worlds is not expected to change, so it is not guarded by a mutex. Getting and setting world's blocks is, naturally, unsafe, as is calling other plugins, or creating entities.</p>
+
+<h2>Example</h2>
+The Core has the facility to kick players using the web interface. It used the following code for the kicking (inside the webadmin handler):
+<pre class="prettyprint lang-lua">
+local KickPlayerName = Request.Params["players-kick"]
+local FoundPlayerCallback = function(Player)
+ if (Player:GetName() == KickPlayerName) then
+ Player:GetClientHandle():Kick("You were kicked from the game!")
+ end
+end
+cRoot:Get():FindAndDoWithPlayer(KickPlayerName, FoundPlayerCallback)
+</pre>
+The cRoot:FindAndDoWithPlayer() is unsafe and could have caused a deadlock. The new solution is queue a task; but since we don't know in which world the player is, we need to queue the task to all worlds:
+<pre class="prettyprint lang-lua">
+cRoot:Get():ForEachWorld( -- For each world...
+ function(World)
+ World:QueueTask( -- ... queue a task...
+ function(a_World)
+ a_World:DoWithPlayer(KickPlayerName, -- ... to walk the playerlist...
+ function (a_Player)
+ a_Player:GetClientHandle():Kick("You were kicked from the game!") -- ... and kick the player
+ end
+ )
+ end
+ )
+ end
+)
+</pre>
+</body>
+</html> \ No newline at end of file
diff --git a/MCServer/Plugins/APIDump/main.css b/MCServer/Plugins/APIDump/main.css
index f9cdfc3ce..777f6d71a 100644
--- a/MCServer/Plugins/APIDump/main.css
+++ b/MCServer/Plugins/APIDump/main.css
@@ -21,3 +21,8 @@ td, th
border: 1px solid #ccc;
}
+pre
+{
+ border: 1px solid #ccc;
+ background-color: #eee;
+} \ No newline at end of file
diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua
index 73acd3e69..3827668e3 100644
--- a/MCServer/Plugins/APIDump/main.lua
+++ b/MCServer/Plugins/APIDump/main.lua
@@ -9,6 +9,7 @@
-- Global variables:
g_Plugin = nil;
+g_PluginFolder = "";
@@ -22,6 +23,8 @@ function Initialize(Plugin)
Plugin:SetVersion(1);
LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
+
+ g_PluginFolder = Plugin:GetLocalFolder();
-- dump all available API functions and objects:
-- DumpAPITxt();
@@ -36,7 +39,6 @@ end
-
function DumpAPITxt()
LOG("Dumping all available functions to API.txt...");
function dump (prefix, a, Output)
@@ -162,6 +164,8 @@ function DumpAPIHtml()
LOG("Dumping all available functions and constants to API subfolder...");
local API, Globals = CreateAPITables();
+ local Hooks = {};
+ local UndocumentedHooks = {};
-- Sort the classes by name:
table.sort(API,
@@ -174,26 +178,44 @@ function DumpAPIHtml()
Globals.Name = "Globals";
table.insert(API, Globals);
+ -- Extract hook constants:
+ for name, obj in pairs(cPluginManager) do
+ if (type(obj) == "number") and (name:match("HOOK_.*")) then
+ table.insert(Hooks, { Name = name });
+ end
+ end
+ table.sort(Hooks,
+ function(Hook1, Hook2)
+ return (Hook1.Name < Hook2.Name);
+ end
+ );
+
-- Read in the descriptions:
ReadDescriptions(API);
+ ReadHooks(Hooks);
+ -- Create the output folder
+ if not(cFile:IsFolder("API")) then
+ cFile:CreateFolder("API");
+ end
+
-- Create a "class index" file, write each class as a link to that file,
-- then dump class contents into class-specific file
local f = io.open("API/index.html", "w");
if (f == nil) then
- -- Create the output folder
- os.execute("mkdir API");
- local err;
- f, err = io.open("API/index.html", "w");
- if (f == nil) then
- LOGINFO("Cannot output HTML API: " .. err);
- return;
- end
+ LOGINFO("Cannot output HTML API: " .. err);
+ return;
end
- f:write([[<html><head><title>MCServer API - class index</title>
+ f:write([[<html><head><title>MCServer API - index</title>
<link rel="stylesheet" type="text/css" href="main.css" />
- </head><body><h1>MCServer API - class index</h1>
+ </head><body><h1>MCServer API - index</h1>
+ <p>The API reference is divided into the following sections:<ul>
+ <li><a href="#classes">Class index</a></li>
+ <li><a href="#hooks">Hooks</a></li>
+ <li><a href="#extra">Extra pages</a></li>
+ </ul></p>
+ <a name="classes"><h2>Class index</h2></a>
<p>The following classes are available in the MCServer Lua scripting language:
<ul>
]]);
@@ -201,7 +223,48 @@ function DumpAPIHtml()
f:write("<li><a href=\"" .. cls.Name .. ".html\">" .. cls.Name .. "</a></li>\n");
WriteHtmlClass(cls, API);
end
- f:write("</ul></p></body></html>");
+ f:write([[</ul></p>
+ <a name="hooks"><h2>Hooks</h2></a>
+ <p>A plugin can register to be called whenever an “interesting event” occurs. It does so by calling
+ <a href="cPluginManager.html">cPluginManager</a>'s AddHook() function and implementing a callback
+ function to handle the event.</p>
+ <p>A plugin can decide whether it will let the event pass through to the rest of the plugins, or hide it
+ from them. This is determined by the return value from the hook callback function. If the function returns
+ false or no value, the event is propagated further. If the function returns true, the processing is
+ stopped, no other plugin receives the notification (and possibly MCServer disables the default behavior
+ for the event). See each hook's details to see the exact behavior.</p>
+ <table><tr><th>Hook name</th><th>Called when</th></tr>
+ ]]);
+ for i, hook in ipairs(Hooks) do
+ if (hook.DefaultFnName == nil) then
+ -- The hook is not documented yet
+ f:write("<tr><td>" .. hook.Name .. "</td><td><i>(No documentation yet)</i></td></tr>\n");
+ table.insert(UndocumentedHooks, hook.Name);
+ else
+ f:write("<tr><td><a href=\"" .. hook.DefaultFnName .. ".html\">" .. hook.Name .. "</a></td><td>" .. LinkifyString(hook.CalledWhen) .. "</td></tr>\n");
+ WriteHtmlHook(hook);
+ end
+ end
+ f:write([[</table>
+ <a name="extra"><h2>Extra pages</h2></a>
+ <p>The following pages provide various extra information</p>
+ <ul>]]);
+ for i, extra in ipairs(g_APIDesc.ExtraPages) do
+ local SrcFileName = g_PluginFolder .. "/" .. extra.FileName;
+ if (cFile:Exists(SrcFileName)) then
+ local DstFileName = "API/" .. extra.FileName;
+ if (cFile:Exists(DstFileName)) then
+ cFile:Delete(DstFileName);
+ end
+ cFile:Copy(SrcFileName, DstFileName);
+ f:write("<li><a href=\"" .. extra.FileName .. "\">" .. extra.Title .. "</a></li>\n");
+ else
+ f:write("<li>" .. extra.Title .. " <i>(file is missing)</i></li>\n");
+ end
+ end
+ f:write([[</ul>
+ </body></html>
+ ]]);
f:close();
-- Copy the CSS file to the output folder (overwrite any existing):
@@ -253,6 +316,24 @@ function DumpAPIHtml()
f:write("\t\t},\n\n");
end
end -- for i, cls - API[]
+ f:write("\t},\n");
+
+ if (#UndocumentedHooks > 0) then
+ f:write("\n\tHooks =\n\t{\n");
+ for i, hook in ipairs(UndocumentedHooks) do
+ if (i > 1) then
+ f:write("\n");
+ end
+ f:write("\t\t" .. hook .. " =\n\t\t{\n");
+ f:write("\t\t\tCalledWhen = \"\",\n");
+ f:write("\t\t\tDefaultFnName = \"On\", -- also used as pagename\n");
+ f:write("\t\t\tDesc = [[]],\n");
+ f:write("\t\t\tParams =\n\t\t\t{\n");
+ f:write("\t\t\t\t{ Name = \"\", Type = \"\", Notes = \"\" },\n\t\t\t},\n");
+ f:write("\t\t\tReturns = [[]],\n");
+ f:write("\t\t}, -- " .. hook .. "\n");
+ end
+ end
f:close();
end
@@ -291,6 +372,19 @@ end
function ReadDescriptions(a_API)
+ -- Returns true if the class of the specified name is to be ignored
+ local function IsClassIgnored(a_ClsName)
+ if (g_APIDesc.IgnoreClasses == nil) then
+ return false;
+ end
+ for i, name in ipairs(g_APIDesc.IgnoreClasses) do
+ if (a_ClsName:match(name)) then
+ return true;
+ end
+ end
+ return false;
+ end
+
-- Returns true if the function (specified by its fully qualified name) is to be ignored
local function IsFunctionIgnored(a_FnName)
if (g_APIDesc.IgnoreFunctions == nil) then
@@ -317,6 +411,18 @@ function ReadDescriptions(a_API)
return false;
end
+ -- Remove ignored classes from a_API:
+ local APICopy = {};
+ for i, cls in ipairs(a_API) do
+ if not(IsClassIgnored(cls.Name)) then
+ table.insert(APICopy, cls);
+ end
+ end
+ for i = 1, #a_API do
+ a_API[i] = APICopy[i];
+ end;
+
+ -- Process the documentation for each class:
for i, cls in ipairs(a_API) do
-- Rename special functions:
for j, fn in ipairs(cls.Functions) do
@@ -335,6 +441,9 @@ function ReadDescriptions(a_API)
elseif (fn.Name == ".sub") then
fn.DocID = "operator_sub";
fn.Name = "<i>operator -</i>";
+ elseif (fn.Name == ".eq") then
+ fn.DocID = "operator_eq";
+ fn.Name = "<i>operator ==</i>";
end
end
@@ -470,19 +579,46 @@ end
+function ReadHooks(a_Hooks)
+ --[[
+ a_Hooks = {
+ { Name = "HOOK_1"},
+ { Name = "HOOK_2"},
+ ...
+ };
+ We want to add hook descriptions to each hook in this array
+ --]]
+ for i, hook in ipairs(a_Hooks) do
+ local HookDesc = g_APIDesc.Hooks[hook.Name];
+ if (HookDesc ~= nil) then
+ for key, val in pairs(HookDesc) do
+ hook[key] = val;
+ end
+ end
+ end -- for i, hook - a_Hooks[]
+end
+
+
+
+
+
+-- Make a link out of anything with the special linkifying syntax {{link|title}}
+function LinkifyString(a_String)
+ local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", "<a href=\"%1.html\">%2</a>") -- {{link|title}}
+ txt = txt:gsub("{{([^|}]*)}}", "<a href=\"%1.html\">%1</a>") -- {{LinkAndTitle}}
+ return txt;
+end
+
+
+
+
+
function WriteHtmlClass(a_ClassAPI, a_AllAPI)
local cf, err = io.open("API/" .. a_ClassAPI.Name .. ".html", "w");
if (cf == nil) then
return;
end
- -- Make a link out of anything with the special linkifying syntax {{link|title}}
- local function LinkifyString(a_String)
- local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", "<a href=\"%1.html\">%2</a>") -- {{link|title}}
- txt = txt:gsub("{{([^|}]*)}}", "<a href=\"%1.html\">%1</a>") -- {{LinkAndTitle}}
- return txt;
- end
-
-- Writes a table containing all functions in the specified list, with an optional "inherited from" header when a_InheritedName is valid
local function WriteFunctions(a_Functions, a_InheritedName)
if (#a_Functions == 0) then
@@ -523,8 +659,10 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
CurrInheritance = CurrInheritance.Inherits;
end
- cf:write([[<html><head><title>MCServer API - ]] .. a_ClassAPI.Name .. [[</title>
+ cf:write([[<html><head><title>MCServer API - ]] .. a_ClassAPI.Name .. [[ class</title>
<link rel="stylesheet" type="text/css" href="main.css" />
+ <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
+ <script src="http://google-code-prettify.googlecode.com/svn/trunk/src/lang-lua.js"></script>
</head><body>
<h1>Contents</h1>
<ul>
@@ -591,7 +729,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
if (a_ClassAPI.AdditionalInfo ~= nil) then
for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do
cf:write("<a name=\"additionalinfo_" .. i .. "\"><h1>" .. additional.Header .. "</h1></a>\n");
- cf:write(additional.Contents);
+ cf:write(LinkifyString(additional.Contents));
end
end
@@ -603,3 +741,54 @@ end
+function WriteHtmlHook(a_Hook)
+ local fnam = "API/" .. a_Hook.DefaultFnName .. ".html";
+ local f, error = io.open(fnam, "w");
+ if (f == nil) then
+ LOG("Cannot write \"" .. fnam .. "\": \"" .. error .. "\".");
+ return;
+ end
+ f:write([[<html><head><title>MCServer API - ]] .. a_Hook.DefaultFnName .. [[ hook</title>
+ <link rel="stylesheet" type="text/css" href="main.css" />
+ <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
+ <script src="http://google-code-prettify.googlecode.com/svn/trunk/src/lang-lua.js"></script>
+ </head><body>
+ <h1>]] .. a_Hook.Name .. [[ hook</h1>
+ <p>
+ ]]);
+ f:write(LinkifyString(a_Hook.Desc));
+ f:write("</p><h1>Callback function</h1><p>The default name for the callback function is ");
+ f:write(a_Hook.DefaultFnName .. ". It has the following signature:");
+ f:write("<pre class=\"prettyprint lang-lua\">function " .. a_Hook.DefaultFnName .. "(");
+ if (a_Hook.Params == nil) then
+ a_Hook.Params = {};
+ end
+ for i, param in ipairs(a_Hook.Params) do
+ if (i > 1) then
+ f:write(", ");
+ end
+ f:write(param.Name);
+ end
+ f:write(")</pre><p>Parameters:\n<table><tr><th>Name</th><th>Type</th><th>Notes</th></tr>\n");
+ for i, param in ipairs(a_Hook.Params) do
+ f:write("<tr><td>" .. param.Name .. "</td><td>" .. LinkifyString(param.Type) .. "</td><td>" .. LinkifyString(param.Notes) .. "</td></tr>\n");
+ end
+ f:write("</table></p>\n<p>" .. (a_Hook.Returns or "") .. "</p>\n");
+ f:write([[<h1>Code examples</h1>
+ <h2>Registering the callback</h2>
+<pre class=\"prettyprint lang-lua\">
+cPluginManager.AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);
+</pre>
+ ]]);
+ local Examples = a_Hook.CodeExamples or {};
+ for i, example in ipairs(Examples) do
+ f:write("<h2>" .. example.Title .. "</h2>\n");
+ f:write("<p>" .. example.Desc .. "</p>\n");
+ f:write("<pre class=\"prettyprint lang-lua\">" .. example.Code .. "</pre>\n");
+ end
+ f:close();
+end
+
+
+
+
diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core
-Subproject e3a45f34303331be77aceacf2ba53e503ad7284
+Subproject 839fb9582b74ef55e596b4e71ddb5663e3ed7c7
diff --git a/MCServer/Plugins/MagicCarpet/coremessaging.lua b/MCServer/Plugins/MagicCarpet/coremessaging.lua
new file mode 100644
index 000000000..9fb2c0db1
--- /dev/null
+++ b/MCServer/Plugins/MagicCarpet/coremessaging.lua
@@ -0,0 +1,19 @@
+Core = cPluginManager:Get():GetPlugin("Core")
+
+function SendMessage(a_Player, a_Message)
+ if (Core ~= nil) then
+ Core:Call("SendMessage", a_Player, a_Message)
+ end
+end
+
+function SendMessageSuccess(a_Player, a_Message)
+ if (Core ~= nil) then
+ Core:Call("SendMessageSuccess", a_Player, a_Message)
+ end
+end
+
+function SendMessageFailure(a_Player, a_Message)
+ if (Core ~= nil) then
+ Core:Call("SendMessageFailure", a_Player, a_Message)
+ end
+end
diff --git a/MCServer/Plugins/MagicCarpet/plugin.lua b/MCServer/Plugins/MagicCarpet/plugin.lua
index 27dcdf45d..81eb02a9c 100644
--- a/MCServer/Plugins/MagicCarpet/plugin.lua
+++ b/MCServer/Plugins/MagicCarpet/plugin.lua
@@ -1,18 +1,16 @@
-local PLUGIN = {}
local Carpets = {}
function Initialize( Plugin )
- PLUGIN = Plugin
-
Plugin:SetName( "MagicCarpet" )
- Plugin:SetVersion( 1 )
+ Plugin:SetVersion( 2 )
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving)
cPluginManager.AddHook(cPluginManager.HOOK_DISCONNECT, OnDisconnect)
+ local PluginManager = cPluginManager:Get()
PluginManager:BindCommand("/mc", "magiccarpet", HandleCarpetCommand, " - Spawns a magical carpet");
- LOG( "Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
+ LOG( "Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion() )
return true
end
@@ -33,14 +31,15 @@ end
function HandleCarpetCommand( Split, Player )
Carpet = Carpets[ Player ]
+
if( Carpet == nil ) then
Carpets[ Player ] = cCarpet:new()
- Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "You're on a magic carpet!" )
- Player:SendMessage(cChatColor.Yellow .. "[INFO] " .. cChatColor.White .. "Look straight down to descend. Jump to ascend!" )
+ SendMessageSuccess(Player, "You're on a magic carpet!")
+ SendMessage(Player, "Look straight down to descend. Jump to ascend.")
else
Carpet:remove()
Carpets[ Player ] = nil
- Player:SendMessage(cChatColor.Green .. "[INFO] " .. cChatColor.White .. "The carpet vanished!" )
+ SendMessageSuccess(Player, "The carpet vanished!")
end
return true
diff --git a/MCServer/Plugins/ProtectionAreas b/MCServer/Plugins/ProtectionAreas
-Subproject 3019c7b396221b987cd3f89d422276f764834ff
+Subproject bef8ff2a883e98db94f842f9db3d256a039b1fc
diff --git a/MCServer/Plugins/TransAPI b/MCServer/Plugins/TransAPI
-Subproject 52e1de4332a026e58fda843aae98c1f51e57199
+Subproject 678696eeedce502199869577b8e03ff72892646