Clean up hasCachedAppearance

- Remove useless inline comment
- Remove blank line after param declaration
- Only call getIndex() once
This commit is contained in:
atomicint
2016-01-22 15:51:52 -05:00
parent c7d1a5a732
commit cebdb811cb
@@ -102,12 +102,15 @@ public final class PlayerSynchronizationTask extends SynchronizationTask {
added++; added++;
blockSet = other.getBlockSet(); blockSet = other.getBlockSet();
if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, other)) {
int index = other.getIndex();
if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, other.getAppearanceTicket())) {
blockSet = blockSet.clone(); blockSet = blockSet.clone();
blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); blockSet.add(SynchronizationBlock.createAppearanceBlock(other));
} }
segments.add(new AddPlayerSegment(blockSet, other.getIndex(), local)); segments.add(new AddPlayerSegment(blockSet, index, local));
} }
} }
@@ -120,27 +123,19 @@ public final class PlayerSynchronizationTask extends SynchronizationTask {
* Tests whether or not the specified Player has a cached appearance within * Tests whether or not the specified Player has a cached appearance within
* the specified appearance ticket array. * the specified appearance ticket array.
* *
* @param tickets The appearance tickets. * @param appearanceTickets The appearance tickets.
* @param player The Player. * @param index The index of the Player.
* @param appearanceTicket The current appearance ticket for the Player.
* @return {@code true} if the specified Player has a cached appearance * @return {@code true} if the specified Player has a cached appearance
* otherwise {@code false}. * otherwise {@code false}.
*/ */
private boolean hasCachedAppearance(int[] tickets, Player player) { private boolean hasCachedAppearance(int[] appearanceTickets, int index, int appearanceTicket) {
if (appearanceTickets[index] != appearanceTicket) {
// If the Player is not active they cannot have a cached appearance appearanceTickets[index] = appearanceTicket;
if (!player.isActive()) {
return false; return false;
} }
int index = player.getIndex() - 1; return true;
int ticket = player.getAppearanceTicket();
if (tickets[index] == ticket) {
return true;
}
tickets[index] = ticket;
return false;
} }
/** /**