From 737bd45883b65409c4944ccf45e1dc4df762137e Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 4 Oct 2023 00:42:27 +0300 Subject: [PATCH] Deleted --- .classpath | 2 +- .../spawnermeta/view/SpawnerEditor.java | 137 -------- .../spawnermeta/view/SpawnerViewLayout.java | 296 ------------------ 3 files changed, 1 insertion(+), 434 deletions(-) delete mode 100644 src/mc/rellox/spawnermeta/view/SpawnerEditor.java delete mode 100644 src/mc/rellox/spawnermeta/view/SpawnerViewLayout.java diff --git a/.classpath b/.classpath index 03dabfe..c6a0714 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + diff --git a/src/mc/rellox/spawnermeta/view/SpawnerEditor.java b/src/mc/rellox/spawnermeta/view/SpawnerEditor.java deleted file mode 100644 index 9b02b03..0000000 --- a/src/mc/rellox/spawnermeta/view/SpawnerEditor.java +++ /dev/null @@ -1,137 +0,0 @@ -package mc.rellox.spawnermeta.view; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import mc.rellox.spawnermeta.SpawnerMeta; -import mc.rellox.spawnermeta.utility.Utils; -import mc.rellox.spawnermeta.view.SpawnerViewLayout.Slot; - -public class SpawnerEditor implements Listener { - - private static Player editor; - private static SpawnerEditor edit; - - public static void open(Player player) { - if(editor != null && edit != null) { - if(editor.isOnline() == false) editor = null; - else { - Inventory t = editor.getOpenInventory().getTopInventory(); - if(t == null) editor = null; - else if(t.equals(edit.v) == false) editor = null; - else { - player.sendMessage(ChatColor.DARK_RED + "(!) " + ChatColor.GOLD + "There already is someone editing!"); - player.playSound(player.getEyeLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 2f, 1f); - return; - } - } - } - edit = new SpawnerEditor(editor = player); - player.playSound(player.getEyeLocation(), Sound.BLOCK_NOTE_BLOCK_XYLOPHONE, 2f, 2f); - player.sendMessage(ChatColor.DARK_GREEN + "(!) " + ChatColor.DARK_AQUA + "Opening Spawner GUI Editor!"); - } - - private final Player player; - private final Inventory v; - - private SpawnerEditor(Player player) { - this.player = player; - this.v = Bukkit.createInventory(null, 36, "Spawner GUI Editor"); - SpawnerViewLayout.setEditor(v); - Bukkit.getPluginManager().registerEvents(this, SpawnerMeta.instance()); - player.openInventory(v); - } - - @EventHandler - private void onClick(InventoryClickEvent event) { - if(check() == false) return; - if(player.equals(event.getWhoClicked()) == false) return; - Inventory c = event.getClickedInventory(); - if(c == null || c.equals(v) == false) return; - event.setCancelled(true); - int s = event.getSlot(); - ClickType t = event.getClick(); - if(s >= 0 && s < 27) { - Slot l = SpawnerViewLayout.LAYOUT[s]; - if(l.c == false) return; - else { - if(t == ClickType.RIGHT) { - if(s == 26) return; - SpawnerViewLayout.LAYOUT[s] = SpawnerViewLayout.LAYOUT[s + 1]; - SpawnerViewLayout.LAYOUT[s + 1] = l; - SpawnerViewLayout.updateLayout(); - player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 2f, 1.5f); - } else if(t == ClickType.LEFT) { - if(s == 0) return; - SpawnerViewLayout.LAYOUT[s] = SpawnerViewLayout.LAYOUT[s - 1]; - SpawnerViewLayout.LAYOUT[s - 1] = l; - SpawnerViewLayout.updateLayout(); - player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 2f, 1.5f); - } else if(t == ClickType.MIDDLE) { - ItemStack item = event.getCursor(); - if(Utils.nulled(item) == true || item.getType() == l.m) return; - l.m = item.getType(); - if(item.hasItemMeta() == true) { - ItemMeta meta = item.getItemMeta(); - if(meta.hasCustomModelData() == true) l.o = meta.getCustomModelData(); - } - player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_FRAME_ADD_ITEM, 2f, 1.25f); - } else if(t == ClickType.SHIFT_LEFT || t == ClickType.SHIFT_RIGHT) { - l.g = !l.g; - player.playSound(player.getEyeLocation(), l.g ? Sound.BLOCK_BEACON_ACTIVATE : Sound.BLOCK_BEACON_DEACTIVATE, 0.75f, 2f); - } - } - } else if(s == 31) { - ItemStack item = event.getCursor(); - if(t.isShiftClick() == true) { - if(SpawnerViewLayout.background == null) return; - SpawnerViewLayout.background = null; - SpawnerViewLayout.background_model = 0; - } else { - if(Utils.nulled(item) == true || item.getType() == SpawnerViewLayout.background) return; - SpawnerViewLayout.background = item.getType(); - if(item.hasItemMeta() == true) { - ItemMeta meta = item.getItemMeta(); - if(meta.hasCustomModelData() == true) - SpawnerViewLayout.background_model = meta.getCustomModelData(); - } - } - SpawnerViewLayout.setBackground(); - player.playSound(player.getEyeLocation(), Sound.ENTITY_ITEM_FRAME_ADD_ITEM, 2f, 1.25f); - } - SpawnerViewLayout.setEditor(v); - } - - @EventHandler - private void onClose(InventoryCloseEvent event) { - if(event.getPlayer().equals(player) == false) return; - player.sendMessage(ChatColor.DARK_GREEN + "(!) " + ChatColor.DARK_AQUA + "Saving and closing editor!"); - player.playSound(player.getEyeLocation(), Sound.BLOCK_NOTE_BLOCK_XYLOPHONE, 0.75f, 0f); - unregister(); - } - - private boolean check() { - boolean o = player.isOnline(); - if(o == false) unregister(); - return o; - } - - private void unregister() { - HandlerList.unregisterAll(this); - edit = null; - editor = null; - SpawnerViewLayout.saveSlots(); - } - -} diff --git a/src/mc/rellox/spawnermeta/view/SpawnerViewLayout.java b/src/mc/rellox/spawnermeta/view/SpawnerViewLayout.java deleted file mode 100644 index 013e1b8..0000000 --- a/src/mc/rellox/spawnermeta/view/SpawnerViewLayout.java +++ /dev/null @@ -1,296 +0,0 @@ -package mc.rellox.spawnermeta.view; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.scheduler.BukkitRunnable; - -import mc.rellox.spawnermeta.SpawnerMeta; -import mc.rellox.spawnermeta.utility.Utils; -import mc.rellox.spawnermeta.utility.reflect.Reflect.RF; - -public final class SpawnerViewLayout { - - private static File lf; - public static FileConfiguration layout; - - private static final Slot[] DEFAULT; - static { - int i = 0; - DEFAULT = new Slot[] { - new Slot(SlotType.STATS, true, i++, Material.NETHER_STAR, true), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.UPGRADE_RANGE, true, i++, Material.COMPASS, true), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.UPGRADE_DELAY, true, i++, Material.CLOCK, true), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.UPGRADE_AMOUNT, true, i++, Material.GOLD_INGOT, true), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.BACKGROUND, false, i++, Material.CYAN_STAINED_GLASS_PANE, false), - new Slot(SlotType.CHARGES, true, i++, Material.COAL, true) - }; - } - public static final Slot[] LAYOUT = new Slot[27]; - public static int charges; - public static Slot background_slot; - public static Material background; - public static int background_model; - private static int rows; - - public static void initialize() { - lf = new File(SpawnerMeta.instance().getDataFolder(), "layout.yml"); - if(lf.getParentFile().exists() == false) lf.getParentFile().mkdirs(); - if(lf.exists() == true) layout = YamlConfiguration.loadConfiguration(lf); - else { - try { - lf.createNewFile(); - } catch(IOException e) {} - layout = YamlConfiguration.loadConfiguration(lf); - } - setDefaultLayout(); - new BukkitRunnable() { - @Override - public void run() { - setSlots(); - for(Slot s : LAYOUT) { - if(s.t == SlotType.BACKGROUND) { - background = s.m; - background_model = s.o; - background_slot = s; - break; - } - } - } - }.runTaskLater(SpawnerMeta.instance(), 5); - rows = layout.getInt("Upgrade-Rows", 3); - if(rows < 1 || rows > 6) rows = 3; - } - - public static void saveLayout() { - try { - layout.save(lf); - } catch(IOException e) {} - } - - public static final class WL { - - public static int size() { - return rows * 9; - } - - public static boolean is(SlotType type, int o) { - return Stream.of(LAYOUT).anyMatch(s -> s.t == type && s.i == o); - } - } - - public static void updateLayout() { - for(int i = 0; i < 27; i++) LAYOUT[i].i = i; - } - - public static void setEditor(Inventory v) { - for(int i = 0; i < 27; i++) v.setItem(i, slot(LAYOUT[i])); - for(int i = 27; i < 36; i++) v.setItem(i, x()); - v.setItem(31, background()); - } - - public static void setBackground() { - Stream.of(LAYOUT) - .filter(s -> s.t == SlotType.BACKGROUND) - .forEach(s -> { - s.m = background; - s.o = background_model; - }); - } - - private static ItemStack background() { - boolean b = background == null; - ItemStack item = new ItemStack(b ? Material.BARRIER : background); - ItemMeta meta = item.getItemMeta(); - if(meta == null) return item; - meta.setDisplayName(ChatColor.AQUA + "Background: " + ChatColor.GRAY - + (b ? "Air" : Utils.displayName(item))); - meta.addItemFlags(ItemFlag.values()); - List lore = new ArrayList<>(); - lore.add(""); - lore.add(ChatColor.GREEN + "Click " + ChatColor.AQUA + "to swap material"); - lore.add(ChatColor.GOLD + "Shift-click " + ChatColor.AQUA + "to set as air"); - meta.setLore(lore); - item.setItemMeta(meta); - return item; - } - - private static void setSlots() { - for(int i = 0; i < 27; i++) { - try { - String path = "Upgrade-Layout." + i; - LAYOUT[i] = new Slot(RF.enumerate(SlotType.class, layout.getString(path + ".Type")), - layout.getBoolean(path + ".Changable"), - i, RF.enumerate(Material.class, layout.getString(path + ".Material")), - layout.getBoolean(path + ".Glint"), - layout.getInt(path + ".Model")); - } catch(Exception e) { - LAYOUT[i] = DEFAULT[i].copy(); - Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + "[" + ChatColor.LIGHT_PURPLE + "SM" - + ChatColor.DARK_PURPLE + "]" + ChatColor.DARK_RED + " Unable to read layout slot: " + i + ", using default"); - } - } - } - - @SuppressWarnings("deprecation") - public static void setDefaultLayout() { - for(int i = 0; i < 27; i++) defaultSlot(DEFAULT[i]); - layout.addDefault("Upgrade-Rows", 3); - layout.options().copyDefaults(true); - layout.options().header("In this file you can modify spawner upgrade inventory layout.\n" - + "After any modifications do /sm update"); - saveLayout(); - } - - private static void defaultSlot(Slot s) { - if(s == null) return; - layout.addDefault("Upgrade-Layout." + s.i + ".Type", s.t.name()); - layout.addDefault("Upgrade-Layout." + s.i + ".Changable", s.c); - layout.addDefault("Upgrade-Layout." + s.i + ".Material", s.m == null ? "AIR" : s.m.name()); - layout.addDefault("Upgrade-Layout." + s.i + ".Glint", s.g); - layout.addDefault("Upgrade-Layout." + s.i + ".Model", s.o); - } - - public static void resetLayout() { - for(int i = 0; i < 27; i++) saveSlot(LAYOUT[i] = DEFAULT[i].copy()); - background = Material.CYAN_STAINED_GLASS_PANE; - background_model = 0; - - } - - public static void saveSlots() { - for(int i = 0; i < 27; i++) saveSlot(LAYOUT[i]); - } - - private static void saveSlot(Slot s) { - if(s == null) return; - layout.set("Upgrade-Layout." + s.i + ".Type", s.t.name()); - layout.set("Upgrade-Layout." + s.i + ".Changable", s.c); - layout.set("Upgrade-Layout." + s.i + ".Material", s.m == null ? "AIR" : s.m.name()); - layout.set("Upgrade-Layout." + s.i + ".Glint", s.g); - layout.set("Upgrade-Layout." + s.i + ".Model", s.o); - saveLayout(); - } - - private static ItemStack slot(Slot s) { - boolean b = s.m == null; - ItemStack item = new ItemStack(b ? Material.BARRIER : s.m); - ItemMeta meta = item.getItemMeta(); - if(meta == null) return item; - meta.setDisplayName(s.t.getName() + ChatColor.GRAY + " (" + (b ? "Air" : Utils.displayName(item)) + ")"); - if(s.g) meta.addEnchant(Enchantment.ARROW_DAMAGE, 0, true); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES); - if(s.c) { - List lore = new ArrayList<>(); - lore.add(""); - lore.add(ChatColor.GREEN + "Right-click " + ChatColor.AQUA + "to shift to right " + ChatColor.GOLD + " -> "); - lore.add(ChatColor.YELLOW + "Left-click " + ChatColor.AQUA + "to shift to left " + ChatColor.GOLD + " <- "); - lore.add(ChatColor.GOLD + "Middle-click " + ChatColor.AQUA + "to swap material"); - lore.add(ChatColor.RED + "Shift-click " + ChatColor.AQUA + "to toggle glint"); - meta.setLore(lore); - } - if(s.o > 0) meta.setCustomModelData(s.o); - item.setItemMeta(meta); - return item; - } - - private static ItemStack x() { - ItemStack item = new ItemStack(Material.GRAY_STAINED_GLASS_PANE); - ItemMeta meta = item.getItemMeta(); - if(meta == null) return item; - meta.setDisplayName(" "); - item.setItemMeta(meta); - return item; - } - - public static class Slot { - - // slot type - protected final SlotType t; - // changable - protected final boolean c; - - // slot - protected int i; - // material - protected Material m; - // glint - protected boolean g; - // model - protected int o; - - public Slot(SlotType t, boolean c, int i, Material m, boolean g, int o) { - this.t = t; - this.c = c; - this.i = i; - this.m = m == Material.AIR ? null : m; - this.g = g; - this.o = o; - } - - public Slot(SlotType t, boolean c, int i, Material m, boolean g) { - this(t, c, i, m, g, 0); - } - - public Slot copy() { - return new Slot(t, c, i, m, g, o); - } - - } - - public static enum SlotType { - - BACKGROUND(ChatColor.DARK_GRAY + "Background"), - UPGRADE_DELAY(ChatColor.GOLD + "Delay Upgrade"), - UPGRADE_AMOUNT(ChatColor.DARK_PURPLE + "Amount Upgrade"), - UPGRADE_RANGE(ChatColor.DARK_AQUA + "Range Upgrade"), - CHARGES(ChatColor.AQUA + "Charges"), - STATS(ChatColor.YELLOW + "Stats"); - - private String name; - - private SlotType(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - } - -}