diff --git a/pom.xml b/pom.xml index d03418a..7af937d 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ org.spigotmc spigot - 1.15 + 1.16.1 provided diff --git a/src/main/java/com/songoda/epicanchors/EpicAnchors.java b/src/main/java/com/songoda/epicanchors/EpicAnchors.java index e32c491..e77e26c 100644 --- a/src/main/java/com/songoda/epicanchors/EpicAnchors.java +++ b/src/main/java/com/songoda/epicanchors/EpicAnchors.java @@ -9,6 +9,8 @@ import com.songoda.core.configuration.Config; import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.EconomyManager; import com.songoda.core.hooks.HologramManager; +import com.songoda.core.nms.NmsManager; +import com.songoda.core.nms.nbt.NBTItem; import com.songoda.core.utils.TextUtils; import com.songoda.epicanchors.anchor.Anchor; import com.songoda.epicanchors.anchor.AnchorManager; @@ -56,6 +58,9 @@ public class EpicAnchors extends SongodaPlugin { HologramManager.removeAllHolograms(); } + @Override + public void onDataLoad() {} + @Override public void onPluginEnable() { // Run Songoda Updater @@ -136,7 +141,7 @@ public class EpicAnchors extends SongodaPlugin { // verify that this is a anchor if (anchor.getLocation().getBlock().getType() != Settings.MATERIAL.getMaterial().getMaterial()) return; // grab the name - String name = Methods.formatName(anchor.getTicksLeft(), false).trim(); + String name = Methods.formatName(anchor.getTicksLeft()).trim(); Location location = correctHeight(anchor.getLocation()); // create the hologram HologramManager.updateHologram(location, name); @@ -168,9 +173,15 @@ public class EpicAnchors extends SongodaPlugin { } public int getTicksFromItem(ItemStack item) { + NBTItem nbtItem = NmsManager.getNbt().of(item); + if (nbtItem.has("ticks")) { + return nbtItem.getNBTObject("ticks").asInt(); + } + + // Legacy code. Tries to get the ticks remaining from hidden text. if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 0; if (item.getItemMeta().getDisplayName().contains(":")) { - return NumberUtils.toInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0); + return Integer.parseInt(item.getItemMeta().getDisplayName().replace("\u00A7", "").split(":")[0], 0); } return 0; } @@ -178,7 +189,7 @@ public class EpicAnchors extends SongodaPlugin { public ItemStack makeAnchorItem(int ticks) { ItemStack item = Settings.MATERIAL.getMaterial().getItem(); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(Methods.formatName(ticks, true)); + meta.setDisplayName(Methods.formatName(ticks)); ArrayList lore = new ArrayList<>(); String[] parts = Settings.LORE.getString().split("\\|"); for (String line : parts) { @@ -186,7 +197,10 @@ public class EpicAnchors extends SongodaPlugin { } meta.setLore(lore); item.setItemMeta(meta); - return item; + + NBTItem nbtItem = NmsManager.getNbt().of(item); + nbtItem.set("ticks", ticks); + return nbtItem.finish(); } public CommandManager getCommandManager() { diff --git a/src/main/java/com/songoda/epicanchors/utils/Methods.java b/src/main/java/com/songoda/epicanchors/utils/Methods.java index b76dda0..25fe998 100644 --- a/src/main/java/com/songoda/epicanchors/utils/Methods.java +++ b/src/main/java/com/songoda/epicanchors/utils/Methods.java @@ -18,19 +18,15 @@ public class Methods { private static Map serializeCache = new HashMap<>(); - public static String formatName(int ticks2, boolean full) { + public static String formatName(int ticks) { - String remaining = TimeUtils.makeReadable((ticks2 / 20L) * 1000L); + String remaining = TimeUtils.makeReadable((ticks / 20L) * 1000L); - String name = Settings.NAMETAG.getString().replace("{REMAINING}", (ticks2 <= 0) + String name = Settings.NAMETAG.getString().replace("{REMAINING}", (ticks <= 0) ? EpicAnchors.getInstance().getLocale().getMessage("infinite").getMessage() : remaining); - String info = ""; - if (full) { - info += TextUtils.convertToInvisibleString(ticks2 + ":"); - } - return info + TextUtils.formatText(name); + return TextUtils.formatText(name); } /**