-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathMatchImpl.java
More file actions
110 lines (90 loc) · 2.91 KB
/
Copy pathMatchImpl.java
File metadata and controls
110 lines (90 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package me.realized.duels.arena;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.Getter;
import me.realized.duels.api.match.Match;
import me.realized.duels.kit.KitImpl;
import me.realized.duels.queue.Queue;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class MatchImpl implements Match {
@Getter
private final ArenaImpl arena;
@Getter
private final long start;
@Getter
private final KitImpl kit;
private final Map<UUID, List<ItemStack>> items;
@Getter
private final double bet;
@Getter
private final Queue source;
@Getter
private boolean finished;
// Default value for players is false, which is set to true if player is killed in the match.
private final Map<Player, Boolean> players = new HashMap<>();
MatchImpl(final ArenaImpl arena, final KitImpl kit, final Map<UUID, List<ItemStack>> items, final double bet, final Queue source) {
this.arena = arena;
this.start = System.currentTimeMillis();
this.kit = kit;
this.items = items;
this.bet = bet;
this.source = source;
}
Map<Player, Boolean> getPlayerMap() {
return players;
}
Set<Player> getAlivePlayers() {
return players.entrySet().stream().filter(entry -> !entry.getValue()).map(Entry::getKey).collect(Collectors.toSet());
}
public Set<Player> getAllPlayers() {
return players.keySet();
}
public boolean isDead(final Player player) {
return players.getOrDefault(player, true);
}
public boolean isFromQueue() {
return source != null;
}
public boolean isOwnInventory() {
return kit == null;
}
public List<ItemStack> getItems() {
return items != null ? items.values().stream().flatMap(Collection::stream).collect(Collectors.toList()) : Collections.emptyList();
}
void setFinished() {
finished = true;
}
public long getDurationInMillis() {
return System.currentTimeMillis() - start;
}
@NotNull
@Override
public List<ItemStack> getItems(@NotNull final Player player) {
Objects.requireNonNull(player, "player");
if (this.items == null) {
return Collections.emptyList();
}
final List<ItemStack> items = this.items.get(player.getUniqueId());
return items != null ? items : Collections.emptyList();
}
@NotNull
@Override
public Set<Player> getPlayers() {
return Collections.unmodifiableSet(getAlivePlayers());
}
@NotNull
@Override
public Set<Player> getStartingPlayers() {
return Collections.unmodifiableSet(getAllPlayers());
}
}