Skip to content

Commit 796017d

Browse files
committed
3. Add advancements endpoint
1 parent ca5ad2c commit 796017d

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.earthmc.emcapi.endpoint;
2+
3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonObject;
5+
import net.earthmc.emcapi.integration.AdvancementsIntegration;
6+
import net.earthmc.emcapi.integration.Integrations;
7+
import net.earthmc.emcapi.object.endpoint.GetEndpoint;
8+
import net.earthmc.lynchpin.api.advancements.AdvancementEntry;
9+
10+
import java.text.SimpleDateFormat;
11+
12+
public class AdvancementsEndpoint extends GetEndpoint {
13+
private final AdvancementsIntegration integration;
14+
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
15+
16+
public AdvancementsEndpoint() {
17+
integration = Integrations.getIntegration("lynchpin-advancements");
18+
}
19+
20+
@Override
21+
public JsonElement getJsonElement() {
22+
JsonObject outer = new JsonObject();
23+
for (AdvancementEntry entry : integration.getAdvancements()) {
24+
JsonObject json = new JsonObject();
25+
json.addProperty("player", entry.player().toString());
26+
json.addProperty("date", formatter.format(entry.date()));
27+
28+
outer.add(entry.advancement(), json);
29+
}
30+
31+
return outer;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.earthmc.emcapi.integration;
2+
3+
import net.earthmc.lynchpin.api.advancements.AdvancementEntry;
4+
import net.earthmc.lynchpin.api.advancements.AdvancementsProvider;
5+
6+
import java.util.Set;
7+
8+
public class AdvancementsIntegration extends Integration {
9+
private AdvancementsProvider module;
10+
11+
public AdvancementsIntegration() {
12+
super("Lynchpin");
13+
try {
14+
module = AdvancementsProvider.instance();
15+
} catch (Exception ignored) {
16+
plugin.getLogger().warning("Not loading advancements integration due to the module not being present/enabled");
17+
}
18+
}
19+
20+
@Override
21+
public boolean isEnabled() {
22+
return super.isEnabled() && module != null && module.isEnabled();
23+
}
24+
25+
@Override
26+
public void register() {
27+
Integrations.addIntegration("lynchpin-advancements", this);
28+
}
29+
30+
public Set<AdvancementEntry> getAdvancements() {
31+
return module.getAdvancements();
32+
}
33+
}

0 commit comments

Comments
 (0)