Skip to content

Commit

Permalink
Fixed multiple players for event flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ImDaMilan committed Jan 27, 2023
1 parent 5e945d1 commit 8144d02
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.plugin.Plugin;

import java.util.HashMap;
import java.util.function.Consumer;

/**
Expand All @@ -17,8 +18,7 @@
*/
public class PlayerEventFlowCallback<T extends PlayerEvent, K extends PlayerEvent> implements Listener {

private Player player;
private boolean done;
private final HashMap<Player, Boolean> map = new HashMap<>();
private Consumer<T> firstEvent;
private Consumer<K> secondEvent;

Expand Down Expand Up @@ -54,14 +54,15 @@ public PlayerEventFlowCallback<T, K> then(Consumer<K> event) {
public void onEvent(T event) {
firstEvent.accept(event);
Player player = event.getPlayer();
this.done = true;
map.put(player, true);
}

@EventHandler
public void onSecondEvent(K event) {
if (done) {
if (event.getPlayer().getUniqueId().equals(player.getUniqueId())) {
if (map.getOrDefault(event.getPlayer(), false)) {
if (map.containsKey(event.getPlayer())) {
secondEvent.accept(event);
map.remove(event.getPlayer());
}
}
}
Expand Down

0 comments on commit 8144d02

Please sign in to comment.