mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-16 20:29:08 +00:00
[AB-xxx] small code improvements
This commit is contained in:
@@ -313,7 +313,10 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
Long userInServerId = userInAServer.getUserInServerId();
|
||||
Optional<AUserExperience> aUserExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(userInAServer.getUserInServerId());
|
||||
AUserExperience aUserExperience = aUserExperienceOptional.orElseGet(() -> userExperienceManagementService.createUserInServer(userInAServer));
|
||||
if(Boolean.FALSE.equals(aUserExperience.getExperienceGainDisabled())) {
|
||||
if (aUserExperience.getExperienceGainDisabled().equals(Boolean.TRUE)) {
|
||||
log.debug("Experience gain was disabled. User did not gain any experience.");
|
||||
return;
|
||||
}
|
||||
List<AExperienceLevel> levels = experienceLevelManagementService.getLevelConfig();
|
||||
levels.sort(Comparator.comparing(AExperienceLevel::getExperienceNeeded));
|
||||
|
||||
@@ -387,7 +390,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
}
|
||||
if(!Objects.equals(result.getOldRoleId(), result.getNewRoleId())) {
|
||||
if(result.getOldRoleId() != null && result.getNewRoleId() != null) {
|
||||
roleService.updateRolesIds(member, Arrays.asList(result.getOldRoleId()), Arrays.asList(result.getNewRoleId())).thenAccept(unused -> {
|
||||
roleService.updateRolesIds(member, List.of(result.getOldRoleId()), List.of(result.getNewRoleId())).thenAccept(unused -> {
|
||||
log.debug("Removed role {} from and added role {} to member {} in server {}.", result.getOldRoleId(), result.getNewRoleId(), member.getIdLong(), member.getGuild().getIdLong());
|
||||
}).exceptionally(throwable -> {
|
||||
log.warn("Failed to remove role {} from and add role {} to member {} in server {}.", result.getOldRoleId(), result.getNewRoleId(), member.getIdLong(), member.getGuild().getIdLong(), throwable);
|
||||
@@ -412,9 +415,6 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.debug("Experience gain was disabled. User did not gain any experience.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -521,7 +521,7 @@ public class AUserExperienceServiceBean implements AUserExperienceService {
|
||||
public LeaderBoardEntry getRankOfUserInServer(AUserInAServer userInAServer) {
|
||||
log.debug("Retrieving rank for {}", userInAServer.getUserReference().getId());
|
||||
Optional<AUserExperience> aUserExperienceOptional = userExperienceManagementService.findByUserInServerIdOptional(userInAServer.getUserInServerId());
|
||||
if(!aUserExperienceOptional.isPresent()) {
|
||||
if(aUserExperienceOptional.isEmpty()) {
|
||||
throw new NoExperienceTrackedException();
|
||||
}
|
||||
Integer rank = 0;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ExperienceLevelServiceBean implements ExperienceLevelService {
|
||||
if(level < 0) {
|
||||
throw new IllegalArgumentException("Level should not be less to 0.");
|
||||
}
|
||||
return 5L * (level * level) + 50 * level + 100;
|
||||
return 5L * ((long) level * level) + 50L * level + 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -88,7 +88,7 @@ public class ExperienceRoleServiceBean implements ExperienceRoleService {
|
||||
@Override
|
||||
public CompletableFuture<Void> unsetRoles(List<ARole> rolesToUnset, GuildMessageChannel messageChannel) {
|
||||
List<AExperienceRole> rolesInServer = experienceRoleManagementService.getRolesInServer(rolesToUnset);
|
||||
Integer totalCount = 0;
|
||||
int totalCount = 0;
|
||||
for (AExperienceRole aExperienceRole : rolesInServer) {
|
||||
totalCount += aExperienceRole.getUsers().size();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.experience.service;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -17,11 +18,9 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
@Component
|
||||
public class RunTimeExperienceService {
|
||||
|
||||
private Map<Long,Map<Long, Instant>> runtimeExperience = new HashMap<>();
|
||||
@Getter
|
||||
private final Map<Long,Map<Long, Instant>> runtimeExperience = new HashMap<>();
|
||||
private static final Lock lock = new ReentrantLock();
|
||||
public Map<Long, Map<Long, Instant>> getRuntimeExperience() {
|
||||
return runtimeExperience;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires the lock of the runtime experience data structure. Operations on it should only be done, while holding the lock
|
||||
|
||||
Reference in New Issue
Block a user