Changed to jdk-16 and made it work with Minecraft 1.16.5 and 1.17.1 as well

This commit is contained in:
Artemis-the-gr8 2022-07-12 23:06:30 +02:00
parent 2b2fa70eab
commit ce8b870560
5 changed files with 22 additions and 16 deletions

View File

@ -10,8 +10,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
@ -101,8 +101,8 @@
</dependency>
</dependencies>
<properties>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<maven.compiler.source>16</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -10,8 +10,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>
@ -78,8 +78,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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: