mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
started moving to pure adventure
This commit is contained in:
parent
dd7751332f
commit
d7a4acc2f5
16
build.gradle
16
build.gradle
@ -14,6 +14,7 @@ description "An awesome placeholder provider!"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
|
||||
maven({ url = "https://repo.codemc.org/repository/maven-public" })
|
||||
maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" })
|
||||
@ -24,10 +25,9 @@ dependencies {
|
||||
implementation "com.google.code.gson:gson:2.8.6"
|
||||
implementation "org.bstats:bstats-bukkit:2.2.1"
|
||||
|
||||
implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT"
|
||||
implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT"
|
||||
|
||||
compileOnly "org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT"
|
||||
compileOnly "org.spigotmc:spigot:+"
|
||||
compileOnly "org.jetbrains:annotations:19.0.0"
|
||||
|
||||
testImplementation "org.openjdk.jmh:jmh-core:1.23"
|
||||
@ -63,6 +63,18 @@ tasks.withType(Javadoc) {
|
||||
shadowJar {
|
||||
archiveClassifier.set("")
|
||||
|
||||
// destinationDirectory.set(file("server/1.17/plugins"))
|
||||
// doLast {
|
||||
// def path = "build/libs/PlaceholderAPI-2.10.10-DEV-null.jar"
|
||||
//
|
||||
// ["1.17", "1.8"].each {dest ->
|
||||
// copy {
|
||||
// from path
|
||||
// into "server/${dest}/plugins/"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
relocate "org.bstats", "me.clip.placeholderapi.metrics"
|
||||
relocate "com.google.gson", "me.clip.placeholderapi.libs.gson"
|
||||
relocate "net.kyori", "me.clip.placeholderapi.libs.kyori"
|
||||
|
@ -75,7 +75,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
|
||||
@NotNull
|
||||
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
|
||||
@NotNull
|
||||
|
||||
private BukkitAudiences adventure;
|
||||
|
||||
/**
|
||||
@ -143,7 +143,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
setupMetrics();
|
||||
setupExpansions();
|
||||
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
adventure = BukkitAudiences.create(this);
|
||||
|
||||
if (config.isCloudEnabled()) {
|
||||
getCloudExpansionManager().load();
|
||||
@ -163,6 +163,9 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
|
||||
adventure.close();
|
||||
adventure = null;
|
||||
|
||||
instance = null;
|
||||
}
|
||||
|
||||
@ -191,11 +194,12 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitAudiences adventure() {
|
||||
if(this.adventure == null) {
|
||||
public BukkitAudiences getAdventure() {
|
||||
if(adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
|
||||
return adventure;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,14 +26,7 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@ -47,12 +40,23 @@ import me.clip.placeholderapi.util.Format;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minecraft.network.chat.ChatMessageType;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutChat;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import static net.kyori.adventure.text.Component.*;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.*;
|
||||
|
||||
public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
|
||||
@ -142,89 +146,55 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
final int page, final int limit, @NotNull final String target) {
|
||||
final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
|
||||
|
||||
// Overall being send
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final TextComponent.Builder message = text();
|
||||
|
||||
for (int index = 0; index < expansions.size(); index++) {
|
||||
final CloudExpansion expansion = expansions.get(index);
|
||||
final TextComponent.Builder line = text();
|
||||
|
||||
// Hover desc per expansion
|
||||
final StringBuilder desc = new StringBuilder();
|
||||
final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1;
|
||||
line.append(text(expansionNumber + ". ", DARK_GRAY));
|
||||
|
||||
desc.append("<blue>Click to download this expansion!")
|
||||
.append('\n')
|
||||
.append('\n')
|
||||
.append("<blue>Author: <white>")
|
||||
.append(expansion.getAuthor())
|
||||
.append('\n')
|
||||
.append("<blue>Verified: ")
|
||||
.append(expansion.isVerified() ? "<green><bold✔</bold></green>" : "<red><bold>❌</bold></red>")
|
||||
.append('\n')
|
||||
.append("<blue>Latest Version: <white>")
|
||||
.append(expansion.getLatestVersion())
|
||||
.append('\n')
|
||||
.append("<blue>Released: <white>")
|
||||
.append(format.format(expansion.getLastUpdate()));
|
||||
final NamedTextColor expansionColour;
|
||||
|
||||
final String description = expansion.getDescription();
|
||||
if (description != null && !description.isEmpty()) {
|
||||
desc.append('\n')
|
||||
.append('\n')
|
||||
.append("<white>")
|
||||
.append(description.replace("\r", "").trim());
|
||||
}
|
||||
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
content.append("<dark_gray>")
|
||||
.append(index + ((page - 1) * PAGE_SIZE) + 1)
|
||||
.append(".</dark_gray> ")
|
||||
.append(expansion.shouldUpdate() ? "<gold>" : expansion.hasExpansion() ? "<green>" : "<gray>")
|
||||
.append(expansion.getName());
|
||||
|
||||
// message.append(Component.text(Msg.color(
|
||||
// "&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6"
|
||||
// : expansion.hasExpansion() ? "&a" : "&7") + expansion.getName()));
|
||||
|
||||
sb.append("<click:suggest_command:/papi ecloud download ")
|
||||
.append(expansion.getName())
|
||||
.append("><hover:show_text:'")
|
||||
.append(desc)
|
||||
.append("'>")
|
||||
.append(content)
|
||||
.append("</hover>");
|
||||
|
||||
// message.tooltip(Msg.color(tooltip.toString()));
|
||||
// message.suggestCommand("/papi ecloud download " + expansion.getName());
|
||||
|
||||
if (index < expansions.size() - 1) {
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
//tooltip.setLength(0);
|
||||
}
|
||||
|
||||
if (limit > 1) {
|
||||
// message.newline();
|
||||
sb.append("\n");
|
||||
|
||||
// message.then("◀").color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY);
|
||||
sb.append(page > 1 ? "<gray>" : "<dark_gray>").append("◀");
|
||||
if (page > 1) {
|
||||
// message.runCommand("/papi ecloud list " + target + " " + (page - 1));
|
||||
}
|
||||
|
||||
// message.then(" " + page + " ").color(ChatColor.GREEN);
|
||||
sb.append("<green> " + page + " </green>");
|
||||
|
||||
// message.then("▶").color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY);
|
||||
sb.append(page < limit ? "<gray>" : "<dark_gray>").append("▶");
|
||||
if (page < limit) {
|
||||
// message.runCommand("/papi ecloud list " + target + " " + (page + 1));
|
||||
if (expansion.shouldUpdate()) {
|
||||
expansionColour = GOLD;
|
||||
} else {
|
||||
if (expansion.hasExpansion()) {
|
||||
expansionColour = GREEN;
|
||||
} else {
|
||||
expansionColour = GRAY;
|
||||
}
|
||||
}
|
||||
|
||||
return MiniMessage.get().parse(sb.toString());
|
||||
line.append(text(expansion.getName(), expansionColour));
|
||||
|
||||
line.clickEvent(ClickEvent.suggestCommand("/papi ecloud download " + expansion.getName()));
|
||||
|
||||
final TextComponent.Builder hoverText = text("Click to download this expansion!", AQUA)
|
||||
.append(newline()).append(newline())
|
||||
.append(text("Author: ", AQUA)).append(text(expansion.getAuthor(), WHITE))
|
||||
.append(newline())
|
||||
.append(text("Verified: ", AQUA)).append(text(expansion.isVerified() ? "✔" : "❌", expansion.isVerified() ? GREEN : RED, TextDecoration.BOLD))
|
||||
.append(newline())
|
||||
.append(text("Released: ", AQUA)).append(text(format.format(expansion.getLastUpdate()), WHITE))
|
||||
.toBuilder();
|
||||
|
||||
Optional.ofNullable(expansion.getDescription())
|
||||
.filter(description -> !description.isEmpty())
|
||||
.ifPresent(description -> hoverText.append(newline()).append(newline())
|
||||
.append(text(description.replace("\r", "").trim(), WHITE))
|
||||
);
|
||||
|
||||
line.hoverEvent(HoverEvent.showText(hoverText.build()));
|
||||
line.append(newline());
|
||||
|
||||
message.append(line.build());
|
||||
}
|
||||
|
||||
message.append(text("test").hoverEvent(HoverEvent.showText(text("testtt"))));
|
||||
|
||||
return message.build();
|
||||
}
|
||||
|
||||
private static void addExpansionTable(@NotNull final List<CloudExpansion> expansions,
|
||||
@ -344,7 +314,9 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
|
||||
|
||||
final Component message = getMessage(values, page, limit, params.get(0));
|
||||
plugin.adventure().player((Player) sender).sendMessage(message);
|
||||
// plugin.getAdventure().player((Player) sender).sendMessage(message);
|
||||
System.out.println(GsonComponentSerializer.gson().serialize(message));
|
||||
((CraftPlayer) sender).getHandle().b.sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(GsonComponentSerializer.gson().serialize(message)), ChatMessageType.a, ((CraftPlayer) sender).getUniqueId()));
|
||||
//message.send(((Player) sender));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user