Skip to content

Commit 5c2ecdd

Browse files
committed
Improve delete and use List in team packet
1 parent eb3cb72 commit 5c2ecdd

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/main/java/fr/mrmicky/fastboard/FastBoard.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ public class FastBoard {
100100
}
101101
}
102102

103-
private Player player;
104-
private String id;
103+
private final Player player;
104+
private final String id;
105105

106106
private String title;
107107
private List<String> lines = new ArrayList<>();
108108

109+
private boolean deleted = false;
110+
109111
/**
110112
* Create a new FastBoard for a player
111113
*
@@ -245,6 +247,10 @@ public Player getPlayer() {
245247
return player;
246248
}
247249

250+
public boolean isDeleted() {
251+
return deleted;
252+
}
253+
248254
/**
249255
* Delete this FastBoard, and will remove the scoreboard for the associated player if he is online.
250256
* After this, all uses of {@link #updateLines} and {@link #updateTitle} will throws an {@link IllegalStateException}
@@ -262,7 +268,7 @@ public void delete() {
262268
e.printStackTrace();
263269
}
264270

265-
player = null;
271+
deleted = true;
266272
}
267273

268274
private void sendObjectivePacket(ObjectiveMode mode) throws ReflectiveOperationException {
@@ -349,7 +355,7 @@ private void sendTeamPacket(int score, TeamMode mode) throws ReflectiveOperation
349355
setField(packet, String.class, "always", 5); // Collisions for 1.9+
350356

351357
if (mode == TeamMode.CREATE) {
352-
setField(packet, Collection.class, Collections.singleton(getColorCode(score))); // Players in the team
358+
setField(packet, Collection.class, Collections.singletonList(getColorCode(score))); // Players in the team
353359
}
354360
}
355361

@@ -361,7 +367,7 @@ private String getColorCode(int score) {
361367
}
362368

363369
private void sendPacket(Object packet) throws ReflectiveOperationException {
364-
if (player == null) {
370+
if (deleted) {
365371
throw new IllegalStateException("This FastBoard is deleted");
366372
}
367373

0 commit comments

Comments
 (0)