File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -181,19 +181,13 @@ public boolean isVisible() {
181181 * @return true if the {@link Bullet} is visible to the specified player, false if the {@link Bullet} is not visible to the specified player.
182182 */
183183 public boolean isVisible (Player player ) {
184- if (player == null ) {
185- player = game .self ();
186- }
184+ player = player == null ? game .self () : player ;
187185 if (player != null ) {
188- final int id = player .getID ();
189- if (id >= 0 && id < 9 ) {
190- return bulletData .isVisible (id );
191- }
192- } else {
193- for (int i = 0 ; i < 9 ; ++i ) {
194- if (bulletData .isVisible (i )) {
195- return true ;
196- }
186+ return player .hasValidId () && bulletData .isVisible (player .getID ());
187+ }
188+ for (int i = 0 ; i < Player .MAX_VALID_ID ; ++i ) {
189+ if (bulletData .isVisible (i )) {
190+ return true ;
197191 }
198192 }
199193 return false ;
Original file line number Diff line number Diff line change 1919 * @see Race
2020 */
2121public class Player implements Comparable <Player > {
22+ static final int MAX_VALID_ID = 9 ;
23+
2224 private final PlayerData playerData ;
2325 private final Game game ;
2426 private final int id ;
@@ -53,6 +55,10 @@ public int getID() {
5355 return id ;
5456 }
5557
58+ boolean hasValidId () {
59+ return id >= 0 && id < MAX_VALID_ID ;
60+ }
61+
5662 /**
5763 * Retrieves the name of the player.
5864 *
@@ -340,13 +346,8 @@ public int supplyTotal() {
340346 * @see #supplyUsed
341347 */
342348 public int supplyTotal (Race race ) {
343- if (race == Race .None ) {
344- race = getRace ();
345- }
346- if (race .id >= 0 && race .id < 3 ) {
347- return playerData .getSupplyTotal (race .id );
348- }
349- return 0 ;
349+ race = race == Race .None ? getRace () : race ;
350+ return race .hasValidId () ? playerData .getSupplyTotal (race .id ) : 0 ;
350351 }
351352
352353 public int supplyUsed () {
@@ -361,10 +362,8 @@ public int supplyUsed() {
361362 * @see #supplyTotal
362363 */
363364 public int supplyUsed (Race race ) {
364- if (race == Race .None ) {
365- race = getRace ();
366- }
367- if (race .id < 0 || race .id >= 3 ) {
365+ race = race == Race .None ? getRace () : race ;
366+ if (!race .hasValidId ()) {
368367 return 0 ;
369368 }
370369 int supplyUsed = playerData .getSupplyUsed (race .id );
Original file line number Diff line number Diff line change @@ -58,12 +58,18 @@ public enum Race {
5858 Arrays .stream (Race .values ()).forEach (v -> idToEnum [v .id ] = v );
5959 }
6060
61+ static final int MAX_VALID_ID = 3 ;
62+
6163 public final int id ;
6264
6365 Race (final int id ) {
6466 this .id = id ;
6567 }
6668
69+ boolean hasValidId () {
70+ return id >= 0 && id < MAX_VALID_ID ;
71+ }
72+
6773 /**
6874 * Retrieves the default worker type for this {@link Race}.
6975 * <p>
Original file line number Diff line number Diff line change @@ -2094,19 +2094,13 @@ public boolean isVisible() {
20942094 * @see #exists
20952095 */
20962096 public boolean isVisible (Player player ) {
2097- if (player == null ) {
2098- player = game .self ();
2099- }
2097+ player = player == null ? game .self () : player ;
21002098 if (player != null ) {
2101- final int id = player .getID ();
2102- if (id >= 0 && id < 9 ) {
2103- return unitData .isVisible (id );
2104- }
2105- } else {
2106- for (int i = 0 ; i < 9 ; ++i ) {
2107- if (unitData .isVisible (i )) {
2108- return true ;
2109- }
2099+ return player .hasValidId () && unitData .isVisible (player .getID ());
2100+ }
2101+ for (int i = 0 ; i < Player .MAX_VALID_ID ; ++i ) {
2102+ if (unitData .isVisible (i )) {
2103+ return true ;
21102104 }
21112105 }
21122106 return false ;
You can’t perform that action at this time.
0 commit comments