diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index b1540a6..b27cd6e 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -10,8 +10,8 @@ maven-compiler-plugin 3.8.1 - 17 - 17 + 16 + 16 @@ -101,8 +101,8 @@ - 17 - 17 + 16 + 16 UTF-8 diff --git a/pom.xml b/pom.xml index ca024f5..91260ca 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ UTF-8 - 17 - 17 + 16 + 16 @@ -78,8 +78,8 @@ maven-compiler-plugin 3.8.1 - 17 - 17 + 16 + 16 diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/ShareManager.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/ShareManager.java index bea6690..21f8e01 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/ShareManager.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/ShareManager.java @@ -8,13 +8,14 @@ import net.kyori.adventure.text.TextComponent; import javax.annotation.Nullable; import java.time.Instant; -import java.time.temporal.ChronoUnit; import java.util.Comparator; import java.util.List; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import static java.time.temporal.ChronoUnit.SECONDS; + public final class ShareManager { private static volatile ShareManager instance; @@ -77,24 +78,26 @@ public final class ShareManager { UUID identifier = UUID.randomUUID(); statResults.put(identifier, new StatResult(playerName, statResult, ID, identifier)); + MyLogger.logMsg("Saving statResults with no. " + ID, DebugLevel.MEDIUM); return identifier; } - public @Nullable TextComponent getStatResult(String playerName, UUID identifier) { + public @Nullable TextComponent getResultMessage(String playerName, UUID identifier) { if (statResults.containsKey(identifier) && playerCanShare(playerName)) { shareTimeStamp.put(playerName, Instant.now()); return statResults.remove(identifier).statResult(); } else { + //TODO send error-message if on time-out, and error-message if request is already shared return null; } } - private boolean playerCanShare(String playerName) { + public boolean playerCanShare(String playerName) { if (waitingTime == 0 || !shareTimeStamp.containsKey(playerName)) { return true; } else { - long seconds = shareTimeStamp.get(playerName).until(Instant.now(), ChronoUnit.SECONDS); - return seconds >= waitingTime; + long seconds = SECONDS.between(shareTimeStamp.get(playerName), Instant.now()); + return seconds >= (long) waitingTime * 60; } } @@ -111,7 +114,7 @@ public final class ShareManager { .parallelStream() .min(Comparator.comparing(StatResult::ID)) .orElseThrow().uuid(); - MyLogger.logMsg("Removing old stat no. " + statResults.get(uuid) + " for player " + playerName, DebugLevel.MEDIUM); + MyLogger.logMsg("Removing old stat no. " + statResults.get(uuid).ID() + " for player " + playerName, DebugLevel.MEDIUM); statResults.remove(uuid); } } diff --git a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ShareCommand.java b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ShareCommand.java index 9028510..21441cc 100644 --- a/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ShareCommand.java +++ b/src/main/java/com/gmail/artemis/the/gr8/playerstats/commands/ShareCommand.java @@ -22,7 +22,10 @@ public class ShareCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, String label, String[] args) { - adventure.all().sendMessage(shareManager.getStatResult(sender.getName(), UUID.fromString(args[0]))); + adventure.all().sendMessage(shareManager.getResultMessage(sender.getName(), UUID.fromString(args[0]))); + //TODO send feedback if stat-result is null: + //can't share again yet (time-out) + //already shared this result (not in statResult list anymore) return true; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f8408b2..2d27198 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ main: com.gmail.artemis.the.gr8.playerstats.Main name: PlayerStats version: 1.6 -api-version: 1.18 +api-version: 1.13 description: adds commands to view player statistics in chat author: Artemis_the_gr8 commands: