Skip to content

Getting Started

Creating New Project

We're going to use Intellij IDEA as our development tool, here's how we can create new gradle project with JFDF:

  1. Go to File > New > Project.
  2. Set project name and location.
  3. Select Gradle as build system.
  4. Toggle Add sample code.
  5. Copy JFDF jar to project's directory.
  6. Open build.gradle.
  7. Add this to dependencies section:

    implementation files('./JFDF-2.0.0b3-all.jar')
    
  8. Now we got project ready for use with JFDF.

Writing Hello World Example

Now let's try to implement Hello World ! example using Java and compile that to DiamondFire templates using JFDF.

First let's create a class inside org.example and call it HelloWorld, like this:

1
2
3
4
5
package org.example;

public class HelloWorld {

}

Then let's create a static method called onJoin, inside our new class

1
2
3
4
5
6
7
8
package org.example;

public class HelloWorld {

    public static void onJoin() {

    }
}

Now we want onJoin method to be executed whenever the player joins our plot, we can use @PlayerEvent annotation for that and we can set the event to join by setting eventType of the annotation to PlayerEventBlock.Event.JOIN

package org.example;

import net.jfdf.jfdf.blocks.PlayerEventBlock;
import net.jfdf.jfdf.mangement.PlayerEvent;

public class HelloWorld {

    @PlayerEvent(eventType = PlayerEventBlock.Event.JOIN)
    public static void onJoin() {

    }
}

@PlayerEvent annotation is used to define a method as a player event, now we want to send Hello World ! to the player who joined, we can do that by using System.out.println

System.out.println("Hello World !");

Compiling Code

Now we need to compile our code, to compile our class we need to use compileClass method inside JFDFCompiler class, now let's open Main class generated by Intellij IDEA and call compileClass method inside main method to compile our HelloWorld class.

1
2
3
4
5
6
7
8
9
package org.example;

import net.jfdf.compiler.JFDFCompiler;

public class Main {
    public static void main(String[] args) {
        JFDFCompiler.compileClass(HelloWorld.class);
    }
}

Exporting to DiamondFire

Since JFDF is a library, there's no executeable that exports our code, if we wanted to export our code, we need to export the code ourselves.

Luckily JFDF has a bunch of methods to help us to export our code, we're going to get give commands using JFDF, we can do that by using getGiveCommands method from CodeManager class and printing each command from it.

package org.example;

import net.jfdf.compiler.JFDFCompiler;
import net.jfdf.jfdf.mangement.CodeManager;

public class Main {
    public static void main(String[] args) {
        JFDFCompiler.compileClass(HelloWorld.class);

        for (String giveCommand : CodeManager.instance.getGiveCommandsAsList()) {
            System.out.println(giveCommand);
        }
    }
}

Now all we need to do is running our Main class and we're going to get give commands on the terminal, after that we need to:

  1. Go to creative singleplayer world.
  2. Get a command block using /give @s command_block.
  3. Place a command block.
  4. Type a command inside command block.
  5. Run command block.
  6. Repeat 3-5 until you do that for each command.
  7. Save templates inside your toolbar
  8. Go to DiamondFire and load templates from your toolbar

Of course, this is not the only way to export templates, there're much more advanced ways to do it, but that's up to you.