# SagaLib API Simplified Usage Examples
## Core API
Code (Java):
// Get API instance
SagaLibAPI sagaLib
= SagaLibAPI.
getInstance
(
)
;
## GUI System
### Creating GUI
Code (Java):
// Create basic GUI
GuiHolder gui
= sagaLib.
createGui
(player,
"Main Menu",
54
)
;
// Create pagination GUI
GuiHolder paginationGui
= sagaLib.
createPaginationGui
(player,
"Pagination Menu",
45
)
;
// Create dynamic size GUI
GuiHolder dynamicGui
= sagaLib.
createDynamicGui
(player,
"Dynamic Menu",
27,
54,
45
)
;
### Button Operations
Code (Java):
// Create button
GuiButton button
=
new SimpleButton
(Material.
DIAMOND,
"Diamond Button"
)
;
button.
setClickHandler
(event
->
{
// Handle click event
}
)
;
// Add button
sagaLib.
addButton
(gui,
0, button
)
;
// Batch add buttons
Map
<
Integer, GuiButton
> buttons
=
new HashMap
<>
(
)
;
buttons.
put
(
0, button1
)
;
buttons.
put
(
1, button2
)
;
sagaLib.
addButtons
(gui, buttons
)
;
### Pagination Operations
Code (Java):
// Get current page number
int currentPage
= sagaLib.
getCurrentPage
(gui
)
;
// Set page number
sagaLib.
setPage
(gui,
0
)
;
// Add navigation buttons
GuiButton prevButton
=
new SimpleButton
(Material.
ARROW,
"Previous Page"
)
;
prevButton.
setClickHandler
(event
->
{
int current
= sagaLib.
getCurrentPage
(gui
)
;
if
(current
>
0
)
{
sagaLib.
setPage
(gui, current
-
1
)
;
}
}
)
;
GuiButton nextButton
=
new SimpleButton
(Material.
ARROW,
"Next Page"
)
;
nextButton.
setClickHandler
(event
->
{
int current
= sagaLib.
getCurrentPage
(gui
)
;
int maxPage
=
(totalItems
-
1
)
/ itemsPerPage
;
if
(current
< maxPage
)
{
sagaLib.
setPage
(gui, current
+
1
)
;
}
}
)
;
### Layout and Style
Code (Java):
// Create layout
GuiLayout layout
= sagaLib.
createCustomLayout
(
6,
9,
1,
1
)
;
sagaLib.
setLayout
(gui, layout
)
;
// Create style
GuiStyle style
= sagaLib.
createDefaultStyle
(
)
;
GuiStyle customStyle
= sagaLib.
createCustomStyle
(
Material.
BLACK_STAINED_GLASS_PANE,
// Border material
Material.
GRAY_STAINED_GLASS_PANE,
// Background material
Material.
WHITE_STAINED_GLASS_PANE
// Button material
)
;
// Apply style
sagaLib.
applyStyle
(gui, style
)
;
### Animation Control
Code (Java):
// Create animation
GuiAnimation animation
=
new FadeAnimation
(
)
;
// Add animation
sagaLib.
addAnimation
(gui, animation
)
;
// Control animation
sagaLib.
startAnimation
(gui, animation
)
;
sagaLib.
stopAnimation
(gui, animation
)
;
// Get animation status
String status
= sagaLib.
getAnimationStatus
(gui, animation
)
;
### Item Operations
Code (Java):
// Add item
sagaLib.
addItem
(gui,
0, item
)
;
// Batch add items
Map
<
Integer, ItemStack
> items
=
new HashMap
<>
(
)
;
items.
put
(
0, item1
)
;
items.
put
(
1, item2
)
;
sagaLib.
addItems
(gui, items
)
;
// Set item lore
List
<String
> lore
=
Arrays.
asList
(
"First line",
"Second line"
)
;
sagaLib.
setItemLore
(item, lore
)
;
## Configuration System
Code (Java):
// Get config manager
ConfigManager config
= sagaLib.
getConfigManager
(
)
;
config.
loadConfig
(
)
;
// Get language manager
LanguageManager lang
= sagaLib.
getLanguageManager
(
)
;
lang.
loadMessages
(
)
;
// Reload configuration
sagaLib.
reloadConfig
(
)
;
// Get message configuration
FileConfiguration messageConfig
= sagaLib.
getMessageConfig
(
)
;
String message
= messageConfig.
getString
(
"message.key"
)
;
// Get debug message configuration
FileConfiguration debugConfig
= sagaLib.
getDebugMessageConfig
(
)
;
## Utility Classes
Code (Java):
// Parse color codes
String colored
= sagaLib.
parseColor
(
"&aGreen text"
)
;
// Parse placeholders
String parsed
= sagaLib.
parsePlaceholders
(player,
"Player name: %player_name%"
)
;
// Check PlaceholderAPI
boolean hasPlaceholderAPI
= sagaLib.
hasPlaceholderAPI
(
)
;
// Register custom placeholder
sagaLib.
registerPlaceholder
(
"custom", player
->
"Custom value"
)
;
// Get other utility classes
ColorUtil colorUtil
= sagaLib.
getColorUtil
(
)
;
TextUtil textUtil
= sagaLib.
getTextUtil
(
)
;
GuiUtil guiUtil
= sagaLib.
getGuiUtil
(
)
;
## Button Update Techniques
Code (Java):
// Create new button to replace existing button
SimpleButton newButton
=
new SimpleButton
(Material.
DIAMOND,
"New Button Name"
)
;
newButton.
setLore
(
Arrays.
asList
(
"&7New description text"
)
)
;
newButton.
setClickHandler
(event
->
{
// New click handler
}
)
;
sagaLib.
addButton
(gui, slot, newButton
)
;
// Button update helper method
private
void updateButton
(GuiHolder gui,
int slot,
boolean state
)
{
SimpleButton button
=
new SimpleButton
(
state
? Material.
EMERALD
: Material.
REDSTONE,
state
?
"Active State"
:
"Disabled State"
)
;
button.
setLore
(
Arrays.
asList
(
"&7Click to "
+
(state
?
"disable"
:
"activate"
)
)
)
;
button.
setClickHandler
(e
->
{
updateButton
(gui, slot,
!state
)
;
}
)
;
sagaLib.
addButton
(gui, slot, button
)
;
}
## Pagination Data Loading
Code (Java):
// Load data for specific page
private
void loadItemsForPage
(GuiHolder gui,
int page,
int itemsPerPage,
int totalItems
)
{
int startIndex
= page
* itemsPerPage
;
int endIndex
=
Math.
min
(startIndex
+ itemsPerPage, totalItems
)
;
for
(
int i
= startIndex
; i
< endIndex
; i
++
)
{
int slotIndex
= i
- startIndex
;
ItemStack item
= createItem
(i
)
;
sagaLib.
addItem
(gui, slotIndex, item
)
;
}
}
## Custom Animation
Code (Java):
// Implement custom animation
public
class CustomAnimation
implements GuiAnimation
{
private
boolean running
=
false
;
@Override
public
void start
(GuiHolder holder
)
{
running
=
true
;
// Animation start logic
}
@Override
public
void stop
(
)
{
running
=
false
;
// Animation stop logic
}
@Override
public
boolean isRunning
(
)
{
return running
;
}
@Override
public
String getName
(
)
{
return
"custom"
;
}
@Override
public
String getDescription
(
)
{
return
"Custom animation effect"
;
}
@Override
public
String getStatus
(
)
{
return running
?
"START"
:
"STOP"
;
}
}
// Or using anonymous inner class
GuiAnimation animation
=
new GuiAnimation
(
)
{
private
boolean running
=
false
;
@Override
public
void start
(GuiHolder holder
)
{
running
=
true
;
// Implement animation logic
}
@Override
public
void stop
(
)
{
running
=
false
;
}
@Override
public
boolean isRunning
(
)
{
return running
;
}
@Override
public
String getName
(
)
{
return
"anonymous"
;
}
@Override
public
String getDescription
(
)
{
return
"Anonymous animation"
;
}
@Override
public
String getStatus
(
)
{
return running
?
"START"
:
"STOP"
;
}
}
;