|
| 1 | +/* |
| 2 | + * Copyright (C) 2026 eccentric_nz |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +package me.eccentric_nz.TARDIS.ARS; |
| 18 | + |
| 19 | +import me.eccentric_nz.TARDIS.TARDIS; |
| 20 | +import me.eccentric_nz.TARDIS.blueprints.TARDISPermission; |
| 21 | +import me.eccentric_nz.TARDIS.custommodels.GUIArs; |
| 22 | +import net.kyori.adventure.text.Component; |
| 23 | +import net.kyori.adventure.text.format.NamedTextColor; |
| 24 | +import org.bukkit.Material; |
| 25 | +import org.bukkit.entity.Player; |
| 26 | +import org.bukkit.inventory.Inventory; |
| 27 | +import org.bukkit.inventory.InventoryHolder; |
| 28 | +import org.bukkit.inventory.ItemStack; |
| 29 | +import org.bukkit.inventory.meta.ItemMeta; |
| 30 | + |
| 31 | +import java.util.ArrayList; |
| 32 | +import java.util.List; |
| 33 | +import java.util.Locale; |
| 34 | + |
| 35 | +/** |
| 36 | + * During his exile on Earth, the Third Doctor altered the TARDIS' Architectural |
| 37 | + * Configuration software to relocate the console outside the ship (as it was |
| 38 | + * too big to go through the doors), allowing him to work on it in his lab. |
| 39 | + * |
| 40 | + * @author eccentric_nz |
| 41 | + */ |
| 42 | +public class ARSInventory implements InventoryHolder { |
| 43 | + |
| 44 | + private final TARDIS plugin; |
| 45 | + private final Inventory inventory; |
| 46 | + |
| 47 | + public ARSInventory(TARDIS plugin, Player player) { |
| 48 | + this.plugin = plugin; |
| 49 | + this.inventory = plugin.getServer().createInventory(this, 54, Component.text("Architectural Reconfiguration", NamedTextColor.DARK_RED)); |
| 50 | + this.inventory.setContents(getItemStack(player)); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public Inventory getInventory() { |
| 55 | + return inventory; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Constructs an inventory for the Architectural Reconfiguration System GUI. |
| 60 | + * |
| 61 | + * @return an Array of itemStacks (an inventory) |
| 62 | + */ |
| 63 | + private ItemStack[] getItemStack(Player player) { |
| 64 | + |
| 65 | + ItemStack[] is = new ItemStack[54]; |
| 66 | + // direction pad up |
| 67 | + ItemStack pad_up = ItemStack.of(GUIArs.BUTTON_UP.material(), 1); |
| 68 | + ItemMeta up = pad_up.getItemMeta(); |
| 69 | + up.displayName(Component.text(plugin.getLanguage().getString("BUTTON_UP", "Up"))); |
| 70 | + pad_up.setItemMeta(up); |
| 71 | + is[GUIArs.BUTTON_UP.slot()] = pad_up; |
| 72 | + // room relocator |
| 73 | + ItemStack relocator = ItemStack.of(GUIArs.BUTTON_RELOCATE.material(), 1); |
| 74 | + ItemMeta rim = relocator.getItemMeta(); |
| 75 | + rim.displayName(Component.text("Room Relocator")); |
| 76 | + relocator.setItemMeta(rim); |
| 77 | + is[GUIArs.BUTTON_RELOCATE.slot()] = relocator; |
| 78 | + // black wool |
| 79 | + ItemStack black = ItemStack.of(GUIArs.BUTTON_MAP_ON.material(), 1); |
| 80 | + ItemMeta wool = black.getItemMeta(); |
| 81 | + wool.displayName(Component.text(plugin.getLanguage().getString("BUTTON_MAP_NO", "Load the map!"))); |
| 82 | + black.setItemMeta(wool); |
| 83 | + for (int j = 0; j < 37; j += 9) { |
| 84 | + for (int k = 0; k < 5; k++) { |
| 85 | + int slot = 4 + j + k; |
| 86 | + is[slot] = black; |
| 87 | + } |
| 88 | + } |
| 89 | + // direction pad left |
| 90 | + ItemStack pad_left = ItemStack.of(GUIArs.BUTTON_LEFT.material(), 1); |
| 91 | + ItemMeta left = pad_left.getItemMeta(); |
| 92 | + left.displayName(Component.text(plugin.getLanguage().getString("BUTTON_LEFT", "Left"))); |
| 93 | + pad_left.setItemMeta(left); |
| 94 | + is[GUIArs.BUTTON_LEFT.slot()] = pad_left; |
| 95 | + // load map |
| 96 | + ItemStack map = ItemStack.of(GUIArs.BUTTON_MAP.material(), 1); |
| 97 | + ItemMeta load = map.getItemMeta(); |
| 98 | + load.displayName(Component.text(plugin.getLanguage().getString("BUTTON_MAP", "Load map"))); |
| 99 | + map.setItemMeta(load); |
| 100 | + is[GUIArs.BUTTON_MAP.slot()] = map; |
| 101 | + // direction pad right |
| 102 | + ItemStack pad_right = ItemStack.of(GUIArs.BUTTON_RIGHT.material(), 1); |
| 103 | + ItemMeta right = pad_right.getItemMeta(); |
| 104 | + right.displayName(Component.text(plugin.getLanguage().getString("BUTTON_RIGHT", "Right"))); |
| 105 | + pad_right.setItemMeta(right); |
| 106 | + is[GUIArs.BUTTON_RIGHT.slot()] = pad_right; |
| 107 | + // set |
| 108 | + ItemStack s = ItemStack.of(GUIArs.BUTTON_RECON.material(), 1); |
| 109 | + ItemMeta sim = s.getItemMeta(); |
| 110 | + sim.displayName(Component.text(plugin.getLanguage().getString("BUTTON_RECON", "Reconfigure!"))); |
| 111 | + s.setItemMeta(sim); |
| 112 | + is[GUIArs.BUTTON_RECON.slot()] = s; |
| 113 | + // direction pad down |
| 114 | + ItemStack pad_down = ItemStack.of(GUIArs.BUTTON_DOWN.material(), 1); |
| 115 | + ItemMeta down = pad_down.getItemMeta(); |
| 116 | + down.displayName(Component.text(plugin.getLanguage().getString("BUTTON_DOWN", "Down"))); |
| 117 | + pad_down.setItemMeta(down); |
| 118 | + is[GUIArs.BUTTON_DOWN.slot()] = pad_down; |
| 119 | + // level bottom |
| 120 | + ItemStack level_bot = ItemStack.of(GUIArs.BUTTON_LEVEL_B.material(), 1); |
| 121 | + ItemMeta bot = level_bot.getItemMeta(); |
| 122 | + bot.displayName(Component.text(plugin.getLanguage().getString("BUTTON_LEVEL_B", "Bottom level"))); |
| 123 | + level_bot.setItemMeta(bot); |
| 124 | + is[GUIArs.BUTTON_LEVEL_B.slot()] = level_bot; |
| 125 | + // level selected |
| 126 | + ItemStack level_sel = ItemStack.of(GUIArs.BUTTON_LEVEL.material(), 1); |
| 127 | + ItemMeta main = level_sel.getItemMeta(); |
| 128 | + main.displayName(Component.text(plugin.getLanguage().getString("BUTTON_LEVEL", "Main level"))); |
| 129 | + level_sel.setItemMeta(main); |
| 130 | + is[GUIArs.BUTTON_LEVEL.slot()] = level_sel; |
| 131 | + // level top |
| 132 | + ItemStack level_top = ItemStack.of(GUIArs.BUTTON_LEVEL_T.material(), 1); |
| 133 | + ItemMeta top = level_top.getItemMeta(); |
| 134 | + top.displayName(Component.text(plugin.getLanguage().getString("BUTTON_LEVEL_T", "Top level"))); |
| 135 | + level_top.setItemMeta(top); |
| 136 | + is[GUIArs.BUTTON_LEVEL_T.slot()] = level_top; |
| 137 | + // reset |
| 138 | + ItemStack reset = ItemStack.of(GUIArs.BUTTON_RESET.material(), 1); |
| 139 | + ItemMeta cobble = reset.getItemMeta(); |
| 140 | + cobble.displayName(Component.text(plugin.getLanguage().getString("BUTTON_RESET", "Reset selected"))); |
| 141 | + reset.setItemMeta(cobble); |
| 142 | + is[GUIArs.BUTTON_RESET.slot()] = reset; |
| 143 | + // scroll left |
| 144 | + ItemStack scroll_left = ItemStack.of(GUIArs.BUTTON_SCROLL_L.material(), 1); |
| 145 | + ItemMeta nim = scroll_left.getItemMeta(); |
| 146 | + nim.displayName(Component.text(plugin.getLanguage().getString("BUTTON_SCROLL_L", "Scroll left"))); |
| 147 | + scroll_left.setItemMeta(nim); |
| 148 | + is[GUIArs.BUTTON_SCROLL_L.slot()] = scroll_left; |
| 149 | + // scroll right |
| 150 | + ItemStack scroll_right = ItemStack.of(GUIArs.BUTTON_SCROLL_R.material(), 1); |
| 151 | + ItemMeta pim = scroll_right.getItemMeta(); |
| 152 | + pim.displayName(Component.text(plugin.getLanguage().getString("BUTTON_SCROLL_R", "Scroll right"))); |
| 153 | + scroll_right.setItemMeta(pim); |
| 154 | + is[GUIArs.BUTTON_SCROLL_R.slot()] = scroll_right; |
| 155 | + // jettison |
| 156 | + ItemStack jettison = ItemStack.of(GUIArs.BUTTON_JETT.material(), 1); |
| 157 | + ItemMeta tnt = jettison.getItemMeta(); |
| 158 | + tnt.displayName(Component.text(plugin.getLanguage().getString("BUTTON_JETT", "Jettison"))); |
| 159 | + jettison.setItemMeta(tnt); |
| 160 | + is[GUIArs.BUTTON_JETT.slot()] = jettison; |
| 161 | + |
| 162 | + int i = 45; |
| 163 | + for (TARDISARS a : TARDISARS.values()) { |
| 164 | + if (a.isInGUI() && i < 54) { |
| 165 | + ItemStack room = ItemStack.of(Material.getMaterial(a.getMaterial()), 1); |
| 166 | + ItemMeta im = room.getItemMeta(); |
| 167 | + im.displayName(Component.text(a.getDescriptiveName())); |
| 168 | + List<Component> lore = new ArrayList<>(); |
| 169 | + lore.add(Component.text("Cost: " + plugin.getRoomsConfig().getInt("rooms." + a + ".cost"))); |
| 170 | + String roomName = TARDISARS.ARSFor(room.getType().toString()).getConfigPath(); |
| 171 | + if (player != null && !TARDISPermission.hasPermission(player, "tardis.room." + roomName.toLowerCase(Locale.ROOT))) { |
| 172 | + lore.add(Component.text(plugin.getLanguage().getString("NO_PERM_CONSOLE", "No permission!"), NamedTextColor.RED)); |
| 173 | + } |
| 174 | + im.lore(lore); |
| 175 | + room.setItemMeta(im); |
| 176 | + is[i] = room; |
| 177 | + i++; |
| 178 | + } |
| 179 | + } |
| 180 | + return is; |
| 181 | + } |
| 182 | +} |
0 commit comments