From 0f15b26d78162e32cd43072d1345e6bf9c4f2e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Su=C3=A1rez?= Date: Sun, 18 Aug 2024 22:11:35 -0400 Subject: [PATCH] Fixed adventure compatibility on paper 1.16.5 --- pom.xml | 21 +++++++++- src/cl/mastercode/DamageIndicator/DIMain.java | 20 +++------- .../command/DamageIndicatorCommand.java | 3 +- .../dependency/Dependency.java | 40 +++++++++++++++++++ .../dependency/DependencyManager.java | 27 +++++++++++++ .../DamageIndicator/util/CompatUtil.java | 4 +- src/resources/plugin.yml | 3 -- 7 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 src/cl/mastercode/DamageIndicator/dependency/Dependency.java create mode 100644 src/cl/mastercode/DamageIndicator/dependency/DependencyManager.java diff --git a/pom.xml b/pom.xml index bea4143..a1b21cf 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,10 @@ jitpack.io https://jitpack.io + + AlessioDP + https://repo.alessiodp.com/releases/ + @@ -61,7 +65,7 @@ net.kyori adventure-text-minimessage - 4.17.0 + 4.13.1 provided @@ -70,6 +74,12 @@ 4.3.4 provided + + net.byteflux + libby-bukkit + 1.3.1 + compile + @@ -97,7 +107,16 @@ net.nifheim.bukkit.commandlib cl.mastercode.DamageIndicator.util.commandlib + + net.byteflux.libby + cl.mastercode.DamageIndicator.libs.libby + + + net.kyori + cl.mastercode.DamageIndicator.libs.kyori + + false diff --git a/src/cl/mastercode/DamageIndicator/DIMain.java b/src/cl/mastercode/DamageIndicator/DIMain.java index a1ad1e1..f685b0f 100644 --- a/src/cl/mastercode/DamageIndicator/DIMain.java +++ b/src/cl/mastercode/DamageIndicator/DIMain.java @@ -16,6 +16,7 @@ package cl.mastercode.DamageIndicator; import cl.mastercode.DamageIndicator.command.DamageIndicatorCommand; +import cl.mastercode.DamageIndicator.dependency.DependencyManager; import cl.mastercode.DamageIndicator.hider.EntityHider; import cl.mastercode.DamageIndicator.hider.LegacyEntityHider; import cl.mastercode.DamageIndicator.hider.Policy; @@ -27,7 +28,6 @@ import cl.mastercode.DamageIndicator.storage.StorageProvider; import cl.mastercode.DamageIndicator.util.CompatUtil; import cl.mastercode.DamageIndicator.util.ConfigUpdateHandler; -import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.nifheim.bukkit.commandlib.CommandAPI; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; @@ -52,7 +52,6 @@ public class DIMain extends JavaPlugin { private EntityHider entityHider; private DamageIndicatorCommand command; private FileConfiguration messages; - private BukkitAudiences adventure; public void reload() { new ConfigUpdateHandler(this).updateConfig(); @@ -115,9 +114,13 @@ public void reload() { reloadMessages(); } + @Override + public void onLoad() { + new DependencyManager(this).loadDependencies(); + } + @Override public void onEnable() { - this.adventure = BukkitAudiences.create(this); saveResource("messages.yml", false); CompatUtil.onEnable(); reload(); @@ -132,10 +135,6 @@ public void onDisable() { if (bloodListener != null) { bloodListener.getBloodItems().forEach((item, time) -> item.remove()); } - if (this.adventure != null) { - this.adventure.close(); - this.adventure = null; - } } private void startTasks() { @@ -195,11 +194,4 @@ public FileConfiguration getMessages() { public void reloadMessages() { messages = YamlConfiguration.loadConfiguration(getDataFolder().toPath().resolve("messages.yml").toFile()); } - - public BukkitAudiences adventure() { - if (this.adventure == null) { - throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!"); - } - return this.adventure; - } } diff --git a/src/cl/mastercode/DamageIndicator/command/DamageIndicatorCommand.java b/src/cl/mastercode/DamageIndicator/command/DamageIndicatorCommand.java index efa4f64..cab2e37 100644 --- a/src/cl/mastercode/DamageIndicator/command/DamageIndicatorCommand.java +++ b/src/cl/mastercode/DamageIndicator/command/DamageIndicatorCommand.java @@ -1,6 +1,7 @@ package cl.mastercode.DamageIndicator.command; import cl.mastercode.DamageIndicator.DIMain; +import static cl.mastercode.DamageIndicator.util.CompatUtil.LEGACY_SERIALIZER; import net.kyori.adventure.text.minimessage.MiniMessage; import net.nifheim.bukkit.commandlib.RegistrableCommand; import org.bukkit.command.CommandSender; @@ -73,7 +74,7 @@ private void sendMessage(CommandSender sender, String path, String... replacemen for (int i = 0; i < replacements.length; i++) { message = message.replace("{" + i + "}", replacements[i]); } - plugin.adventure().sender(sender).sendMessage(miniMessage.deserialize(message)); + sender.sendMessage(LEGACY_SERIALIZER.serialize(miniMessage.deserialize(message))); } private void sendHelpMessage(CommandSender sender) { diff --git a/src/cl/mastercode/DamageIndicator/dependency/Dependency.java b/src/cl/mastercode/DamageIndicator/dependency/Dependency.java new file mode 100644 index 0000000..b3ff07b --- /dev/null +++ b/src/cl/mastercode/DamageIndicator/dependency/Dependency.java @@ -0,0 +1,40 @@ +package cl.mastercode.DamageIndicator.dependency; + +public enum Dependency { + KYORI_API("net{}kyori", "adventure-api", DependencyManager.KYORI_VERSION), + KYORI_KEY("net{}kyori", "adventure-key", DependencyManager.KYORI_VERSION), + KYORI_EXAMINATION_API("net{}kyori", "examination-api", DependencyManager.KYORI_EXAMINATION_VERSION), + KYORI_EXAMINATION_STRING("net{}kyori", "examination-string", DependencyManager.KYORI_EXAMINATION_VERSION), + KYORI_NBT("net{}kyori", "adventure-nbt", DependencyManager.KYORI_VERSION), + KYORI_GSON("net{}kyori", "adventure-text-serializer-gson", DependencyManager.KYORI_VERSION), + KYORI_GSON_LEGACY("net{}kyori", "adventure-text-serializer-gson-legacy-impl", DependencyManager.KYORI_VERSION), + KYORI_LEGACY_SERIALIZER("net{}kyori", "adventure-text-serializer-legacy", DependencyManager.KYORI_VERSION), + KYORI_MINI_MESSAGE("net{}kyori", "adventure-text-minimessage", DependencyManager.KYORI_VERSION), + KYORI_PLATFORM_API("net{}kyori", "adventure-platform-api", DependencyManager.KYORI_PLATFORM_VERSION), + KYORI_PLATFORM_BUKKIT("net{}kyori", "adventure-platform-bukkit", DependencyManager.KYORI_PLATFORM_VERSION), + KYORI_PLATFORM_BUNGEECORD("net{}kyori", "adventure-text-serializer-bungeecord", DependencyManager.KYORI_PLATFORM_VERSION), + KYORI_PLATFORM_FACET("net{}kyori", "adventure-platform-facet", DependencyManager.KYORI_PLATFORM_VERSION), + KYORI_PLATFORM_VIAVERSION("net{}kyori", "adventure-platform-viaversion", DependencyManager.KYORI_PLATFORM_VERSION); + + private final String groupId; + private final String artifactId; + private final String version; + + Dependency(String groupId, String artifactId, String version) { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + } + + public String getGroupId() { + return groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public String getVersion() { + return version; + } +} diff --git a/src/cl/mastercode/DamageIndicator/dependency/DependencyManager.java b/src/cl/mastercode/DamageIndicator/dependency/DependencyManager.java new file mode 100644 index 0000000..af35b7b --- /dev/null +++ b/src/cl/mastercode/DamageIndicator/dependency/DependencyManager.java @@ -0,0 +1,27 @@ +package cl.mastercode.DamageIndicator.dependency; + +import cl.mastercode.DamageIndicator.DIMain; +import net.byteflux.libby.BukkitLibraryManager; +import net.byteflux.libby.Library; +import net.byteflux.libby.relocation.Relocation; + +public class DependencyManager { + public static final String KYORI_VERSION = "4.13.1"; + public static final String KYORI_EXAMINATION_VERSION = "1.3.0"; + public static final String KYORI_PLATFORM_VERSION = "4.3.4"; + + private final BukkitLibraryManager libraryManager; + + public DependencyManager(DIMain plugin) { + libraryManager = new BukkitLibraryManager(plugin); + } + + public void loadDependencies() { + Relocation relocation = Relocation.builder().pattern("net{}kyori").relocatedPattern("cl{}mastercode{}DamageIndicator{}libs{}kyori").build(); + libraryManager.addMavenCentral(); + for (Dependency dependency : Dependency.values()) { + Library library = Library.builder().groupId(dependency.getGroupId()).artifactId(dependency.getArtifactId()).version(dependency.getVersion()).relocate(relocation).build(); + libraryManager.loadLibrary(library); + } + } +} diff --git a/src/cl/mastercode/DamageIndicator/util/CompatUtil.java b/src/cl/mastercode/DamageIndicator/util/CompatUtil.java index f038357..1324fc3 100644 --- a/src/cl/mastercode/DamageIndicator/util/CompatUtil.java +++ b/src/cl/mastercode/DamageIndicator/util/CompatUtil.java @@ -32,8 +32,8 @@ */ public final class CompatUtil { + public static final LegacyComponentSerializer LEGACY_SERIALIZER = BukkitComponentSerializer.legacy(); private static final MiniMessage miniMessage = MiniMessage.miniMessage(); - private static final LegacyComponentSerializer legacySerializer = BukkitComponentSerializer.legacy(); public static Particle BLOOD_PARTICLE = null; public static int MINOR_VERSION = 16; @@ -63,7 +63,7 @@ private static int _getMinorVersion() { public static ArmorStand buildArmorStand(Location location, double distance, FixedMetadataValue fixedMetadataValue, String name) { ArmorStand armorStand = location.getWorld().spawn(location.clone().add(0, location.getWorld().getMaxHeight() - location.getY(), 0), ArmorStand.class, stand -> setStandProperties(stand, location, distance, fixedMetadataValue)); - armorStand.setCustomName(legacySerializer.serialize(miniMessage.deserialize(name))); + armorStand.setCustomName(LEGACY_SERIALIZER.serialize(miniMessage.deserialize(name))); armorStand.setCustomNameVisible(true); return armorStand; } diff --git a/src/resources/plugin.yml b/src/resources/plugin.yml index 7794a8d..c7ccfa2 100644 --- a/src/resources/plugin.yml +++ b/src/resources/plugin.yml @@ -6,6 +6,3 @@ softdepend: [ ProtocolLib, EcoSkills ] api-version: 1.16 website: 'https://www.spigotmc.org/resources/55974/' description: 'DamageIndicator is a plugin that shows the damage you do to a mob or player.' -libraries: -- 'net.kyori:adventure-text-minimessage:4.17.0' -- 'net.kyori:adventure-platform-bukkit:4.3.4'