mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
Initial test on adventure
This commit is contained in:
parent
89053354e9
commit
dd7751332f
10
build.gradle
10
build.gradle
@ -17,12 +17,16 @@ repositories {
|
||||
|
||||
maven({ url = "https://repo.codemc.org/repository/maven-public" })
|
||||
maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" })
|
||||
maven({ url = "https://oss.sonatype.org/content/repositories/snapshots/" })
|
||||
}
|
||||
|
||||
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.jetbrains:annotations:19.0.0"
|
||||
|
||||
@ -60,6 +64,8 @@ shadowJar {
|
||||
archiveClassifier.set("")
|
||||
|
||||
relocate "org.bstats", "me.clip.placeholderapi.metrics"
|
||||
relocate "com.google.gson", "me.clip.placeholderapi.libs.gson"
|
||||
relocate "net.kyori", "me.clip.placeholderapi.libs.kyori"
|
||||
}
|
||||
|
||||
license {
|
||||
@ -69,10 +75,6 @@ license {
|
||||
header = file('config/headers/main.txt')
|
||||
}
|
||||
|
||||
matching('**/JSONMessage.java') {
|
||||
header = file('config/headers/jsonmessage.txt')
|
||||
}
|
||||
|
||||
ext {
|
||||
year = 2021
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import me.clip.placeholderapi.expansion.manager.CloudExpansionManager;
|
||||
import me.clip.placeholderapi.expansion.manager.LocalExpansionManager;
|
||||
import me.clip.placeholderapi.listeners.ServerLoadEventListener;
|
||||
import me.clip.placeholderapi.updatechecker.UpdateChecker;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.AdvancedPie;
|
||||
import org.bstats.charts.SimplePie;
|
||||
@ -74,6 +75,8 @@ 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;
|
||||
|
||||
/**
|
||||
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
|
||||
@ -140,6 +143,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
setupMetrics();
|
||||
setupExpansions();
|
||||
|
||||
this.adventure = BukkitAudiences.create(this);
|
||||
|
||||
if (config.isCloudEnabled()) {
|
||||
getCloudExpansionManager().load();
|
||||
}
|
||||
@ -185,6 +190,14 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
|
||||
return cloudExpansionManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitAudiences adventure() {
|
||||
if(this.adventure == null) {
|
||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||
}
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the configuration class for PlaceholderAPI.
|
||||
*
|
||||
|
@ -43,9 +43,11 @@ import me.clip.placeholderapi.commands.PlaceholderCommand;
|
||||
import me.clip.placeholderapi.configuration.ExpansionSort;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import me.clip.placeholderapi.libs.JSONMessage;
|
||||
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 org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -136,73 +138,93 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
.append('\n');
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JSONMessage getMessage(@NotNull final List<CloudExpansion> expansions,
|
||||
final int page, final int limit, @NotNull final String target) {
|
||||
private static Component getMessage(@NotNull final List<CloudExpansion> expansions,
|
||||
final int page, final int limit, @NotNull final String target) {
|
||||
final SimpleDateFormat format = PlaceholderAPIPlugin.getDateFormat();
|
||||
|
||||
final StringBuilder tooltip = new StringBuilder();
|
||||
final JSONMessage message = JSONMessage.create();
|
||||
// Overall being send
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int index = 0; index < expansions.size(); index++) {
|
||||
final CloudExpansion expansion = expansions.get(index);
|
||||
|
||||
tooltip.append("&bClick to download this expansion!")
|
||||
// Hover desc per expansion
|
||||
final StringBuilder desc = new StringBuilder();
|
||||
|
||||
desc.append("<blue>Click to download this expansion!")
|
||||
.append('\n')
|
||||
.append('\n')
|
||||
.append("&bAuthor: &f")
|
||||
.append("<blue>Author: <white>")
|
||||
.append(expansion.getAuthor())
|
||||
.append('\n')
|
||||
.append("&bVerified: ")
|
||||
.append(expansion.isVerified() ? "&a&l✔&r" : "&c&l❌&r")
|
||||
.append("<blue>Verified: ")
|
||||
.append(expansion.isVerified() ? "<green><bold✔</bold></green>" : "<red><bold>❌</bold></red>")
|
||||
.append('\n')
|
||||
.append("&bLatest Version: &f")
|
||||
.append("<blue>Latest Version: <white>")
|
||||
.append(expansion.getLatestVersion())
|
||||
.append('\n')
|
||||
.append("&bReleased: &f")
|
||||
.append("<blue>Released: <white>")
|
||||
.append(format.format(expansion.getLastUpdate()));
|
||||
|
||||
final String description = expansion.getDescription();
|
||||
if (description != null && !description.isEmpty()) {
|
||||
tooltip.append('\n')
|
||||
desc.append('\n')
|
||||
.append('\n')
|
||||
.append("&f")
|
||||
.append("<white>")
|
||||
.append(description.replace("\r", "").trim());
|
||||
}
|
||||
|
||||
message.then(Msg.color(
|
||||
"&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6"
|
||||
: expansion.hasExpansion() ? "&a" : "&7") + expansion.getName()));
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
message.tooltip(Msg.color(tooltip.toString()));
|
||||
message.suggestCommand("/papi ecloud download " + expansion.getName());
|
||||
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) {
|
||||
message.newline();
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
tooltip.setLength(0);
|
||||
//tooltip.setLength(0);
|
||||
}
|
||||
|
||||
if (limit > 1) {
|
||||
message.newline();
|
||||
// message.newline();
|
||||
sb.append("\n");
|
||||
|
||||
message.then("◀")
|
||||
.color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY);
|
||||
// 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.runCommand("/papi ecloud list " + target + " " + (page - 1));
|
||||
}
|
||||
|
||||
message.then(" " + page + " ").color(ChatColor.GREEN);
|
||||
// message.then(" " + page + " ").color(ChatColor.GREEN);
|
||||
sb.append("<green> " + page + " </green>");
|
||||
|
||||
message.then("▶")
|
||||
.color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY);
|
||||
// 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));
|
||||
// message.runCommand("/papi ecloud list " + target + " " + (page + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
return MiniMessage.get().parse(sb.toString());
|
||||
}
|
||||
|
||||
private static void addExpansionTable(@NotNull final List<CloudExpansion> expansions,
|
||||
@ -321,8 +343,9 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
|
||||
final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE);
|
||||
|
||||
final JSONMessage message = getMessage(values, page, limit, params.get(0));
|
||||
message.send(((Player) sender));
|
||||
final Component message = getMessage(values, page, limit, params.get(0));
|
||||
plugin.adventure().player((Player) sender).sendMessage(message);
|
||||
//message.send(((Player) sender));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user