-
-
Notifications
You must be signed in to change notification settings - Fork 9
How to create custom sheeps
In this tutorial, we will explain how to use the latest API version for developers in order to create your own sheeps.
We will assume that this is not your first Java programming session with the bukkit API so as not to waste time going back over details like : how to install an IDE as eclipse and how to create its first bukkit plugin. There's already a lot of really good tutorials on the internet for that.
First of all, you will need to add USW-DEV-API.jar to the Librairies of your plugin if it's not already done.
Eclipse Path : Right click on your Java Project → Build Path → Configure Build Path → Librairies → Add External JARs...
Then, you can create a new class with your sheep's name. In this tutorial, we will take as example the explosive sheep.
TIP : Never forget what is the main goal of your sheep. For us, the explosive sheep is supposed to create an explosion where it lands after 5 seconds.
Now that you've created your class, you can extend it with SheepWarsSheep located at fr.asynchronous.sheepwars.api.SheepWarsSheep, then add the default methods & constructor to your class.
It should look something like this :
public class ExplosiveSheep extends SheepManager
{
public ExplosiveSheep() {
super(name, color, duration, friendly, health, drop, random, sheepAbilities);
}
@Override
public boolean onGive(Player player) {
return true;
}
@Override
public void onSpawn(Player player, Sheep bukkitSheep, Plugin plugin) {
}
@Override
public boolean onTicking(Player player, long ticks, Sheep bukkitSheep, Plugin plugin) {
return false;
}
@Override
public void onFinish(Player player, Sheep bukkitSheep, boolean death, Plugin plugin) {
}
}A strong description of each method & constructor is available thanks to the javadocs.
Regarding our example :
-
onGive([...])We will always return true because we have no restrictions to apply to this sheep. If a player must receive it, he will receive it. But if, for example, you want to check that the player is VIP in order to get this sheep, you can do it here!
return true;-
onSpawn([...])We have nothing to do when the sheep spawns. It just has to be launched in the usual way but this is already managed.
// Do nothing-
onTicking([...])Probably most important part. We want our sheep to live 5 seconds after landing. So first we will set a duration of 5 in the class constructor. Then, we want the sheep to land, wait 2 seconds, then we add a flashing wool effect alternating between the white and red during 3 seconds before the explosion.
if (ticks <= 60L && ticks % 3L == 0L) {
if (ticks == 60L) {
Sounds.playSoundAll(bukkitSheep.getLocation(), Sounds.FUSE, 1f, 1f);
}
bukkitSheep.setColor((bukkitSheep.getColor() == DyeColor.WHITE) ? DyeColor.RED : DyeColor.WHITE);
}
return false;-
onFinish([...])We just do an explosion. Note: check ifdeathis false allows us to be sure that this sheep wasn't killed by a player before it explodes.
if (!death) {
UltimateSheepWarsPlugin.getVersionManager().getWorldUtils().createExplosion(player, bukkitSheep.getLocation(), 3.7f);
}You can have a look at the final class ExplosiveSheep here.
Finally, to register your sheep, simply use SheepWarsAPI.registerSheep(<Instance of your sheep class>);
If you have any question, feel free to contact us on Twitter. It will be a pleasure to help you to use our product.
Have a good day/night !
- If you find any bugs or issues, just create a new bug report on github and it'll be fixed as soon as possible.
- Have any suggestions? Leave them in a new feature request.
- Introduction ✔️
- SheepWars API ✏️
- Calendar events ✏️
- Custom events ✔️
- Player data ✏️
- Item builder ✏️
- Game state ✏️
- Language ✏️
- Team manager ✏️
- If you find any bugs or issues, just create a new bug report on github and it'll be fixed as soon as possible.
- Have any suggestions? Leave them in a new feature request.