Skip to content

Creating Behavior Providers for Honeypot 3.0.0

Nate Reprogle edited this page Feb 23, 2024 · 4 revisions

Creating custom Behavior Providers

Initial setup

This wiki page assumes you've configured your project to use Honeypot as a dependency. If not, head here

Adding the Behavior Provider

Creating a behavior provider is rather simple, it only requires a few steps

  1. Create a new class, name it the name of your provider (This isn't required, but helps with debugging registration issues). Let's create one called "DemoBehavior".
  2. Extend the BehaviorProvider class from the org.reprogle.honeypot.providers package.
  3. Annotate the class with the @Behavior annotation, also from the same package. The @Behavior annotation requires three arguments: The type, the name, and the icon. The type is a BehaviorType from the previously mentioned package, the name is a standard string, and the icon is a Bukkit Material. Currently, the Type field is unused, but be sure to type it as accurately as possible as it may be used in the future. The icon field is what icon will be displayed to someone in the Honeypot GUI for your action.

At this point, your class should look like this:

package me.terrorbyte.test;

import org.jetbrains.annotations.Nullable;
import org.reprogle.honeypot.common.providers.Behavior;
import org.reprogle.honeypot.common.providers.BehaviorProvider;
import org.reprogle.honeypot.common.providers.BehaviorType;

@Behavior(type = BehaviorType.CUSTOM, name = "chicken-storm", icon = Material.CHICKEN_SPAWN_EGG)
public class DemoBehavior extends BehaviorProvider {

}

You should be receiving an error at this point because your provider doesn't implement the required methods. Go ahead and create them, most proper IDE's and code editors can do this for you. The method definition is #process(Player p, Block block). Return true if your behavior provider succeeded at processing, false if not. Your class will now look like this

package me.terrorbyte.test;

import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import org.reprogle.honeypot.common.providers.Behavior;
import org.reprogle.honeypot.common.providers.BehaviorProvider;
import org.reprogle.honeypot.common.providers.BehaviorType;

import java.util.Objects;

@Behavior(type = BehaviorType.CUSTOM, name = "chicken-storm", icon = Material.CHICKEN_SPAWN_EGG)
public class DemoBehavior extends BehaviorProvider {

	@Override
	public boolean process(Player p, Block block) {
		return true;
	}
}

At this point, you can put whatever code you want in the process method. The player is the player that triggered the action, and the Block that is/was the Honeypot block. Player and Block will always be provided, even if they're not needed in your case.

Finally, you need to register your provider. To do so, head to your main class where your lifecycle methods are, and in your #onLoad() method (If you don't have one, create one), register the provider as such:

@Override
public void onLoad() {
    Honeypot.getRegistry().register(new DemoBehavior());
}

Where new DemoBehavior() would be the name of your class. Honeypot only allows registration during plugin load, and will prevent registration afterwards. If you attempt to register in your onEnable(), it will throw errors in console on purpose. This is not an error, you need to properly register your behavior. If you attempt to use /reload or a plugin such as PlugManX to reload Honeypot or any plugin providing custom behaviors, you will experience errors and support will not be provided.

That's it! When you boot Honeypot, if you don't have any other custom behavior providers, you should see that Honeypot registers 5 behavior providers: 4 internal, and yours! When you go to create a Honeypot, yours should be in the list.

Check out the demo plugin for an example behavior provider. This provider spawns 50 chickens over the course of 2.5 seconds, then kills them all and plays an extremely loud Enderman death noise 😁