Skip to content

Commit

Permalink
Improve delete and use List in team packet
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Apr 15, 2019
1 parent eb3cb72 commit 5c2ecdd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/fr/mrmicky/fastboard/FastBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ public class FastBoard {
}
}

private Player player;
private String id;
private final Player player;
private final String id;

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

private boolean deleted = false;

/**
* Create a new FastBoard for a player
*
Expand Down Expand Up @@ -245,6 +247,10 @@ public Player getPlayer() {
return player;
}

public boolean isDeleted() {
return deleted;
}

/**
* Delete this FastBoard, and will remove the scoreboard for the associated player if he is online.
* After this, all uses of {@link #updateLines} and {@link #updateTitle} will throws an {@link IllegalStateException}
Expand All @@ -262,7 +268,7 @@ public void delete() {
e.printStackTrace();
}

player = null;
deleted = true;
}

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

if (mode == TeamMode.CREATE) {
setField(packet, Collection.class, Collections.singleton(getColorCode(score))); // Players in the team
setField(packet, Collection.class, Collections.singletonList(getColorCode(score))); // Players in the team
}
}

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

private void sendPacket(Object packet) throws ReflectiveOperationException {
if (player == null) {
if (deleted) {
throw new IllegalStateException("This FastBoard is deleted");
}

Expand Down

0 comments on commit 5c2ecdd

Please sign in to comment.