Skip to content

JEFF-Media-GbR/CustomBlockData

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

CustomBlockData

SpigotMC Thread Javadocs Discord Donate

Maven

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 CustomBlockDataEvents
    • (This is disabled by default for backwards compatibility - just call CustomBlockData#registerListener(Plugin) to enable it)

Maven

Repository

<repository>
    <id>jeff-media-gbr</id>
    <url>https://hub.jeff-media.com/nexus/repository/jeff-media-public/</url>
</repository>

Dependency

<dependency>
    <groupId>com.jeff_media</groupId>
    <artifactId>CustomBlockData</artifactId>
    <version>2.2.0</version>
    <scope>compile</scope>
</dependency>

Shading and relocating

You must shade (and you should relocate) the CustomBlockData class. Just add this to the <configuration> section of your maven-shade-plugin declaration:

<relocations>
    <relocation>
        <pattern>com.jeff_media.customblockdata</pattern>
        <shadedPattern>YOUR.PACKAGE.customblockdata</shadedPattern>
    </relocation>
</relocations>

Gradle

Repository

repositories {
    maven {
      url = 'https://hub.jeff-media.com/nexus/repository/jeff-media-public/'
    }
}

Dependencies

dependencies {
    implementation 'com.jeff_media:CustomBlockData:2.2.0'
}

Shading & Relocating

You must shade (and you should relocate) the CustomBlockData class. You will need Shadow found on here. Add the following to your shadowJar section!

shadowJar {
    relocate 'com.jeff_media.customblockdata', 'your.package.customblockdata'
}

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:

PersistentDataContainer customBlockData = new CustomBlockData(block, plugin);

For more information about how to use it, just look at the API docs for the PersistentDataContainer or look at this tutorial.

Javadocs

Javadocs can be found here: https://hub.jeff-media.com/javadocs/customblockdata/

Example plugin

Click here 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 :)

Donate with PayPal

About

Provides a PersistentDataContainer for every Block location

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages