I've had a few private conversations with people asking for the basics on how to create an ability in ProjectKorra, so I’m writing this is a tutorial for anyone interested in learning. I will assume that you have some experience with Java but I will provide some links for any beginners that are extremely interested in learning. I’m much better at coding then I am at explaining information, so if I leave out information or anything is unclear please let me know and I’ll try to fix it as soon as possible.
I would like other developers to go ahead and put together tutorials as-well, as a community we have 100’s of ideas but hardly any people to create them. Besides that, there are plenty of ways to create an ability and I’m sure mine isn’t the best way, so it would be great if we could have different perspectives.
Since I can’t find the spoiler button in the forums I will be uploading all the code to PasteBin and then posting the PasteBin link.
Requirement: A server on your computer that you can use to test the ability.
Step 1: “If you don’t have any experience with Java”
There are many tutorials online to learn the basics of Java but this one seemed to be fairly decent
http://www.learnjavaonline.org/
Complete “Hello, World!”, “Variables and Types”, and “Conditionals” at the minimum.
Additionally, I recommend you finish “Arrays”, “Loops”, “Functions”, and “Objects”.
Step 2: “If you don’t have any experience with Bukkit or setting up Eclipse”
This is a fairly clear tutorial on how to setup Bukkit for Eclipse and create a working plugin for your server. ProjectKorra uses a similar format to what you will learn in these videos so you should try to understand the majority of what is going on in these videos.
Bukkit Download Link:
https://dl.bukkit.org/downloads/bukkit/
The first two videos will give you an understanding of how to setup the plugin, and the third video will introduce you to Listeners. In ProjectKorra we use Listeners to determine whether the player pressed LeftClick or Shift.
Before you move on from this step your plugin should be complete and working on your test server.
Step 3: “Setting up the Ability”
The ability that we will be creating is a very simple fire ability called “Ignite”. If you left click an enemy in range with Ignite it will cause the enemy to burst into flames.
Download the latest ProjectKorra build and remember where you saved it to:
https://github.com/ProjectKorra/ProjectKorra/blob/master/Dev Builds/Korra.jar?raw=true
Open up Eclipse
Click File > new > Java Project
Make the Project Name “Ignite”
Press Next (not finish)
Click Libraries
Click Add External Jars
Double Click Korra.Jar, it should be in the folder that you saved it to.
Click Add External Jars again
Double Click Bukkit.jar, if you followed the videos in step 2 it is in the same location. If you don’t have it then download it here
Bukkit Download Link:
https://dl.bukkit.org/downloads/bukkit/
*Note* Bukkit is not the same thing as CraftBukkit, Bukkit should be about 4.8M in size.
Click Finish
Step 4:
Right Click the Ignite Project in Eclipse. If you can’t see Ignite then look at the top of Eclipse, Click Window > Show View > Package Explorer.
Click New Package
Name the package “me.whatevermynameis.korra.abilities”, so in my case it would be “me.coolade.korra.abilities”.
Right Click the package “me.whatevermynameis.korra.abilities”
Click New
Click Class
Name the Class: “IgniteInformation”
Right Click the package “me.whatevermynameis.korra.abilities”
Click New
Click Class
Name the Class: “IgniteListener”
Right Click the Ignite Project
Click New
Click File
Name the file “path.yml”
Click Finish
At this point you should have 3 files: “IgniteInformation.java”, “IgniteListener.java”, and “path.yml”.
IgniteInformation.java and IgniteListener.java should be inside the project “me.whatevermynameis.korra.abilities”
Step 5:
*** IgniteInformation.java ***
Copy the code from
http://pastebin.com/LQSsUSxU and paste it in IgniteInformation.java
*** IgniteListener.java ***
Copy the code from
http://pastebin.com/WqDam0pk and paste it into IgniteListener.java
Make sure to change the package names to fit your name instead of “coolade”
*** path.yml ***
Copy the line from
http://pastebin.com/AgAQuSg2 and paste it into path.yml
Make sure to change the package name to fit your name instead of “coolade”
Everything so far should be pretty self-explanatory except for this part:
Code:
public void onThisLoad() {
ProjectKorra.plugin.getServer().getPluginManager().registerEvents(new IgniteListener(), ProjectKorra.plugin);
}
Recall the third video in step two which taught you about listeners. This code is simply registering a new IgniteListener so that we will be able to check when the player presses Shift or Left Click. Since we are developing a small Ability and not a full plugin we will register our Listener to ProjectKorra.plugin. It’s alright if you don’t understand exactly what this does, just know that it goes inside of onThisLoad().
Step 6:
Go to IgniteListener.java
Create a new method inside of IgniteListener called onLeftClick which has a PlayerAnimationEvent as its argument.
It should look like:
Code:
@EventHandler(priority = EventPriority.NORMAL)
public void onLeftClick(PlayerAnimationEvent event){
}
If there is a red line under @EventHandler move your mouse over the words and it should give you an option to fix the error.
If there is a red line under PlayerAnimationEvent move your mouse over the words and press import, or press Ctrl + Shift + o.
We are creating a method named “onLeftClick” that will tell us whenever a player left clicks. A PlayerAnimationEvent happens whenever a player left clicks, (also known as animating). If we were interested in whether or not the player pressed Shift we could use a PlayerToggleSneakEvent but we don’t need this for Ignite.
Step 7:
Inside of the onLeftClick method we need to do the following:
1. Find the player that did the left clicking.
Code:
Player player = event.getPlayer();
2. Get the ability that the player has bound and if it is not ignite then we need to exit.
Code:
String ability = Methods.getBoundAbility(player);
if(ability == null || !ability.equalsIgnoreCase("Ignite"))
return;
3. If the player can’t use “Ignite” then we need to exit.
Code:
if(!Methods.canBend(player.getName(), "Ignite"))
return;
4. If the player is standing in a location that he is not allowed to bend in then we need to exit the ability.
Code:
if(Methods.isRegionProtectedFromBuild(player, "Ignite", player.getLocation()))
return;
5. Get the object that the player is looking at within a range of 10. If the target does not exist then we need to exit. Don’t worry about the ArrayList<Entity>() in our case it doesn’t serve any purpose but the syntax still needs it.
Code:
Entity target = Methods.getTargetedEntity(player, 10, new ArrayList<Entity>());
if(target == null)
return;
6. If the player is looking at an object we need to make sure it is living. Make sure to import LivingEntity. The keyword “instanceof” allows us to check if a target falls into a specific category, we could have substituted the LivingEntity with Zombie if we wanted to see if it was a Zombie. Similarly, we could have done Zombie, Player, Bat, SilverFish, Spider, etc. Examples of non-living objects are Anvils or Floating stacks of items, if we tried to set those on fire then we would get errors.
Code:
if(!(target instanceof LivingEntity))
return;
7. If it’s living then we will put the enemy on fire for 100 ticks (5 seconds). We have to convert the target into a LivingEntity now that we know the target is alive.
Code:
LivingEntity livingTarget = (LivingEntity) target;
livingTarget.setFireTicks(100);
Click here to see the complete version:
IgniteListener.java
http://pastebin.com/vHnAfcMs
Step 8:
Right Click the Ignite Project
Press Export
Click Java
Click Jar File
Press Next
Make sure Ignite is the only Box highlighted, and .classpath, .project, .path.yml and any other files are checked.
Make sure Export generated class files and resources is checked.
Click Browse
Save the file as Ignite
Now that you created Ignite.jar move it into your ProjectKorra/abilities folder and test it out. If the ability doesn’t work check the console and see if it is giving you errors. Make sure that the path.yml matches the same path as your package.