mirror of
https://github.com/itHotL/PlayerStats.git
synced 2025-02-10 00:41:21 +01:00
Started experimenting with serializing my Components into String
This commit is contained in:
parent
8be8d7962a
commit
fe4f5db12e
6
pom.xml
6
pom.xml
@ -63,12 +63,6 @@
|
||||
<version>4.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-plain</artifactId>
|
||||
<version>4.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
|
@ -2,14 +2,22 @@ package com.gmail.artemis.the.gr8.playerstats.api;
|
||||
|
||||
import com.gmail.artemis.the.gr8.playerstats.Main;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentIteratorType;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.renderer.TranslatableComponentRenderer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static net.kyori.adventure.translation.GlobalTranslator.renderer;
|
||||
|
||||
/** This is the outgoing API that you can use to access the core functionality of PlayerStats.
|
||||
To work with it, you need to call PlayerStats.{@link #getAPI()} to get an instance of {@link PlayerStatsAPI}.
|
||||
You can then use this object to access any of the further methods.
|
||||
@ -42,7 +50,7 @@ public interface PlayerStats {
|
||||
Adventure's TextComponents, you can call this method to turn any stat-result into a String.
|
||||
@return a String representation of this TextComponent, without color and style, but with line-breaks*/
|
||||
default String statResultComponentToString(TextComponent statResult) {
|
||||
return PlainTextComponentSerializer.plainText().serialize(statResult);
|
||||
return LegacyComponentSerializer.builder().hexColors().build().serialize(statResult);
|
||||
}
|
||||
|
||||
/** Get a formatted player-statistic of Statistic.Type UNTYPED.
|
||||
|
@ -4,16 +4,15 @@ import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.msg.OutputManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.statistic.RequestManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.models.StatRequest;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Color;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
public class StatCommand implements CommandExecutor {
|
||||
|
||||
@ -38,10 +37,28 @@ public class StatCommand implements CommandExecutor {
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase(">:(")) {
|
||||
java.awt.Color color = new java.awt.Color(178, 102, 255);
|
||||
ChatColor one = ChatColor.of(color);
|
||||
TextComponent msg = new TextComponent(">:(((((");
|
||||
msg.setColor(one);
|
||||
sender.spigot().sendMessage(msg);
|
||||
// ChatColor one = ChatColor.of(color);
|
||||
// TextComponent msg = new TextComponent(">:(((((");
|
||||
// msg.setColor(one);
|
||||
// sender.spigot().sendMessage(msg);
|
||||
// sender.sendMessage("regular msg with ChatColor: " + one + ">:((((((");
|
||||
// sender.sendMessage("regular msg Component.toLegacyText: " + msg.toLegacyText());
|
||||
// sender.sendMessage("regular msg Component.toString: " + msg);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase(">:((")) {
|
||||
Component msg = MiniMessage.miniMessage().deserialize("<gradient:#f74040:#FF6600:#f74040>fire demon</gradient>");
|
||||
String msgString = LegacyComponentSerializer.builder().hexColors().build().serialize(msg);
|
||||
sender.sendMessage("LCS.hexColors(): " + msgString);
|
||||
MyLogger.logMsg(msgString);
|
||||
|
||||
String msgString2 = LegacyComponentSerializer.legacySection().serialize(msg);
|
||||
sender.sendMessage("LCS.legacySection: " + msgString2);
|
||||
MyLogger.logMsg(msgString2);
|
||||
|
||||
//only this one works both in-game and in-console
|
||||
String msgString3 = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build().serialize(msg);
|
||||
sender.sendMessage("LCS.hexColors().spigotformat...: " + msgString3);
|
||||
MyLogger.logMsg(msgString3);
|
||||
}
|
||||
else {
|
||||
StatRequest request = requestManager.generateRequest(sender, args);
|
||||
|
@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public final class StatRequest {
|
||||
|
||||
private final CommandSender sender;
|
||||
private final boolean isAPIRequest;
|
||||
private boolean isAPIRequest;
|
||||
private Statistic statistic;
|
||||
private String playerName;
|
||||
private Target selection;
|
||||
@ -38,6 +38,10 @@ public final class StatRequest {
|
||||
playerFlag = false;
|
||||
}
|
||||
|
||||
public void setAPIRequest() {
|
||||
this.isAPIRequest = true;
|
||||
}
|
||||
|
||||
public boolean isAPIRequest() {
|
||||
return isAPIRequest;
|
||||
}
|
||||
|
@ -62,6 +62,9 @@ public class RequestManager implements RequestGenerator {
|
||||
request.setPlayerName(arg);
|
||||
request.setSelection(Target.PLAYER);
|
||||
}
|
||||
else if (arg.equalsIgnoreCase("api")) {
|
||||
request.setAPIRequest();
|
||||
}
|
||||
}
|
||||
patchRequest(request);
|
||||
return request;
|
||||
|
@ -8,6 +8,8 @@ import com.gmail.artemis.the.gr8.playerstats.reload.ReloadThread;
|
||||
import com.gmail.artemis.the.gr8.playerstats.ThreadManager;
|
||||
import com.gmail.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
@ -63,7 +65,16 @@ public class StatThread extends Thread {
|
||||
case TOP -> outputManager.formatTopStat(request, statManager.getTopStats(request));
|
||||
case SERVER -> outputManager.formatServerStat(request, statManager.getServerStat(request));
|
||||
};
|
||||
outputManager.sendToCommandSender(request.getCommandSender(), statResult);
|
||||
if (request.isAPIRequest()) {
|
||||
String msg = LegacyComponentSerializer.builder().hexColors().build().serialize(statResult);
|
||||
request.getCommandSender().sendMessage(msg);
|
||||
|
||||
String msg2 = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build().serialize(statResult);
|
||||
request.getCommandSender().sendMessage(msg2);
|
||||
}
|
||||
else {
|
||||
outputManager.sendToCommandSender(request.getCommandSender(), statResult);
|
||||
}
|
||||
}
|
||||
catch (ConcurrentModificationException e) {
|
||||
if (!request.isConsoleSender()) {
|
||||
|
Loading…
Reference in New Issue
Block a user