Skip to content

Commit

Permalink
fix(event): 采用新Event唤起方式
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmJos committed Jul 1, 2022
1 parent 2beefb7 commit cbd2a43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.function.Consumer;

public class UserPrefixChangeEvent extends UserPrefixEvent implements Cancellable {
Expand Down Expand Up @@ -61,11 +61,8 @@ public static void call(@NotNull Player who,
@Nullable PrefixConfig before,
@NotNull PrefixConfig after,
@Nullable Consumer<@Nullable PrefixConfig> finish) {
Main.getInstance().getScheduler().run(() -> {
UserPrefixChangeEvent event = new UserPrefixChangeEvent(who, before, after);
Bukkit.getPluginManager().callEvent(event);
if (finish != null) finish.accept(event.isCancelled() ? null : event.getAfter());
});
Main.getInstance().callSync(new UserPrefixChangeEvent(who, before, after))
.thenAccept((e) -> Optional.ofNullable(finish).ifPresent(f -> f.accept(e.getAfter())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public HandlerList getHandlers() {
}

public static void call(@NotNull Player player, @NotNull PrefixConfig currentPrefix) {
Main.getInstance().callEventSync(new UserPrefixExpireEvent(player, currentPrefix));
Main.getInstance().callSync(new UserPrefixExpireEvent(player, currentPrefix));
}

}

0 comments on commit cbd2a43

Please sign in to comment.