aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/chat/PartyContext.java
blob: 87d1a264c9589e5190f0b6f26914e9d422989aa5 (plain)
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
/*
 * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
 * Copyright (C) 2021  cyoung06
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package kr.syeyoung.dungeonsguide.chat;

import lombok.Data;
import net.minecraft.client.Minecraft;

import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;


@Data
public class PartyContext {
    private String partyID;

    private String partyOwner;
    private Set<String> partyModerator; private boolean isModeratorComplete;
    private Set<String> partyMember; private boolean isMemberComplete;

    private Set<String> partyRawMembers = new HashSet<>(); private boolean isRawMemberComplete;

    private Boolean allInvite;

    private boolean partyExistHypixel = true;

    public void setPartyOwner(String partyOwner) {
            this.partyOwner = partyOwner;
            if (partyMember != null) partyMember.remove(partyOwner);
            if (partyModerator != null) partyModerator.remove(partyOwner);
            addRawMember(partyOwner);
    }
    public void addPartyModerator(String partyModerator) {
        if (partyModerator.equalsIgnoreCase(partyOwner)) partyOwner = null;
        if (partyMember != null) partyMember.remove(partyModerator);

        if (this.partyModerator == null) this.partyModerator = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        this.partyModerator.add(partyModerator);
        addRawMember(partyModerator);
    }
    public void addPartyMember(String partyMember) {
        if (partyMember.equalsIgnoreCase(partyOwner)) partyOwner = null;
        if (partyModerator != null) partyModerator.remove(partyMember);

        if (this.partyMember == null) this.partyMember = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        this.partyMember.add(partyMember);
        addRawMember(partyMember);
    }
    public void addRawMember(String partyMember){
        partyRawMembers.add(partyMember);
    }
    public void removeFromParty(String username) {
        if (username.equalsIgnoreCase(partyOwner)) {
            partyOwner = null;
        }
        if (partyModerator != null) partyModerator.remove(username);
        if (partyMember != null) partyMember.remove(username);
        partyRawMembers.remove(username);
    }
    
    public boolean hasModerator(String username) {
        return partyModerator != null && partyModerator.contains(username);
    }
    public boolean hasMember(String username) {
        return partyMember != null && partyMember.contains(username);
    }
    public boolean hasLeader(String username) {
        return username.equalsIgnoreCase(partyOwner);
    }
    public boolean isSelfSolo() {
        return hasLeader(Minecraft.getMinecraft().getSession().getUsername()) && getPartyRawMembers().size() == 1;
    }
}