Behavior Providers
In Honeypot, a Behavior
is a custom action type that is registered via a plugin rather than defined as a Custom Honeypots Action. A behavior allows developers to programmatically process a Honeypot instead of just running basic server commands. Behavior providers can be as complex or simple as you make them. The native actions in Honeypot are actually behavior providers, as well!
When the server loads, Honeypot allows registration of Behavior Providers via its onLoad()
method. Once loaded, Honeypot stores all of those providers in its internal registry. Behavior providers take precedence over Custom Honeypot Actions
Creating a Behavior Provider
Creating a behavior provider is just as simple as the storage provider. Create a class that extends BehaviorProvider
and annotate it with the @Behavior
annotation. This annotation requires a type
, name
, and icon
. Currently, type
is unused, but be sure to label it properly as there are plans to utilize it in the near future.
package me.terrorbyte.test;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.block.Block;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
import [[[org.reprogle.honeypot.common.providers.Behavior|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/common/providers/Behavior.html]]];
import [[[org.reprogle.honeypot.common.providers.BehaviorProvider|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/common/providers/BehaviorProvider.html]]];
import [[[org.reprogle.honeypot.common.providers.BehaviorType|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/common/providers/BehaviorType.html]]];
import java.util.Objects;
[[[@Behavior|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/common/providers/Behavior.html]]](type = [[[BehaviorType|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/common/providers/BehaviorType.html]]].CUSTOM, name = "chicken-storm", icon = Material.CHICKEN_SPAWN_EGG)
public class DemoBehavior extends [[[BehaviorProvider|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/common/providers/BehaviorProvider.html]]] {
private BukkitTask task;
@Override
public boolean process(Player p, @Nullable Block block) {
// Over the course of 2.5 seconds, summon 50 chickens.
// Then, 10 seconds after *each individual chicken* is summoned, kill it and play the Enderman death sound >:)
final int[] j = {0};
task = Bukkit.getScheduler().runTaskTimer(Test.getPlugin(), () -> {
if (j[0] > 50) {
task.cancel();
return;
} else {
j[0]++;
}
Chicken chicken = (Chicken) Objects.requireNonNull(Bukkit.getWorld(p.getWorld().getName()).spawnEntity(p.getLocation().add(0, 1, 0), EntityType.CHICKEN));
chicken.setAdult();
new BukkitRunnable() {
@Override
public void run() {
chicken.setHealth(0.0);
p.playSound(chicken.getLocation(), Sound.ENTITY_ENDERMAN_DEATH, SoundCategory.HOSTILE, 2, 1);
}
}.runTaskLater(Test.getPlugin(), 20L * 10);
}, 0L, 1L);
Bukkit.getServer().broadcastMessage("The chicken storm has arrived, good luck");
return true;
}
w}
The example above spawn 50 chickens over 2.5 seconds, then after another 10 seconds it kills them all and plays a really loud Enderman death sound. That's the kind of customization you can get with Behavior Providers!
Once you have your provider created, you can register it the same way you did your Storage Provider in your onLoad()
method
package me.terrorbyte.test;
import org.bukkit.plugin.java.JavaPlugin;
import [[[org.reprogle.honeypot.Registry|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/Registry.html]]];
public class Test extends JavaPlugin {
// This is how you would register behavior providers
@Override
public void onLoad() {
[[[Registry|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/Registry.html]]].[[[getBehaviorRegistry()|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/Registry.html#getBehaviorRegistry()]]].[[[register|https://javadoc.jitpack.io/com/github/TerrorByteTW/Honeypot/honeypot-api/3.4.0/javadoc/org/reprogle/honeypot/BehaviorRegistry.html#register(org.reprogle.honeypot.common.providers.BehaviorProvider)]]](new DemoBehavior());
}
@Override
public void onEnable() {
this.getLogger().info("Enabling!");
}
@Override
public void onDisable(){
this.getLogger().info("Disabling!");
}
}
Last modified: 02 November 2024