Skip to content

Commit

Permalink
Fixed adventure compatibility on paper 1.16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezl committed Aug 19, 2024
1 parent c26328f commit 0f15b26
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 21 deletions.
21 changes: 20 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>AlessioDP</id>
<url>https://repo.alessiodp.com/releases/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -61,7 +65,7 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.17.0</version>
<version>4.13.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -70,6 +74,12 @@
<version>4.3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.byteflux</groupId>
<artifactId>libby-bukkit</artifactId>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -97,7 +107,16 @@
<pattern>net.nifheim.bukkit.commandlib</pattern>
<shadedPattern>cl.mastercode.DamageIndicator.util.commandlib</shadedPattern>
</relocation>
<relocation>
<pattern>net.byteflux.libby</pattern>
<shadedPattern>cl.mastercode.DamageIndicator.libs.libby</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>cl.mastercode.DamageIndicator.libs.kyori</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
Expand Down
20 changes: 6 additions & 14 deletions src/cl/mastercode/DamageIndicator/DIMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
40 changes: 40 additions & 0 deletions src/cl/mastercode/DamageIndicator/dependency/Dependency.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
4 changes: 2 additions & 2 deletions src/cl/mastercode/DamageIndicator/util/CompatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions src/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 0f15b26

Please sign in to comment.