cLuaWindow


Index:
Articles
Classes
Hooks

Quick navigation:
cArrowEntity
cBeaconEntity
cBlockArea
cBlockEntity
cBlockEntityWithItems
cBlockInfo
cBoundingBox
cBrewingstandEntity
cChatColor
cChestEntity
cChunkDesc
cClientHandle
cCommandBlockEntity
cCompositeChat
cCraftingGrid
cCraftingRecipe
cCryptoHash
cCuboid
cDispenserEntity
cDropperEntity
cDropSpenserEntity
cEnchantments
cEntity
cEntityEffect
cExpBottleEntity
cFile
cFireChargeEntity
cFireworkEntity
cFloater
cFlowerPotEntity
cFurnaceEntity
cGhastFireballEntity
cHangingEntity
cHopperEntity
cIniFile
cInventory
cItem
cItemFrame
cItemGrid
cItems
cJson
cJukeboxEntity
cLineBlockTracer
cLuaWindow
cMap
cMapManager
cMobHeadEntity
cMobSpawnerEntity
cMojangAPI
cMonster
cNetwork
cNoteEntity
cObjective
cPainting
cPawn
cPickup
cPlayer
cPlugin
cPluginLua
cPluginManager
cProjectileEntity
cRankManager
cRoot
cScoreboard
cServer
cServerHandle
cSignEntity
cSplashPotionEntity
cStatManager
cStringCompression
cTCPLink
cTeam
cThrownEggEntity
cThrownEnderPearlEntity
cThrownSnowballEntity
cTNTEntity
cTracer
cUDPEndpoint
cUrlClient
cUrlParser
cWebAdmin
cWindow
cWitherSkullEntity
cWorld
HTTPFormData
HTTPRequest
HTTPTemplateRequest
ItemCategory
lxp
sqlite3
TakeDamageInfo
tolua
Vector3d
Vector3f
Vector3i
Globals

Contents


cLuaWindow class

This class is used by plugins wishing to display a custom window to the player, unrelated to block entities or entities near the player. The window can be of any type and have any contents that the plugin defines. Callbacks for when the player modifies the window contents and when the player closes the window can be set.

This class inherits from the cWindow class, so all cWindow's functions and constants can be used, in addition to the cLuaWindow-specific functions listed below.

The contents of this window are represented by a cWindow:GetSlot() etc. or cPlayer:GetInventory() to access the player inventory.

When creating a new cLuaWindow object, you need to specify both the window type and the contents' width and height. Note that Cuberite accepts any combination of these, but opening a window for a player may crash their client if the contents' dimensions don't match the client's expectations.

To open the window for a player, call cPlayer:OpenWindow(). Multiple players can open window of the same cLuaWindow object. All players see the same items in the window's contents (like chest, unlike crafting table).


Inheritance

This class inherits from the following parent classes:


Constants

Constants inherited from cWindow

NameValueNotes
wtAnimalChest 11 A horse or donkey window
wtAnvil 8 An anvil window
wtBeacon 7 A beacon window
wtBrewery 5 A brewing stand window
wtChest 0 A chest or doublechest window
wtDropSpenser 3 A dropper or a dispenser window
wtDropper 10
wtEnchantment 4 An enchantment table window
wtFurnace 2 A furnace window
wtHopper 9 A hopper window
wtInventory -1 An inventory window
wtNPCTrade 6 A villager trade window
wtWorkbench 1 A workbench (crafting table) window

Functions

NameParametersReturn valueNotes
() (constructor) WindowType, ContentsWidth, ContentsHeight, Title Creates a new object of this class
GetContents cItemGrid Returns the cItemGrid object representing the internal storage in this window
SetOnClosing OnClosingCallback Sets the function that the window will call when it is about to be closed by a player
SetOnSlotChanged OnSlotChangedCallback Sets the function that the window will call when a slot is changed by a player

Functions inherited from cWindow

NameParametersReturn valueNotes
GetSlot Player, SlotNumber cItem Returns the item at the specified slot for the specified player. Returns nil and logs to server console on error.
GetWindowID number Returns the ID of the window, as used by the network protocol
GetWindowTitle string Returns the window title that will be displayed to the player
GetWindowType number Returns the type of the window, one of the constants in the table above
GetWindowTypeName string Returns the textual representation of the window's type, such as "minecraft:chest".
IsSlotInPlayerHotbar SlotNum bool Returns true if the specified slot number is in the player hotbar
IsSlotInPlayerInventory SlotNum bool Returns true if the specified slot number is in the player's main inventory or in the hotbar. Note that this returns false for armor slots!
IsSlotInPlayerMainInventory SlotNum bool Returns true if the specified slot number is in the player's main inventory
SetProperty PropertyID, PropartyValue, [Player] Updates a numerical property associated with the window. Typically used for furnace progressbars. Sends the UpdateWindowProperty packet to the specified Player, or to all current clients of the window if Player is not specified.
SetSlot Player, SlotNum, cItem Sets the contents of the specified slot for the specified player. Ignored if the slot number is invalid
SetWindowTitle string Sets the window title that will be displayed to the player

Callbacks

The object calls the following functions at the appropriate time:

OnClosing Callback

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).

function OnWindowClosing(a_Window, a_Player, a_CanRefuse)

The a_Window parameter is the cLuaWindow object representing the window, a_Player is the player for whom the window is about to close. a_CanRefuse specifies whether the callback can refuse the closing. If the callback returns true and a_CanRefuse is true, the window is not closed (internally, the server sends a new OpenWindow packet to the client).

OnSlotChanged Callback

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.

function OnWindowSlotChanged(a_Window, a_SlotNum)

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:DoWithPlayer().

Any returned values are ignored.

Example

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.
-- Callback that refuses to close the window twice, then allows:
local Attempt = 1;
local OnClosing = function(Window, Player, CanRefuse)
	Player:SendMessage("Window closing attempt #" .. Attempt .. "; CanRefuse = " .. tostring(CanRefuse));
	Attempt = Attempt + 1;
	return CanRefuse and (Attempt <= 3);  -- refuse twice, then allow, unless CanRefuse is set to true
end

-- Log the slot changes:
local OnSlotChanged = function(Window, SlotNum)
	LOG("Window \"" .. Window:GetWindowTitle() .. "\" slot " .. SlotNum .. " changed.");
end

-- Set window contents:
-- a_Player is a cPlayer object received from the outside of this code fragment
local Window = cLuaWindow(cWindow.wtHopper, 3, 3, "TestWnd");
Window:SetSlot(a_Player, 0, cItem(E_ITEM_DIAMOND, 64));
Window:SetOnClosing(OnClosing);
Window:SetOnSlotChanged(OnSlotChanged);

-- Open the window:
a_Player:OpenWindow(Window);
Generated on 2016-08-22 23:53:06, Build ID Unknown, Commit approx: 2ed4af74edd14ae17e1c6c64d44caa7b7fc30d5a