Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
imDMK committed Dec 27, 2024
1 parent cf3cf83 commit af67b24
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public class UserCache {

public void put(User user) {
this.uuidUserCache.put(user.getUuid(), user);
this.nameUserCache.put(user.getName(), user);
}

public void remove(UUID uuid) {
this.uuidUserCache.invalidate(uuid);
public void remove(User user) {
this.uuidUserCache.invalidate(user.getUuid());
this.nameUserCache.invalidate(user.getName());
}

public Optional<User> get(UUID uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface UserRepository {

CompletableFuture<User> save(User user);

CompletableFuture<Void> delete(UUID uuid);
CompletableFuture<Void> delete(User user);

CompletableFuture<Void> resetGlobalSpentTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public DaoUserRepositoryImpl(ConnectionSource connectionSource, UserCache userCa
public CompletableFuture<Optional<User>> findByUUID(UUID uuid) {
return CompletableFuture.supplyAsync(() -> {
try {
User user = this.userDao.queryBuilder()
Optional<User> userOptional = Optional.ofNullable(this.userDao.queryBuilder()
.where().eq("uuid", uuid)
.queryForFirst();
.queryForFirst());

this.userCache.put(user);
userOptional.ifPresent(this.userCache::put);

return Optional.ofNullable(user);
return userOptional;
}
catch (SQLException sqlException) {
throw new CompletionException(sqlException);
Expand All @@ -54,13 +54,13 @@ public CompletableFuture<Optional<User>> findByUUID(UUID uuid) {
@Override
public Optional<User> findByName(String name) {
try {
User user = this.userDao.queryBuilder()
Optional<User> userOptional = Optional.ofNullable(this.userDao.queryBuilder()
.where().eq("name", name)
.queryForFirst();
.queryForFirst());

this.userCache.put(user);
userOptional.ifPresent(this.userCache::put);

return Optional.ofNullable(user);
return userOptional;
}
catch (SQLException sqlException) {
throw new CompletionException(sqlException);
Expand Down Expand Up @@ -101,11 +101,11 @@ public CompletableFuture<User> save(User user) {
}

@Override
public CompletableFuture<Void> delete(UUID uuid) {
public CompletableFuture<Void> delete(User user) {
return CompletableFuture.runAsync(() -> {
try {
this.userDao.deleteById(uuid);
this.userCache.remove(uuid);
this.userDao.deleteById(user.getUuid());
this.userCache.remove(user);
}
catch (SQLException sqlException) {
throw new CompletionException(sqlException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CompletableFuture<User> save(User user) {
}

@Override
public CompletableFuture<Void> delete(UUID uuid) {
public CompletableFuture<Void> delete(User user) {
return CompletableFuture.failedFuture(new UnsupportedOperationException());
}

Expand Down
5 changes: 2 additions & 3 deletions spenttime-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ bukkit {
name = "SpentTime"
version = "${project.version}"
apiVersion = "1.17"
main = "com.github.imdmk.spenttime.plugin.SpentTimePlugin"
main = "com.github.imdmk.spenttime.SpentTimePlugin"
author = "DMK ([email protected])"
description = "An efficient plugin for calculating your time spent in the game with many features and configuration possibilities."
website = "https://github.com/imDMK/SpentTime"

}

tasks.withType<ShadowJar> {
archiveFileName.set("${project.name} v${project.version}.jar")
archiveFileName.set("SpentTime v${project.version}.jar")

dependsOn("checkstyleMain")
dependsOn("checkstyleTest")
Expand All @@ -69,7 +69,6 @@ tasks.withType<ShadowJar> {
"net.kyori",
"org.bstats",
"org.json",
"org.slf4j",
"org.yaml",
"org.checkerframework",
).forEach { lib ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.imdmk.spenttime.configuration.PluginConfiguration;
import com.github.imdmk.spenttime.gui.SpentTimeTopGui;
import com.github.imdmk.spenttime.litecommands.argument.PlayerArgument;
import com.github.imdmk.spenttime.litecommands.argument.UserArgument;
import com.github.imdmk.spenttime.litecommands.contextual.PlayerContextual;
import com.github.imdmk.spenttime.litecommands.handler.MissingPermissionHandler;
import com.github.imdmk.spenttime.litecommands.handler.UsageHandler;
Expand All @@ -19,7 +20,6 @@
import com.github.imdmk.spenttime.user.User;
import com.github.imdmk.spenttime.user.UserCache;
import com.github.imdmk.spenttime.user.UserService;
import com.github.imdmk.spenttime.litecommands.argument.UserArgument;
import com.github.imdmk.spenttime.user.repository.UserRepository;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UpdateController implements Listener {

private static final String PREFIX = "<dark_gray>[<rainbow>SpentTime<dark_gray>]";

private static final Notification UPDATE_AVAILABLE = new Notification(NotificationType.CHAT, PREFIX + " <yellow>A new version is available: {TAG}\n<yellow>Download it here: {URL}");
private static final Notification UPDATE_AVAILABLE = new Notification(NotificationType.CHAT, PREFIX + " <red><yellow>A new version is available: {TAG}\n<green>Download it here: {URL}");
private static final Notification UPDATE_EXCEPTION = new Notification(NotificationType.CHAT, PREFIX + "<red>An error occurred while checking for update: {MESSAGE}");

private final Logger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public Duration getSpentTime(OfflinePlayer player) {
return Duration.ofSeconds(secondsPlayed);
}

public Duration getSpentTime(UUID playerUuid) {
long secondsPlayed = this.server.getOfflinePlayer(playerUuid).getStatistic(Statistic.PLAY_ONE_MINUTE) / 20;
return Duration.ofSeconds(secondsPlayed);
}

public void resetSpentTime(OfflinePlayer offlinePlayer) {
offlinePlayer.setStatistic(Statistic.PLAY_ONE_MINUTE, 0);
}
Expand Down

0 comments on commit af67b24

Please sign in to comment.