Skip to content

Provides a PersistentDataContainer for every Block location

License

Notifications You must be signed in to change notification settings

milkdrinkers/CustomBlockData

 
 

Repository files navigation

CustomBlockData

license Maven metadata URL javadoc GitHub last commit


Description

Note

This is a fork of the original repository found here. All credit goes to the original creator and contributors.

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.5 onwards, including all forks. Older versions are not supported because Chunk only implements PersistentDataHolder since 1.16.3.


Useful Links


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)

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);

If you want CustomBlockData to automatically 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 or look at this tutorial.


Build Tool Setup


Gradle Dependency Setup

Repository

repositories { 
    maven("https://maven.athyrium.eu/releases/")
}

Dependencies

dependencies {
    implementation("com.github.milkdrinkers:customblockdata:1.0.0")
}

Shading & Relocating

Important

You must shade (and you should relocate) the customblockdata package. You will need the Shadow plugin found here. Add the following to your shadowJar section!

shadowJar {
    relocate("com.github.milkdrinkers.customblockdata", "your.package.customblockdata")
}

Optionally, make the build task depend on shadowJar:

build { 
    dependsOn(shadowJar)
}

Maven Dependency Setup

Repository

<repository>
    <id>milkdrinkers-releases</id>
    <name>Milkdrinkers Maven Repository</name>
    <url>https://maven.athyrium.eu/releases</url>
</repository>

Dependencies

<dependency>
    <groupId>com.github.milkdrinkers</groupId>
    <artifactId>customblockdata</artifactId>
    <version>1.0.0</version>
    <scope>compile</scope>
</dependency>

Shading & Relocating

Important

You must shade (and you should relocate) the customblockdata package.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.5.0</version>
      <configuration>
        <relocations>
          <relocation>
            <pattern>com.github.milkdrinkers.customblockdata</pattern>
            <shadedPattern>YOUR.PACKAGE.NAME.customblockdata</shadedPattern>
          </relocation>
        </relocations>
      </configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

About

Provides a PersistentDataContainer for every Block location

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%