Implemented the SongodaCore NBT API.

This commit is contained in:
Brianna 2020-11-23 16:03:36 -06:00
parent be60612762
commit 8a117929fb
5 changed files with 32 additions and 28 deletions

View File

@ -8,6 +8,9 @@ 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.NBTCore;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.epicfurnaces.boost.BoostData;
import com.songoda.epicfurnaces.boost.BoostManager;
import com.songoda.epicfurnaces.commands.CommandBoost;
@ -368,14 +371,26 @@ public class EpicFurnaces extends SongodaPlugin {
if (Settings.FURNACE_ITEM.getBoolean()) {
ItemMeta itemmeta = item.getItemMeta();
itemmeta.setDisplayName(Methods.formatText(Methods.formatName(level, uses, true)));
itemmeta.setDisplayName(Methods.formatText(Methods.formatName(level)));
item.setItemMeta(itemmeta);
}
return item;
NBTCore nbt = NmsManager.getNbt();
NBTItem nbtItem = nbt.of(item);
nbtItem.set("level", level);
nbtItem.set("uses", uses);
return nbtItem.finish();
}
public int getFurnceLevel(ItemStack item) {
public int getFurnaceLevel(ItemStack item) {
NBTCore nbt = NmsManager.getNbt();
NBTItem nbtItem = nbt.of(item);
if (nbtItem.has("level"))
return nbtItem.getNBTObject("level").asInt();
// Legacy trash.
if (item.getItemMeta().getDisplayName().contains(":")) {
String arr[] = (item.getItemMeta().getDisplayName().replace("§", "")).split(":");
return Integer.parseInt(arr[0]);
@ -385,6 +400,13 @@ public class EpicFurnaces extends SongodaPlugin {
}
public int getFurnaceUses(ItemStack item) {
NBTCore nbt = NmsManager.getNbt();
NBTItem nbtItem = nbt.of(item);
if (nbtItem.has("uses"))
return nbtItem.getNBTObject("uses").asInt();
// Legacy trash.
if (item.getItemMeta().getDisplayName().contains(":")) {
String arr[] = (item.getItemMeta().getDisplayName().replace("§", "")).split(":");
return Integer.parseInt(arr[1]);

View File

@ -128,7 +128,7 @@ public class Furnace {
event.getResult().setAmount(event.getResult().getAmount() + randomAmount);
}
public void upgrade(Player player, CostType type) {
if (!plugin.getLevelManager().getLevels().containsKey(this.level.getLevel() + 1)) return;
@ -195,7 +195,7 @@ public class Furnace {
private void syncName() {
org.bukkit.block.Furnace furnace = (org.bukkit.block.Furnace) location.getBlock().getState();
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_10))
furnace.setCustomName(Methods.formatName(level.getLevel(), uses, false));
furnace.setCustomName(Methods.formatName(level.getLevel()));
furnace.update(true);
}
@ -272,7 +272,6 @@ public class Furnace {
return radiusOverheat.isEmpty() ? null : Collections.unmodifiableList(radiusOverheat);
else
return radiusFuelshare.isEmpty() ? null : Collections.unmodifiableList(radiusFuelshare);
}
@ -281,7 +280,6 @@ public class Furnace {
radiusOverheat.add(location);
else
radiusFuelshare.add(location);
}

View File

@ -38,7 +38,7 @@ public class GUIOverview extends Gui {
this.player = player;
setRows(3);
setTitle(Methods.formatName(furnace.getLevel().getLevel(), furnace.getUses(), false));
setTitle(Methods.formatName(furnace.getLevel().getLevel()));
runTask();
constructGUI();
this.setOnClose(action -> Bukkit.getScheduler().cancelTask(task));

View File

@ -55,9 +55,9 @@ public class BlockListeners implements Listener {
Location location = event.getBlock().getLocation();
Furnace furnace = event.getItemInHand().getItemMeta().hasDisplayName() && plugin.getFurnceLevel(item) != 1
Furnace furnace = event.getItemInHand().getItemMeta().hasDisplayName() && plugin.getFurnaceLevel(item) != 1
? new FurnaceBuilder(location)
.setLevel(plugin.getLevelManager().getLevel(plugin.getFurnceLevel(item)))
.setLevel(plugin.getLevelManager().getLevel(plugin.getFurnaceLevel(item)))
.setUses(plugin.getFurnaceUses(item))
.setPlacedBy(event.getPlayer().getUniqueId()).build()
: new FurnaceBuilder(location).setPlacedBy(event.getPlayer().getUniqueId()).build();

View File

@ -26,28 +26,12 @@ public class Methods {
return type;
}
public static String formatName(int level, int uses, boolean full) {
public static String formatName(int level) {
String name = EpicFurnaces.getInstance().getLocale().getMessage("general.nametag.nameformat")
.processPlaceholder("level", level).getMessage();
String info = "";
if (full) {
info += convertToInvisibleString(level + ":" + uses + ":");
}
return info + formatText(name);
}
/**
* Serializes the location of the block specified.
*
* @param b The block whose location is to be saved.
* @return The serialized data.
*/
public static String serializeLocation(Block b) {
if (b == null)
return "";
return serializeLocation(b.getLocation());
return formatText(name);
}
/**