mirror of
https://github.com/itHotL/PlayerStats.git
synced 2024-11-26 12:36:16 +01:00
Fixed some message bugs, tested ArrayBlockingQueue, turned order of checks in ShareCommand around
This commit is contained in:
parent
1c8d77e9cd
commit
bf4a1aed03
@ -103,9 +103,10 @@ public final class ShareManager {
|
||||
|
||||
synchronized (this) { //put the last 50 values in the new Queue
|
||||
UUID[] lastValues = sharedResults.toArray(new UUID[0]);
|
||||
Arrays.stream(Arrays.copyOfRange(lastValues, 450, 499))
|
||||
Arrays.stream(Arrays.copyOfRange(lastValues, 450, 500))
|
||||
.parallel().iterator()
|
||||
.forEachRemaining(newQueue::offer);
|
||||
|
||||
sharedResults = newQueue;
|
||||
}
|
||||
sharedResults.offer(identifier);
|
||||
@ -118,10 +119,10 @@ public final class ShareManager {
|
||||
|
||||
public boolean isOnCoolDown(String playerName) {
|
||||
if (waitingTime == 0 || !shareTimeStamp.containsKey(playerName)) {
|
||||
return true;
|
||||
return false;
|
||||
} else {
|
||||
long seconds = SECONDS.between(shareTimeStamp.get(playerName), Instant.now());
|
||||
return seconds >= (long) waitingTime * 60;
|
||||
return seconds <= (long) waitingTime * 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,12 @@ public class ShareCommand implements CommandExecutor {
|
||||
MyLogger.logException(e, "ShareCommand", "/statshare is being called without a valid UUID argument");
|
||||
return false;
|
||||
}
|
||||
if (shareManager.isOnCoolDown(sender.getName())) {
|
||||
adventure.sender(sender).sendMessage(messageWriter.stillOnShareCoolDown());
|
||||
}
|
||||
else if (shareManager.requestAlreadyShared(shareCode)) {
|
||||
if (shareManager.requestAlreadyShared(shareCode)) {
|
||||
adventure.sender(sender).sendMessage(messageWriter.resultsAlreadyShared());
|
||||
}
|
||||
else if (shareManager.isOnCoolDown(sender.getName())) {
|
||||
adventure.sender(sender).sendMessage(messageWriter.stillOnShareCoolDown());
|
||||
}
|
||||
else {
|
||||
TextComponent result = shareManager.getStatResult(sender.getName(), shareCode);
|
||||
if (result == null) { //at this point the only possible cause of statResult being null is the request being older than 25 player-requests ago
|
||||
|
@ -63,7 +63,7 @@ public class ComponentFactory {
|
||||
}
|
||||
|
||||
public TextComponent messageAccentComponent() {
|
||||
return text().color(PluginColor.LIGHT_GOLD.getColor()).build();
|
||||
return text().color(PluginColor.MEDIUM_GOLD.getColor()).build();
|
||||
}
|
||||
|
||||
public TextComponent.Builder playerNameBuilder(String playerName, Target selection) {
|
||||
|
@ -14,6 +14,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -113,9 +114,11 @@ public class MessageWriter {
|
||||
.append(space())
|
||||
.append(componentFactory.messageComponent().content("You need to wait")
|
||||
.append(space())
|
||||
.append(componentFactory.messageAccentComponent().content(config.getStatShareWaitingTime() + ""))
|
||||
.append(space()))
|
||||
.append(text("minutes before you are able to share again!"));
|
||||
.append(componentFactory.messageAccentComponent()
|
||||
.content(config.getStatShareWaitingTime() + " minute(s)")
|
||||
.decorate(TextDecoration.ITALIC))
|
||||
.append(space())
|
||||
.append(text("between sharing!")));
|
||||
}
|
||||
|
||||
public TextComponent resultsAlreadyShared() {
|
||||
@ -199,8 +202,9 @@ public class MessageWriter {
|
||||
.build();
|
||||
}
|
||||
|
||||
public TextComponent addShareButton(TextComponent component, UUID shareCode) {
|
||||
return component.append(newline())
|
||||
public TextComponent addShareButton(TextComponent component, UUID shareCode, Target selection) {
|
||||
TextComponent toAdd = selection == Target.TOP ? Component.newline() : Component.space();
|
||||
return component.append(toAdd)
|
||||
.append(text("[SHARE]").color(PluginColor.LIGHT_BLUE.getColor())
|
||||
.clickEvent(ClickEvent.runCommand("/statshare " + shareCode))
|
||||
.hoverEvent(HoverEvent.showText(text("CLICK ME").color(PluginColor.LIGHT_GOLD.getColor()))));
|
||||
|
@ -87,7 +87,7 @@ public class StatThread extends Thread {
|
||||
|
||||
if (shareManager.isEnabled() && request.getCommandSender().hasPermission("playerstats.share")) {
|
||||
UUID shareCode = shareManager.saveStatResult(request.getCommandSender().getName(), statResult);
|
||||
statResult = messageWriter.addShareButton(statResult, shareCode);
|
||||
statResult = messageWriter.addShareButton(statResult, shareCode, request.getSelection());
|
||||
}
|
||||
adventure.sender(request.getCommandSender()).sendMessage(statResult);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user