Developer API
Repository Information
Maven:
<repository>
<id>mysticalkingdoms-public</id>
<url>https://nexus.mysticalkingdoms.com/repository/public/</url>
</repository>
<dependency>
<groupId>com.mysticalkingdoms</groupId>
<artifactId>mysticalquests-api</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
Gradle:
maven {
url = uri('https://nexus.mysticalkingdoms.com/repository/public/')
}
compileOnly 'com.mysticalkingdoms:mysticalquests-api:1.0.0'
To create your own expansion, you first need to have a main class that will handle enabling, disabling and reloading the expansion, just like a plugin. This is an example of a main class for an expansion:
package com.mysticalkingdoms.mysticalquests.quests.expansions.builtin;
import com.mysticalkingdoms.mysticalquests.api.MysticalQuestsAPI;
import com.mysticalkingdoms.mysticalquests.api.quests.expansions.QuestExpansion;
import com.mysticalkingdoms.mysticalquests.api.quests.expansions.QuestExpansionDescription;
import org.bukkit.plugin.Plugin;
import java.io.File;
public class InternalExpansion extends QuestExpansion {
public InternalExpansion(Plugin plugin, QuestExpansionDescription expansionDescription, File dataFolder) {
super(plugin, expansionDescription, dataFolder);
}
@Override
public boolean onEnable() {
MysticalQuestsAPI.registerQuestType(
new BlockBreakType(),
new BlockPlaceType(),
new EntityKillType(),
new CraftItemType());
return true;
}
@Override
public void onDisable() {
}
@Override
public void onReload() {
}
}
Keep the constructor as is, otherwise your expansion will not load.
- onEnable: You should register any logic here, and then register your quest types.
- onDisable: Disable any logic that needs to be disabled (example: databases)
- onReload: Unused for now, but will be used in the future for a reload command.
Now, for your quest type, you need to extend the class "QuestType".
You must specify a quest type key. This should be unique. A good idea is to prefix it with the name of your plugin/expansion.
package com.mysticalkingdoms.mysticalquests.quests.expansions.builtin;
import com.mysticalkingdoms.mysticalquests.api.quests.expansions.QuestType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
import java.util.Map;
public class BlockBreakType extends QuestType {
public BlockBreakType() {
super("BLOCK_BREAK");
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
String blockType = event.getBlock().getType().name();
Map<String, String> placeholders = new HashMap<>();
placeholders.put("%block%", blockType);
execute(event.getPlayer(), placeholders, 1);
}
}
QuestType implements Listener, so you can listen to any Bukkit events. In the example above, we're listening to BlockBreakEvent, and then calling execute on the player.
You can choose to pass placeholders so end users can evaluate them with whatever they want. In this case, I'm passing the placeholder %block%.
The final argument is the amount of progress to grant the player in case the conditions pass. In this case, we pass 1.
If you have any questions, feel free to ask on Discord!
No Comments