cLuaWindow
Index: Articles Classes Hooks Quick navigation: BannerPattern BossBarColor BossBarDivisionType cArrowEntity cBeaconEntity cBedEntity cBlockArea cBlockEntity cBlockEntityWithItems cBlockInfo cBoat cBoundingBox cBrewingstandEntity cChatColor cChestEntity cChunkDesc cClientHandle cColor cCommandBlockEntity cCompositeChat cCraftingGrid cCraftingRecipe cCryptoHash cCuboid cDispenserEntity cDropperEntity cDropSpenserEntity cEnchantments cEnderCrystal cEntity cEntityEffect cExpBottleEntity cExpOrb cFallingBlock cFile cFireChargeEntity cFireworkEntity cFloater cFlowerPotEntity cFurnaceEntity cGhastFireballEntity cHangingEntity cHopperEntity cIniFile cInventory cItem cItemFrame cItemGrid cItems cJson cJukeboxEntity cLeashKnot 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 cStringCompression cTCPLink cTeam cThrownEggEntity cThrownEnderPearlEntity cThrownSnowballEntity cTNTEntity cUDPEndpoint cUrlClient cUrlParser CustomStatistic cUUID cWebAdmin cWindow cWitherSkullEntity cWorld EffectID HTTPFormData HTTPRequest HTTPTemplateRequest ItemCategory lxp SmokeDirection sqlite3 StatisticsManager TakeDamageInfo tolua Vector3d Vector3f Vector3i Globals | Contents
cLuaWindow classThis 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). InheritanceThis class inherits from the following parent classes: Functions
Functions inherited from cWindow
CallbacksThe object calls the following functions at the appropriate time:OnClicked CallbackThis callback, settable via the SetOnClicked() function, will be called when the player clicks a slot in the window. The callback can cancel the click.function OnWindowClicked(a_Window, a_Player, a_SlotNum, a_ClickAction, a_ClickedItem)
The a_Window parameter is the cLuaWindow object representing the window, a_Player is the player who made the click, a_SlotNum is the slot the player clicked, a_ClickAction is the type of click the player made, and a_ClickedItem is the item the player clicked on, if applicable. If the function returns true, the click is cancelled (internally, the server resends the window slots to the player to keep the player in sync).
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).
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.
-- 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 -- Prevent shift-clicking: local OnClicked = function(Window, ClickingPlayer, SlotNum, ClickAction, ClickedItem) if ClickAction == caShiftLeftClick then return true end 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:SetOnClicked(OnClicked); Window:SetOnClosing(OnClosing); Window:SetOnSlotChanged(OnSlotChanged); -- Open the window: a_Player:OpenWindow(Window); |