88import java .sql .ResultSet ;
99import java .sql .Timestamp ;
1010import java .time .LocalDateTime ;
11- import java .util .Deque ;
1211import java .util .HashMap ;
13- import java .util .LinkedList ;
1412import java .util .Map ;
1513import java .util .Optional ;
1614
1715public class TutorialPlotProvider {
1816 public static final Map <TutorialPlot , Integer > tutorialPlots = new HashMap <>();
19- public static final Deque <Integer > freeTutorialPlotIds = new LinkedList <>();
2017
2118 public Optional <TutorialPlot > getById (int id ) {
2219 return tutorialPlots .keySet ().stream ().filter (t -> tutorialPlots .get (t ) == id ).findFirst ();
@@ -34,7 +31,7 @@ public Optional<TutorialPlot> getByTutorialId(int tutorialId, String playerUUID)
3431 ps .setString (2 , playerUUID );
3532 ResultSet rs = ps .executeQuery ();
3633 if (rs .next ()) {
37- int plotId = freeTutorialPlotIds . isEmpty () ? 0 : freeTutorialPlotIds . poll ();
34+ int plotId = getNextTutorialPlotId ();
3835 int stageId = rs .getInt (1 );
3936 boolean isComplete = rs .getBoolean (2 );
4037 Date lastStageCompleteDate = rs .getDate (3 );
@@ -46,7 +43,6 @@ public Optional<TutorialPlot> getByTutorialId(int tutorialId, String playerUUID)
4643 }
4744 return Optional .empty ();
4845 }));
49-
5046 }
5147
5248 public boolean add (int tutorialId , String playerUUID ) {
@@ -81,4 +77,12 @@ public boolean setComplete(int tutorialId, String playerUUID) {
8177 return ps .executeUpdate () > 0 ;
8278 })));
8379 }
80+
81+ private int getNextTutorialPlotId () {
82+ int id = 0 ;
83+ while (tutorialPlots .containsValue (id )) {
84+ id ++;
85+ }
86+ return id ;
87+ }
8488}
0 commit comments