diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/Main.java index 025da1f..2f1a081 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/Main.java @@ -1,7 +1,8 @@ package me.night.nullvalkyrie; +import com.mongodb.client.MongoDatabase; import io.github.cdimascio.dotenv.Dotenv; -import me.night.nullvalkyrie.chests.MenuListener; +import me.night.nullvalkyrie.ui.inventory.InventoryListener; import me.night.nullvalkyrie.database.NPCDataManager; import me.night.nullvalkyrie.discord.DiscordClientManager; import me.night.nullvalkyrie.enchantments.EnchantmentManager; @@ -15,15 +16,16 @@ import org.bukkit.*; import org.bukkit.plugin.java.JavaPlugin; public final class Main extends JavaPlugin { public static Dotenv env; + public static MongoDatabase database; @Override public void onEnable() { EnchantmentManager.register(); + new FileManager(); env = Dotenv.configure().directory("E:\\Files\\SB\\plugins\\NullValkyrie").filename(".env").load(); new DatabaseManager(); - new FileManager(); new CommandManager(); Bukkit.getPluginManager().registerEvents(new ServerEvents(), this); - Bukkit.getPluginManager().registerEvents(new MenuListener(), this); + Bukkit.getPluginManager().registerEvents(new InventoryListener(), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this); Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(this), this); diff --git a/src/main/java/me/night/nullvalkyrie/chests/WitherChest.java b/src/main/java/me/night/nullvalkyrie/chests/WitherChest.java deleted file mode 100644 index 6ad79f3..0000000 --- a/src/main/java/me/night/nullvalkyrie/chests/WitherChest.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.night.nullvalkyrie.chests; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.inventory.Inventory; - -public class WitherChest { - public static Inventory witherchest = Bukkit.createInventory(null,54, ChatColor.DARK_AQUA + "Whiter Chest"); -} diff --git a/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java index 8c00eb2..722b46f 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MenuCommand.java @@ -1,69 +1,20 @@ package me.night.nullvalkyrie.commands; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; +import me.night.nullvalkyrie.ui.inventory.Menu; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import java.util.Arrays; import java.util.List; public class MenuCommand extends Command { - public static Inventory inv = Bukkit.createInventory(null, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); - public MenuCommand() { - super( - "menu", - new String[]{"m"}, - "Open the menu", - "" - ); + super("menu", new String[]{"m"}, "Open the menu", ""); } @Override public void onCommand(CommandSender sender, String[] args) { if (sender instanceof Player) { - Player player = (Player) sender; - inv = Bukkit.createInventory(player, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); - - ItemStack KYS = new ItemStack(Material.WOODEN_SWORD); - ItemMeta KYSmeta = KYS.getItemMeta(); - KYSmeta.setDisplayName(ChatColor.RED + "KILL YOURSELF WHEN???"); - KYSmeta.setLore(Arrays.asList(ChatColor.GRAY + "KYS", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); - KYS.setItemMeta(KYSmeta); - inv.setItem(20, KYS); - - ItemStack home = new ItemStack(Material.MAP); - ItemMeta homemeta = home.getItemMeta(); - homemeta.setDisplayName(ChatColor.BLUE + "Teleport to home"); - homemeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to teleport back to home", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); - home.setItemMeta(homemeta); - inv.setItem(22, home); - - ItemStack chest = new ItemStack(Material.ENDER_CHEST); - ItemMeta chestmeta = chest.getItemMeta(); - chestmeta.setDisplayName(ChatColor.GREEN + "Open your chest"); - chestmeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to open the chest", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); - chest.setItemMeta(chestmeta); - inv.setItem(24, chest); - - ItemStack close = new ItemStack(Material.BARRIER); - ItemMeta closemeta = close.getItemMeta(); - closemeta.setDisplayName(ChatColor.WHITE + "Close the menu"); - closemeta.setLore(Arrays.asList(ChatColor.GRAY + "Close the menu", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); - close.setItemMeta(closemeta); - inv.setItem(0, close); - - ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); - for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44}) { - inv.setItem(i, frame); - } - player.openInventory(inv); - + new Menu().UI((Player) sender); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java index e19a59a..419051b 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java @@ -1,7 +1,7 @@ package me.night.nullvalkyrie.commands; import me.night.nullvalkyrie.database.MinerDataManager; -import me.night.nullvalkyrie.miners.MinerGUI; +import me.night.nullvalkyrie.ui.inventory.Miner; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -26,7 +26,7 @@ public class MinerCommand extends Command { public void onCommand(CommandSender sender, String[] args) { if (sender instanceof Player player) { if (args.length == 0) { - new MinerGUI(player); + new Miner().UI(player); int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000; generate(50, seconds); } else if (args[0].equalsIgnoreCase("new")) { diff --git a/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java b/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java index 58c914c..865a070 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/ShopCommand.java @@ -1,44 +1,19 @@ package me.night.nullvalkyrie.commands; -import me.night.nullvalkyrie.database.ShopDataManager; -import me.night.nullvalkyrie.items.CustomItemManager; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; +import me.night.nullvalkyrie.ui.inventory.Shop; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import java.util.HashMap; import java.util.List; public class ShopCommand extends Command { public ShopCommand() { - super("7elven", - new String[]{"711", "seven", "7ven"}, - "Shop", - "" - ); + super("7elven", new String[]{"711", "seven", "7ven"}, "Shop", ""); } @Override public void onCommand(CommandSender sender, String[] args) { - Inventory inv = Bukkit.createInventory(null, 45, ChatColor.GREEN + "7-Eleven 24/7"); - int counter = 0; - HashMap list = ShopDataManager.getItems(); - for (String c : list.keySet()) { - ItemStack item = CustomItemManager.produceItem(c).clone(); - ItemMeta itemMeta = item.getItemMeta(); - List lore = itemMeta.getLore(); - lore.add("Price (BIN): " + list.get(c)); - itemMeta.setLore(lore); - item.setItemMeta(itemMeta); - inv.setItem(counter, item); - counter++; - } - Player player = (Player) sender; - player.openInventory(inv); + new Shop().UI((Player) sender); } @Override diff --git a/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java b/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java index 8f98970..c89a22e 100644 --- a/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/CustomWeaponsDataManager.java @@ -13,7 +13,7 @@ import java.util.List; public class CustomWeaponsDataManager { public static HashMap getWeapon(String itemName) { HashMap item = new HashMap<>(); - try (MongoCursor cursor = DatabaseManager.custom_weapons.find(Filters.eq("Name", itemName)).cursor()) { + try (MongoCursor cursor = DatabaseManager.getCustomWeaponsDB().find(Filters.eq("Name", itemName)).cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); String name = doc.getString("Name"); @@ -51,7 +51,7 @@ public class CustomWeaponsDataManager { public static HashMap getWeapons() { HashMap list = new HashMap<>(); - try (MongoCursor cursor = DatabaseManager.custom_weapons.find().cursor()) { + try (MongoCursor cursor = DatabaseManager.getCustomWeaponsDB().find().cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); HashMap item = new HashMap<>(); diff --git a/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java b/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java index a52e408..2885c74 100644 --- a/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java @@ -5,21 +5,26 @@ import me.night.nullvalkyrie.Main; import org.bson.Document; public class DatabaseManager { - public static MongoCollection users; - public static MongoCollection custom_weapons; - public static MongoCollection ranks; - public static MongoCollection npcs; - public static MongoCollection miners; - public static MongoCollection shops; public static MongoDatabase database; - public DatabaseManager() { database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie"); - users = database.getCollection("users"); - custom_weapons = database.getCollection("custom_weapons"); - ranks = database.getCollection("ranks"); - npcs = database.getCollection("npcs"); - miners = database.getCollection("miners"); - shops = database.getCollection("shops"); + } + public static MongoCollection getMinersDB() { + return database.getCollection("miners"); + } + public static MongoCollection getShopsDB() { + return database.getCollection("shops"); + } + public static MongoCollection getRanksDB() { + return database.getCollection("ranks"); + } + public static MongoCollection getNPCsDB() { + return database.getCollection("npcs"); + } + public static MongoCollection getUsersDB() { + return database.getCollection("users"); + } + public static MongoCollection getCustomWeaponsDB() { + return database.getCollection("custom_weapons"); } } diff --git a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java index 3c70c42..67a01f8 100644 --- a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java @@ -12,27 +12,27 @@ import java.util.HashMap; public class MinerDataManager { public static void setNPC(String name, Material material, int level, double rate, boolean enabled, long lastclaim) { Document newDocument = new Document(); - newDocument.put("ID", DatabaseManager.miners.countDocuments() + 1); + newDocument.put("ID", DatabaseManager.getMinersDB().countDocuments() + 1); newDocument.put("Name", name); newDocument.put("Material", material.name()); newDocument.put("Level", level); newDocument.put("Rate", rate); newDocument.put("Enabled", enabled); newDocument.put("LastClaim", lastclaim); - DatabaseManager.miners.insertOne(newDocument); + DatabaseManager.getMinersDB().insertOne(newDocument); } public static void setLastClaim(long id) { - Document document = DatabaseManager.miners.find(new Document("ID", id)).first(); + Document document = DatabaseManager.getMinersDB().find(new Document("ID", id)).first(); if (document != null) { Bson updated = new Document("LastClaim", System.currentTimeMillis()); Bson update = new Document("$set", updated); - DatabaseManager.miners.updateOne(document, update); + DatabaseManager.getMinersDB().updateOne(document, update); } } public static long getLastClaim(long id) { - try (MongoCursor cursor = DatabaseManager.miners.find(Filters.eq("ID", id)).cursor()) { + try (MongoCursor cursor = DatabaseManager.getMinersDB().find(Filters.eq("ID", id)).cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); for (String key : doc.keySet()) { @@ -44,7 +44,7 @@ public class MinerDataManager { } public static CryptoMiner getMiner(long id) { - try (MongoCursor cursor = DatabaseManager.miners.find(Filters.eq("ID", id)).cursor()) { + try (MongoCursor cursor = DatabaseManager.getMinersDB().find(Filters.eq("ID", id)).cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); return new CryptoMiner(doc.getString("Name"), Material.matchMaterial(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim")); @@ -55,7 +55,7 @@ public class MinerDataManager { public static HashMap getMiners() { HashMap list = new HashMap<>(); - try (MongoCursor cursor = DatabaseManager.miners.find().cursor()) { + try (MongoCursor cursor = DatabaseManager.getMinersDB().find().cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); list.put(doc.getLong("ID"), new CryptoMiner(doc.getString("Name"), Material.matchMaterial(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim"))); diff --git a/src/main/java/me/night/nullvalkyrie/database/NPCDataManager.java b/src/main/java/me/night/nullvalkyrie/database/NPCDataManager.java index a091bbe..6c111df 100644 --- a/src/main/java/me/night/nullvalkyrie/database/NPCDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/NPCDataManager.java @@ -20,7 +20,7 @@ import static me.night.nullvalkyrie.npc.NPCManager.*; public class NPCDataManager { public static void setNPC(String name, int x, int y, int z, int pitch, int yaw, String world, String texture, String signature) { - Document document = DatabaseManager.npcs.find(new Document("Name", name)).first(); + Document document = DatabaseManager.getNPCsDB().find(new Document("Name", name)).first(); if (document != null) { System.out.println("A NPC with this name already exist"); } else { @@ -34,12 +34,12 @@ public class NPCDataManager { newDocument.put("world", world); newDocument.put("texture", texture); newDocument.put("signature", signature); - DatabaseManager.npcs.insertOne(newDocument); + DatabaseManager.getNPCsDB().insertOne(newDocument); } } public static void reloadNPC() { - try (MongoCursor cursor = DatabaseManager.npcs.find().cursor()) { + try (MongoCursor cursor = DatabaseManager.getNPCsDB().find().cursor()) { while (cursor.hasNext()) { Document document = cursor.next(); String name = document.getString("Name"); diff --git a/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java b/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java index cb62558..9be5d04 100644 --- a/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java @@ -14,16 +14,16 @@ import static me.night.nullvalkyrie.ui.ScoreboardListener.nameTagManager; public class RankDataManager { public static void setRank(UUID uuid, Rank rank) { - Document document = DatabaseManager.ranks.find(new Document("UUID", uuid.toString())).first(); + Document document = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).first(); if(document != null) { Bson updated = new Document("Rank", rank.name()); Bson update = new Document("$set", updated); - DatabaseManager.ranks.updateOne(document, update); + DatabaseManager.getRanksDB().updateOne(document, update); } else { Document newDocument = new Document(); newDocument.put("UUID", uuid.toString()); newDocument.put("Rank", rank.name()); - DatabaseManager.ranks.insertOne(newDocument); + DatabaseManager.getRanksDB().insertOne(newDocument); } for(Player player : Bukkit.getOnlinePlayers()) { if(player.hasPlayedBefore()) { @@ -33,7 +33,7 @@ public class RankDataManager { } } public static Rank getRank(UUID uuid) { - try (MongoCursor cursor = DatabaseManager.ranks.find(Filters.eq("UUID", uuid.toString())).cursor()) { + try (MongoCursor cursor = DatabaseManager.getRanksDB().find(Filters.eq("UUID", uuid.toString())).cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); for (String key : doc.keySet()) { diff --git a/src/main/java/me/night/nullvalkyrie/database/ShopDataManager.java b/src/main/java/me/night/nullvalkyrie/database/ShopDataManager.java index cac6c24..9e0e585 100644 --- a/src/main/java/me/night/nullvalkyrie/database/ShopDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/ShopDataManager.java @@ -8,7 +8,7 @@ import java.util.HashMap; public class ShopDataManager { public static HashMap getItems() { HashMap list = new HashMap<>(); - try (MongoCursor cursor = DatabaseManager.shops.find().cursor()) { + try (MongoCursor cursor = DatabaseManager.getShopsDB().find().cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); list.put(doc.getString("Name"), doc.getInteger("Price")); diff --git a/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java b/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java index c2afb0d..9951f2e 100644 --- a/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java @@ -8,23 +8,24 @@ import org.bson.conversions.Bson; import java.util.HashMap; public class UserDataManager { - public static void createUserSchema(String username) { + public static void createUserSchema(String uuid) { Document document = new Document(); - document.put("Username", username); + document.put("UUID", uuid); document.put("Bank", 0); - DatabaseManager.users.insertOne(document); + DatabaseManager.getUsersDB().insertOne(document); } - public void updateUserBank(String username, Number coins) { - Document document = DatabaseManager.users.find(new Document("Username", username)).first(); + + public void updateUserBank(String uuid, Number coins) { + Document document = DatabaseManager.getUsersDB().find(new Document("UUID", uuid)).first(); if (document != null) { Bson updated = new Document("Bank", coins); Bson update = new Document("$set", updated); - DatabaseManager.users.updateOne(document, update); + DatabaseManager.getUsersDB().updateOne(document, update); } } - public static HashMap getUser(String username) { - try (MongoCursor cursor = DatabaseManager.users.find(Filters.eq("Username", username)).cursor()) { + public static HashMap getUser(String uuid) { + try (MongoCursor cursor = DatabaseManager.getUsersDB().find(Filters.eq("UUID", uuid)).cursor()) { while (cursor.hasNext()) { Document doc = cursor.next(); HashMap map = new HashMap<>(); diff --git a/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java b/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java index 672f0d3..d38c1cc 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java @@ -33,7 +33,7 @@ public class ScoreboardListener implements Listener { if (!player.hasPlayedBefore()) { e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20); RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE); - createUserSchema(e.getPlayer().getDisplayName()); + createUserSchema(e.getPlayer().getUniqueId().toString()); } e.getPlayer().setPlayerListHeaderFooter(ChatColor.AQUA + "You are playing on " + ChatColor.GREEN + "127.0.0.1", ChatColor.GOLD + "Ranks, boosters, & more!" + ChatColor.AQUA + "127.0.0.1"); nameTagManager.setNametags(player); diff --git a/src/main/java/me/night/nullvalkyrie/chests/MenuListener.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java similarity index 62% rename from src/main/java/me/night/nullvalkyrie/chests/MenuListener.java rename to src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java index 22bdea2..096448b 100644 --- a/src/main/java/me/night/nullvalkyrie/chests/MenuListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java @@ -1,16 +1,16 @@ -package me.night.nullvalkyrie.chests; +package me.night.nullvalkyrie.ui.inventory; -import me.night.nullvalkyrie.commands.MenuCommand; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; -public class MenuListener implements Listener { + +public class InventoryListener implements Listener { @EventHandler public void onClick(InventoryClickEvent e) { - if(e.getInventory().equals(MenuCommand.inv) && e.getCurrentItem() != null) { + if (e.getInventory().equals(Menu.GUI) && e.getCurrentItem() != null) { e.setCancelled(true); Player player = (Player) e.getWhoClicked(); switch (e.getRawSlot()) { @@ -24,14 +24,19 @@ public class MenuListener implements Listener { break; case 24: player.closeInventory(); - player.openInventory(WitherChest.witherchest); + player.openInventory(Shop.GUI); return; default: return; } - - player.closeInventory(); - }else { return; } + } + if (e.getInventory().equals(Shop.GUI) && e.getCurrentItem() != null) { + e.setCancelled(true); + Player player = (Player) e.getWhoClicked(); + if (e.getRawSlot() == 0) { + player.closeInventory(); + } + } } } diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/Menu.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/Menu.java new file mode 100644 index 0000000..7f35427 --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/Menu.java @@ -0,0 +1,53 @@ +package me.night.nullvalkyrie.ui.inventory; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Arrays; + +public class Menu { + public static Inventory GUI; + + public void UI(Player player) { + GUI = Bukkit.createInventory(player, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); + + ItemStack KYS = new ItemStack(Material.WOODEN_SWORD); + ItemMeta KYSmeta = KYS.getItemMeta(); + KYSmeta.setDisplayName(ChatColor.RED + "KILL YOURSELF WHEN???"); + KYSmeta.setLore(Arrays.asList(ChatColor.GRAY + "KYS", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); + KYS.setItemMeta(KYSmeta); + GUI.setItem(20, KYS); + + ItemStack home = new ItemStack(Material.MAP); + ItemMeta homemeta = home.getItemMeta(); + homemeta.setDisplayName(ChatColor.BLUE + "Teleport to home"); + homemeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to teleport back to home", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); + home.setItemMeta(homemeta); + GUI.setItem(22, home); + + ItemStack chest = new ItemStack(Material.ENDER_CHEST); + ItemMeta chestmeta = chest.getItemMeta(); + chestmeta.setDisplayName(ChatColor.GREEN + "Open your chest"); + chestmeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to open the chest", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); + chest.setItemMeta(chestmeta); + GUI.setItem(24, chest); + + ItemStack close = new ItemStack(Material.BARRIER); + ItemMeta closemeta = close.getItemMeta(); + closemeta.setDisplayName(ChatColor.WHITE + "Close the menu"); + closemeta.setLore(Arrays.asList(ChatColor.GRAY + "Close the menu", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); + close.setItemMeta(closemeta); + GUI.setItem(0, close); + + ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); + for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44}) + GUI.setItem(i, frame); + + player.openInventory(GUI); + } +} diff --git a/src/main/java/me/night/nullvalkyrie/miners/MinerGUI.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java similarity index 69% rename from src/main/java/me/night/nullvalkyrie/miners/MinerGUI.java rename to src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java index 6d789d5..0a270d8 100644 --- a/src/main/java/me/night/nullvalkyrie/miners/MinerGUI.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java @@ -1,58 +1,52 @@ -package me.night.nullvalkyrie.miners; - -import me.night.nullvalkyrie.database.MinerDataManager; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class MinerGUI { - private Inventory inv; - - public MinerGUI(Player player) { - createUI(); - player.openInventory(inv); - } - - public void createUI() { - inv = Bukkit.createInventory(null, 45, ChatColor.DARK_AQUA + "Crypto Miners"); - ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); - for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44}) { - inv.setItem(i, frame); - } - ItemStack close = new ItemStack(Material.BARRIER); - ItemMeta closemeta = close.getItemMeta(); - closemeta.setDisplayName(ChatColor.WHITE + "Close the menu"); - closemeta.setLore(List.of(ChatColor.GRAY + "Close the menu")); - close.setItemMeta(closemeta); - inv.setItem(0, close); - int[] a = new int[]{10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34}; - int ind = 0; - - for (CryptoMiner c : MinerDataManager.getMiners().values()) { - if (ind <= 20) { - ItemStack item = new ItemStack(c.getType()); - ItemMeta itemMeta = item.getItemMeta(); - itemMeta.setDisplayName(c.getName()); - List lore = new ArrayList<>(); - lore.add("Level: " + c.getLevel()); - lore.add("Rate: " + c.getRate()); - lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(c.getLastclaim()))); - itemMeta.setLore(lore); - item.setItemMeta(itemMeta); - inv.setItem(a[ind], item); - ind++; - } - - } - } - -} +package me.night.nullvalkyrie.ui.inventory; + +import me.night.nullvalkyrie.database.MinerDataManager; +import me.night.nullvalkyrie.miners.CryptoMiner; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class Miner { + public static Inventory GUI; + + public void UI(Player player) { + GUI = Bukkit.createInventory(null, 45, ChatColor.DARK_AQUA + "Crypto Miners"); + ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); + for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44}) { + GUI.setItem(i, frame); + } + ItemStack close = new ItemStack(Material.BARRIER); + ItemMeta closemeta = close.getItemMeta(); + if (closemeta != null) closemeta.setDisplayName(ChatColor.WHITE + "Close the menu"); + close.setItemMeta(closemeta); + GUI.setItem(0, close); + int[] a = new int[]{10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34}; + int counter = 0; + for (CryptoMiner c : MinerDataManager.getMiners().values()) { + if (counter <= 20) { + ItemStack item = new ItemStack(c.getType()); + ItemMeta itemMeta = item.getItemMeta(); + itemMeta.setDisplayName(c.getName()); + List lore = new ArrayList<>(); + lore.add("Level: " + c.getLevel()); + lore.add("Rate: " + c.getRate()); + lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(c.getLastclaim()))); + itemMeta.setLore(lore); + item.setItemMeta(itemMeta); + GUI.setItem(a[counter], item); + counter++; + } + player.openInventory(GUI); + } + } + +} diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java new file mode 100644 index 0000000..4075b92 --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/Shop.java @@ -0,0 +1,46 @@ +package me.night.nullvalkyrie.ui.inventory; + +import me.night.nullvalkyrie.database.ShopDataManager; +import me.night.nullvalkyrie.items.CustomItemManager; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.List; + +public class Shop { + public static Inventory GUI; + + public void UI(Player player) { + GUI = Bukkit.createInventory(null, 54, ChatColor.GREEN + "7-Eleven 24/7"); + ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); + for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53}) + GUI.setItem(i, frame); + ItemStack close = new ItemStack(Material.BARRIER); + ItemMeta closemeta = close.getItemMeta(); + if (closemeta != null) closemeta.setDisplayName(ChatColor.WHITE + "Close the menu"); + close.setItemMeta(closemeta); + GUI.setItem(0, close); + HashMap list = ShopDataManager.getItems(); + int[] a = new int[]{10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43, 44}; + int counter = 0; + for (String c : list.keySet()) { + if (counter <= 20) { + ItemStack item = CustomItemManager.produceItem(c).clone(); + ItemMeta itemMeta = item.getItemMeta(); + List lore = itemMeta.getLore(); + lore.add("Price (BIN): " + list.get(c)); + itemMeta.setLore(lore); + item.setItemMeta(itemMeta); + GUI.setItem(a[counter], item); + counter++; + } + } + player.openInventory(GUI); + } +}