Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit e806c60

Browse files
committed
Fix timed groups check + possibly ConcurrentModificationExceptions
Fixes #1875. Fixes #1827. Fixes #1687.
1 parent 526afd3 commit e806c60

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/main/java/ru/tehkode/permissions/PermissionUser.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
*/
1919
package ru.tehkode.permissions;
2020

21+
import com.google.common.collect.Maps;
2122
import org.bukkit.Bukkit;
2223
import org.bukkit.entity.Player;
2324
import ru.tehkode.permissions.events.PermissionEntityEvent;
2425
import ru.tehkode.permissions.exceptions.RankingException;
2526

2627
import java.util.*;
2728
import 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

Comments
 (0)