frengor / UltimateAdvancementAPI

A powerful API to create custom advancements for your Minecraft server.
https://modrinth.com/plugin/ultimateadvancementapi
GNU General Public License v3.0
75 stars 5 forks source link

Add an onRevoke method to Advancement class #59

Open Fusezion opened 5 months ago

Fusezion commented 5 months ago

I'll try to make this as clear as I can. Add an onRevoke method that is called when you use any of the Advancement#revoke() methods. Currently there's onGrant but no way to revert what it does when `revoke is called. This prevents servers from more accurately handling specific cases for grant.

frengor commented 5 months ago

We don't think this is currently possible to implement. To start, it is not clear when onRevoke should be called:

  1. when the progression is no longer the maxProgression;
  2. when the progression is no longer the maxProgression but the onGrant method has already been called (due to unredeemed advancements onGrant might not be called immediately at the time the advancement was completed);
  3. when the progression reaches 0 after the progression had reached maxProgression;
  4. when the progression reaches 0 after the progression had reached maxProgression and the onGrant method has already been called.

Note that the revoke(player) method is just a shortcut for setProgression(player, 0, false).

Every of the four options previously mentioned has its own challenges:

  1. onRevoke might get called before onGrant (due to unredeemed advancements) and implementations of onRevoke should deal with it;
  2. we should record whether onGrant has already been executed in the db, which poses issues regarding synchronization;
  3. we should record the fact that the progression reached the maxProgression in the db and then check whether it reached zero, plus the issue of point 1;
  4. basically the same problems of points 2 and 3.