Added signed-by-player to shared results
This commit is contained in:
parent
dcdb4293c0
commit
644a9c0e0b
|
@ -5,6 +5,8 @@ import com.gmail.artemis.the.gr8.playerstats.enums.DebugLevel;
|
|||
import com.gmail.artemis.the.gr8.playerstats.models.StatResult;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.time.Instant;
|
||||
|
@ -15,7 +17,6 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static java.time.temporal.ChronoUnit.SECONDS;
|
||||
|
||||
|
@ -80,6 +81,10 @@ public final class ShareManager {
|
|||
return isEnabled;
|
||||
}
|
||||
|
||||
public boolean senderHasPermission(CommandSender sender) {
|
||||
return !(sender instanceof ConsoleCommandSender) && sender.hasPermission("playerstats.share");
|
||||
}
|
||||
|
||||
public UUID saveStatResult(String playerName, TextComponent statResult) {
|
||||
removeExcessResults(playerName);
|
||||
|
||||
|
@ -91,6 +96,19 @@ public final class ShareManager {
|
|||
return shareCode;
|
||||
}
|
||||
|
||||
public boolean isOnCoolDown(String playerName) {
|
||||
if (waitingTime == 0 || !shareTimeStamp.containsKey(playerName)) {
|
||||
return false;
|
||||
} else {
|
||||
long seconds = SECONDS.between(shareTimeStamp.get(playerName), Instant.now());
|
||||
return seconds <= (long) waitingTime * 60;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean requestAlreadyShared(UUID shareCode) {
|
||||
return sharedResults.contains(shareCode);
|
||||
}
|
||||
|
||||
/** Takes a statResult from the internal ConcurrentHashmap,
|
||||
puts the current time in the shareTimeStamp (ConcurrentHashMap),
|
||||
puts the shareCode (UUID) in the sharedResults (ArrayBlockingQueue),
|
||||
|
@ -122,19 +140,6 @@ public final class ShareManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isOnCoolDown(String playerName) {
|
||||
if (waitingTime == 0 || !shareTimeStamp.containsKey(playerName)) {
|
||||
return false;
|
||||
} else {
|
||||
long seconds = SECONDS.between(shareTimeStamp.get(playerName), Instant.now());
|
||||
return seconds <= (long) waitingTime * 60;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean requestAlreadyShared(UUID shareCode) {
|
||||
return sharedResults.contains(shareCode);
|
||||
}
|
||||
|
||||
/** If the given player already has more than x (in this case 25) StatResults saved,
|
||||
remove the oldest one.*/
|
||||
private void removeExcessResults(String playerName) {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.gmail.artemis.the.gr8.playerstats.commands;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import com.gmail.artemis.the.gr8.playerstats.ShareManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.StandardMessage;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
@ -16,12 +14,10 @@ import java.util.UUID;
|
|||
|
||||
public class ShareCommand implements CommandExecutor {
|
||||
|
||||
private static BukkitAudiences adventure;
|
||||
private static ShareManager shareManager;
|
||||
private static OutputManager outputManager;
|
||||
|
||||
public ShareCommand(ShareManager s, OutputManager m) {
|
||||
adventure = Main.adventure();
|
||||
shareManager = s;
|
||||
outputManager = m;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ public class TabCompleter implements org.bukkit.command.TabCompleter {
|
|||
|
||||
private final List<String> commandOptions;
|
||||
|
||||
//TODO add "example" to the list
|
||||
public TabCompleter(OfflinePlayerHandler o) {
|
||||
offlinePlayerHandler = o;
|
||||
tabCompleteHelper = new TabCompleteHelper();
|
||||
|
|
|
@ -305,7 +305,7 @@ public class ComponentFactory {
|
|||
.color(HOVER_ACCENT))));
|
||||
}
|
||||
|
||||
public TextComponent sharedButtonComponent(String playerName) {
|
||||
public TextComponent sharedMessageComponent(String playerName) {
|
||||
if (playerName == null) {
|
||||
return surroundingBracketComponent(
|
||||
text("Shared!")
|
||||
|
|
|
@ -6,6 +6,9 @@ import com.gmail.artemis.the.gr8.playerstats.msg.msgutils.HelpMessage;
|
|||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
|
||||
public class ConsoleMessageWriter extends MessageWriter {
|
||||
|
||||
|
@ -24,8 +27,8 @@ public class ConsoleMessageWriter extends MessageWriter {
|
|||
if (isBukkit) {
|
||||
componentFactory = new BukkitConsoleComponentFactory(config);
|
||||
}
|
||||
else if (config.enableFestiveFormatting() || config.enableRainbowMode()) {
|
||||
//TODO Check for date
|
||||
else if (config.enableRainbowMode() ||
|
||||
(config.enableFestiveFormatting() && LocalDate.now().getMonth().equals(Month.JUNE))) {
|
||||
componentFactory = new PrideComponentFactory(config);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -11,10 +11,12 @@ import com.gmail.artemis.the.gr8.playerstats.utils.EnumHandler;
|
|||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import org.bukkit.Statistic;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
@ -39,9 +41,10 @@ public class MessageWriter {
|
|||
}
|
||||
|
||||
protected void getComponentFactory() {
|
||||
if (config.enableFestiveFormatting() || config.enableRainbowMode()) {
|
||||
//TODO check for date
|
||||
componentFactory = new PrideComponentFactory(config);
|
||||
if (config.enableRainbowMode() ||
|
||||
(config.enableFestiveFormatting() && LocalDate.now().getMonth().equals(Month.JUNE))) {
|
||||
|
||||
componentFactory = new PrideComponentFactory(config);
|
||||
}
|
||||
else {
|
||||
componentFactory = new ComponentFactory(config);
|
||||
|
@ -108,13 +111,15 @@ public class MessageWriter {
|
|||
|
||||
//TODO Make this say amount of time left
|
||||
public TextComponent stillOnShareCoolDown() {
|
||||
int waitTime = config.getStatShareWaitingTime();
|
||||
String minutes = waitTime == 1 ? " minute" : " minutes";
|
||||
|
||||
return componentFactory.pluginPrefixComponent()
|
||||
.append(space())
|
||||
.append(componentFactory.messageComponent().content("You need to wait")
|
||||
.append(space())
|
||||
.append(componentFactory.messageAccentComponent()
|
||||
.content(config.getStatShareWaitingTime() + " minute(s)")
|
||||
.decorate(TextDecoration.ITALIC))
|
||||
.content(waitTime + minutes))
|
||||
.append(space())
|
||||
.append(text("between sharing!")));
|
||||
}
|
||||
|
@ -204,12 +209,15 @@ public class MessageWriter {
|
|||
};
|
||||
}
|
||||
|
||||
public TextComponent sharedButton() {
|
||||
return componentFactory.sharedButtonComponent(null);
|
||||
//TODO add fancy hover-text with sharedResults
|
||||
public TextComponent messageShared(TextComponent statResults) {
|
||||
return componentFactory.sharedMessageComponent(null);
|
||||
//.hoverEvent(HoverEvent.showText(statResults));
|
||||
}
|
||||
|
||||
public TextComponent sharedSignature(String playerName) {
|
||||
return componentFactory.sharedButtonComponent(playerName);
|
||||
public TextComponent addSharedSignature(TextComponent statResults, String playerName) {
|
||||
return statResults.append(newline())
|
||||
.append(componentFactory.sharedMessageComponent(playerName));
|
||||
}
|
||||
|
||||
private TextComponent getTopStatsTitle(StatRequest request, int statListSize) {
|
||||
|
|
|
@ -76,11 +76,11 @@ public class OutputManager {
|
|||
}
|
||||
|
||||
public void shareStatResults(CommandSender sender, @NotNull TextComponent statResult) {
|
||||
adventure.all()
|
||||
adventure.players()
|
||||
.filterAudience(player -> !player.get(Identity.NAME)
|
||||
.orElse("").equalsIgnoreCase(sender.getName())).sendMessage(statResult);
|
||||
//TODO add sharedSignature
|
||||
adventure.sender(sender).sendMessage(msg.sharedButton());
|
||||
.orElse("").equalsIgnoreCase(sender.getName())).sendMessage(
|
||||
msg.addSharedSignature(statResult, sender.getName()));
|
||||
adventure.sender(sender).sendMessage(msg.messageShared(statResult));
|
||||
}
|
||||
|
||||
public void sendPlayerStat(StatRequest request, int playerStat) {
|
||||
|
@ -108,9 +108,7 @@ public class OutputManager {
|
|||
}
|
||||
|
||||
private void processAndSend(CommandSender sender, Function<UUID, TextComponent> buildFunction) {
|
||||
if (shareManager.isEnabled() &&
|
||||
!(sender instanceof ConsoleCommandSender) &&
|
||||
sender.hasPermission("playerstats.share")) {
|
||||
if (shareManager.isEnabled() && shareManager.senderHasPermission(sender)) {
|
||||
|
||||
UUID shareCode = shareManager.saveStatResult(sender.getName(), buildFunction.apply(null));
|
||||
adventure.sender(sender).sendMessage(buildFunction.apply(shareCode));
|
||||
|
|
Loading…
Reference in New Issue