Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ version "2.10.10-DEV-${System.getProperty("BUILD_NUMBER")}"
description "An awesome placeholder provider!"

repositories {
maven({ url = "https://oss.sonatype.org/content/repositories/snapshots/" })

mavenCentral()
mavenLocal()

maven({ url = "https://repo.codemc.org/repository/maven-public" })
maven({ url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" })
}

dependencies {
implementation "com.google.code.gson:gson:2.8.6"
implementation "org.bstats:bstats-bukkit:2.2.1"

compileOnly "org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT"
implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT"

compileOnly "org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT"
compileOnly "org.jetbrains:annotations:19.0.0"

testImplementation "org.openjdk.jmh:jmh-core:1.23"
Expand Down Expand Up @@ -60,6 +64,7 @@ shadowJar {
archiveClassifier.set("")

relocate "org.bstats", "me.clip.placeholderapi.metrics"
relocate "net.kyori", "me.clip.placeholderapi.libs.kyori"
}

license {
Expand All @@ -69,10 +74,6 @@ license {
header = file('config/headers/main.txt')
}

matching('**/JSONMessage.java') {
header = file('config/headers/jsonmessage.txt')
}

ext {
year = 2021
}
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
18 changes: 18 additions & 0 deletions src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
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 net.kyori.adventure.text.serializer.craftbukkit.MinecraftComponentSerializer;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.AdvancedPie;
import org.bstats.charts.SimplePie;
Expand Down Expand Up @@ -75,6 +77,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin {
@NotNull
private final CloudExpansionManager cloudExpansionManager = new CloudExpansionManager(this);

private BukkitAudiences adventure;

/**
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
* class, this is the main class that extends JavaPlugin. For most API methods, use static methods
Expand Down Expand Up @@ -140,6 +144,8 @@ public void onEnable() {
setupMetrics();
setupExpansions();

adventure = BukkitAudiences.create(this);

if (config.isCloudEnabled()) {
getCloudExpansionManager().load();
}
Expand All @@ -158,6 +164,9 @@ public void onDisable() {

Bukkit.getScheduler().cancelTasks(this);

adventure.close();
adventure = null;

instance = null;
}

Expand Down Expand Up @@ -185,6 +194,15 @@ public CloudExpansionManager getCloudExpansionManager() {
return cloudExpansionManager;
}

@NotNull
public BukkitAudiences getAdventure() {
if(adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}

return adventure;
}

/**
* Obtain the configuration class for PlaceholderAPI.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,7 @@
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;
Expand All @@ -43,15 +36,22 @@
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 org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
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 org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;

import static net.kyori.adventure.text.Component.*;
import static net.kyori.adventure.text.format.NamedTextColor.*;

public final class CommandECloudExpansionList extends PlaceholderCommand {

private static final int PAGE_SIZE = 10;
Expand Down Expand Up @@ -132,77 +132,81 @@ public static void addExpansionTitle(@NotNull final StringBuilder builder,

builder.append(" &bPage&7: &a")
.append(page)
.append("&r")
.append('\n');
.append("&r");
}

@NotNull
private static JSONMessage getMessage(@NotNull final List<CloudExpansion> expansions,
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();
final TextComponent.Builder message = text();

for (int index = 0; index < expansions.size(); index++) {
final CloudExpansion expansion = expansions.get(index);
final TextComponent.Builder line = text();

final int expansionNumber = index + ((page - 1) * PAGE_SIZE) + 1;
line.append(text(expansionNumber + ". ", DARK_GRAY));

tooltip.append("&bClick to download this expansion!")
.append('\n')
.append('\n')
.append("&bAuthor: &f")
.append(expansion.getAuthor())
.append('\n')
.append("&bVerified: ")
.append(expansion.isVerified() ? "&a&l✔&r" : "&c&l❌&r")
.append('\n')
.append("&bLatest Version: &f")
.append(expansion.getLatestVersion())
.append('\n')
.append("&bReleased: &f")
.append(format.format(expansion.getLastUpdate()));

final String description = expansion.getDescription();
if (description != null && !description.isEmpty()) {
tooltip.append('\n')
.append('\n')
.append("&f")
.append(description.replace("\r", "").trim());
final NamedTextColor expansionColour;

if (expansion.shouldUpdate()) {
expansionColour = GOLD;
} else {
if (expansion.hasExpansion()) {
expansionColour = GREEN;
} else {
expansionColour = GRAY;
}
}

message.then(Msg.color(
"&8" + (index + ((page - 1) * PAGE_SIZE) + 1) + ".&r " + (expansion.shouldUpdate() ? "&6"
: expansion.hasExpansion() ? "&a" : "&7") + expansion.getName()));
line.append(text(expansion.getName(), expansionColour));

line.clickEvent(ClickEvent.suggestCommand("/papi ecloud download " + expansion.getName()));

message.tooltip(Msg.color(tooltip.toString()));
message.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();

if (index < expansions.size() - 1) {
message.newline();
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()));

if (index != expansions.size() - 1) {
line.append(newline());
}

tooltip.setLength(0);
message.append(line.build());
}

if (limit > 1) {
message.newline();
message.append(newline());

final TextComponent.Builder left = text("◀", page > 1 ? GRAY : DARK_GRAY).toBuilder();

message.then("◀")
.color(page > 1 ? ChatColor.GRAY : ChatColor.DARK_GRAY);
if (page > 1) {
message.runCommand("/papi ecloud list " + target + " " + (page - 1));
left.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page - 1)));
}

message.then(" " + page + " ").color(ChatColor.GREEN);
final TextComponent.Builder right = text("▶", page < limit ? GRAY : DARK_GRAY).toBuilder();

message.then("▶")
.color(page < limit ? ChatColor.GRAY : ChatColor.DARK_GRAY);
if (page < limit) {
message.runCommand("/papi ecloud list " + target + " " + (page + 1));
right.clickEvent(ClickEvent.runCommand("/papi ecloud list " + target + " " + (page + 1)));
}

message.append(left, text(" " + page + " ", GREEN), right);
}

return message;
return message.build();
}

private static void addExpansionTable(@NotNull final List<CloudExpansion> expansions,
Expand Down Expand Up @@ -321,8 +325,8 @@ public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,

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.getAdventure().player((Player) sender).sendMessage(message);
}

@Override
Expand Down
Loading