Power Creation

Note: This page is a work in progress and is not yet complete.

Introduction

One of the major improvements added to S86 Powers in v4.0 was dynamic power loading. The main reason for this feature's implimentation was fairly simple: allow other developers to add content to my plugin.

Getting Started

Before we get started let me first state the following:

  1. I consider myself a beginner in Java. Some of my coding methods may be improper or inefficient.
  2. I use Eclipse for creating Java applications, and will therefore refer to it on this page.

Now, to create your own powers for S86 Powers you will need the following:

  • Beginner or intermediate knowledge of Java programming.
  • Java editing software (as stated, I use and recommend Eclipse).
  • S86 Powers v4.1.0 or greater (the included S86_PowerPack.jar is not required).
  • A fairly recent version of CraftBukkit.
  • A dedicated server to test your created powers, preferably local. (As of v4.1.0, the physical power class files themselves can not be reloaded via Bukkit's /reload command, the server must be stopped and restarted.)

Creating the Class File

Again, these are steps one would take while using Eclipse to create a power class. The methods may differ with other Java editing software.

  1. In Eclipse, go to File > New > Java Project. Give it any project name you want (as an example, the power pack I include with S86 Powers is named "S86_PowerPack"). In the JRE section, click the Use an execution environment JRE: bullet, then pick JavaSE-1.6. When done hit Next.
  2. Click on the Libraries tab, then click Add External JARs... on the right. You will want to add both "S86_Powers.jar" and a CraftBukkit jar here. When done hit Finish.
  3. Your new project should show up in Eclipse's Package Explorer on the left. The project should only contain a src folder. Right-click the src folder, go to New and click on Package. You can technically name the package anything you want, though it's recommended you identify yourself in its name (for example, in S86 Powers I use "me.sirrus86,s86powers"). Hit Finish and this should create the new package under src.
  4. Right-click the newly created package, go to New, and click on Class. For the purposes of power creation, the name of the power class IS important. In S86 Powers, every power has a tag. The tag for a power is literally the power's class name, so make sure the name you enter is as close to the power's actual name as possible (for example, a power called "Thunder Sword" would be given the class name "ThunderSword" since class names cannot have spaces). When you're done, hit Finish.

You should now be looking at a java file similar to this:

package me.sirrus86.s86test;

public class TestPower {

}

Making a Power Class

For a power class to be read by S86 Powers, it must first do three things: include the PowerManifest annotation, extend Power, and implement Listener.

  1. Above the public class line, type @PowerManifest. Eclipse will underline this as an error. Hover your mouse over the line until a small window appears, then choose Import 'PowerManifest' (me.sirrus86.s86powers.powers).
  2. Even after being imported, Eclipse still underlines the PowerManifest line as an error. Hover over it again, then click Add missing attributes. This will populate PowerManifest with six variables: author, concept, description, name, type, and version.
    • Next to author, you can put your own name.
    • Next to concept, put the name of whoever came up with the power idea.
    • Next to description, put a full description of what the power does, how it's activated, etc. This is usually long enough that it may need its own line.
    • Next to name, put the full name of the power.
    • Next to type, type in "PowerType." You should see a list of options: DEFENSE, ELITE, OFFENSE, PASSIVE, and UTILITY. Choose DEFENSE if the power is manually activated and defensive, OFFENSE if the power is manually activated and offensive, or PASSIVE if the power activates automatically (ELITE and UTILITY will be discussed later).
    • Next to version, put the version number of this power class. Note that this must be a double value.
  3. Next, the class must extend Power, so after public class <name> type extends Power. Again Eclipse will mark this as an error. Hover over it and select Import 'Power' (me.sirrus86.s86powers.power).
  4. Now Eclipse will mark the class name with an error. This is because Power includes an abstract method which power classes must inherit and override. Hover over your class' name and click Add unimplemented methods. This will add the onEnable() method. Within the method, make sure to change the line return false to return true, otherwise the power won't load.
  5. Finally, the class must implement Listener. Simply add implements Listener to the public class line. Again, Listener will be flagged as an error, just hover over it and click Import 'Listener' (org.bukkit.event).

Your class file should now look like this:

package me.sirrus86.s86test;

import org.bukkit.event.Listener;

import me.sirrus86.s86powers.powers.Power;
import me.sirrus86.s86powers.powers.PowerManifest;
import me.sirrus86.s86powers.powers.PowerType;

@PowerManifest(author = "sirrus86", concept = "someone else", name = "S86 Test", type = PowerType.PASSIVE, version = 1.0,
    description = "Creates a test power that does something cool.")
public class TestPower extends Power implements Listener {

    @Override
    public boolean onEnable() {
        // TODO Auto-generated method stub
        return true;
    }

}

Congrats, you now have the core elements of a power class! Everything that follows may vary wildly depending on needs for the power.


Comments

Posts Quoted:
Reply
Clear All Quotes