Skip to content

Commit 3444a52

Browse files
committed
Add Javadocs
1 parent b49c613 commit 3444a52

File tree

4 files changed

+162
-6
lines changed

4 files changed

+162
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
package net.citizensnpcs.trait.scoreboard;
22

3+
/**
4+
* Represents a scoreboard that can be used to manage teams and their entries.
5+
* This is an abstraction over the underlying {@link org.bukkit.scoreboard.Scoreboard} and
6+
* {@link net.megavex.scoreboardlibrary.api.team.ScoreboardTeam} objects.
7+
*/
38
public interface AbstractScoreboard {
49

10+
/**
11+
* Gets a team by name.
12+
* @param name Name of the team.
13+
* @return Team with the given name, or null if no such team exists.
14+
*/
515
AbstractTeam getTeam(String name);
616

17+
/**
18+
* Deletes a team from this scoreboard.
19+
* @param name Name of the team.
20+
*/
721
void removeTeam(String name);
822

23+
24+
/**
25+
* Creates a new team if it does not exist.
26+
* @param name Name of the team.
27+
* @return Team with the given name, or the existing team if it already exists.
28+
*/
929
AbstractTeam createTeam(String name);
1030
}

main/src/main/java/net/citizensnpcs/trait/scoreboard/AbstractTeam.java

Lines changed: 136 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,145 @@
55
import org.bukkit.entity.Player;
66
import org.bukkit.scoreboard.Team;
77

8+
9+
/**
10+
* Represents a team that can be used to manage entries and their display properties.
11+
* This is an abstraction over the underlying {@link Team} and {@link net.megavex.scoreboardlibrary.api.team.ScoreboardTeam} objects.
12+
* Entries can be either player display names (usernames) or entity UUIDs represented as strings.
13+
*/
814
public interface AbstractTeam {
915

16+
/**
17+
* Adds an entry to the team.
18+
* For players, this should be their display name (username).
19+
* For entities, this should be their UUID represented as a string.
20+
*
21+
* @param entry Entry to add.
22+
*/
1023
void addEntry(String entry);
1124

25+
/**
26+
* Checks if the team has an entry.
27+
* For players, this should be their display name (username).
28+
* For entities, this should be their UUID represented as a string.
29+
*
30+
* @param entry Entry to check.
31+
* @return True if the team has the entry, false otherwise.
32+
*/
1233
boolean hasEntry(String entry);
1334

35+
/**
36+
* Removes an entry from the team.
37+
* For players, this should be their display name (username).
38+
* For entities, this should be their UUID represented as a string.
39+
*
40+
* @param entry Entry to remove.
41+
*/
1442
void removeEntry(String entry);
1543

44+
/**
45+
* Gets the color of the team.
46+
* @return The color of the team.
47+
*/
1648
ChatColor getColor();
1749

50+
/**
51+
* Gets the name tag visibility of the team.
52+
* @return The name tag visibility of the team.
53+
*/
1854
NameTags getNameTagVisibility();
1955

56+
/**
57+
* Gets the collision rule of the team.
58+
* @return The collision rule of the team.
59+
*/
2060
CollisionRule getCollisionRule();
2161

62+
/**
63+
* Sets the color of the team.
64+
* @param color The color of the team.
65+
*/
2266
void setColor(ChatColor color);
2367

68+
/**
69+
* Sets the name tag visibility of the team.
70+
* @param visibility The name tag visibility of the team.
71+
*/
2472
void setNameTagVisibility(NameTags visibility);
2573

74+
/**
75+
* Sets the collision rule of the team.
76+
* @param rule The collision rule of the team.
77+
*/
2678
void setCollisionRule(CollisionRule rule);
2779

80+
/**
81+
* Gets the underlying delegate object.
82+
* This may either be a {@link Team} or {@link net.megavex.scoreboardlibrary.api.team.ScoreboardTeam}
83+
* @return The underlying delegate object.
84+
*/
2885
Object getDelegate();
2986

87+
/**
88+
* Gets the name of the team.
89+
* @return The name of the team.
90+
*/
3091
String getName();
3192

93+
/**
94+
* Sends the team to a player.
95+
* @param player Player to send to.
96+
* @param mode Send mode.
97+
*/
3298
void sendToPlayer(Player player, SendMode mode);
3399

100+
/**
101+
* Gets the number of entries in the team.
102+
* @return The number of entries in the team.
103+
*/
34104
int getSize();
35105

36106

107+
/**
108+
* Interface for team options that can be represented as both a packet-based value and a Bukkit value.
109+
* @param <P> Packet-based (folia) value type.
110+
*/
37111
interface TeamOption<P> {
112+
113+
/**
114+
* Gets the packet-based (folia) value of this option.
115+
* @return The packet-based (folia) value of this option.
116+
*/
38117
P getFoliaValue();
118+
119+
/**
120+
* Gets the Bukkit value of this option.
121+
* @return The Bukkit value of this option.
122+
*/
39123
Team.OptionStatus getBukkitValue();
40124

41-
static <E extends TeamOption<P>, P> E fromPacket(E[] values, P packetValue) {
125+
/**
126+
* Utility method to convert from a packet-based (folia) value to the corresponding enum constant.
127+
* @param values Array of enum constants.
128+
* @param foliaValue Packet-based (folia) value to convert.
129+
* @return The corresponding enum constant.
130+
* @param <E> Enum type.
131+
* @param <P> Packet-based (folia) value type.
132+
*/
133+
static <E extends TeamOption<P>, P> E fromFolia(E[] values, P foliaValue) {
42134
for (E e : values) {
43-
if (e.getFoliaValue().equals(packetValue)) return e;
135+
if (e.getFoliaValue().equals(foliaValue)) return e;
44136
}
45137
return values[0];
46138
}
47139

140+
/**
141+
* Utility method to convert from a Bukkit value to the corresponding enum constant.
142+
* @param values Array of enum constants.
143+
* @param bukkitValue Bukkit value to convert.
144+
* @return The corresponding enum constant.
145+
* @param <E> Enum type.
146+
*/
48147
static <E extends TeamOption<?>> E fromBukkit(E[] values, Team.OptionStatus bukkitValue) {
49148
for (E e : values) {
50149
if (e.getBukkitValue() == bukkitValue) return e;
@@ -53,6 +152,9 @@ static <E extends TeamOption<?>> E fromBukkit(E[] values, Team.OptionStatus bukk
53152
}
54153
}
55154

155+
/**
156+
* Enum representing name tag visibility options.
157+
*/
56158
enum NameTags implements TeamOption<NameTagVisibility> {
57159
ALWAYS_SHOW(NameTagVisibility.ALWAYS, Team.OptionStatus.ALWAYS),
58160
NEVER_SHOW(NameTagVisibility.NEVER, Team.OptionStatus.NEVER),
@@ -67,26 +169,41 @@ enum NameTags implements TeamOption<NameTagVisibility> {
67169
this.bukkitValue = bukkitValue;
68170
}
69171

172+
/**
173+
* {@inheritDoc}
174+
*/
70175
@Override
71176
public NameTagVisibility getFoliaValue() {
72177
return packetBasedValue;
73178
}
74179

180+
/**
181+
* {@inheritDoc}
182+
*/
75183
@Override
76184
public Team.OptionStatus getBukkitValue() {
77185
return bukkitValue;
78186
}
79187

188+
/**
189+
* @see #fromPacket(NameTagVisibility)
190+
*/
80191
public static NameTags fromPacket(NameTagVisibility value) {
81-
return TeamOption.fromPacket(values(), value);
192+
return TeamOption.fromFolia(values(), value);
82193
}
83194

195+
/**
196+
* @see #fromBukkit(Team.OptionStatus)
197+
*/
84198
public static NameTags fromBukkit(Team.OptionStatus value) {
85199
return TeamOption.fromBukkit(values(), value);
86200
}
87201
}
88202

89203

204+
/**
205+
* Enum representing collision rule options.
206+
*/
90207
enum CollisionRule implements TeamOption<net.megavex.scoreboardlibrary.api.team.enums.CollisionRule> {
91208
ALWAYS(net.megavex.scoreboardlibrary.api.team.enums.CollisionRule.ALWAYS, Team.OptionStatus.ALWAYS),
92209
NEVER(net.megavex.scoreboardlibrary.api.team.enums.CollisionRule.NEVER, Team.OptionStatus.NEVER),
@@ -101,25 +218,40 @@ enum CollisionRule implements TeamOption<net.megavex.scoreboardlibrary.api.team.
101218
this.bukkitValue = bukkitValue;
102219
}
103220

221+
/**
222+
* {@inheritDoc}
223+
*/
104224
@Override
105225
public net.megavex.scoreboardlibrary.api.team.enums.CollisionRule getFoliaValue() {
106226
return packetBasedValue;
107227
}
108228

229+
/**
230+
* {@inheritDoc}
231+
*/
109232
@Override
110233
public Team.OptionStatus getBukkitValue() {
111234
return bukkitValue;
112235
}
113236

237+
/**
238+
* @see #fromBukkit(Team.OptionStatus)
239+
*/
114240
public static CollisionRule fromPacket(net.megavex.scoreboardlibrary.api.team.enums.CollisionRule value) {
115-
return TeamOption.fromPacket(values(), value);
241+
return TeamOption.fromFolia(values(), value);
116242
}
117243

244+
/**
245+
* @see #fromBukkit(Team.OptionStatus)
246+
*/
118247
public static CollisionRule fromBukkit(Team.OptionStatus value) {
119248
return TeamOption.fromBukkit(values(), value);
120249
}
121250
}
122251

252+
/**
253+
* Enum representing send modes.
254+
*/
123255
enum SendMode {
124256
ADD_OR_MODIFY(0),
125257
REMOVE(1);

main/src/main/java/net/citizensnpcs/trait/scoreboard/BukkitScoreboardImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
public class BukkitScoreboardImpl implements AbstractScoreboard {
99

1010

11-
Scoreboard scoreboard = Util.getDummyScoreboard();
11+
private final Scoreboard scoreboard;
12+
13+
public BukkitScoreboardImpl() {
14+
this.scoreboard = Util.getDummyScoreboard();
15+
}
1216

1317
@Nullable
1418
@Override

main/src/main/java/net/citizensnpcs/trait/scoreboard/FoliaTeamImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public int getSize() {
8686

8787
@Override
8888
public void sendToPlayer(Player player, SendMode mode) {
89-
// no-op
89+
// TODO: Currently not implemented
9090
/*if (mode == SendMode.ADD_OR_MODIFY) {
9191
delegateDisplay.refresh();
9292
delegateTeam.display(player, delegateDisplay);

0 commit comments

Comments
 (0)