@@ -89,8 +89,9 @@ private HashMap<Integer, String> handlePlaces(Set<String> places) {
8989
9090 public void loadPreviousMonthTopVoters () {
9191 if (plugin .getConfigFile ().isStoreMonthTotalsWithDate ()) {
92- HashMap < UUID , ArrayList < Column >> cols = plugin . getUserManager (). getAllKeys ();
92+
9393 LocalDateTime now = plugin .getTimeChecker ().getTime ();
94+
9495 for (String column : plugin .getUserManager ().getAllColumns ()) {
9596 if (column .startsWith ("MonthTotal-" )) {
9697 String [] data = column .split ("-" );
@@ -102,14 +103,55 @@ public void loadPreviousMonthTopVoters() {
102103 if (yearMonth .atDay (now .getDayOfMonth ()).atTime (23 , 59 ).isBefore (now )) {
103104 plugin .debug ("Loading previous month top voters of " + yearMonth .toString ());
104105 plugin .getPreviousMonthsTopVoters ().put (yearMonth ,
105- getTopVotersOfMonth ( yearMonth , cols ));
106+ new LinkedHashMap < TopVoterPlayer , Integer >( ));
106107 }
107108 }
108109 }
109110 }
110111 }
111- cols .clear ();
112- cols = null ;
112+
113+ if (plugin .getPreviousMonthsTopVoters ().size () > 0 ) {
114+ HashMap <UUID , ArrayList <Column >> cols = plugin .getUserManager ().getAllKeys ();
115+ for (Entry <UUID , ArrayList <Column >> playerData : cols .entrySet ()) {
116+
117+ String uuid = playerData .getKey ().toString ();
118+ if (uuid != null && !uuid .isEmpty ()) {
119+ VotingPluginUser user = plugin .getVotingPluginUserManager ()
120+ .getVotingPluginUser (UUID .fromString (uuid ), false );
121+ user .dontCache ();
122+ user .updateTempCacheWithColumns (playerData .getValue ());
123+
124+ for (YearMonth month : plugin .getPreviousMonthsTopVoters ().keySet ()) {
125+ LocalDateTime atTime = month .atDay (15 ).atTime (0 , 0 );
126+ int total = user .getTotal (TopVoter .Monthly , atTime );
127+ if (total > 0 ) {
128+ plugin .getPreviousMonthsTopVoters ().get (month ).put (user .getTopVoterPlayer (), total );
129+ }
130+ }
131+
132+ cols .put (playerData .getKey (), null );
133+ user .clearTempCache ();
134+ }
135+ }
136+
137+ cols .clear ();
138+ cols = null ;
139+ }
140+
141+ for (YearMonth month : plugin .getPreviousMonthsTopVoters ().keySet ()) {
142+ plugin .getPreviousMonthsTopVoters ().put (month ,
143+ sortByValues (plugin .getPreviousMonthsTopVoters ().get (month ), false ));
144+ }
145+
146+ plugin .extraDebug ("Previous Months: " + plugin .getPreviousMonthsTopVoters ().keySet ().toString ());
147+
148+ for (Entry <YearMonth , LinkedHashMap <TopVoterPlayer , Integer >> entry : plugin .getPreviousMonthsTopVoters ()
149+ .entrySet ()) {
150+ for (Entry <TopVoterPlayer , Integer > entry2 : entry .getValue ().entrySet ()) {
151+ plugin .extraDebug (entry .getKey ().toString () + ": " + entry2 .getKey ().getUser ().getPlayerName () + ":"
152+ + entry2 .getValue ().intValue ());
153+ }
154+ }
113155 }
114156 }
115157
@@ -121,21 +163,18 @@ public LinkedHashMap<TopVoterPlayer, Integer> getTopVotersOfMonth(YearMonth mont
121163 for (Entry <UUID , ArrayList <Column >> playerData : cols .entrySet ()) {
122164
123165 String uuid = playerData .getKey ().toString ();
124- if (plugin != null && plugin .isEnabled ()) {
125- if (uuid != null && !uuid .isEmpty ()) {
126- VotingPluginUser user = plugin .getVotingPluginUserManager ()
127- .getVotingPluginUser (UUID .fromString (uuid ), false );
128- user .dontCache ();
129- user .updateTempCacheWithColumns (playerData .getValue ());
130- cols .put (playerData .getKey (), null );
131- int total = 0 ;
132- total = user .getTotal (TopVoter .Monthly , atTime );
133-
134- if (total > 0 ) {
135- totals .put (user .getTopVoterPlayer (), total );
136- }
137- user .clearTempCache ();
166+ if (uuid != null && !uuid .isEmpty ()) {
167+ VotingPluginUser user = plugin .getVotingPluginUserManager ().getVotingPluginUser (UUID .fromString (uuid ),
168+ false );
169+ user .dontCache ();
170+ user .updateTempCacheWithColumns (playerData .getValue ());
171+ int total = 0 ;
172+ total = user .getTotal (TopVoter .Monthly , atTime );
173+
174+ if (total > 0 ) {
175+ totals .put (user .getTopVoterPlayer (), total );
138176 }
177+ user .clearTempCache ();
139178 }
140179 }
141180
0 commit comments