Correct garbage collection error for voice chat

This commit is contained in:
Sebastien 2019-09-27 09:16:16 +02:00
parent d2c8729a87
commit 2473d0d0a4
2 changed files with 6 additions and 5 deletions

View File

@ -128,10 +128,10 @@ public class BotListener extends ListenerAdapter {
super.onGuildVoiceJoin(event);
if(!event.getMember().getUser().isBot()){
UserStatsUtils userStatsUtils = UserStatsUtils.getINSTANCE();
if(!userStatsUtils.runningCounters.containsKey(event.getMember())){
if (!userStatsUtils.runningCounters.containsKey(event.getMember().getId())) {
UserStatsUtils.VoicePresenceCounter temp = new UserStatsUtils.VoicePresenceCounter(event.getMember());
temp.start();
userStatsUtils.runningCounters.put(event.getMember(), temp);
userStatsUtils.runningCounters.put(event.getMember().getId(), temp);
}
}

View File

@ -21,7 +21,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@ -36,11 +35,13 @@ public class UserStatsUtils {
private static UserStatsUtils INSTANCE = new UserStatsUtils();
public static UserStatsUtils getINSTANCE() {
if(INSTANCE == null)
INSTANCE = new UserStatsUtils();
return INSTANCE;
}
public HashMap<Member, VoicePresenceCounter> runningCounters = new HashMap<>();
public HashMap<String, VoicePresenceCounter> runningCounters = new HashMap<>();
private UserStatsRepository userStatsRepository;
private UserRepository userRepository;
@ -281,7 +282,7 @@ public class UserStatsUtils {
e.printStackTrace();
}
}
UserStatsUtils.getINSTANCE().runningCounters.remove(member);
UserStatsUtils.getINSTANCE().runningCounters.remove(member.getId());
}
}