1818 */
1919package ru .tehkode .permissions ;
2020
21+ import com .google .common .collect .Maps ;
2122import org .bukkit .Bukkit ;
2223import org .bukkit .entity .Player ;
2324import ru .tehkode .permissions .events .PermissionEntityEvent ;
2425import ru .tehkode .permissions .exceptions .RankingException ;
2526
2627import java .util .*;
2728import java .util .concurrent .ConcurrentHashMap ;
29+ import java .util .logging .Level ;
2830
2931/**
3032 * @author code
@@ -575,23 +577,31 @@ public boolean explainExpression(String expression) {
575577
576578 protected void updateTimedGroups () {
577579 long nextExpiration = Long .MAX_VALUE ;
580+ final Set <Map .Entry <String , String >> removeGroups = new HashSet <>();
578581 for (Map .Entry <String , Map <String , String >> world : getAllOptions ().entrySet ()) {
579582 for (Map .Entry <String , String > entry : world .getValue ().entrySet ()) {
580583 final String group = getTimedGroupName (entry .getKey ());
581584 if (group == null ) { // Not a timed group
582585 continue ;
583586 }
584587 long groupLifetime = Long .parseLong (entry .getValue ());
585- if (groupLifetime > 0 && groupLifetime < System .currentTimeMillis () / 1000 ) { // check for expiration
586- this .setOption ("group-" + group + "-until" , null , world .getKey ()); // remove option
587- this .removeGroup (group , world .getKey ()); // remove membership
588- // @TODO Make notification of player about expired memebership
588+ if (groupLifetime > 0 && groupLifetime <= System .currentTimeMillis () / 1000 ) { // check for expiration
589+ removeGroups .add (Maps .immutableEntry (group , world .getKey ()));
589590 } else {
590591 nextExpiration = Math .min (nextExpiration , groupLifetime );
591592 }
592593 }
593594 }
594595
596+ for (Map .Entry <String , String > ent : removeGroups ) {
597+ this .setOption ("group-" + ent .getKey () + "-until" , null , ent .getValue ()); // remove option
598+ this .removeGroup (ent .getKey (), ent .getValue ()); // remove membership
599+ if (isDebug ()) {
600+ manager .getLogger ().log (Level .INFO , ent .getValue () != null ? "Timed group '{0}' in world '{1}' expired from user {2}/{3}"
601+ : "Timed group {0} expired from user {2}/{3}" , new Object []{ent .getKey (), ent .getValue (), getIdentifier (), getName ()});
602+ }
603+ }
604+
595605 if (nextExpiration < Long .MAX_VALUE ) {
596606 // Schedule the next timed groups check with the permissions manager
597607 manager .scheduleTimedGroupsCheck (nextExpiration , getIdentifier ());
@@ -602,9 +612,7 @@ static String getTimedGroupName(String option) {
602612 if (!option .startsWith ("group-" ) && !option .endsWith ("-until" )) {
603613 return null ;
604614 }
605- String groupName = option .substring ("group-" .length (), option .length () - "-until" .length ());
606- System .out .println (groupName );
607- return groupName ;
615+ return option .substring ("group-" .length (), option .length () - "-until" .length ());
608616 }
609617
610618 // Compatibility methods
0 commit comments