Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add Frame Types [Fix] Fix Build [Chore] Update Dough #25

Merged
merged 2 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SlimefunAdvancements

a slimefun addon that lets you do things like complete and configure advancements
A slimefun addon that lets you do things like complete and configure advancements

[download here](https://blob.build/project/SlimefunAdvancements)

Expand All @@ -13,6 +13,8 @@ The configuration files can be found in your `plugins/SFAdvancements/` folder.
Each item in the yml represents an advancement group, where the key is the key of the group.<br>
The key is used to refer to the group in `advancements.yml`.<br>
Each group has a `display`, which is an item. It should be an item representation.<br>
You can optionally specify a `frame_type` for the frame type surrounding the display item in the vanilla GUI. (By default, groups will have a Goal frame type)<br>
The valid types for a frame are `GOAL`, `TASK`, and `CHALLENGER`<br>
The item is used to display the group in the GUI.<br>
You can optionally specify a `background` string for the group, which is used in the vanilla GUI. (By default, groups will have a bedrock texture)<br>
It should be the name of a block texture file. These files can be found on https://mcasset.cloud/ in `assets/minecraft/textures/block/` for the specified version.
Expand All @@ -32,6 +34,7 @@ Examples of #1 in `groups.yml`
my_cool_group:
display: NETHER_STAR
background: glass
frame_type: CHALLENGER

my_other_group:
display: ELECTRIC_MOTOR
Expand Down Expand Up @@ -83,8 +86,8 @@ The group is the id defined in `groups.yml`.
The parent is the id of a different Advancement for this to be under. (For Advancement Trees)

The display is an item, represented as described in Item Representation. This is the item that is displayed in both the
SFA GUI and the vanilla GUI. You can specify a placeholder line `%criteria%` in the lore, which will be replaced with the
criteria of the advancement.
SFA GUI and the vanilla GUI. You can specify a frame type that will appear in the vanilla gui. (GOAL, TASK, CHALLENGER).
You can specify a placeholder line `%criteria%` in the lore, which will be replaced with the criteria of the advancement.

The name is what will appear in chat when someone completes the advancement.

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<dependency>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>b646e15974</version>
<version>RC-36</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -195,7 +195,7 @@
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-api</artifactId>
<version>a6519e666c</version>
<version>1108163a49</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/me/char321/sfadvancements/SFAdvancements.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public void loadGroups() {
for (String key : groupConfig.getKeys(false)) {
String background = groupConfig.getString(key + ".background", "BEDROCK");
ItemStack display = ConfigUtils.getItem(groupConfig, key + ".display");
AdvancementGroup group = new AdvancementGroup(key, display, background);
String frameType = groupConfig.getString(key + ".frame_type", "GOAL");
AdvancementGroup group = new AdvancementGroup(key, display, frameType, background);
group.register();
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/char321/sfadvancements/api/Advancement.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,25 @@ public class Advancement {
private final NamespacedKey parent;
private final AdvancementGroup group;
private final ItemStack display;
private final String frameType;
private final String name;
private final boolean hidden;
private final Criterion[] criteria;
private final Reward[] rewards;

public Advancement(NamespacedKey key, @Nullable NamespacedKey parent, AdvancementGroup group, ItemStack display, String name, boolean hidden, Criterion[] criteria, Reward[] rewards) {
this(key, parent, group, display, "GOAL", name, hidden, criteria, rewards);
}

public Advancement(NamespacedKey key, @Nullable NamespacedKey parent, AdvancementGroup group, ItemStack display, String frameType, String name, boolean hidden, Criterion[] criteria, Reward[] rewards) {
this.key = key;
if (parent == null) {
parent = Utils.keyOf(group.getId());
}
this.parent = parent;
this.group = group;
this.display = display;
this.frameType = frameType;
this.name = ChatColor.translateAlternateColorCodes('&', name);
this.hidden = hidden;
this.criteria = criteria;
Expand All @@ -62,6 +68,10 @@ public ItemStack getDisplay() {
return display;
}

public String getFrameType() {
return frameType;
}

public String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class AdvancementBuilder {
private NamespacedKey parent;
private AdvancementGroup group;
private ItemStack display;
private String frame;
private String name;
private boolean hidden;
private List<Criterion> criteria = new ArrayList<>();
Expand Down Expand Up @@ -52,6 +53,12 @@ public static AdvancementBuilder loadFromConfig(String key, ConfigurationSection
}
builder.display(display);

String frame = config.getString("frame_type");
if (frame == null) {
frame = "GOAL";
}
builder.frame(frame);

String advname = config.getString("name");
if (advname == null) {
advname = key;
Expand Down Expand Up @@ -136,6 +143,11 @@ public AdvancementBuilder display(ItemStack display) {
return this;
}

public AdvancementBuilder frame(String frame) {
this.frame = frame;
return this;
}

public AdvancementBuilder name(String name) {
this.name = name;
return this;
Expand All @@ -161,7 +173,7 @@ public void register() {
criterion.setAdvancement(key);
criterion.register();
}
Advancement adv = new Advancement(key, parent, group, display, name, hidden, criteria.toArray(new Criterion[0]), rewards.toArray(new Reward[0]));
Advancement adv = new Advancement(key, parent, group, display, name, frame, hidden, criteria.toArray(new Criterion[0]), rewards.toArray(new Reward[0]));
adv.register();
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/char321/sfadvancements/api/AdvancementGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class AdvancementGroup {
private final ItemStack display;
private final String frameType;
private List<Advancement> advancements = new ArrayList<>();
private String id;
private String background;
Expand All @@ -20,9 +21,14 @@ public AdvancementGroup(String id, ItemStack display) {
}

public AdvancementGroup(String id, ItemStack display, String background) {
this(id, display, "GOAL", background);
}

public AdvancementGroup(String id, ItemStack display, String frameType, String background) {
this.id = id;
this.background = background;
this.display = display;
this.frameType = frameType;
}

public void register() {
Expand All @@ -33,6 +39,10 @@ public ItemStack getDisplayItem() {
return display;
}

public String getFrameType() {
return frameType;
}

/**
* gets an immutable view of the advancements
* @return list of all advancements in this group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.roxeez.advancement.AdvancementManager;
import net.roxeez.advancement.display.FrameType;
import net.roxeez.advancement.display.Icon;
import net.roxeez.advancement.trigger.TriggerType;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -67,6 +68,7 @@ private static void registerGroups(AdvancementManager manager) {
}
display.setDescription(String.join("\n", lore));
display.setIcon(new Icon(item));
display.setFrame(FrameType.valueOf(group.getFrameType()));
display.setBackground(NamespacedKey.minecraft("textures/block/" + background.toLowerCase() + ".png"));
display.setAnnounce(false);
});
Expand Down Expand Up @@ -116,6 +118,7 @@ private static void registerAdvancement(AdvancementManager manager, Advancement
display.setTitle(title);
display.setDescription(description);
display.setIcon(new Icon(item));
display.setFrame(FrameType.valueOf(advancement.getFrameType()));
display.setHidden(advancement.isHidden());
display.setAnnounce(false);
});
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/advancements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ portable_workbench:
name: "&aPortable Crafting"
lore:
- "Use a portable crafting table"
frame_type: GOAL
name: "&a[Portable Crafting]"
criteria:
interact:
Expand All @@ -24,6 +25,7 @@ dust:
name: "&aInto dust it turns"
lore:
- "Crush an ore using an ore crusher"
frame_type: TASK
name: "&a[Into dust it turns]"
criteria:
inventory:
Expand Down Expand Up @@ -136,6 +138,7 @@ carbonado:
name: "&aShiny darkness"
lore:
- "Create a carbonado diamond"
frame_type: CHALLENGER
name: "&a[Shiny darkness]"
criteria:
carbonado:
Expand Down
Loading