File tree Expand file tree Collapse file tree
src/main/java/net/earthmc/emcapi Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments