Giter Site home page Giter Site logo

customblockdata's Introduction

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 Dependency

The dependency is available on Maven Central:

<dependency>
    <groupId>com.jeff-media</groupId>
    <artifactId>custom-block-data</artifactId>
    <version>2.2.2</version>
    <scope>compile</scope>
</dependency>

Shading and relocating

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.jeff_media.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>

Gradle

Repository

repositories {
    mavenCentral()
}

Dependencies

dependencies {
    implementation 'com.jeff-media:custom-block-data:2.2.2'
}

Shading & Relocating

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.jeff_media.customblockdata', 'your.package.customblockdata'
}

Optionally, make the build task depend on shadowJar:

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:

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 or look at this tutorial.

Javadocs

Javadocs can be found here: https://hub.jeff-media.com/javadocs/com/jeff-media/custom-block-data/2.2.2/

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

customblockdata's People

Contributors

mfnalex avatar justadeni avatar the-epic avatar mcrtin avatar sirsalad avatar traquolix avatar wizardlybump17 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.