mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-07 12:37:14 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9022daf07f | ||
|
|
675b305cac | ||
|
|
d49c76c560 | ||
|
|
13e492cf44 | ||
|
|
d561afbb63 | ||
|
|
2a3f4482a0 |
@@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "me.clip"
|
||||
version = "2.12.1-DEV-${System.getProperty("BUILD_NUMBER")}"
|
||||
version = "2.12.2-DEV-${System.getProperty("BUILD_NUMBER")}"
|
||||
|
||||
description = "An awesome placeholder provider!"
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.impl.cloud.CommandECloud;
|
||||
import me.clip.placeholderapi.commands.impl.local.CommandDump;
|
||||
@@ -119,14 +120,18 @@ public final class PlaceholderCommandRouter implements CommandExecutor, TabCompl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command, @NotNull final String alias, @NotNull final String[] args) {
|
||||
public List<String> onTabComplete(@NotNull final CommandSender sender, @NotNull final Command command,
|
||||
@NotNull final String alias, @NotNull final String[] args) {
|
||||
final List<String> suggestions = new ArrayList<>();
|
||||
|
||||
if (args.length > 1) {
|
||||
final PlaceholderCommand target = this.commands.get(args[0].toLowerCase(Locale.ROOT));
|
||||
|
||||
if (target != null) {
|
||||
if (target.getPermission() != null && !target.getPermission().isEmpty() && !sender.hasPermission(target.getPermission())) {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
target.complete(plugin, sender, args[0].toLowerCase(Locale.ROOT),
|
||||
Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions);
|
||||
}
|
||||
|
||||
@@ -170,6 +170,8 @@ public final class CommandECloudExpansionList extends PlaceholderCommand {
|
||||
.append(newline()).append(newline())
|
||||
.append(text("Author: ", AQUA)).append(text(expansion.getAuthor(), WHITE))
|
||||
.append(newline())
|
||||
.append(text("Version: ", AQUA)).append(text(expansion.getVersion().getVersion(), WHITE))
|
||||
.append(newline())
|
||||
.append(text("Verified: ", AQUA)).append(text(expansion.getVersion().isVerified() ? "✔" : "❌", expansion.getVersion().isVerified() ? GREEN : RED, TextDecoration.BOLD))
|
||||
.append(newline())
|
||||
.append(text("Released: ", AQUA)).append(text(format.format(expansion.getLastUpdate()), WHITE))
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.scheduler.scheduling.schedulers.TaskScheduler;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
@@ -36,12 +38,13 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class UpdateChecker implements Listener {
|
||||
private static final String MODRINTH_URL = "https://api.modrinth.com/v2/project/lKEzGugV/version";
|
||||
|
||||
private static final int RESOURCE_ID = 6245;
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
private final TaskScheduler scheduler;
|
||||
private final String pluginVersion;
|
||||
private String spigotVersion;
|
||||
private String modrinthVersion;
|
||||
private boolean updateAvailable;
|
||||
|
||||
public UpdateChecker(PlaceholderAPIPlugin plugin) {
|
||||
@@ -54,27 +57,27 @@ public class UpdateChecker implements Listener {
|
||||
return updateAvailable;
|
||||
}
|
||||
|
||||
public String getSpigotVersion() {
|
||||
return spigotVersion;
|
||||
public String getModrinthVersion() {
|
||||
return modrinthVersion;
|
||||
}
|
||||
|
||||
public void fetch() {
|
||||
scheduler.runTaskAsynchronously(() -> {
|
||||
try {
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(
|
||||
"https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection();
|
||||
HttpsURLConnection con = (HttpsURLConnection) new URL(MODRINTH_URL).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
spigotVersion = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
|
||||
final JsonElement json = JsonParser.parseReader(new BufferedReader(new InputStreamReader(con.getInputStream())));
|
||||
modrinthVersion = json.getAsJsonArray().get(0).getAsJsonObject().get("version_number").getAsString();
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().info("Failed to check for updates on spigot.");
|
||||
plugin.getLogger().info("Failed to check for updates on modrinth.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
||||
if (modrinthVersion == null || modrinthVersion.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateAvailable = spigotIsNewer();
|
||||
updateAvailable = modrinthIsNewer();
|
||||
|
||||
if (!updateAvailable) {
|
||||
return;
|
||||
@@ -82,21 +85,21 @@ public class UpdateChecker implements Listener {
|
||||
|
||||
scheduler.runTask(() -> {
|
||||
plugin.getLogger()
|
||||
.info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:");
|
||||
.info("An update for PlaceholderAPI (v" + getModrinthVersion() + ") is available at:");
|
||||
plugin.getLogger()
|
||||
.info("https://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID + "/");
|
||||
.info("https://modrinth.com/plugin/placeholderapi");
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private boolean spigotIsNewer() {
|
||||
if (spigotVersion == null || spigotVersion.isEmpty()) {
|
||||
private boolean modrinthIsNewer() {
|
||||
if (modrinthVersion == null || modrinthVersion.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int[] plV = toReadable(pluginVersion);
|
||||
int[] spV = toReadable(spigotVersion);
|
||||
int[] spV = toReadable(modrinthVersion);
|
||||
|
||||
if (plV[0] < spV[0]) {
|
||||
return true;
|
||||
@@ -119,10 +122,9 @@ public class UpdateChecker implements Listener {
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (e.getPlayer().hasPermission("placeholderapi.updatenotify")) {
|
||||
Msg.msg(e.getPlayer(),
|
||||
"&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getSpigotVersion()
|
||||
"&bAn update for &fPlaceholder&7API &e(&fPlaceholder&7API &fv" + getModrinthVersion()
|
||||
+ "&e)"
|
||||
, "&bis available at &ehttps://www.spigotmc.org/resources/placeholderapi." + RESOURCE_ID
|
||||
+ "/");
|
||||
, "&bis available at &ehttps://modrinth.com/plugin/placeholderapi");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user