API
Want to add a new jetpack, item and more?
The API has been developed to make the creation of various items much easier. This isn't the hardest thing to achieve in Bukkit, but it generally takes perfection, and item conflicts can occur as well. You don't have to use this for Jetpacks, as you can use it for any custom item you can think of - just get creative!
A very basic Jetpack starts something like this:
import net.jselby.ej.VisualCandy; import net.jselby.ej.api.FlightTypes; import net.jselby.ej.api.Jetpack; import net.jselby.ej.api.JetpackEvent; import net.jselby.ej.impl.CraftingRecipe; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.util.Vector; public class ExampleJetpack extends Jetpack { @Override public String getName() { return ChatColor.RESET + "Example Jetpack"; } @Override public String[] getDescription() { return new String[] {"Super special item"}; } @Override public Material getMaterial() { // We can load materials from configurations here, using their name return Material.getMaterial("GOLD_CHESTPLATE"); } @Override public void onFlyEvent(JetpackEvent event) { Vector dir = event.getPlayer().getLocation().getDirection(); Vector vec = new Vector(dir.getX() * 0.8D, 0.8D, dir.getZ() * 0.8D); event.getPlayer().setVelocity(vec); VisualCandy.jetpackEffect(event.getPlayer()); } @Override public void onFuelUsageEvent(JetpackEvent event) { } @Override public boolean onFuelCheckEvent(JetpackEvent event) { return true; } @Override public FlightTypes getMovementType() { return FlightTypes.CROUCH; } @Override public CraftingRecipe getCraftingRecipe() { return null; } @Override public String getGiveName() { return "example"; } @Override public Slot getSlot() { return Slot.CHESTPLATE; } }
You can create this Jetpack using the getItem() method, however, the Jetpack will be useless! The events won't get called, and it won't fly/your custom action. To fix this, you need to register the Jetpack with the EasyJetpackAPI class.
The syntax for the above example is as follows:
EasyJetpackAPI.getManager().addJetpack(new ExampleJetpack());
Want more information? The plugin has been fully commented on Github here.
Comments