This commit is contained in:
NK 2022-12-02 18:41:59 +00:00
parent 2c9727e99e
commit 94a0106f01
17 changed files with 222 additions and 199 deletions

View file

@ -1,7 +1,8 @@
package me.night.nullvalkyrie; package me.night.nullvalkyrie;
import com.mongodb.client.MongoDatabase;
import io.github.cdimascio.dotenv.Dotenv; 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.database.NPCDataManager;
import me.night.nullvalkyrie.discord.DiscordClientManager; import me.night.nullvalkyrie.discord.DiscordClientManager;
import me.night.nullvalkyrie.enchantments.EnchantmentManager; import me.night.nullvalkyrie.enchantments.EnchantmentManager;
@ -15,15 +16,16 @@ import org.bukkit.*;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin { public final class Main extends JavaPlugin {
public static Dotenv env; public static Dotenv env;
public static MongoDatabase database;
@Override @Override
public void onEnable() { public void onEnable() {
EnchantmentManager.register(); EnchantmentManager.register();
new FileManager();
env = Dotenv.configure().directory("E:\\Files\\SB\\plugins\\NullValkyrie").filename(".env").load(); env = Dotenv.configure().directory("E:\\Files\\SB\\plugins\\NullValkyrie").filename(".env").load();
new DatabaseManager(); new DatabaseManager();
new FileManager();
new CommandManager(); new CommandManager();
Bukkit.getPluginManager().registerEvents(new ServerEvents(), this); 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 ScoreboardListener(this), this);
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this);
Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(this), this); Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(this), this);

View file

@ -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");
}

View file

@ -1,69 +1,20 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import org.bukkit.Bukkit; import me.night.nullvalkyrie.ui.inventory.Menu;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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; import java.util.List;
public class MenuCommand extends Command { public class MenuCommand extends Command {
public static Inventory inv = Bukkit.createInventory(null, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu");
public MenuCommand() { public MenuCommand() {
super( super("menu", new String[]{"m"}, "Open the menu", "");
"menu",
new String[]{"m"},
"Open the menu",
""
);
} }
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; new Menu().UI((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);
} }
} }

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.MinerDataManager; 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.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +26,7 @@ public class MinerCommand extends Command {
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player player) { if (sender instanceof Player player) {
if (args.length == 0) { if (args.length == 0) {
new MinerGUI(player); new Miner().UI(player);
int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000; int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000;
generate(50, seconds); generate(50, seconds);
} else if (args[0].equalsIgnoreCase("new")) { } else if (args[0].equalsIgnoreCase("new")) {

View file

@ -1,44 +1,19 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.ShopDataManager; import me.night.nullvalkyrie.ui.inventory.Shop;
import me.night.nullvalkyrie.items.CustomItemManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; 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; import java.util.List;
public class ShopCommand extends Command { public class ShopCommand extends Command {
public ShopCommand() { public ShopCommand() {
super("7elven", super("7elven", new String[]{"711", "seven", "7ven"}, "Shop", "");
new String[]{"711", "seven", "7ven"},
"Shop",
""
);
} }
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
Inventory inv = Bukkit.createInventory(null, 45, ChatColor.GREEN + "7-Eleven 24/7"); new Shop().UI((Player) sender);
int counter = 0;
HashMap<String, Integer> list = ShopDataManager.getItems();
for (String c : list.keySet()) {
ItemStack item = CustomItemManager.produceItem(c).clone();
ItemMeta itemMeta = item.getItemMeta();
List<String> 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);
} }
@Override @Override

View file

@ -13,7 +13,7 @@ import java.util.List;
public class CustomWeaponsDataManager { public class CustomWeaponsDataManager {
public static HashMap<String, Object> getWeapon(String itemName) { public static HashMap<String, Object> getWeapon(String itemName) {
HashMap<String, Object> item = new HashMap<>(); HashMap<String, Object> item = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.custom_weapons.find(Filters.eq("Name", itemName)).cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getCustomWeaponsDB().find(Filters.eq("Name", itemName)).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
String name = doc.getString("Name"); String name = doc.getString("Name");
@ -51,7 +51,7 @@ public class CustomWeaponsDataManager {
public static HashMap<String, Object> getWeapons() { public static HashMap<String, Object> getWeapons() {
HashMap<String, Object> list = new HashMap<>(); HashMap<String, Object> list = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.custom_weapons.find().cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getCustomWeaponsDB().find().cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
HashMap<String, Object> item = new HashMap<>(); HashMap<String, Object> item = new HashMap<>();

View file

@ -5,21 +5,26 @@ import me.night.nullvalkyrie.Main;
import org.bson.Document; import org.bson.Document;
public class DatabaseManager { public class DatabaseManager {
public static MongoCollection<Document> users;
public static MongoCollection<Document> custom_weapons;
public static MongoCollection<Document> ranks;
public static MongoCollection<Document> npcs;
public static MongoCollection<Document> miners;
public static MongoCollection<Document> shops;
public static MongoDatabase database; public static MongoDatabase database;
public DatabaseManager() { public DatabaseManager() {
database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie"); database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie");
users = database.getCollection("users"); }
custom_weapons = database.getCollection("custom_weapons"); public static MongoCollection<Document> getMinersDB() {
ranks = database.getCollection("ranks"); return database.getCollection("miners");
npcs = database.getCollection("npcs"); }
miners = database.getCollection("miners"); public static MongoCollection<Document> getShopsDB() {
shops = database.getCollection("shops"); return database.getCollection("shops");
}
public static MongoCollection<Document> getRanksDB() {
return database.getCollection("ranks");
}
public static MongoCollection<Document> getNPCsDB() {
return database.getCollection("npcs");
}
public static MongoCollection<Document> getUsersDB() {
return database.getCollection("users");
}
public static MongoCollection<Document> getCustomWeaponsDB() {
return database.getCollection("custom_weapons");
} }
} }

View file

@ -12,27 +12,27 @@ import java.util.HashMap;
public class MinerDataManager { public class MinerDataManager {
public static void setNPC(String name, Material material, int level, double rate, boolean enabled, long lastclaim) { public static void setNPC(String name, Material material, int level, double rate, boolean enabled, long lastclaim) {
Document newDocument = new Document(); Document newDocument = new Document();
newDocument.put("ID", DatabaseManager.miners.countDocuments() + 1); newDocument.put("ID", DatabaseManager.getMinersDB().countDocuments() + 1);
newDocument.put("Name", name); newDocument.put("Name", name);
newDocument.put("Material", material.name()); newDocument.put("Material", material.name());
newDocument.put("Level", level); newDocument.put("Level", level);
newDocument.put("Rate", rate); newDocument.put("Rate", rate);
newDocument.put("Enabled", enabled); newDocument.put("Enabled", enabled);
newDocument.put("LastClaim", lastclaim); newDocument.put("LastClaim", lastclaim);
DatabaseManager.miners.insertOne(newDocument); DatabaseManager.getMinersDB().insertOne(newDocument);
} }
public static void setLastClaim(long id) { 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) { if (document != null) {
Bson updated = new Document("LastClaim", System.currentTimeMillis()); Bson updated = new Document("LastClaim", System.currentTimeMillis());
Bson update = new Document("$set", updated); Bson update = new Document("$set", updated);
DatabaseManager.miners.updateOne(document, update); DatabaseManager.getMinersDB().updateOne(document, update);
} }
} }
public static long getLastClaim(long id) { public static long getLastClaim(long id) {
try (MongoCursor<Document> cursor = DatabaseManager.miners.find(Filters.eq("ID", id)).cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getMinersDB().find(Filters.eq("ID", id)).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
for (String key : doc.keySet()) { for (String key : doc.keySet()) {
@ -44,7 +44,7 @@ public class MinerDataManager {
} }
public static CryptoMiner getMiner(long id) { public static CryptoMiner getMiner(long id) {
try (MongoCursor<Document> cursor = DatabaseManager.miners.find(Filters.eq("ID", id)).cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getMinersDB().find(Filters.eq("ID", id)).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
return new CryptoMiner(doc.getString("Name"), Material.matchMaterial(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim")); 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<Long, CryptoMiner> getMiners() { public static HashMap<Long, CryptoMiner> getMiners() {
HashMap<Long, CryptoMiner> list = new HashMap<>(); HashMap<Long, CryptoMiner> list = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.miners.find().cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getMinersDB().find().cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); 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"))); list.put(doc.getLong("ID"), new CryptoMiner(doc.getString("Name"), Material.matchMaterial(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim")));

View file

@ -20,7 +20,7 @@ import static me.night.nullvalkyrie.npc.NPCManager.*;
public class NPCDataManager { 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) { 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) { if (document != null) {
System.out.println("A NPC with this name already exist"); System.out.println("A NPC with this name already exist");
} else { } else {
@ -34,12 +34,12 @@ public class NPCDataManager {
newDocument.put("world", world); newDocument.put("world", world);
newDocument.put("texture", texture); newDocument.put("texture", texture);
newDocument.put("signature", signature); newDocument.put("signature", signature);
DatabaseManager.npcs.insertOne(newDocument); DatabaseManager.getNPCsDB().insertOne(newDocument);
} }
} }
public static void reloadNPC() { public static void reloadNPC() {
try (MongoCursor<Document> cursor = DatabaseManager.npcs.find().cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getNPCsDB().find().cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document document = cursor.next(); Document document = cursor.next();
String name = document.getString("Name"); String name = document.getString("Name");

View file

@ -14,16 +14,16 @@ import static me.night.nullvalkyrie.ui.ScoreboardListener.nameTagManager;
public class RankDataManager { public class RankDataManager {
public static void setRank(UUID uuid, Rank rank) { 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) { if(document != null) {
Bson updated = new Document("Rank", rank.name()); Bson updated = new Document("Rank", rank.name());
Bson update = new Document("$set", updated); Bson update = new Document("$set", updated);
DatabaseManager.ranks.updateOne(document, update); DatabaseManager.getRanksDB().updateOne(document, update);
} else { } else {
Document newDocument = new Document(); Document newDocument = new Document();
newDocument.put("UUID", uuid.toString()); newDocument.put("UUID", uuid.toString());
newDocument.put("Rank", rank.name()); newDocument.put("Rank", rank.name());
DatabaseManager.ranks.insertOne(newDocument); DatabaseManager.getRanksDB().insertOne(newDocument);
} }
for(Player player : Bukkit.getOnlinePlayers()) { for(Player player : Bukkit.getOnlinePlayers()) {
if(player.hasPlayedBefore()) { if(player.hasPlayedBefore()) {
@ -33,7 +33,7 @@ public class RankDataManager {
} }
} }
public static Rank getRank(UUID uuid) { public static Rank getRank(UUID uuid) {
try (MongoCursor<Document> cursor = DatabaseManager.ranks.find(Filters.eq("UUID", uuid.toString())).cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getRanksDB().find(Filters.eq("UUID", uuid.toString())).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
for (String key : doc.keySet()) { for (String key : doc.keySet()) {

View file

@ -8,7 +8,7 @@ import java.util.HashMap;
public class ShopDataManager { public class ShopDataManager {
public static HashMap<String, Integer> getItems() { public static HashMap<String, Integer> getItems() {
HashMap<String, Integer> list = new HashMap<>(); HashMap<String, Integer> list = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.shops.find().cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getShopsDB().find().cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
list.put(doc.getString("Name"), doc.getInteger("Price")); list.put(doc.getString("Name"), doc.getInteger("Price"));

View file

@ -8,23 +8,24 @@ import org.bson.conversions.Bson;
import java.util.HashMap; import java.util.HashMap;
public class UserDataManager { public class UserDataManager {
public static void createUserSchema(String username) { public static void createUserSchema(String uuid) {
Document document = new Document(); Document document = new Document();
document.put("Username", username); document.put("UUID", uuid);
document.put("Bank", 0); 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) { if (document != null) {
Bson updated = new Document("Bank", coins); Bson updated = new Document("Bank", coins);
Bson update = new Document("$set", updated); Bson update = new Document("$set", updated);
DatabaseManager.users.updateOne(document, update); DatabaseManager.getUsersDB().updateOne(document, update);
} }
} }
public static HashMap<String, Object> getUser(String username) { public static HashMap<String, Object> getUser(String uuid) {
try (MongoCursor<Document> cursor = DatabaseManager.users.find(Filters.eq("Username", username)).cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getUsersDB().find(Filters.eq("UUID", uuid)).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();

View file

@ -33,7 +33,7 @@ public class ScoreboardListener implements Listener {
if (!player.hasPlayedBefore()) { if (!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20); e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20);
RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE); 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"); 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); nameTagManager.setNametags(player);

View file

@ -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.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
public class MenuListener implements Listener {
public class InventoryListener implements Listener {
@EventHandler @EventHandler
public void onClick(InventoryClickEvent e) { 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); e.setCancelled(true);
Player player = (Player) e.getWhoClicked(); Player player = (Player) e.getWhoClicked();
switch (e.getRawSlot()) { switch (e.getRawSlot()) {
@ -24,14 +24,19 @@ public class MenuListener implements Listener {
break; break;
case 24: case 24:
player.closeInventory(); player.closeInventory();
player.openInventory(WitherChest.witherchest); player.openInventory(Shop.GUI);
return; return;
default: default:
return; return;
} }
player.closeInventory(); 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();
}
}
} }
} }

View file

@ -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);
}
}

View file

@ -1,6 +1,7 @@
package me.night.nullvalkyrie.miners; package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.database.MinerDataManager; import me.night.nullvalkyrie.database.MinerDataManager;
import me.night.nullvalkyrie.miners.CryptoMiner;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -14,31 +15,24 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
public class MinerGUI { public class Miner {
private Inventory inv; public static Inventory GUI;
public MinerGUI(Player player) { public void UI(Player player) {
createUI(); GUI = Bukkit.createInventory(null, 45, ChatColor.DARK_AQUA + "Crypto Miners");
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); 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}) { 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); GUI.setItem(i, frame);
} }
ItemStack close = new ItemStack(Material.BARRIER); ItemStack close = new ItemStack(Material.BARRIER);
ItemMeta closemeta = close.getItemMeta(); ItemMeta closemeta = close.getItemMeta();
closemeta.setDisplayName(ChatColor.WHITE + "Close the menu"); if (closemeta != null) closemeta.setDisplayName(ChatColor.WHITE + "Close the menu");
closemeta.setLore(List.of(ChatColor.GRAY + "Close the menu"));
close.setItemMeta(closemeta); close.setItemMeta(closemeta);
inv.setItem(0, close); 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[] 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; int counter = 0;
for (CryptoMiner c : MinerDataManager.getMiners().values()) { for (CryptoMiner c : MinerDataManager.getMiners().values()) {
if (ind <= 20) { if (counter <= 20) {
ItemStack item = new ItemStack(c.getType()); ItemStack item = new ItemStack(c.getType());
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(c.getName()); itemMeta.setDisplayName(c.getName());
@ -48,10 +42,10 @@ public class MinerGUI {
lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(c.getLastclaim()))); lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(c.getLastclaim())));
itemMeta.setLore(lore); itemMeta.setLore(lore);
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
inv.setItem(a[ind], item); GUI.setItem(a[counter], item);
ind++; counter++;
} }
player.openInventory(GUI);
} }
} }

View file

@ -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<String, Integer> 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<String> 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);
}
}