diff --git a/src/xyz/soper/arty/item/MortarTuner.java b/src/xyz/soper/arty/item/MortarTuner.java index 6f61819..cede647 100644 --- a/src/xyz/soper/arty/item/MortarTuner.java +++ b/src/xyz/soper/arty/item/MortarTuner.java @@ -1,4 +1,63 @@ package xyz.soper.arty.item; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; + +import java.util.List; + public class MortarTuner { -} + + /** + * Linked location of the mortar object. Contains only coordinate data. + */ + private final Location linkedLocation; + + public static final String BASIC_TUNER_NAME = ChatColor.RESET + "Basic Tuner"; + public static final String NORMAL_TUNER_NAME = ChatColor.RESET + "Mortar Tuner"; + + MortarTuner(ItemStack tuner){ + if(isTuner(tuner)){ + String[] coords = tuner.getItemMeta().getLore().get(0).substring(20).split(", "); + linkedLocation = new Location( + null, + Double.parseDouble(coords[0]), + Double.parseDouble(coords[1]), + Double.parseDouble(coords[2]) + ); + } else throw new IllegalArgumentException("Incompatible ItemStack in MortarTuner constructor"); + } + + /** + * Gets the last location of the linked mortar. + * WARNING: Contains a null world, must be changed before it can be used. + * @return Location of last linked mortar with a null world. + */ + public Location getLinkedLocation() { + return linkedLocation; + } + + public static void updateTunerLocation(ItemStack tuner, Location location) throws IllegalArgumentException{ + if(!isTuner(tuner)){ + throw new IllegalArgumentException("Tried to update an non-tuner item with tuner data"); + } + List lore = tuner.getItemMeta().getLore(); + lore.set(0, ChatColor.GOLD + "Linked to Mortar at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ()); + tuner.getItemMeta().setLore(lore); + } + +// public static void updateTunerStatus(ItemStack tuner, boolean reset){ +// if(!isTuner(tuner)){ +// throw new IllegalArgumentException("Tried to update an non-tuner item with tuner data"); +// } +// if(reset || ) +// List lore = tuner.getItemMeta().getLore(); +// if(lore.size() == 1) lore.add(ChatColor.RED + "VERT"); +// } + + public static boolean isTuner(ItemStack item){ + return (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) + && (item.getItemMeta().getDisplayName().equals(BASIC_TUNER_NAME) + || item.getItemMeta().getDisplayName().equals(NORMAL_TUNER_NAME)); + } +} \ No newline at end of file