RuneHive-Game
Loading...
Searching...
No Matches
ClanMember.java
Go to the documentation of this file.
1package com.runehive.content.clanchannel;
2
3import com.runehive.content.clanchannel.channel.ClanChannel;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.entity.mob.player.relations.PrivacyChatMode;
6import com.runehive.net.packet.out.SendClanDetails;
7
8import java.util.Objects;
9import java.util.Optional;
10
11/**
12 * Handles the clan channel member.
13 *
14 * @author Daniel
15 * @author Michael
16 */
17public class ClanMember {
18 /** The name of the clan member. */
19 public final String name;
20
21 /** The rank of the clan member. */
22 public ClanRank rank;
23
24 /** The total level of the clan member. */
25 public int totalLevel;
26
27 /** The join date of the clan member. */
28 public String joined;
29
30 /** The experienced gained by the clan member. */
31 public double expGained;
32
33 /** The npcs killed by the clan member. */
34 public int npcKills;
35
36 /** The players killed by the clan member. */
37 public int playerKills;
38
39 /** The player instance of the clan member . */
40 public Optional<Player> player;
41
42 /** Constructs a new <code>ClanMember</code>. */
43 public ClanMember(String name) {
44 this.name = name;
45 this.rank = ClanRank.MEMBER;
46 this.player = Optional.empty();
47 }
48
49 /** Constructs a new <code>ClanMember</code>. */
51 this.name = player.getName();
52 this.player = Optional.of(player);
53 this.rank = ClanRank.MEMBER;
54 }
55
56 /** Handles messaging the clan member. */
57 public void message(Object... messages) {
58 player.ifPresent(p -> {
59 ClanChannel channel = p.clanChannel;
60 for (Object message : messages) {
61 p.send(new SendClanDetails(String.valueOf(message), channel.getName(), ClanRank.SYSTEM));
62 }
63 });
64 }
65
66 /** Handles messaging the clan member. */
67 public void chat(ClanMember speaker, Object message) {
68 player.ifPresent(p -> {
69 final ClanChannel channel = p.clanChannel;
70
71 final Optional<Player> result = speaker.player;
72
73 if (!result.isPresent()) {
74 return;
75 }
76
77 final Player playerTalking = result.get();
78
79 if (p.relations.getClanChatMode() == PrivacyChatMode.OFF
80 || p.relations.getClanChatMode() == PrivacyChatMode.FRIENDS_ONLY && !p.relations.isFriendWith(playerTalking.getName())) {
81 return;
82 }
83
84 p.send(new SendClanDetails(speaker.name, String.valueOf(message), channel.getName(), speaker.rank));
85 });
86 }
87
88 /** Gets the value of the clan member based on their contribution. */
89 public int getValue() {
90 return (int) expGained;
91 }
92
93 public boolean hasContributed() {
94 return !(npcKills == 0 && expGained == 0 && playerKills == 0);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (obj == this) return true;
100 if (obj instanceof ClanMember) {
101 ClanMember other = (ClanMember) obj;
102 return Objects.equals(name, other.name)
103 && Objects.equals(rank, other.rank)
104 && Objects.equals(totalLevel, other.totalLevel)
105 && Objects.equals(joined, other.joined)
106 && Objects.equals(expGained, other.expGained)
107 && Objects.equals(npcKills, other.npcKills)
108 && Objects.equals(playerKills, other.playerKills);
109 }
110 return false;
111 }
112
113 @Override
114 public int hashCode() {
115 return name.hashCode();
116 }
117
118 @Override
119 public String toString() {
120 return name + " " + rank;
121 }
122
123}
ClanRank rank
The rank of the clan member.
int playerKills
The players killed by the clan member.
void message(Object... messages)
Handles messaging the clan member.
int getValue()
Gets the value of the clan member based on their contribution.
Optional< Player > player
The player instance of the clan member .
void chat(ClanMember speaker, Object message)
Handles messaging the clan member.
ClanMember(String name)
Constructs a new ClanMember.
final String name
The name of the clan member.
double expGained
The experienced gained by the clan member.
int totalLevel
The total level of the clan member.
String joined
The join date of the clan member.
int npcKills
The npcs killed by the clan member.
ClanMember(Player player)
Constructs a new ClanMember.
This class represents a character controlled by a player.
Definition Player.java:125
String getName()
Gets the name of this entity.
Definition Player.java:774
The enum containing all the rank's data within a clan channel.
Definition ClanRank.java:8