|
| 1 | +package me.eccentric_nz.TARDIS.control.actions; |
| 2 | + |
| 3 | +import me.eccentric_nz.TARDIS.TARDIS; |
| 4 | +import me.eccentric_nz.TARDIS.TARDISConstants; |
| 5 | +import me.eccentric_nz.TARDIS.advanced.TARDISSerializeInventory; |
| 6 | +import me.eccentric_nz.TARDIS.customblocks.TARDISDisplayItem; |
| 7 | +import me.eccentric_nz.TARDIS.customblocks.TARDISDisplayItemUtils; |
| 8 | +import me.eccentric_nz.TARDIS.database.resultset.ResultSetDiskStorage; |
| 9 | +import me.eccentric_nz.TARDIS.enumeration.GlowstoneCircuit; |
| 10 | +import me.eccentric_nz.TARDIS.enumeration.Storage; |
| 11 | +import me.eccentric_nz.TARDIS.enumeration.TardisModule; |
| 12 | +import me.eccentric_nz.TARDIS.floodgate.TARDISFloodgate; |
| 13 | +import me.eccentric_nz.TARDIS.utility.TARDISStaticUtils; |
| 14 | +import org.bukkit.Material; |
| 15 | +import org.bukkit.block.Block; |
| 16 | +import org.bukkit.entity.Player; |
| 17 | +import org.bukkit.inventory.Inventory; |
| 18 | +import org.bukkit.inventory.ItemStack; |
| 19 | +import org.bukkit.inventory.meta.ItemMeta; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | +import java.util.HashMap; |
| 23 | +import java.util.UUID; |
| 24 | + |
| 25 | +public class DiskStorageAction { |
| 26 | + |
| 27 | + private final TARDIS plugin; |
| 28 | + |
| 29 | + public DiskStorageAction(TARDIS plugin) { |
| 30 | + this.plugin = plugin; |
| 31 | + } |
| 32 | + |
| 33 | + public void openGUI(UUID ownerUUID, Player player, int id, Block block) { |
| 34 | + UUID playerUUID = player.getUniqueId(); |
| 35 | + if (plugin.getTrackerKeeper().getUpdatePlayers().containsKey(playerUUID)) { |
| 36 | + return; |
| 37 | + } |
| 38 | + // only the time lord of this tardis |
| 39 | + if (!ownerUUID.equals(playerUUID)) { |
| 40 | + plugin.getMessenger().send(player, TardisModule.TARDIS, "NOT_OWNER"); |
| 41 | + return; |
| 42 | + } |
| 43 | + // do they have a storage record? |
| 44 | + HashMap<String, Object> wherestore = new HashMap<>(); |
| 45 | + wherestore.put("uuid", playerUUID); |
| 46 | + ResultSetDiskStorage rsstore = new ResultSetDiskStorage(plugin, wherestore); |
| 47 | + ItemStack[] stack = new ItemStack[54]; |
| 48 | + if (rsstore.resultSet()) { |
| 49 | + try { |
| 50 | + if (!rsstore.getSavesOne().isEmpty()) { |
| 51 | + stack = TARDISSerializeInventory.itemStacksFromString(rsstore.getSavesOne()); |
| 52 | + } else { |
| 53 | + stack = TARDISSerializeInventory.itemStacksFromString(Storage.SAVE_1.getEmpty()); |
| 54 | + } |
| 55 | + } catch (IOException ex) { |
| 56 | + plugin.debug("Could not get Storage Inventory: " + ex.getMessage()); |
| 57 | + } |
| 58 | + } else { |
| 59 | + try { |
| 60 | + stack = TARDISSerializeInventory.itemStacksFromString(Storage.SAVE_1.getEmpty()); |
| 61 | + for (ItemStack is : stack) { |
| 62 | + if (is != null && is.hasItemMeta()) { |
| 63 | + ItemMeta im = is.getItemMeta(); |
| 64 | + if (im.hasDisplayName()) { |
| 65 | + if (is.getType().equals(Material.FILLED_MAP)) { |
| 66 | + GlowstoneCircuit glowstone = GlowstoneCircuit.getByName().get(im.getDisplayName()); |
| 67 | + if (glowstone != null) { |
| 68 | + im.setCustomModelData(glowstone.getCustomModelData()); |
| 69 | + is.setType(Material.GLOWSTONE_DUST); |
| 70 | + is.setItemMeta(im); |
| 71 | + } |
| 72 | + } else { |
| 73 | + if (TARDISStaticUtils.isMusicDisk(is)) { |
| 74 | + im.setCustomModelData(10000001); |
| 75 | + } else if (is.getType().equals(Material.LIME_WOOL)) { |
| 76 | + im.setCustomModelData(86); |
| 77 | + is.setType(Material.BOWL); |
| 78 | + is.setItemMeta(im); |
| 79 | + } else if (is.getType().equals(Material.RED_WOOL)) { |
| 80 | + im.setCustomModelData(87); |
| 81 | + is.setType(Material.BOWL); |
| 82 | + is.setItemMeta(im); |
| 83 | + } else if (is.getType().equals(Material.GLOWSTONE_DUST) && !im.hasCustomModelData() && im.getDisplayName().equals("Circuits")) { |
| 84 | + im.setCustomModelData(10001985); |
| 85 | + } |
| 86 | + is.setItemMeta(im); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } catch (IOException ex) { |
| 92 | + plugin.debug("Could not get default Storage Inventory: " + ex.getMessage()); |
| 93 | + } |
| 94 | + // make a record |
| 95 | + HashMap<String, Object> setstore = new HashMap<>(); |
| 96 | + setstore.put("uuid", player.getUniqueId().toString()); |
| 97 | + setstore.put("tardis_id", id); |
| 98 | + plugin.getQueryFactory().doInsert("storage", setstore); |
| 99 | + } |
| 100 | + Inventory inv = plugin.getServer().createInventory(player, 54, Storage.SAVE_1.getTitle()); |
| 101 | + inv.setContents(stack); |
| 102 | + player.openInventory(inv); |
| 103 | + // update note block if it's not BARRIER + Item Display |
| 104 | + if (!TARDISFloodgate.isFloodgateEnabled() || !TARDISFloodgate.isBedrockPlayer(player.getUniqueId())) { |
| 105 | + if (block.getType().equals(Material.NOTE_BLOCK) || block.getType().equals(Material.MUSHROOM_STEM)) { |
| 106 | + block.setBlockData(TARDISConstants.BARRIER, true); |
| 107 | + TARDISDisplayItemUtils.set(TARDISDisplayItem.DISK_STORAGE, block); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments