Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mfnalex/CustomBlockData
Provides a PersistentDataContainer for every Block location
https://github.com/mfnalex/CustomBlockData
bukkit pdc persistentdatacontainer spigot
Last synced: about 2 months ago
JSON representation
Provides a PersistentDataContainer for every Block location
- Host: GitHub
- URL: https://github.com/mfnalex/CustomBlockData
- Owner: mfnalex
- License: gpl-3.0
- Created: 2021-06-24T14:32:39.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T14:35:41.000Z (9 months ago)
- Last Synced: 2024-08-03T17:11:18.531Z (5 months ago)
- Topics: bukkit, pdc, persistentdatacontainer, spigot
- Language: Java
- Homepage:
- Size: 119 KB
- Stars: 105
- Watchers: 2
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-minecraft - CustomBlockData - Provides a PersistentDataContainer for every Block locatio (NBT & PDC)
README
# CustomBlockData
CustomBlockData is a library for the Bukkit API that allows you to store ANY information inside blocks.
It does so by providing the `CustomBlockData` class which implements the `PersistentDataContainer` interface.It does not need any files or databases by saving the information inside the chunk's PersistentDataContainer, and the information is persistent even after server restarts.
CustomBlockData is compatible with all Bukkit versions from 1.16.3 onwards, including all forks. Older versions are not supported because *Chunk* only implements *PersistentDataHolder* since 1.16.3.
## Advantages
- It does not need any files or databases
- When the chunk where the block is inside gets deleted, there will be no leftover information
- You can store anything that can be stored inside a normal `PersistantDataContainer` (which means, basically, **anything**)
- It can automatically keep track of block changes and automatically delete block data when a block gets broken, move data when a block gets moved, etc
- You can make specific blocks protected from this, or listen to the cancellable `CustomBlockDataEvent`s
- (This is disabled by default for backwards compatibility - just call `CustomBlockData#registerListener(Plugin)` to enable it)## Maven Dependency
The dependency is available on Maven Central:
```xmlcom.jeff-media
custom-block-data
2.2.3
compile```
**Shading and relocating**
You must shade (and you should relocate) the `customblockdata` package.
```xml
org.apache.maven.plugins
maven-shade-plugin
3.5.0
com.jeff_media.customblockdata
YOUR.PACKAGE.NAME.customblockdata
package
shade
```
## Gradle
**Repository**
```groovy
repositories {
mavenCentral()
}
```**Dependencies**
```groovy
dependencies {
implementation 'com.jeff-media:custom-block-data:2.2.3'
}
```**Shading & Relocating**
You must shade (and you should relocate) the `customblockdata` package. You will need the Shadow plugin found [here](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow). Add the following to your shadowJar section!
```groovy
shadowJar {
relocate 'com.jeff_media.customblockdata', 'your.package.customblockdata'
}
```Optionally, make the build task depend on shadowJar:
```groovy
build.dependsOn += shadowJar
```## Usage
To get a block's PersistentDataContainer, all you have to do is create an instance of `CustomBlockData` providing the block and
the instance of your main class:```java
PersistentDataContainer customBlockData = new CustomBlockData(block, plugin);
```If you want CustomBlockData to autimatically handle moving/removing block data for changed blocks (e.g. move data when a block gets moved with a piston, or to remove data when a player breaks a block, etc) you must call CustomBlockData.registerListener(Plugin) once in your onEnable().
For more information about how to use it, just look at the [API docs for the PersistentDataContainer](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/persistence/PersistentDataContainer.html) or look at [this tutorial](https://www.spigotmc.org/threads/a-guide-to-1-14-persistentdataholder-api.371200/).
## Javadocs
Javadocs can be found here: https://hub.jeff-media.com/javadocs/com/jeff-media/custom-block-data/2.2.2/
[//]: # (## Example plugin)
[//]: # ()
[//]: # (Click [here](https://github.com/JEFF-Media-GbR/CustomBlockData-Example) for an example plugin.)[//]: # (It lets you left-click on a block to store your currently held ItemStack inside. Once the block is broken,)
[//]: # (it will drop the stored item.)
## Discord
If you need help, feel free to join my Discord server and head to #programming-help:
## Donate
If you are using this project in your paid plugins, or if you just want to buy me a coffee, I would be happy over a small donation :)