From 98ef29d1b2def0472492bcf5fd55bd614862d9f2 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Sat, 20 Jul 2024 15:07:32 +0800 Subject: [PATCH 01/10] Add missing repositories to example project --- example/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/build.gradle.kts b/example/build.gradle.kts index e5eed4e..023838f 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -9,6 +9,8 @@ repositories { mavenCentral() maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/repositories/snapshots") + maven("https://lib.alpn.cloud/alpine-public/") + maven("https://repo.panda-lang.org/releases") } dependencies { From dd0f3436f00f58cfef05d7332d18885084fa6818 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Sat, 20 Jul 2024 15:24:06 +0800 Subject: [PATCH 02/10] Fix pre-release tag in buildscript --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3dd8c9f..46faf80 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -201,7 +201,7 @@ fun compileVersion(): String { val minor = project.properties["version_minor"] val patch = project.properties["version_patch"] val preRelease = project.properties["version_pre_release"] - return "${major}.${minor}.${patch}${if (preRelease == "none") "" else preRelease}" + return "${major}.${minor}.${patch}${if (preRelease == "none") "" else "-${preRelease}"}" } fun depend(scope: DependencyHandlerScope, dependency: String, api: Boolean = false) { From 3dde45d48172e2503dcaa80f7886782598bef30b Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Mon, 29 Jul 2024 21:53:43 +0800 Subject: [PATCH 03/10] Add various helper methods --- .../network/packet/PacketCooldownAdd.java | 6 +- .../network/packet/PacketNotificationAdd.java | 8 +- .../plugin/util/CollectionUtils.java | 161 ++++++++++++++++++ .../alpineclient/plugin/util/Formatting.java | 36 ++++ .../plugin/util/MsgPackUtils.java | 18 +- 5 files changed, 215 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/alpineclient/plugin/util/CollectionUtils.java diff --git a/src/main/java/com/alpineclient/plugin/network/packet/PacketCooldownAdd.java b/src/main/java/com/alpineclient/plugin/network/packet/PacketCooldownAdd.java index a8e298b..d986954 100644 --- a/src/main/java/com/alpineclient/plugin/network/packet/PacketCooldownAdd.java +++ b/src/main/java/com/alpineclient/plugin/network/packet/PacketCooldownAdd.java @@ -6,7 +6,6 @@ package com.alpineclient.plugin.network.packet; -import com.alpineclient.plugin.api.objects.ClientResource; import com.alpineclient.plugin.api.objects.Cooldown; import com.alpineclient.plugin.network.Packet; import com.alpineclient.plugin.network.WriteOnly; @@ -36,10 +35,7 @@ public void write(@NotNull MessagePacker packer) throws IOException { packer.packString(this.cooldown.getName()); packer.packInt(this.cooldown.getColor()); packer.packLong(this.cooldown.getDuration()); - - ClientResource texture = this.cooldown.getTexture(); - packer.packBoolean(texture.getType() == ClientResource.Type.INTERNAL); - packer.packString(texture.getValue()); + MsgPackUtils.packClientResource(packer, this.cooldown.getTexture()); } @Override diff --git a/src/main/java/com/alpineclient/plugin/network/packet/PacketNotificationAdd.java b/src/main/java/com/alpineclient/plugin/network/packet/PacketNotificationAdd.java index 2b12f8a..be331a8 100644 --- a/src/main/java/com/alpineclient/plugin/network/packet/PacketNotificationAdd.java +++ b/src/main/java/com/alpineclient/plugin/network/packet/PacketNotificationAdd.java @@ -6,10 +6,10 @@ package com.alpineclient.plugin.network.packet; -import com.alpineclient.plugin.api.objects.ClientResource; import com.alpineclient.plugin.api.objects.Notification; import com.alpineclient.plugin.network.Packet; import com.alpineclient.plugin.network.WriteOnly; +import com.alpineclient.plugin.util.MsgPackUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.msgpack.core.MessagePacker; @@ -32,15 +32,11 @@ public PacketNotificationAdd(@NotNull Notification notification) { @Override public void write(@NotNull MessagePacker packer) throws IOException { String title = this.notification.getTitle() == null ? "" : this.notification.getTitle(); - packer.packString(title); packer.packString(this.notification.getDescription()); packer.packInt(this.notification.getColor()); packer.packLong(this.notification.getDuration()); - - ClientResource texture = this.notification.getTexture(); - packer.packBoolean(texture.getType() == ClientResource.Type.INTERNAL); - packer.packString(texture.getValue()); + MsgPackUtils.packClientResource(packer, this.notification.getTexture()); } @Override diff --git a/src/main/java/com/alpineclient/plugin/util/CollectionUtils.java b/src/main/java/com/alpineclient/plugin/util/CollectionUtils.java new file mode 100644 index 0000000..0625b9f --- /dev/null +++ b/src/main/java/com/alpineclient/plugin/util/CollectionUtils.java @@ -0,0 +1,161 @@ +package com.alpineclient.plugin.util; + +import lombok.experimental.UtilityClass; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +/** + * Utility for instantiating commonly used {@link Collection}s with concise + * and clean syntax. + * + * @author Thomas Wearmouth + */ +@UtilityClass +@SuppressWarnings("unchecked") @ApiStatus.Internal +public final class CollectionUtils { + /** + * Creates a new list with the specified objects. + *

+ * This method makes no assertion as to the ordering of + * the list. For an ordered list, use {@link CollectionUtils#linkedList(Object[])}. + * + * @param the type of the elements in the list + * + * @param items the objects to add to the list + * @return the list + * + * @see java.util.ArrayList + */ + @SafeVarargs @Contract("null -> fail") + public static @NotNull List list(@NotNull T... items) { + ArrayList list = new ArrayList<>(items.length); + Collections.addAll(list, items); + return list; + } + + /** + * Creates a new ordered list with the specified objects. + * + * @param the type of the elements in the list + * + * @param items the objects to add to the list + * @return the list + * + * @see java.util.LinkedList + */ + @SafeVarargs @Contract("null -> fail") + public static @NotNull LinkedList linkedList(@NotNull T... items) { + LinkedList list = new LinkedList<>(); + Collections.addAll(list, items); + return list; + } + + /** + * Creates a new set with the specified objects. + *

+ * This method makes no assertion as to the ordering of + * the list. For an ordered list, use {@link CollectionUtils#linkedSet(Object[])}. + * + * @param the type of the elements in the set + * + * @param items the objects to add to the set + * @return the set + * + * @see java.util.HashSet + */ + @SafeVarargs @Contract("null -> fail") + public static @NotNull Set set(@NotNull T... items) { + HashSet set = new HashSet<>(items.length); + Collections.addAll(set, items); + return set; + } + + /** + * Creates a new ordered list with the specified objects. + * + * @param the type of the elements in the set + * + * @param items the objects to add to the set + * @return the set + * + * @see java.util.LinkedHashSet + */ + @SafeVarargs @Contract("null -> fail") + public static @NotNull LinkedHashSet linkedSet(@NotNull T... items) { + LinkedHashSet set = new LinkedHashSet<>(items.length); + Collections.addAll(set, items); + return set; + } + + /** + * Creates a new map with the specified objects. + *

+ * This method makes no assertion as to the ordering of + * the map. For an ordered map, use {@link CollectionUtils#linkedMap(Object, Object, Object...)}. + *

+ * Varargs should be specified by alternating keys and values. + *

+ * If the number of varargs is odd, the method will quietly + * ignore them. + * + * @param the type of the keys in the map + * @param the type of the values in the map + * + * @param items the keys and values to add to the map + * @return the map + * + * @see java.util.HashMap + */ + public static @NotNull Map map(@NotNull K firstKey, @NotNull V firstValue, @NotNull Object... items) { + int initialCapacity = (items.length / 2) + 1; + HashMap map = new HashMap<>(initialCapacity); + map.put(firstKey, firstValue); + + if (items.length > 1 || items.length % 2 != 0) { + for (int i = 0; i < (items.length / 2) * 2; i += 2) { + K key = (K) items[i]; + V value = (V) items[i + 1]; + + map.put(key, value); + } + } + + return map; + } + + /** + * Creates a new ordered map with the specified objects. + *

+ * Varargs should be specified by alternating keys and values. + *

+ * If the number of varargs is odd, the method will quietly + * ignore them. + * + * @param the type of the keys in the map + * @param the type of the values in the map + * + * @param items the keys and values to add to the map + * @return the map + * + * @see java.util.LinkedHashMap + */ + public static @NotNull LinkedHashMap linkedMap(@NotNull K firstKey, @NotNull V firstValue, @NotNull Object... items) { + int initialCapacity = (items.length / 2) + 1; + LinkedHashMap map = new LinkedHashMap<>(initialCapacity); + map.put(firstKey, firstValue); + + if (items.length > 1 || items.length % 2 != 0) { + for (int i = 0; i < (items.length / 2) * 2; i += 2) { + K key = (K) items[i]; + V value = (V) items[i + 1]; + + map.put(key, value); + } + } + + return map; + } +} diff --git a/src/main/java/com/alpineclient/plugin/util/Formatting.java b/src/main/java/com/alpineclient/plugin/util/Formatting.java index 2b39bfa..a3d45b4 100644 --- a/src/main/java/com/alpineclient/plugin/util/Formatting.java +++ b/src/main/java/com/alpineclient/plugin/util/Formatting.java @@ -9,12 +9,14 @@ import com.alpineclient.plugin.Reference; import lombok.experimental.UtilityClass; import net.kyori.adventure.text.Component; +import org.bukkit.ChatColor; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.text.DecimalFormat; +import java.util.Map; /** * @author BestBearr @@ -23,8 +25,42 @@ @UtilityClass @ApiStatus.Internal public final class Formatting { + private static final Map COLOR_HEX_CODES = CollectionUtils.map( + ChatColor.DARK_RED, 0xFFAA0000, + ChatColor.RED, 0xFFFF5555, + ChatColor.GOLD, 0xFFFFAA00, + ChatColor.YELLOW, 0xFFFFFF55, + ChatColor.DARK_GREEN, 0xFF00AA00, + ChatColor.GREEN, 0xFF55FF55, + ChatColor.DARK_AQUA, 0xFF00AAAA, + ChatColor.AQUA, 0xFF55FFFF, + ChatColor.DARK_BLUE, 0xFF0000AA, + ChatColor.BLUE, 0xFF5555FF, + ChatColor.DARK_PURPLE, 0xFFAA00AA, + ChatColor.LIGHT_PURPLE, 0xFFFF55FF, + ChatColor.BLACK, 0xFF000000, + ChatColor.DARK_GRAY, 0xFF555555, + ChatColor.GRAY, 0xFFAAAAAA, + ChatColor.WHITE, 0xFFFFFFFF + ); + private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##"); + /** + * Retrieve the hex code for a chat formatting code. + *
+ * Returns {@code -1} for non-color codes. + * + * @param color The Bukkit {@link ChatColor} + * @return The corresponding hex code. + */ + public static int getHexColor(@NotNull ChatColor color) { + if (color.isColor()) { + return COLOR_HEX_CODES.get(color); + } + else return -1; + } + /** * Formats a material name to a more readable format. * diff --git a/src/main/java/com/alpineclient/plugin/util/MsgPackUtils.java b/src/main/java/com/alpineclient/plugin/util/MsgPackUtils.java index e96701d..f1d86f6 100644 --- a/src/main/java/com/alpineclient/plugin/util/MsgPackUtils.java +++ b/src/main/java/com/alpineclient/plugin/util/MsgPackUtils.java @@ -6,6 +6,7 @@ package com.alpineclient.plugin.util; +import com.alpineclient.plugin.api.objects.ClientResource; import lombok.experimental.UtilityClass; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -22,14 +23,25 @@ @UtilityClass @ApiStatus.Internal public final class MsgPackUtils { + public static void packUuid(@NotNull MessagePacker packer, @NotNull UUID id) throws IOException { + packer.packLong(id.getMostSignificantBits()); + packer.packLong(id.getLeastSignificantBits()); + } + public static @NotNull UUID unpackUuid(@NotNull MessageUnpacker unpacker) throws IOException { long msb = unpacker.unpackLong(); long lsb = unpacker.unpackLong(); return new UUID(msb, lsb); } - public static void packUuid(@NotNull MessagePacker packer, @NotNull UUID id) throws IOException { - packer.packLong(id.getMostSignificantBits()); - packer.packLong(id.getLeastSignificantBits()); + public static void packClientResource(@NotNull MessagePacker packer, @NotNull ClientResource resource) throws IOException { + packer.packBoolean(resource.getType() == ClientResource.Type.INTERNAL); + packer.packString(resource.getValue()); + } + + public static @NotNull ClientResource unpackClientResource(@NotNull MessageUnpacker unpacker) throws IOException { + boolean internal = unpacker.unpackBoolean(); + String value = unpacker.unpackString(); + return internal ? ClientResource.internal(value) : ClientResource.external(value); } } From 52b8e59b6e0bff0f8992ba6fb31739ddf4e967e9 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Wed, 31 Jul 2024 06:11:00 +0800 Subject: [PATCH 04/10] Make better use of modern ConfigLib APIs; general config cleanup --- .../plugin/config/AbstractConfig.java | 12 +-- .../plugin/config/ConfigManager.java | 79 ++++++++----------- .../plugin/config/impl/GeneralConfig.java | 6 -- .../plugin/config/impl/MessageConfig.java | 7 -- 4 files changed, 34 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/alpineclient/plugin/config/AbstractConfig.java b/src/main/java/com/alpineclient/plugin/config/AbstractConfig.java index 71a1c94..8eeab12 100644 --- a/src/main/java/com/alpineclient/plugin/config/AbstractConfig.java +++ b/src/main/java/com/alpineclient/plugin/config/AbstractConfig.java @@ -7,13 +7,10 @@ package com.alpineclient.plugin.config; import de.exlll.configlib.Configuration; -import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; + import net.kyori.adventure.text.format.TextColor; -import org.jetbrains.annotations.NotNull; -import java.nio.file.Path; /** * @author BestBearr @@ -29,11 +26,4 @@ public class AbstractConfig { public static final TextColor DIVIDER_COLOR = TextColor.color(0x777777); public static final TextColor TEXT_COLOR = TextColor.color(0xdbfce9); public static final TextColor ERROR_TEXT_COLOR = TextColor.color(0xfcd5cc); - - @Getter @Setter - private transient Path configPath; - - public AbstractConfig(@NotNull Path configPath) { - this.configPath = configPath; - } } diff --git a/src/main/java/com/alpineclient/plugin/config/ConfigManager.java b/src/main/java/com/alpineclient/plugin/config/ConfigManager.java index b0dadbf..0a9e628 100644 --- a/src/main/java/com/alpineclient/plugin/config/ConfigManager.java +++ b/src/main/java/com/alpineclient/plugin/config/ConfigManager.java @@ -10,14 +10,18 @@ import com.alpineclient.plugin.Reference; import com.alpineclient.plugin.config.impl.GeneralConfig; import com.alpineclient.plugin.config.impl.MessageConfig; +import com.google.common.collect.ImmutableMap; import de.exlll.configlib.ConfigLib; import de.exlll.configlib.YamlConfigurationProperties; import de.exlll.configlib.YamlConfigurations; import lombok.Getter; import org.jetbrains.annotations.NotNull; -import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -26,74 +30,57 @@ * Created on 02/06/23 */ public final class ConfigManager { - @Getter - private static ConfigManager instance; + private static final Map, Path> CONFIGURATIONS = ImmutableMap.of( + GeneralConfig.class, Paths.get("config.yml"), + MessageConfig.class, Paths.get("messages.yml") + ); - public static final YamlConfigurationProperties PROPERTIES = ConfigLib.BUKKIT_DEFAULT_PROPERTIES.toBuilder() + private static final YamlConfigurationProperties PROPERTIES = ConfigLib.BUKKIT_DEFAULT_PROPERTIES.toBuilder() .header(String.join("\n", Reference.NAME + " (" + Reference.VERSION + ")", - "Copyright (c) 2023, Crystal Development, LLC. All rights reserved.", "", "Messages are deserialized by the Adventure library", " - https://webui.advntr.dev/", "")) .inputNulls(true).outputNulls(true) + .charset(StandardCharsets.UTF_8) .build(); @Getter - private final Map, AbstractConfig> registeredConfigurations = new HashMap<>(); + private static ConfigManager instance; - public ConfigManager() { - instance = this; - PluginMain main = PluginMain.getInstance(); + private final Path directory; - File path = main.getDataFolder(); - if (!path.exists() && !path.mkdirs()) - throw new IllegalStateException("Unable to generate configuration directory"); + private final Map, AbstractConfig> loadedConfigs = new HashMap<>(CONFIGURATIONS.size()); - File dataFolder = main.getDataFolder(); - this.registeredConfigurations.put(GeneralConfig.class, new GeneralConfig(new File(dataFolder, "config.yml").toPath())); - this.registeredConfigurations.put(MessageConfig.class, new MessageConfig(new File(dataFolder, "messages.yml").toPath())); + public ConfigManager() { + instance = this; + this.directory = PluginMain.getInstance().getDataFolder().toPath(); - // Load/save the config - for (Map.Entry, AbstractConfig> abstractConfigEntry : this.registeredConfigurations.entrySet()) { - AbstractConfig config = abstractConfigEntry.getValue(); - if (Files.exists(config.getConfigPath())) { - AbstractConfig newConfig = YamlConfigurations.load(config.getConfigPath(), config.getClass(), PROPERTIES); - newConfig.setConfigPath(config.getConfigPath()); - this.registeredConfigurations.put(config.getClass(), newConfig); - YamlConfigurations.save(config.getConfigPath(), (Class) config.getClass(), newConfig, PROPERTIES); + if (!Files.exists(this.directory)) { + try { + Files.createDirectories(this.directory); } - else { - YamlConfigurations.save(config.getConfigPath(), (Class) config.getClass(), config, PROPERTIES); + catch (IOException ex) { + Reference.LOGGER.error("Unable to create config directory at \"{}\"", this.directory, ex); } } - } - public void loadConfigs() { - for (Map.Entry, AbstractConfig> abstractConfigEntry : this.registeredConfigurations.entrySet()) { - AbstractConfig config = abstractConfigEntry.getValue(); - if (!Files.exists(config.getConfigPath())) - YamlConfigurations.save(config.getConfigPath(), (Class) config.getClass(), config, PROPERTIES); - else { - AbstractConfig newConfig = YamlConfigurations.load(config.getConfigPath(), config.getClass(), PROPERTIES); - newConfig.setConfigPath(config.getConfigPath()); - this.registeredConfigurations.put(config.getClass(), newConfig); + CONFIGURATIONS.forEach((key, val) -> { + try { + AbstractConfig loadedConfig = YamlConfigurations.update(this.directory.resolve(val), key, PROPERTIES); + this.loadedConfigs.put(key, loadedConfig); } - } - } - - public void saveConfigs() { - for (Map.Entry, AbstractConfig> abstractConfigEntry : this.registeredConfigurations.entrySet()) { - AbstractConfig config = abstractConfigEntry.getValue(); - YamlConfigurations.save(config.getConfigPath(), (Class) config.getClass(), config, PROPERTIES); - } + catch (RuntimeException ex) { + Reference.LOGGER.error("Unable to load config file \"{}\"", val, ex); + } + }); } - public @NotNull T getConfig(@NotNull Class configClass) { - AbstractConfig config = this.registeredConfigurations.get(configClass); + public @NotNull T getConfig(@NotNull Class clazz) { + AbstractConfig config = this.loadedConfigs.get(clazz); if (config != null) return (T) config; - throw new IllegalStateException("config was not registered"); + throw new IllegalStateException("No config was loaded for " + clazz.getSimpleName()); } } diff --git a/src/main/java/com/alpineclient/plugin/config/impl/GeneralConfig.java b/src/main/java/com/alpineclient/plugin/config/impl/GeneralConfig.java index 9c074c5..2206dae 100644 --- a/src/main/java/com/alpineclient/plugin/config/impl/GeneralConfig.java +++ b/src/main/java/com/alpineclient/plugin/config/impl/GeneralConfig.java @@ -10,9 +10,7 @@ import com.google.common.collect.ImmutableMap; import de.exlll.configlib.Comment; import lombok.NoArgsConstructor; -import org.jetbrains.annotations.NotNull; -import java.nio.file.Path; import java.util.Map; /** @@ -34,8 +32,4 @@ public final class GeneralConfig extends AbstractConfig { " A list of all module IDs can be found in the GitHub repository under \"MODULES.md\"." }) public Map modules = ImmutableMap.of("cannon_view", false); - - public GeneralConfig(@NotNull Path configPath) { - super(configPath); - } } diff --git a/src/main/java/com/alpineclient/plugin/config/impl/MessageConfig.java b/src/main/java/com/alpineclient/plugin/config/impl/MessageConfig.java index 715660a..86b1675 100644 --- a/src/main/java/com/alpineclient/plugin/config/impl/MessageConfig.java +++ b/src/main/java/com/alpineclient/plugin/config/impl/MessageConfig.java @@ -14,9 +14,6 @@ import lombok.NoArgsConstructor; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; -import org.jetbrains.annotations.NotNull; - -import java.nio.file.Path; /** * @author BestBearr @@ -102,8 +99,4 @@ public final class MessageConfig extends AbstractConfig { Component.text(" * ").color(DIVIDER_COLOR), Component.text("%syntax%").color(SECONDARY_ERROR_COLOR) ); - - public MessageConfig(@NotNull Path configPath) { - super(configPath); - } } From 2a270f3d3ffe98275bd21b6a7754f3b88283f240 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Thu, 22 Aug 2024 13:54:57 +0800 Subject: [PATCH 05/10] Update dependencies --- build.gradle.kts | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 46faf80..3e9d69f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { id("java-library") id("maven-publish") id("net.kyori.blossom") version "1.3.1" - id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.gradleup.shadow") version "8.3.0" } group = this.compileGroup() @@ -38,7 +38,7 @@ dependencies { depend(this, "dev.rollczi:litecommands-adventure-platform:${liteCommands}") val adventure = "4.17.0" - depend(this, "net.kyori:adventure-platform-bukkit:4.3.2") + depend(this, "net.kyori:adventure-platform-bukkit:4.3.4") depend(this, "net.kyori:adventure-api:${adventure}") depend(this, "net.kyori:adventure-text-minimessage:${adventure}") depend(this, "net.kyori:adventure-text-serializer-legacy:${adventure}") diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f518141..b2b6475 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Fri Jun 02 18:20:52 EDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From aceffdc1062a845100a8edb5523b6bfb1cac65e4 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Thu, 22 Aug 2024 14:11:10 +0800 Subject: [PATCH 06/10] Deprecate AlpinePlayer#getMods --- .../plugin/api/objects/AlpinePlayer.java | 13 +++++++------ .../plugin/util/object/HandshakeData.java | 7 +------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/alpineclient/plugin/api/objects/AlpinePlayer.java b/src/main/java/com/alpineclient/plugin/api/objects/AlpinePlayer.java index f25436c..6f43053 100644 --- a/src/main/java/com/alpineclient/plugin/api/objects/AlpinePlayer.java +++ b/src/main/java/com/alpineclient/plugin/api/objects/AlpinePlayer.java @@ -32,19 +32,17 @@ public final class AlpinePlayer { private final Player bukkitPlayer; private final String platform; private final String version; - private final List mods; @ApiStatus.Internal public AlpinePlayer(@NotNull Player bukkitPlayer, @NotNull HandshakeData data) { - this(bukkitPlayer, data.getPlatform(), data.getVersion(), data.getMods()); + this(bukkitPlayer, data.getPlatform(), data.getVersion()); } @ApiStatus.Internal - public AlpinePlayer(@NotNull Player bukkitPlayer, @NotNull String platform, @NotNull String version, @NotNull List mods) { + public AlpinePlayer(@NotNull Player bukkitPlayer, @NotNull String platform, @NotNull String version) { this.bukkitPlayer = bukkitPlayer; this.platform = platform; this.version = version; - this.mods = mods; } /** @@ -84,16 +82,19 @@ public AlpinePlayer(@NotNull Player bukkitPlayer, @NotNull String platform, @Not * e.g. {@code ["sodium", "lithium", "alpineclient"]} * * @return a list containing mod IDs + * @deprecated functionality removed; no replacement */ + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "1.4.0") public @NotNull List getMods() { - return Collections.unmodifiableList(this.mods); + return Collections.emptyList(); } /** * Get the full client brand consisting of their version * and platform. *

- * e.g. {@code 1.20-fabric} + * e.g. {@code 1.18.2-fabric} * * @return the client brand */ diff --git a/src/main/java/com/alpineclient/plugin/util/object/HandshakeData.java b/src/main/java/com/alpineclient/plugin/util/object/HandshakeData.java index 5da6809..a74ec01 100644 --- a/src/main/java/com/alpineclient/plugin/util/object/HandshakeData.java +++ b/src/main/java/com/alpineclient/plugin/util/object/HandshakeData.java @@ -10,8 +10,6 @@ import lombok.Getter; import org.jetbrains.annotations.ApiStatus; -import java.util.List; - /** * @author Thomas Wearmouth * Created on 21/06/2023 @@ -23,12 +21,9 @@ public final class HandshakeData { private final String platform; @SerializedName("version") private final String version; - @SerializedName("mods") - private final List mods; - public HandshakeData(String platform, String version, List mods) { + public HandshakeData(String platform, String version) { this.platform = platform; this.version = version; - this.mods = mods; } } From f1696312afff76b88fef12ced98bbe55c67f0112 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Thu, 22 Aug 2024 14:42:35 +0800 Subject: [PATCH 07/10] Improve failed handshake logging --- .../alpineclient/plugin/listener/plugin/HandshakeListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java b/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java index 6531468..b049188 100644 --- a/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java +++ b/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java @@ -40,7 +40,7 @@ public void onMessage(@NotNull Player player, byte[] message) { } } catch (JsonSyntaxException ex) { - Reference.LOGGER.warn("Invalid handshake payload received from {}", player.getName()); + Reference.LOGGER.warn("Invalid handshake payload received from {}", player.getName(), ex); } } else { From 90f8b4c4bcc0fa39e40d75e2ef30befe57bb1c2e Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Thu, 22 Aug 2024 14:51:40 +0800 Subject: [PATCH 08/10] Change handshake magic bytes --- .../plugin/listener/plugin/HandshakeListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java b/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java index b049188..30e5081 100644 --- a/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java +++ b/src/main/java/com/alpineclient/plugin/listener/plugin/HandshakeListener.java @@ -21,7 +21,7 @@ public final class HandshakeListener extends PluginListener { public static final String CHANNEL_ID = "ac:handshake"; - private static final byte[] MAGIC_NUMBER = new byte[] { 0x3A, 0x3D }; + private static final byte[] MAGIC_BYTES = new byte[] { 0x41, 0x4C, 0x50, 0x4E }; public HandshakeListener() { super(CHANNEL_ID); @@ -36,7 +36,7 @@ public void onMessage(@NotNull Player player, byte[] message) { boolean success = this.main.getPlayerHandler().addConnectedPlayer(player, data); if (success) { player.setMetadata("IsOnAlpineClient", new FixedMetadataValue(this.main, true)); - player.sendPluginMessage(this.main, this.getChannelId(), MAGIC_NUMBER); + player.sendPluginMessage(this.main, this.getChannelId(), MAGIC_BYTES); } } catch (JsonSyntaxException ex) { From a188f8e35128a82e5e8071ed7d3b33d0b476b8ea Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Thu, 22 Aug 2024 14:52:23 +0800 Subject: [PATCH 09/10] Bump version (1.3.1) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1c592ad..66b6a85 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,5 +8,5 @@ plugin_id=alpineclientapi version_major=1 version_minor=3 -version_patch=0 +version_patch=1 version_pre_release=none \ No newline at end of file From 1a293df4e2ee95d629473d9ed2fc1dfe47cd59a7 Mon Sep 17 00:00:00 2001 From: Thomas Wearmouth Date: Thu, 22 Aug 2024 16:49:08 +0800 Subject: [PATCH 10/10] Update README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d62803..9fbc66e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This plugin does the following by default: - `/acnotify [player] [content]` - Sends a notification to the given player containing the given content. Requires the `alpineapi.notify` permission. - `/aclist` - Displays a list of all online Alpine Client users. Requires the `alpineapi.list` permission. -The plugin should work on any server running on at least `1.8.8` and Java 8. +The plugin should work on any server running on at least `1.8.8`, Spigot and Java 8. Much more is possible with this API, however it would require your development team to implement it with your plugins manually. This is what is available by default with no extra development work. @@ -21,7 +21,6 @@ This plugin exposes an API that can be leveraged to add Alpine Client integratio - Accessing certain user data: - Minecraft version - Mod platform - - Loaded mod IDs - Sending custom notifications to the client - Sending temporary waypoints to the client - Sending cooldown information to the client