forked from Solara-Development/Neptune
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchService.java
More file actions
148 lines (124 loc) · 5.2 KB
/
MatchService.java
File metadata and controls
148 lines (124 loc) · 5.2 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package dev.lrxh.neptune.game.match;
import dev.lrxh.api.events.MatchReadyEvent;
import dev.lrxh.api.match.IMatch;
import dev.lrxh.api.match.IMatchService;
import dev.lrxh.api.match.participant.IParticipant;
import dev.lrxh.neptune.API;
import dev.lrxh.neptune.Neptune;
import dev.lrxh.neptune.game.arena.ArenaService;
import dev.lrxh.neptune.game.arena.VirtualArena;
import dev.lrxh.neptune.game.kit.Kit;
import dev.lrxh.neptune.game.kit.KitService;
import dev.lrxh.neptune.game.match.impl.ffa.FfaFightMatch;
import dev.lrxh.neptune.game.match.impl.participant.Participant;
import dev.lrxh.neptune.game.match.impl.participant.ParticipantColor;
import dev.lrxh.neptune.game.match.impl.solo.SoloFightMatch;
import dev.lrxh.neptune.game.match.impl.team.MatchTeam;
import dev.lrxh.neptune.game.match.impl.team.TeamFightMatch;
import dev.lrxh.neptune.game.match.tasks.MatchStartRunnable;
import dev.lrxh.neptune.profile.impl.Profile;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.*;
public class MatchService implements IMatchService {
private static MatchService instance;
public final HashSet<Match> matches = new HashSet<>();
public static MatchService get() {
if (instance == null) instance = new MatchService();
return instance;
}
public void startMatch(Participant playerRed, Participant playerBlue, Kit kit, VirtualArena arena, boolean duel, int rounds) {
if (!Neptune.get().isAllowMatches()) return;
kit.addPlaying();
kit.addPlaying();
playerRed.setOpponent(playerBlue);
playerRed.setColor(ParticipantColor.RED);
playerBlue.setOpponent(playerRed);
playerBlue.setColor(ParticipantColor.BLUE);
SoloFightMatch match = new SoloFightMatch(arena, kit, duel, Arrays.asList(playerRed, playerBlue), playerRed, playerBlue, rounds);
playerRed.setMatch(match);
playerBlue.setMatch(match);
MatchReadyEvent event = new MatchReadyEvent(match);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
matches.add(match);
new MatchStartRunnable(match).start(0L, 20L);
}
public void startMatch(MatchTeam teamA, MatchTeam teamB, Kit kit, VirtualArena arena) {
if (!Neptune.get().isAllowMatches()) return;
for (Participant participant : teamA.participants()) {
for (Participant opponent : teamB.participants()) {
participant.setOpponent(opponent);
participant.setColor(ParticipantColor.RED);
opponent.setOpponent(participant);
opponent.setColor(ParticipantColor.BLUE);
}
}
List<Participant> participants = new ArrayList<>(teamA.participants());
participants.addAll(teamB.participants());
TeamFightMatch match = new TeamFightMatch(arena, kit, participants, teamA, teamB);
for (Participant participant : participants) {
participant.setMatch(match);
}
MatchReadyEvent event = new MatchReadyEvent(match);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
matches.add(match);
new MatchStartRunnable(match).start(0L, 20L);
}
public void startMatch(List<Participant> participants, Kit kit, VirtualArena arena) {
if (!Neptune.get().isAllowMatches()) return;
for (Participant participant : participants) {
participant.setColor(ParticipantColor.RED);
}
FfaFightMatch match = new FfaFightMatch(arena, kit, participants);
MatchReadyEvent event = new MatchReadyEvent(match);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
matches.add(match);
new MatchStartRunnable(match).start(0L, 20L);
}
@Override
public void startMatch(IMatch match, Player redPlayer, Player bluePlayer) {
if (!Neptune.get().isAllowMatches()) return;
MatchReadyEvent event = new MatchReadyEvent(match);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
ArenaService.get().copyFrom(match.getArena()).createDuplicate().thenAccept(virtualArena ->{
Match neptuneMatch = new SoloFightMatch(
virtualArena,
KitService.get().copyFrom(match.getKit()),
true,
new ArrayList<>(),
new Participant(redPlayer),
new Participant(bluePlayer),
1
);
matches.add(neptuneMatch);
new MatchStartRunnable(neptuneMatch).start(0L, 20L);
});
}
public Optional<Match> getMatch(Player player) {
Profile profile = API.getProfile(player);
return Optional.ofNullable(profile)
.map(Profile::getMatch);
}
public Optional<Match> getMatch(UUID uuid) {
Profile profile = API.getProfile(uuid);
return Optional.ofNullable(profile)
.map(Profile::getMatch);
}
public void stopAllGames() {
for (Match match : matches) {
match.resetArena();
}
}
}