mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-01-22 21:41:19 +01:00
Finally got Adventure library to work
This commit is contained in:
parent
bc0ec51f36
commit
dab141f4ca
@ -11,6 +11,11 @@
|
||||
<option name="name" value="spigot-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype-oss-snapshots1" />
|
||||
<option name="name" value="sonatype-oss-snapshots1" />
|
||||
<option name="url" value="https://s01.oss.sonatype.org/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
|
71
dependency-reduced-pom.xml
Normal file
71
dependency-reduced-pom.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.gmail.artemis-the-gr8</groupId>
|
||||
<artifactId>PlayerStats</artifactId>
|
||||
<version>1.0</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer>
|
||||
<mainClass>com.gmail.artemis.the.gr8.playerstats.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.jetbrains:annotations</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-oss-snapshots1</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
</properties>
|
||||
</project>
|
62
pom.xml
62
pom.xml
@ -8,11 +8,22 @@
|
||||
<artifactId>PlayerStats</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sonatype-oss-snapshots1</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -23,19 +34,56 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>com.gmail.artemis.the.gr8.playerstats.Main</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>org.jetbrains:annotations</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -7,19 +7,32 @@ import com.gmail.artemis.the.gr8.playerstats.filehandlers.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.listeners.JoinListener;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OutputFormatter;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
private static boolean enableHexColors;
|
||||
private BukkitAudiences adventure;
|
||||
|
||||
public @NotNull BukkitAudiences adventure() {
|
||||
if (adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return adventure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
//initialize the Adventure library
|
||||
adventure = BukkitAudiences.create(this);
|
||||
|
||||
//check if Spigot ChatColors can be used, and prepare accordingly
|
||||
try {
|
||||
Class.forName("net.md_5.bungee.api.ChatColor");
|
||||
@ -37,9 +50,6 @@ public class Main extends JavaPlugin {
|
||||
OfflinePlayerHandler offlinePlayerHandler = new OfflinePlayerHandler(config);
|
||||
getLogger().info("Amount of offline players: " + offlinePlayerHandler.getOfflinePlayerCount());
|
||||
|
||||
//get private lists ready with item/material/entity/stat names
|
||||
//EnumHandler.prepareLists();
|
||||
|
||||
//register the commands
|
||||
PluginCommand statcmd = this.getCommand("statistic");
|
||||
if (statcmd != null) {
|
||||
@ -47,7 +57,7 @@ public class Main extends JavaPlugin {
|
||||
statcmd.setTabCompleter(new TabCompleter(offlinePlayerHandler));
|
||||
}
|
||||
PluginCommand reloadcmd = this.getCommand("statisticreload");
|
||||
if (reloadcmd != null) reloadcmd.setExecutor(new ReloadCommand(config, offlinePlayerHandler, outputFormatter, this));
|
||||
if (reloadcmd != null) reloadcmd.setExecutor(new ReloadCommand(adventure(), config, offlinePlayerHandler, outputFormatter, this));
|
||||
|
||||
//register the listener
|
||||
Bukkit.getPluginManager().registerEvents(new JoinListener(offlinePlayerHandler), this);
|
||||
@ -57,6 +67,11 @@ public class Main extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (adventure != null) {
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
}
|
||||
|
||||
this.getLogger().info("Disabled PlayerStats!");
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,15 @@ package com.gmail.artemis.the.gr8.playerstats.commands;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import com.gmail.artemis.the.gr8.playerstats.filehandlers.ConfigHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.ComponentFactory;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OfflinePlayerHandler;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.OutputFormatter;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -12,13 +19,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ReloadCommand implements CommandExecutor {
|
||||
|
||||
private final BukkitAudiences adventure;
|
||||
private final ConfigHandler config;
|
||||
private final OfflinePlayerHandler offlinePlayerHandler;
|
||||
private final OutputFormatter outputFormatter;
|
||||
private final Main plugin;
|
||||
|
||||
|
||||
public ReloadCommand(ConfigHandler c, OfflinePlayerHandler of, OutputFormatter o, Main p) {
|
||||
public ReloadCommand(BukkitAudiences b, ConfigHandler c, OfflinePlayerHandler of, OutputFormatter o, Main p) {
|
||||
adventure = b;
|
||||
offlinePlayerHandler = of;
|
||||
outputFormatter = o;
|
||||
config = c;
|
||||
@ -32,7 +41,15 @@ public class ReloadCommand implements CommandExecutor {
|
||||
offlinePlayerHandler.updateOfflinePlayerList();
|
||||
|
||||
plugin.getLogger().info("Amount of players: " + offlinePlayerHandler.getOfflinePlayerCount());
|
||||
sender.sendMessage(outputFormatter.getPluginPrefix() + ChatColor.GREEN + "Config reloaded!");
|
||||
|
||||
TextComponent t = Component.text("Hello :D").color(TextColor.fromHexString("#fc4e03"));
|
||||
TextComponent subt = Component.text("Red ").color(NamedTextColor.RED)
|
||||
.append(Component.text(" - for comparison - ").color(TextColor.fromHexString("#fc4e03")))
|
||||
.append(Component.text(" Gold").color(NamedTextColor.GOLD));
|
||||
Title title = Title.title(t, subt);
|
||||
adventure.player(offlinePlayerHandler.getOfflinePlayerUUID("Artemis_the_gr8")).showTitle(title);
|
||||
adventure.sender(sender).sendMessage(ComponentFactory.helpMsg());
|
||||
sender.sendMessage(OutputFormatter.getPluginPrefix() + ChatColor.GREEN + "Config reloaded!");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -72,7 +72,7 @@ public class StatCommand implements CommandExecutor {
|
||||
}
|
||||
else {
|
||||
if (Main.hexEnabled()) {
|
||||
sender.spigot().sendMessage(outputFormatter.formatHelpSpigot());
|
||||
//sender.spigot().sendMessage(outputFormatter.formatHelpSpigot());
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(outputFormatter.formatHelpBukkit());
|
||||
@ -83,7 +83,7 @@ public class StatCommand implements CommandExecutor {
|
||||
|
||||
else {
|
||||
if (Main.hexEnabled()) {
|
||||
sender.spigot().sendMessage(outputFormatter.formatHelpSpigot());
|
||||
//sender.spigot().sendMessage(outputFormatter.formatHelpSpigot());
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(outputFormatter.formatHelpBukkit());
|
||||
|
@ -0,0 +1,85 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
import static net.kyori.adventure.text.Component.newline;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class ComponentFactory {
|
||||
|
||||
public static TextComponent helpMsg() {
|
||||
TextComponent spaces = text(" ");
|
||||
TextComponent underscores = text("____________").color(TextColor.fromHexString("#6E3485"));
|
||||
TextComponent arrow = text("→ ").color(NamedTextColor.GOLD);
|
||||
|
||||
//the builder
|
||||
TextComponent helpMsg = Component.newline()
|
||||
.append(underscores).append(spaces).append(text(OutputFormatter.getPluginPrefix())).append(spaces).append(underscores)
|
||||
.append(newline())
|
||||
.append(text("Hover over the arguments for more information!").color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC))
|
||||
.append(newline())
|
||||
.append(text("Usage: ").color(NamedTextColor.GOLD)).append(text("/statistic").color(NamedTextColor.YELLOW))
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow)
|
||||
.append(text("name").color(NamedTextColor.YELLOW)
|
||||
.hoverEvent(HoverEvent.showText(text("The name of the statistic").color(TextColor.fromHexString("#FFD52B"))
|
||||
.append(newline())
|
||||
.append(text("Example: ").color(TextColor.fromHexString("#FFD52B")))
|
||||
.append(text("\"mine_block\"").color(NamedTextColor.YELLOW)))))
|
||||
.append(newline())
|
||||
.append(spaces).append(arrow)
|
||||
.append(text("sub-statistic"));
|
||||
|
||||
return helpMsg;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public BaseComponent[] formatHelpSpigot() {
|
||||
String spaces = " ";
|
||||
String underscores = "____________";
|
||||
|
||||
ComponentBuilder underscore = new ComponentBuilder(underscores).color(net.md_5.bungee.api.ChatColor.of("#6E3485"));
|
||||
TextComponent arrow = new TextComponent("→ ");
|
||||
arrow.setColor(net.md_5.bungee.api.ChatColor.GOLD);
|
||||
|
||||
TextComponent statName = new TextComponent("name");
|
||||
statName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
statName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("The name of the statistic (Example: \"mine_block\")")));
|
||||
|
||||
TextComponent subStatName = new TextComponent("sub-statistic");
|
||||
subStatName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
subStatName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Some statistics require an item, block or entity as sub-statistic (example: \"mine_block diorite\")")));
|
||||
|
||||
TextComponent target = new TextComponent("me | player | top");
|
||||
target.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
target.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("Choose whether you want to see your own statistic, another player's, or the top " + config.getTopListMaxSize())));
|
||||
|
||||
TextComponent playerName = new TextComponent("player-name");
|
||||
playerName.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
|
||||
playerName.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text("In case you selected \"player\", specify the player's name here")));
|
||||
|
||||
ComponentBuilder help = new ComponentBuilder()
|
||||
.append("\n").append(underscore.create()).append(spaces).append(pluginPrefix).append(spaces).append(underscore.create()).append("\n")
|
||||
.append("Hover over the arguments for more information!").color(net.md_5.bungee.api.ChatColor.GRAY).italic(true).append("\n")
|
||||
.append("Usage: ").color(net.md_5.bungee.api.ChatColor.GOLD).italic(false)
|
||||
.append("/statistic ").color(net.md_5.bungee.api.ChatColor.YELLOW).append("\n")
|
||||
.append(spaces).append(arrow).append(statName).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(subStatName).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(target).append("\n").reset()
|
||||
.append(spaces).append(arrow).append(playerName);
|
||||
|
||||
return help.create();
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
@ -51,4 +51,8 @@ public class OfflinePlayerHandler {
|
||||
public OfflinePlayer getOfflinePlayer(String playerName) {
|
||||
return Bukkit.getOfflinePlayer(offlinePlayerUUIDs.get(playerName));
|
||||
}
|
||||
|
||||
public UUID getOfflinePlayerUUID(String playerName) {
|
||||
return offlinePlayerUUIDs.get(playerName);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,6 @@
|
||||
package com.gmail.artemis.the.gr8.playerstats.utils;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.filehandlers.ConfigHandler;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.map.MinecraftFont;
|
||||
|
||||
@ -19,7 +14,7 @@ public class OutputFormatter {
|
||||
private HashMap<String, ChatColor> chatColors;
|
||||
private HashMap<String, ChatColor> styleOptions;
|
||||
private HashMap<String, net.md_5.bungee.api.ChatColor> hexChatColors;
|
||||
private final String pluginPrefix;
|
||||
private static String pluginPrefix;
|
||||
|
||||
public OutputFormatter(ConfigHandler c, boolean enableHexColors) {
|
||||
config = c;
|
||||
@ -33,7 +28,7 @@ public class OutputFormatter {
|
||||
updateOutPutColors(useHex);
|
||||
}
|
||||
|
||||
public String getPluginPrefix() {
|
||||
public static String getPluginPrefix() {
|
||||
return pluginPrefix;
|
||||
}
|
||||
|
||||
@ -41,6 +36,8 @@ public class OutputFormatter {
|
||||
return pluginPrefix + exception;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public BaseComponent[] formatHelpSpigot() {
|
||||
String spaces = " ";
|
||||
String underscores = "____________";
|
||||
@ -82,6 +79,8 @@ public class OutputFormatter {
|
||||
return help.create();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public String formatHelpBukkit() {
|
||||
String spaces = " ";
|
||||
String underscores = ChatColor.GRAY + "____________";
|
||||
|
Loading…
Reference in New Issue
Block a user