Puffinlump's Data API

Puffinlump's Data API

194 Downloads

Hello Bukkit users! This is an API I've created to make saving and loading custom plugin data easily.

It makes it possible to save things like block metadata and such. This is my first plugin so expect it to have issues or over complications.

Getting Started

 Here is some example code:

import com.puffinlump.Data.*;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Location;

// This is an example for getting started

// Keep in mind this would use 2 blocks with some metadata, CustomBlockType and CustomBlockName for example.

public class Main extends JavaPlugin {
	
	private Data data = null;
	
	public void onEnable() {
		data = new Data(); // Create the data handler
		data.RegisteredPlugin = this; // Register this to the data handler
		data.registerMetadata("CustomBlockType"); // Register some metadata
		data.registerMetadata("CustomBlockName"); // Register some more metadata
		data.load(); // You can supply a boolean to cause all saved blocks to be force loaded. If you load it at startup this won't be needed because the blocks will have the same data and id
		// NEVER LOAD BEFORE REGISTERING ANYTHING! This will cause it to either not load or break the API.
		Location loc = new Location(Bukkit.getWorlds().get(0), 0F, 50F, 0F); // The location of an example block. This is usually the overworld, but if for some reason it's not, figure out the world
		data.addBlock(loc.getBlock()); // Add a block to the data handler
		// When the plugin is disabled, the block will be saved. When it is enabled, it will have the registered metadatas.
	}
	
	public void onDisable() {
		data.onDisable(); // This is required for the plugin data to be saved!
	}
	
}

Things to keep in mind:

Do not load before registering stuff.

If the plugin has an error or is failing to load you can rename or delete the pluginData.PDAT file in server\plugins\The internal name of your plugin and post a link to the file here (E.g. through Dropbox) so that I can take a look at it and see if it's repairable.

Documentation

Incomplete, sorry about that!

Class List

[Main API Class] Data - The heart of the API

[Data Class] DataBlock - A class for saving blocks

[Data Class] DataItemMeta - A class for saving just item meta data. (Name, material etc.)

[Data Class] DataItemStack - A class for saving item stacks
[Data Class] DataLocation - A class for saving Bukkit locations

[Data Class] DataMetadataValue - A class for saving meta data values. (FixedMetadataValue etc.)

[System Class] DataObject - A class which all data classes extend
[System Class] Main - The main class of the plugin. Sort of self explainatory.

Note: Not all API functions are tested as of now! If you encounter an error, please notify me!