WitchCraft Framework

WitchCraft Framework

97 Downloads

WitchCraft

WitchCraft Framework is a java framework for creating Bukkit plugins. It provides annotation-based command configuration and plugin.yml file generation.

Setup

If you want to use WitchCraft Framework with building tools like maven or gradle, you will need to add Ivan1pl's repository.

Maven

<repositories>
    <repository>
        <id>ivan1pl</id>
        <name>ivan1pl</name>
        <url>http://nexus.ivan1pl.com/repository/maven-releases/</url>
    </repository>
</repositories>

Gradle

repositories {
    maven {
        url 'http://nexus.ivan1pl.com/repository/maven-releases/'
    }
}

Dependency injection

WitchCraft Framework will create instances of your classes for you, and it will also link them together. Your classes can depend on other classes or configuration values. The framework will create a single instance of each managed class. Dependencies are injected by constructor parameters.

Read more here: [Dependency injection]

Modules

WitchCraft allows its users to create their own modules and hook them into the framework. This section explains how to do that. Predefined modules will be explained in separate sections.

To be able to create modules, you need the exact same dependencies as for the dependency injection feature.

Read more here: [Modules]

Commands

WitchCraft Framework provides a very simple way of defining commands using annotated classes and functions. The framework will take care of everything: annotated classes will be automatically registered and added to command executor.

Read more here: [Commands]

JDBC module

WitchCraft comes with its own JDBC module that can be enabled if you need it, but does not need to be included in your classpath. This module makes database connection management very easy. It will create connections for you, it supports named query parameters and greatly simplifies transaction management. And it will work with any JDBC you want! You can use PostgreSQL, MySQL, Oracle, pretty much any database for which a JDBC driver exists.

Read more here: [JDBC module]

Plugin.yml generation

If you want to save yourself some time and avoid some of the boring work while developing your plugins, this is a feature you need. WitchCraft will generate your plugin.yml for you! Of course you still need to provide all the required data for generation, but it is now much easier and quicker.

Read more here: [Plugin.yml generation]

Other features

WitchCraft Framework comes with several other features, mostly added to be used within other features of the project. However, you can use them separately, you don't even need to include libraries containing those other features, thus keeping your jar file small.

Read more here: [Other features]

Building your plugin

When you use external libraries in your plugin development, remember one important principle: ALWAYS shade your jar. This way you avoid any issues that may arise if more than one plugin uses the same library.

Maven

To properly shade this library using maven tool, simply include this section in your pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <!-- Run shade goal on package phase -->

                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <relocations>
                    <relocation>
                        <pattern>com.ivan1pl.witchcraft</pattern>
                        <shadedPattern>{plugin name}.com.ivan1pl.witchcraft</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>org.reflections</pattern>
                        <shadedPattern>{plugin name}.org.reflections</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>javassist</pattern>
                        <shadedPattern>{plugin name}.javassist</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </plugin>
    </plugins>
</build>

Replace {plugin name} with your plugin's name and that's it.

Gradle

To properly shade this library using gradle tool, include this in your build.gradle:

plugins {
    id 'com.github.johnrengelman.shadow' version '5.2.0'
    id 'java'
    // other plugins you want to use
}

Then configure relocations and replace jar task with shadowJar:

shadowJar {
    classifier = ''
    relocate 'com.ivan1pl.witchcraft', '{plugin name}.com.ivan1pl.witchcraft'
    relocate 'org.reflections', '{plugin name}.org.reflections'
    relocate 'javassist', '{plugin name}.javassist'
}

jar {
    enabled = false
    dependsOn(shadowJar)
}

Replace {plugin name} with your plugin's name and that's it.