mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-11-26 03:55:33 +01:00
Updated to 1.16.1 + added NBT data storage for ticks.
This commit is contained in:
parent
2dd9aff6c5
commit
eb96225760
2
pom.xml
2
pom.xml
@ -105,7 +105,7 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.15</version>
|
||||
<version>1.16.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -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<String> 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() {
|
||||
|
@ -18,19 +18,15 @@ public class Methods {
|
||||
|
||||
private static Map<String, Location> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user