Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package io.papermc.paper.event.player;

import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

/**
* An event fired when a {@link Player} has an advancement revoked.
* If cancelled the criteria will be granted.
*/
@NullMarked
public final class PlayerAdvancementCriterionRevokeEvent extends PlayerEvent implements Cancellable {

private static final HandlerList HANDLER_LIST = new HandlerList();

private final Advancement advancement;
private final String criterion;
private final AdvancementProgress advancementProgress;

private boolean cancelled;

@ApiStatus.Internal
public PlayerAdvancementCriterionRevokeEvent(final Player player, final Advancement advancement, final String criterion) {
super(player);
this.advancement = advancement;
this.criterion = criterion;
this.advancementProgress = player.getAdvancementProgress(advancement);
}

/**
* Get the advancement which has been affected.
*
* @return affected advancement
*/
public Advancement getAdvancement() {
return this.advancement;
}

/**
* Get the criterion which has been revoked.
*
* @return revoked criterion
*/
public String getCriterion() {
return this.criterion;
}

/**
* Gets the current AdvancementProgress.
*
* @return advancement progress
*/
public AdvancementProgress getAdvancementProgress() {
return this.advancementProgress;
}

public boolean isCancelled() {
return this.cancelled;
}

public void setCancelled(final boolean cancel) {
this.cancelled = cancel;
}

@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.papermc.paper.event.player;

import org.bukkit.advancement.Advancement;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

/**
* An event fired when a {@link Player} has an advancement revoked.
*/
@NullMarked
public final class PlayerAdvancementRevokeEvent extends PlayerEvent implements Cancellable {

private static final HandlerList HANDLER_LIST = new HandlerList();

private final Advancement advancement;

private boolean cancelled;

@ApiStatus.Internal
public PlayerAdvancementRevokeEvent(final Player player, final Advancement advancement) {
super(player);
this.advancement = advancement;
}

/**
* Get the advancement which has been revoked.
*
* @return revoked advancement
*/
public Advancement getAdvancement() {
return this.advancement;
}

public boolean isCancelled() {
return this.cancelled;
}

public void setCancelled(final boolean cancel) {
this.cancelled = cancel;
}

@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@
}
});
}
@@ -193,10 +_,28 @@
boolean result = false;
AdvancementProgress progress = this.getOrStartProgress(advancement);
boolean wasDone = progress.isDone();
+
if (progress.revokeProgress(criterion)) {
+ // Paper start - Add PlayerAdvancementCriterionRevokeEvent
+ if (!new io.papermc.paper.event.player.PlayerAdvancementCriterionRevokeEvent(this.player.getBukkitEntity(), advancement.toBukkit(), criterion).callEvent()) {
+ progress.grantProgress(criterion);
+ return false;
+ }
+ // Paper end - Add PlayerAdvancementCriterionRevokeEvent
+
this.registerListeners(advancement);
this.progressChanged.add(advancement);
result = true;
+
+ if (wasDone && !progress.isDone()) {
+ // Paper start - Add PlayerAdvancementRevokeEvent
+ final io.papermc.paper.event.player.PlayerAdvancementRevokeEvent event = new io.papermc.paper.event.player.PlayerAdvancementRevokeEvent(this.player.getBukkitEntity(), advancement.toBukkit());
+ if (!event.callEvent()) {
+ progress.grantProgress(criterion);
+ return false;
+ }
+ // Paper end - Add PlayerAdvancementRevokeEvent
Comment on lines +78 to +85

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay i check this... not sure about a good case for cancel (the Done event not has that because for this its better handle criterion rather than the whole "advancement)
and when test this event its not fired in the final of the criterion remove not sure if that is the correct behaviour....

@FlowerDevelops FlowerDevelops Nov 2, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you change it already? (I'm sorry, but I didn't understand what you said). I think it's best if you change it since you know what you mean?

@FlowerDevelops FlowerDevelops Nov 2, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Feel free to change up my code xD)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already change (you need pull the changes)
Can be good if you can check the thing about the advancement revoke

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see tomorrow, I have homework and am tired 🫡

+ }
Comment thread
FlowerDevelops marked this conversation as resolved.
Resolved
}

if (wasDone && !progress.isDone()) {
@@ -239,7 +_,7 @@
public void flushDirty(final ServerPlayer player, final boolean showAdvancements) {
if (this.isFirstPacket || !this.rootsToUpdate.isEmpty() || !this.progressChanged.isEmpty()) {
Expand Down
Loading