API/Example Plugin

package com.relick.hookexample;

import java.util.logging.Logger;

import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

import com.relick.banrecipehook.BanRecipeHook;
import com.relick.banrecipehook.RecipeHandler;

public class HookExample extends JavaPlugin {
	public static RecipeHandler recipeHandler;
	public final Logger logger = Logger.getLogger("Minecraft");

	public void onEnable() {
		logger.info("hookexample enabled");
		setupBanRecipeHook();
		recipeHandler.setBanMessage("%%PLAYER%%! You cannot craft %%MATERIAL%%!");
		recipeHandler.addGlobalBlockedItem(46, null);
		recipeHandler.addGlobalBlockedItem(259, "op");
		recipeHandler.addBlockedItem("Zantom07", 5);
	}

	public void onDisable() {
		logger.info("hookexample disabled");
	}

	public void setupBanRecipeHook() {
		if (recipeHandler != null) {
			return;
		}

		final BanRecipeHook banRecipeHook = new BanRecipeHook();
		
		Plugin banRecipeHookPlugin = this.getServer().getPluginManager()
				.getPlugin("BanRecipeHook");

		PluginDescriptionFile description = this.getDescription();
		String prefix = "[" + description.getName() + "] ";

		if (banRecipeHookPlugin == null) {
			this.logger.info(prefix
					+ "BanRecipeHook not detected, disabling plugin.");
			this.getPluginLoader().disablePlugin(this);
			return;
		}
		
		recipeHandler = new RecipeHandler(banRecipeHook);

		this.logger.info(prefix + "Found and will use BanRecipeHook version ["
				+ banRecipeHookPlugin.getDescription().getVersion() + "]");
	}

}

Here is a full example of using BanRecipe within your plugin. This plugin's entire purpose is to hook into it, however you can also utilise BanRecipe within larger plugins.

This one sets up BanRecipe's API for use, then does multiple things. First it sets the message sent to a player trying to craft any blocked item. Next it blocks everyone from crafting TNT, regardless of any position. It also blocks everyone except ops from crafting a flint and steel. Finally it blocks the user called 'Zantom07' from turning logs into wood.


Comments

Posts Quoted:
Reply
Clear All Quotes