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
- Host: GitHub
- URL: https://github.com/cubbossa/disposables
- Owner: CubBossa
- License: gpl-3.0
- Created: 2024-03-29T07:50:12.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-07T06:32:44.000Z (about 2 years ago)
- Last Synced: 2025-01-26T11:12:05.128Z (over 1 year ago)
- Language: Java
- Size: 65.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.

```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
```