This repository was archived by the owner on Nov 25, 2019. It is now read-only.
forked from OvercastNetwork/ProjectAres
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathAutoJoinMatchModule.java
More file actions
81 lines (64 loc) · 2.5 KB
/
AutoJoinMatchModule.java
File metadata and controls
81 lines (64 loc) · 2.5 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
package tc.oc.pgm.autojoin;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Stream;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import tc.oc.commons.bukkit.settings.SettingManagerProvider;
import tc.oc.pgm.events.ListenerScope;
import tc.oc.pgm.events.PlayerChangePartyEvent;
import tc.oc.pgm.join.JoinMatchModule;
import tc.oc.pgm.join.JoinMethod;
import tc.oc.pgm.match.MatchModule;
import tc.oc.pgm.match.MatchPlayer;
import tc.oc.pgm.match.MatchScope;
import javax.inject.Inject;
/**
* New join feature that allows players to join without interfacing with GUI
* with an AutoJoinSetting that allows players to use the legacy join feature
* instead.
*/
@ListenerScope(MatchScope.LOADED)
public class AutoJoinMatchModule extends MatchModule implements Listener {
private Set<MatchPlayer> joiningPlayers;
private final SettingManagerProvider settingManagerProvider;
private final JoinMatchModule joinMatchModule;
@Inject public AutoJoinMatchModule(SettingManagerProvider settingManagerProvider, JoinMatchModule joinMatchModule) {
this.joiningPlayers = new LinkedHashSet<>();
this.settingManagerProvider = settingManagerProvider;
this.joinMatchModule = joinMatchModule;
}
@Override
public void disable() {
joiningPlayers.clear();
}
@EventHandler(priority = EventPriority.MONITOR)
public void playerJoin(final PlayerChangePartyEvent event) {
MatchPlayer player = event.getPlayer();
if(match.hasStarted()) return;
if(event.getNewParty() == null) {
joiningPlayers.remove(player);
return;
}
if(event.getNewParty().isParticipatingType()) return;
if(joiningPlayers.contains(player)) return;
if(!settingManagerProvider.getManager(player.getBukkit()).getValue(AutoJoinSetting.get(), Boolean.class, true)) return;
joiningPlayers.add(player);
}
public boolean shouldAutoJoin(MatchPlayer player) {
return joiningPlayers.contains(player);
}
public void cancelAutojoin(MatchPlayer player) {
joiningPlayers.remove(player);
}
public void requestJoin(MatchPlayer player) {
joinMatchModule.requestJoin(player, JoinMethod.USER);
}
public void enterAllPlayers() {
if(!joiningPlayers.isEmpty()) joiningPlayers.forEach(this::requestJoin);
}
public Stream<MatchPlayer> joiningPlayers() {
return joiningPlayers.stream();
}
}