DE
# SagaLib API Simplified Usage Examples
## Core API
// Get API instance
SagaLibAPI sagaLib = SagaLibAPI.getInstance();
## GUI System
### Creating GUI
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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";
}
};Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta