Creating your first plugin

Paweł Pastuszak edited this page Dec 31, 2015 · 5 revisions


Don't try to do anything yet, please

This article assumes you have followed steps in Plugin API and you are able to launch editor from Intellij IDEA.

You are almost ready to write your own plugin, now just need to checkout source version you will be targeting, to do this in your cloned VisEditor repository run command git checkout viseditor-0.3.1 this will make sure that you are working with correct version of source so your IDE can provide right code competition.

Let's create our plugin project.

  1. In IDEA press File|New|Module..., pick Maven on the right and press Next.
  2. Set groupId to your package name, eg. com.kotcrab.vis, articaftId will be your plugin id eg. first-plugin. Version is up to you, you can leave it at 1.0-SNAPSHOT and press Next
  3. Set Module name to your artifactId. For content root select some folder where your plugin project will be stored. Press Next.
  4. If you see dialog saying "This files does not belong to the project` press OK.
  5. Your project POM file should open, if that doesn't happen find it in project browser on the right and open it.

Editing POM file

  1. Copy and paste this fragment under version.
                            <Plugin-Description>Plugin that does all the fancy things</Plugin-Description>
2. Look for `manifestEntries` section, edit it so it will match your plugin.
3. Look for `outputDirectory` and modify it so it will match your case, you can even set it to absolute path if needed. Generally it needs to points into: `your cloned repository/Editor/target/your plugin id`
4. At the bottom modify version field so it will match your editor version that you are targeting.
5. In project explorer, in your project folder delete `src` directory, then recreate it, inside it create your package like in any other Java project (eg. `src/com/kotcrab/vis/firstplugin`)

### Launching editor with your plugin
Now, when everything is ready you can compile your plugin and launch editor, thanks to IDEA this can be combined into single launch action. 

1. Open `Run configurations` settings (Ctrl+Shift+A then search for Edit Configurations). Clone you normal Editor launch configuration and call it eg. `Editor with MyPlguin`
2. Find `Before launch` section, add new item `Run Maven Goal`
3. Select your plugin project folter
4. In command line field put `package`, press OK
5. Save and run your config. Your plugin will be automatically compiled, packaged and placed in editor directory then Editor will be run.
6. In Editor go to Plugins settings, active your new plugin and close editor.

### First plugin class

Let's create our first plugin class, create new Java file in your package. It swill simply say something when editor is loading:
import com.kotcrab.vis.editor.Log;
import com.kotcrab.vis.editor.module.Module;
import com.kotcrab.vis.editor.module.editor.EditorModule;
import com.kotcrab.vis.editor.plugin.api.ContainerExtension;
import com.kotcrab.vis.runtime.plugin.VisPlugin;

public class FirstClass extends EditorModule implements ContainerExtension {
	private static final String TAG = "FirstClass";

	public void init () {, "Hello from plugin!");

	public ExtensionScope getScope () {
		return ExtensionScope.EDITOR;

Project auto loading

Creating plugin requires launching editor many times, it may be inconvient to load project manually every time. There is one trick that will allow to automatize it. In VisEditor click Help|About and Open App Data Folder, there create new file debug.this, open it in text editor and put two lines, one with project path to load and second with full scene path to load. If you don't want to auto load scene put single space in second line but don't leave it empty. Example file:

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.