mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-02-02 23:31:21 +01:00
Added rough share-button for testing, sharing works!
This commit is contained in:
parent
347e59220c
commit
608dfcc215
@ -7,7 +7,7 @@ import com.gmail.artemis.the.gr8.playerstats.commands.TabCompleter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.listeners.JoinListener;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.MessageWriter;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.ShareQueue;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.ShareManager;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -33,9 +33,10 @@ public class Main extends JavaPlugin {
|
||||
//first get an instance of all the classes that need to be passed along to different classes
|
||||
ConfigHandler config = new ConfigHandler(this);
|
||||
MessageWriter messageWriter = new MessageWriter(config);
|
||||
ShareManager shareManager = new ShareManager(config);
|
||||
|
||||
//initialize the threadManager
|
||||
ThreadManager threadManager = new ThreadManager(adventure(), config, messageWriter);
|
||||
ThreadManager threadManager = new ThreadManager(adventure(), config, messageWriter, shareManager);
|
||||
|
||||
//register all commands and the tabCompleter
|
||||
PluginCommand statcmd = this.getCommand("statistic");
|
||||
@ -46,7 +47,7 @@ public class Main extends JavaPlugin {
|
||||
PluginCommand reloadcmd = this.getCommand("statisticreload");
|
||||
if (reloadcmd != null) reloadcmd.setExecutor(new ReloadCommand(threadManager));
|
||||
PluginCommand sharecmd = this.getCommand("statisticshare");
|
||||
if (sharecmd != null) sharecmd.setExecutor(new ShareCommand());
|
||||
if (sharecmd != null) sharecmd.setExecutor(new ShareCommand(adventure(), shareManager));
|
||||
|
||||
//register the listener
|
||||
Bukkit.getPluginManager().registerEvents(new JoinListener(threadManager), this);
|
||||
|
@ -28,11 +28,11 @@ public class ThreadManager {
|
||||
private final HashMap<String, Thread> statThreads;
|
||||
private static long lastRecordedCalcTime;
|
||||
|
||||
public ThreadManager(BukkitAudiences a, ConfigHandler c, MessageWriter m) {
|
||||
public ThreadManager(BukkitAudiences a, ConfigHandler c, MessageWriter m, ShareManager s) {
|
||||
adventure = a;
|
||||
config = c;
|
||||
messageWriter = m;
|
||||
shareManager = new ShareManager(config);
|
||||
shareManager = s;
|
||||
|
||||
statThreads = new HashMap<>();
|
||||
statThreadID = 0;
|
||||
|
@ -1,16 +1,27 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.commands;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.ShareManager;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ShareCommand implements CommandExecutor {
|
||||
|
||||
private final BukkitAudiences adventure;
|
||||
private final ShareManager shareManager;
|
||||
|
||||
public ShareCommand(BukkitAudiences a, ShareManager s) {
|
||||
adventure = a;
|
||||
shareManager = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, String label, String[] args) {
|
||||
//TODO use UUID code as arg to share the appropriate statResult
|
||||
|
||||
return false;
|
||||
adventure.all().sendMessage(shareManager.getStatResult(sender.getName(), UUID.fromString(args[0])));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.msg;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.DebugLevel;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.PluginColor;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Target;
|
||||
import com.gmail.artemis.the.gr8.playerstats.config.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.enums.Unit;
|
||||
@ -11,9 +12,12 @@ import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
|
||||
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.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.map.MinecraftFont;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@ -192,6 +196,13 @@ public class MessageWriter {
|
||||
.build();
|
||||
}
|
||||
|
||||
public TextComponent addShareButton(TextComponent component, UUID shareCode) {
|
||||
return component.append(newline())
|
||||
.append(text("[SHARE]").color(PluginColor.LIGHT_BLUE.getColor())
|
||||
.clickEvent(ClickEvent.runCommand("/statshare " + shareCode))
|
||||
.hoverEvent(HoverEvent.showText(text("CLICK ME").color(PluginColor.LIGHT_GOLD.getColor()))));
|
||||
}
|
||||
|
||||
/** Depending on the config settings, return either a TranslatableComponent representing
|
||||
the statName (and potential subStatName), or a TextComponent with capitalized English names.*/
|
||||
private TextComponent getStatNameComponent(StatRequest request) {
|
||||
|
@ -26,6 +26,7 @@ public class ShareManager {
|
||||
isEnabled = config.enableStatSharing();
|
||||
waitingTime = config.getStatShareWaitingTime();
|
||||
if (isEnabled) {
|
||||
resultID = new AtomicInteger();
|
||||
statResults = new ConcurrentHashMap<>();
|
||||
shareTimeStamp = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public class StatThread extends Thread {
|
||||
}
|
||||
if (shareManager.isEnabled()) {
|
||||
UUID shareCode = shareManager.saveStatResult(request.getCommandSender().getName(), statResult);
|
||||
statResult = messageWriter.addShareButton(statResult, shareCode);
|
||||
}
|
||||
adventure.sender(request.getCommandSender()).sendMessage(statResult);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user