Skip to content

Commit

Permalink
Fixed minimessage support on messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezl committed Aug 19, 2024
1 parent 0ffdde3 commit c5b3a23
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cl.mastercode</groupId>
<artifactId>DamageIndicator</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<packaging>jar</packaging>

<properties>
Expand Down
14 changes: 14 additions & 0 deletions src/cl/mastercode/DamageIndicator/DIMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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,6 +53,7 @@ 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 @@ -121,6 +123,7 @@ public void onLoad() {

@Override
public void onEnable() {
this.adventure = BukkitAudiences.create(this);
saveResource("messages.yml", false);
CompatUtil.onEnable();
reload();
Expand All @@ -135,6 +138,10 @@ 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 @@ -194,4 +201,11 @@ 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,7 +1,6 @@
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 @@ -74,7 +73,7 @@ private void sendMessage(CommandSender sender, String path, String... replacemen
for (int i = 0; i < replacements.length; i++) {
message = message.replace("{" + i + "}", replacements[i]);
}
sender.sendMessage(LEGACY_SERIALIZER.serialize(miniMessage.deserialize(message)));
plugin.adventure().sender(sender).sendMessage(miniMessage.deserialize(message));
}

private void sendHelpMessage(CommandSender sender) {
Expand Down
6 changes: 3 additions & 3 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 LEGACY_SERIALIZER = BukkitComponentSerializer.legacy();
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
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(LEGACY_SERIALIZER.serialize(miniMessage.deserialize(name)));
armorStand.setCustomName(LEGACY_SERIALIZER.serialize(MINI_MESSAGE.deserialize(name)));
armorStand.setCustomNameVisible(true);
return armorStand;
}
Expand Down

0 comments on commit c5b3a23

Please sign in to comment.