Skip to content

Alontrle/Xilla-Boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XillaBoot

XillaBoot is a lightweight Java framework that makes it easy to store, retrieve, and manage large amounts of data efficiently.

  • Built on Gson for automatic serialisation/deserialisation
  • Supports JSON files (single file or one file per object) and in-memory caching
  • Optional automatic object unloading – keeps memory usage low when enabled
  • Buffered file reader (256 bytes at a time) with file indexing for minimal disk overhead
  • Annotation-driven – no managers to write
  • Thread-safe

Quick Start

1. Annotate your data class:

@JsonFolderManager(folderName = "players/")
public class Player {
    private String uuid;
    private String name;
    
    public String getId() { return uuid; }
}

2. Initialize XillaBoot:

XillaApplication.initialize();
XillaApplication.getInstance().startup();

3. Use the API:

Player player = new Player("123", "Alice");
XillaAPI.setObject(Player.class, player);

Player samePlayer = XillaAPI.getObject(Player.class, "123");

Annotations

Annotation Storage
@CacheManager In-memory only, no persistence
@JsonManager(fileName = "data.json") Single JSON file
@JsonFolderManager(folderName = "data/") One JSON file per object

Object Keys

Every stored object needs a unique identifier. XillaBoot checks for these methods in order:

  1. getId()
  2. getID()
  3. getName()
  4. toString() (last resort)

API Methods

Method Description
getObject(Class, String key) Retrieve an object by key
setObject(Class, T obj) Save or update an object
removeObject(Class, T obj) Delete an object
getObjects(Class) Get all objects of a type
getManager(Class) Get the manager for advanced use
generateSettings(String fileName) Create a new settings file
getSetting(String, String key) Get a setting value
setSetting(String, String key, T value) Set a setting value

Manual Manager Registration (without annotations)

XillaApplication.initialize(false);

Manager<MyClass> manager = new Manager<>(MyClass.class, new JsonFolderLoader("data/"));
XillaApplication.getInstance().registerManager(manager);

XillaApplication.getInstance().startup();

Startup Processes

XillaApplication.getInstance().registerStartupProcess(new StartupProcess("Init", StartupPriority.COMPLETE) {
    @Override
    public void run() {
        // code here
    }
});

Settings Files

XillaAPI.generateSettings("config.json");
XillaAPI.setSetting("config.json", "maxPlayers", 100);
int max = XillaAPI.getSetting("config.json", "maxPlayers");

Working with Managers Directly

Manager<Player> manager = XillaAPI.getManager(Player.class);
for (String key : manager.keySet()) {
    boolean wasLoaded = manager.isLoaded(key);
    if (!wasLoaded) manager.loadSingle(key);
    
    Player p = manager.get(key);
    // do something
    
    if (!wasLoaded) manager.unloadObject(key);
}

Installation

Build from source:

git clone https://github.com/your-repo/XillaBoot.git
cd XillaBoot
mvn install

Add dependency:

Maven:

<dependency>
    <groupId>net.xilla.boot</groupId>
    <artifactId>XillaBoot</artifactId>
    <version>1.0.1-SNAPSHOT</version>
</dependency>

Gradle:

implementation 'net.xilla.boot:XillaBoot:1.0.1-SNAPSHOT'

Optional shading/relocation for plugin environments:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <relocations>
                    <relocation>
                        <pattern>net.xilla.boot</pattern>
                        <shadedPattern>your.package.boot</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </execution>
    </executions>
</plugin>

Example: Spigot Plugin

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        XillaApplication.initialize(false);
        
        SettingsFile config = new SettingsFile("config.yml", 
            new YamlConfigFileLoader(getDataFolder() + "/config.yml"));
        XillaApplication.getInstance().registerManager(config);
        
        XillaApplication.start();
    }
}

Example: Spring Boot Integration

@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
    
    public MyApp() {
        XillaApplication.initialize();
        XillaAPI.generateSettings("settings.json");
        XillaApplication.start();
    }
}

Troubleshooting

"Manager X does not exist or is not registered"

  • Did you call XillaApplication.start()?
  • If reflection is disabled, did you manually register the manager?
  • Check that your class has the correct annotation

Objects are not saving

  • Ensure your class has a valid getId() method
  • Call manager.save() or enable auto-save with manager.setAutoSave(true)

Memory usage is high

  • Enable auto-unloading with manager.setAutoUnload(true)
  • Manually unload objects with manager.unloadObject(key)

If you need additional help, please reach out in our discord! https://discord.gg/AyJhdHYbGw

About

An efficient java data-management framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages