-
Notifications
You must be signed in to change notification settings - Fork 6
Special Advancement
TaskAdvancements are advances that are saved on the database but cannot be shown to the players in the tabs. They are used to keep track of tasks or quests and these do not want to be shown to players; but useful in code development. They require an instance of the multitask as a parameter.
The completion of this advancement requires the completion of some tasks (TaskadvAncement). The shown maxCriteria is the sum of the maxCriteria of the tasks. The shown progression is the sum of the task progressions. The tasks must not be registered in the tab but in the multitask.
Example:
private AdvancementTab advancementTab;
private Root root;
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
//if you want to the enable SqlLite
main.enableSQLite(new File(getDataFolder(), "sqlLiteDbName"));
advancementTab = UltimateAdvancementAPI.getInstance(this).createAdvancementTab("a_tab");
AdvancementDisplay rootDisplay = new AdvancementDisplay(Material.GRASS_BLOCK, "Root §c", AdvancementFrameType.TASK, false, false, 0, 0, "Your adventure start here");
root = new Root(advancementTab, "root", rootDisplay, "textures/block/stone.png");
AdvancementDisplay ad = new AdvancementDisplay(Material.ACACIA_LOG, "Dig!", AdvancementFrameType.TASK, true, true, 1, 0, "-Break 2 of Dirt", "-Break 4 of stone");
MultiTasksExample multiTasksExample = new MultiTasksExample("eg", ad, root, 6);
DirtTask dirtTask = new DirtTask("dirt", multiTasksExample, 2);
StoneTask stoneTask = new StoneTask("stone", multiTasksExample, 4);
multiTasksExample.registerTasks(dirtTask, stoneTask);
advancementTab.registerAdvancements(root, multiTasksExample);
}
@EventHandler
public void onJoin(PlayerLoadingCompletedEvent e) {
Player p = e.getPlayer();
advancementTab.showTab(p);
root.grant(p);
}
public class DirtTask extends TaskAdvancement {
public DirtTask(@NotNull String key, @NotNull AbstractMultiTasksAdvancement multitask, @Range(from = 1L, to = 2147483647L) int maxCriteria) {
super(key, multitask, maxCriteria);
registerEvent(BlockBreakEvent.class, e -> {
Player p = e.getPlayer();
if (!isGranted(p) && e.getBlock().getType() == Material.DIRT) {
incrementProgression(p);
}
});
}
}
public class MultiTasksExample extends MultiTasksAdvancement {
public MultiTasksExample(@NotNull String key, @NotNull AdvancementDisplay display, @NotNull Advancement parent, @Range(from = 1L, to = 2147483647L) int maxCriteria) {
super(key, display, parent, maxCriteria);
}
@Override
public void giveReward(@NotNull Player player) {
player.sendMessage("You did it! You won nothing");
}
}
public class StoneTask extends TaskAdvancement {
public StoneTask(@NotNull String key, @NotNull AbstractMultiTasksAdvancement multitask, @Range(from = 1L, to = 2147483647L) int maxCriteria) {
super(key, multitask, maxCriteria);
registerEvent(BlockBreakEvent.class, e -> {
Player p = e.getPlayer();
if (!isGranted(p) && e.getBlock().getType() == Material.STONE) {
incrementProgression(p);
}
});
}
}
FakeAdvancements are advancements that are created and used only to recreate visible lines and connect multiple advancements. They are used in the API for multiparent management. These are not saved to the database.
They are advancements that have multiple parents, i.e. when they have multiple advancements that converge into multiparent. FakeAdvancements are used to show missing lines. The root cannot be one of the parents. Parents must be registered in the tab.
Example:
private AdvancementTab advancementTab;
private Root root;
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(this, this);
//if you want to the enable SqlLite
main.enableSQLite(new File(getDataFolder(), "sqlLiteDbName"));
advancementTab = UltimateAdvancementAPI.getInstance(this).createAdvancementTab("atab");
AdvancementDisplay rootDisplay = new AdvancementDisplay(Material.GRASS_BLOCK, "Root §c", AdvancementFrameType.TASK, false, false, 0, 1, "Your adventure start here");
root = new Root(advancementTab, "root", rootDisplay, "textures/block/stone.png");
AdvancementDisplay ad = new AdvancementDisplay(Material.ACACIA_LOG, "MultiParent!", AdvancementFrameType.TASK, true, true, 2, 1);
AdvancementDisplay base = new AdvancementDisplay(Material.LAVA_BUCKET, "Advancement", AdvancementFrameType.TASK, true, true, 1, 0);
AdvancementDisplay base2 = new AdvancementDisplay(Material.WATER_BUCKET, "Advancement", AdvancementFrameType.TASK, true, true, 1, 2);
Adv adv1 = new Adv( "adv1", base, root);
Adv adv2 = new Adv("adv2", base2, root);
MultiparentExample multiParentsAdvancement = new MultiparentExample( "multipare", ad, adv1, adv2);
advancementTab.registerAdvancements(root, adv1 , adv2,multiParentsAdvancement);
}
@EventHandler
public void onJoin(PlayerLoadingCompletedEvent e) {
Player p = e.getPlayer();
advancementTab.showTab(p);
root.grant(p);
}
public class Adv extends BaseAdvancement {
public Adv( @NotNull String key, @NotNull AdvancementDisplay display, @NotNull Advancement parent) {
super( key, display, parent);
}
//todo
}
public class MultiparentExample extends MultiParentsAdvancement {
public MultiparentExample(@NotNull String key, @NotNull AdvancementDisplay display, @NotNull BaseAdvancement... parents) {
super(key, display, parents);
}
//todo
}
UltimateAdvancementAPI Wiki © 2021 fren_gor, EscanorTargaryen is licensed under CC BY-SA 4.0.
Except where otherwise noted, code snippets inside the wiki are licensed under The Unlicense.