Package xyz.gmitch215.socketmc.screen
Class CustomScreen
java.lang.Object
xyz.gmitch215.socketmc.screen.AbstractScreen
xyz.gmitch215.socketmc.screen.CustomScreen
- All Implemented Interfaces:
Serializable
,Narratable
Represents a custom screen to be displayed on the client's screen.
- See Also:
-
Constructor Summary
ConstructorDescriptionCustomScreen
(@NotNull Text title) Constructs a new screen with the given title. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(@NotNull Positionable child) Adds a child to this screen.void
Removes all children from this screen.getAttribute
(@NotNull String key) Gets an attribute from this screen.<T> T
getAttribute
(@NotNull String key, @NotNull Class<T> type) Gets an attribute from this screen.<T> T
getAttribute
(@NotNull String key, @NotNull Class<T> type, T def) Gets an attribute from this screen.getAttribute
(@NotNull String key, @Nullable Object def) Gets an attribute from this screen.Gets an immutable copy of the attributes of this screen.Gets the background of this screen.Gets an immutable copy of the children in this screen.Gets the layout of this screen.Gets the JSON message that represents the narration of this element.Gets the title of this screen.boolean
Gets whether this screen can be closed with the escape key.void
removeChild
(@NotNull Positionable child) Removes a child from this screen.void
setAttribute
(@NotNull String key, @Nullable Object value) Sets an attribute for this screen.void
setBackground
(@NotNull ScreenBackground background) Sets the background of this screen.void
setCloseableOnEscape
(boolean closeableOnEscape) Sets whether this screen can be closed with the escape key.void
Sets the layout of this screen.void
setNarrationMessage
(@Nullable Text narrationMessage) Sets the narration message of this screen.void
setNarrationMessageJSON
(@Nullable String narrationMessageJSON) Sets the narration message of this screen.void
Sets the title of this screen.void
setTitleJSON
(@NotNull String titleJSON) Sets the title of this screen.toString()
Methods inherited from class xyz.gmitch215.socketmc.screen.AbstractScreen
fromByteArray, toByteArray
-
Constructor Details
-
CustomScreen
Constructs a new screen with the given title.- Parameters:
title
- the title
-
-
Method Details
-
getTitleJSON
Description copied from class:AbstractScreen
Gets the title of this screen.- Specified by:
getTitleJSON
in classAbstractScreen
- Returns:
- Title in JSON Format
-
setTitleJSON
Sets the title of this screen.- Parameters:
titleJSON
- the title in JSON format
-
setTitle
Sets the title of this screen.- Parameters:
title
- the title
-
getNarrationMessageJSON
Description copied from interface:Narratable
Gets the JSON message that represents the narration of this element. By default, this is the title of the element.- Specified by:
getNarrationMessageJSON
in interfaceNarratable
- Overrides:
getNarrationMessageJSON
in classAbstractScreen
- Returns:
- the JSON message
-
setNarrationMessageJSON
Sets the narration message of this screen.- Parameters:
narrationMessageJSON
- the narration message in JSON format
-
setNarrationMessage
Sets the narration message of this screen.- Parameters:
narrationMessage
- the narration message
-
addChild
Adds a child to this screen.- Parameters:
child
- the child element- Throws:
IllegalArgumentException
- if the child is null or if an element already exists at the same position
-
removeChild
Removes a child from this screen.- Parameters:
child
- the child element
-
clearChildren
public void clearChildren()Removes all children from this screen. -
getChildren
Gets an immutable copy of the children in this screen.- Returns:
- List of Screen Elements
-
getBackground
Gets the background of this screen.- Returns:
- Screen Background
-
setBackground
public void setBackground(@NotNull @NotNull ScreenBackground background) throws IllegalArgumentException Sets the background of this screen.- Parameters:
background
- Screen Background- Throws:
IllegalArgumentException
- if the background is null
-
getLayout
Gets the layout of this screen.- Returns:
- Layout
-
setLayout
Sets the layout of this screen. Setting it to null will not remove the elements from the layout.- Parameters:
layout
- Layout
-
isCloseableOnEscape
public boolean isCloseableOnEscape()Gets whether this screen can be closed with the escape key.- Returns:
- true if screen can be closed with escape
-
setCloseableOnEscape
public void setCloseableOnEscape(boolean closeableOnEscape) Sets whether this screen can be closed with the escape key.- Parameters:
closeableOnEscape
- true if screen can be closed with escape
-
getAttributes
Gets an immutable copy of the attributes of this screen.- Returns:
- Map of Attributes
-
getAttribute
@Nullable public @Nullable Object getAttribute(@NotNull @NotNull String key) throws IllegalArgumentException Gets an attribute from this screen.- Parameters:
key
- the key of the attribute- Returns:
- the attribute value, or null if the attribute does not exist
- Throws:
IllegalArgumentException
- if the key is null
-
getAttribute
public Object getAttribute(@NotNull @NotNull String key, @Nullable @Nullable Object def) throws IllegalArgumentException Gets an attribute from this screen.- Parameters:
key
- the key of the attributedef
- the default value if the attribute does not exist- Returns:
- the attribute value, or the default value if the attribute does not exist
- Throws:
IllegalArgumentException
- if the key is null
-
getAttribute
Gets an attribute from this screen.- Type Parameters:
T
- the type of the attribute- Parameters:
key
- the key of the attributetype
- the type of the attribute- Returns:
- the attribute value, or null if the attribute does not exist
-
getAttribute
@Nullable public <T> T getAttribute(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type, @Nullable T def) Gets an attribute from this screen.- Type Parameters:
T
- the type of the attribute- Parameters:
key
- the key of the attributetype
- the type of the attributedef
- the default value if the attribute does not exist- Returns:
- the attribute value, or the default value if the attribute does not exist
-
setAttribute
public void setAttribute(@NotNull @NotNull String key, @Nullable @Nullable Object value) throws IllegalArgumentException Sets an attribute for this screen.- Parameters:
key
- the key of the attributevalue
- the value of the attribute- Throws:
IllegalArgumentException
- if the key is null
-
toString
-