started moving to pure adventure

This commit is contained in:
PiggyPiglet 2021-07-07 15:37:35 +08:00
parent dd7751332f
commit d7a4acc2f5
No known key found for this signature in database
GPG Key ID: 0DADDAC359165A31
3 changed files with 74 additions and 86 deletions

View File

@ -14,6 +14,7 @@ description "An awesome placeholder provider!"
repositories { repositories {
mavenCentral() mavenCentral()
mavenLocal()
maven({ url = "https://repo.codemc.org/repository/maven-public" }) maven({ url = "https://repo.codemc.org/repository/maven-public" })
maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }) 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 "com.google.code.gson:gson:2.8.6"
implementation "org.bstats:bstats-bukkit:2.2.1" 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" 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" compileOnly "org.jetbrains:annotations:19.0.0"
testImplementation "org.openjdk.jmh:jmh-core:1.23" testImplementation "org.openjdk.jmh:jmh-core:1.23"
@ -63,6 +63,18 @@ tasks.withType(Javadoc) {
shadowJar { shadowJar {
archiveClassifier.set("") 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 "org.bstats", "me.clip.placeholderapi.metrics"
relocate "com.google.gson", "me.clip.placeholderapi.libs.gson" relocate "com.google.gson", "me.clip.placeholderapi.libs.gson"
relocate "net.kyori", "me.clip.placeholderapi.libs.kyori" relocate "net.kyori", "me.clip.placeholderapi.libs.kyori"

View File

@ -75,7 +75,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this); private final LocalExpansionManager localExpansionManager = new LocalExpansionManager(this);
@NotNull @NotNull
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this); private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);
@NotNull
private BukkitAudiences adventure; private BukkitAudiences adventure;
/** /**
@ -143,7 +143,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
setupMetrics(); setupMetrics();
setupExpansions(); setupExpansions();
this.adventure = BukkitAudiences.create(this); adventure = BukkitAudiences.create(this);
if (config.isCloudEnabled()) { if (config.isCloudEnabled()) {
getCloudExpansionManager().load(); getCloudExpansionManager().load();
@ -163,6 +163,9 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
Bukkit.getScheduler().cancelTasks(this); Bukkit.getScheduler().cancelTasks(this);
adventure.close();
adventure = null;
instance = null; instance = null;
} }
@ -191,11 +194,12 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
} }
@NotNull @NotNull
public BukkitAudiences adventure() { public BukkitAudiences getAdventure() {
if(this.adventure == null) { if(adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
} }
return this.adventure;
return adventure;
} }
/** /**

View File

@ -26,14 +26,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
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.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -47,12 +40,23 @@ import me.clip.placeholderapi.util.Format;
import me.clip.placeholderapi.util.Msg; import me.clip.placeholderapi.util.Msg;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.ChatColor; 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.command.CommandSender;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable; 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 { 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 int page, final int limit, @NotNull final String target) {
final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat(); final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
// Overall being send final TextComponent.Builder message = text();
final StringBuilder sb = new StringBuilder();
for (int index = 0; index < expansions.size(); index++) { for (int index = 0; index < expansions.size(); index++) {
final CloudExpansion expansion = expansions.get(index); final CloudExpansion expansion = expansions.get(index);
final TextComponent.Builder line = text();
// Hover desc per expansion final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1;
final StringBuilder desc = new StringBuilder(); line.append(text(expansionNumber + ". ", DARK_GRAY));
desc.append("<blue>Click to download this expansion!") final NamedTextColor expansionColour;
.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 String description = expansion.getDescription(); if (expansion.shouldUpdate()) {
if (description != null && !description.isEmpty()) { expansionColour = GOLD;
desc.append('\n') } else {
.append('\n') if (expansion.hasExpansion()) {
.append("<white>") expansionColour = GREEN;
.append(description.replace("\r", "").trim()); } else {
} expansionColour = GRAY;
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));
} }
} }
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, 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 int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
final Component message = getMessage(values, page, limit, params.get(0)); 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)); //message.send(((Player) sender));
} }