An open API service indexing awesome lists of open source software.

https://github.com/cubbossa/disposables

A Minecraft library to easily link resources and their lifespans
https://github.com/cubbossa/disposables

Last synced: about 1 month ago
JSON representation

A Minecraft library to easily link resources and their lifespans

Awesome Lists containing this project

README

          

# Disposables

The library allows you to link the lifespan of different objects.
Objects may only exist while another parent object exists, which results in a tree structure of logical dependency.
With this library, you may link the object to its parent and execute code as soon as the parent
gets disposed.

The graphic below illustrates lifetime dependencies and how a crashing plugin
will no longer claim resources beyond its lifetime if combined with this library.

![lifetimes](docs/lifetime_overview.svg)

```Java
public class MyPlugin extends JavaPlugin {
BukkitDisposer disposer;
public void onEnable() {
disposer = BukkitDisposer.disposer(this);

World minigameWorld = createMyPluginWorldForMinigame();
// disable world when plugin shuts down
disposer.register(MyPlugin.this, minigameWorld);

Player player = ...;
ChestMenu menu = createMyLobbyGUI(player);

// close menu when plugin crashes
disposer.register(MyPlugin.this, menu);

// run menu close code when player quits (like save settings)
disposer.register(player, menu);

// unregister inventory listeners when not needed
disposer.register(menu, mySpecificInventoryListener);
disposer.register(player, mySpecificInventoryListener);
}

class ChestMenu implements Disposable {
@Override
public void dispose() {
// save player settings from lobby menu here
}
}
}
```

## Maven

```xml


CubBossa
https://nexus.leonardbausenwein.de/repository/maven-public/


de.cubbossa
disposables-api
1.2


de.cubbossa
disposables-bukkit
1.2

```