lucky draw system with inventory redo

This commit is contained in:
NK 2022-12-17 19:29:43 +00:00
parent e64481bda0
commit a54932f9c0
11 changed files with 328 additions and 105 deletions

View file

@ -1,34 +1,24 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.entities.miners.CryptoMiner; import me.night.nullvalkyrie.ui.inventory.LuckyDraw;
import me.night.nullvalkyrie.enums.Items;
import me.night.nullvalkyrie.util.RandomCollection;
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 java.util.List; import java.util.List;
public class BetaCommand extends Command { public class BetaCommand extends Command {
RandomCollection<String> randomCollection;
public BetaCommand() { public BetaCommand() {
super("beta", new String[]{"b", "npc"}, "Beta", ""); super("beta", new String[]{"b", "npc"}, "Beta", "");
randomCollection = new RandomCollection<>();
for (Items e : Items.values()) {
randomCollection.add(e.getWeight(), e.getName());
}
} }
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player player) { if (sender instanceof Player player) {
// String s = randomCollection.getRandom();
// if (s == null) System.out.println("You have got all rewards from the draw"); // CryptoMiner miner = new CryptoMiner(args[0], Material.DIAMOND_ORE, 1, 0.5, System.currentTimeMillis());
// System.out.println(s + " with the probability " + Math.round(randomCollection.getChance(s))); // miner.spawn(player, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198");
// randomCollection.remove(s); new LuckyDraw().UI(player);
CryptoMiner miner = new CryptoMiner(args[0], Material.DIAMOND_ORE, 1, 0.5, System.currentTimeMillis());
miner.spawn(player, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198");
} }
} }

View file

@ -40,19 +40,21 @@ public class CustomWeaponsDataManager {
for (String a : attributes.keySet()) attr.put(a, attributes.get(a)); for (String a : attributes.keySet()) attr.put(a, attributes.get(a));
Document pdc = (Document) doc.get("PDC"); Document pdc = (Document) doc.get("PDC");
HashMap<String, Object> pdcdata = new HashMap<>(); HashMap<String, Object> pdcdata = new HashMap<>();
for (String i : pdc.keySet()) if (pdc != null)
pdcdata.put(i, pdc.get(i)); for (String a : pdc.keySet()) pdcdata.put(a, pdc.get(a));
Document recipe = (Document) doc.get("Recipes"); Document recipe = (Document) doc.get("Recipes");
HashMap<String, Object> recipes = new HashMap<>(); HashMap<String, Object> recipes = new HashMap<>();
Document ing = (Document) recipe.get("Ingredients"); if (recipe != null) {
HashMap<String, String> ingredients = new HashMap<>(); Document ing = (Document) recipe.get("Ingredients");
for (String i : ing.keySet()) HashMap<String, String> ingredients = new HashMap<>();
ingredients.put(i, ing.getString(i)); for (String i : ing.keySet())
List<String> shapes = new ArrayList<>(); ingredients.put(i, ing.getString(i));
if (recipe.get("Shapes") != null) shapes.addAll((List<String>) recipe.get("Shapes")); List<String> shapes = new ArrayList<>();
recipes.put("Shape", shapes); if (recipe.get("Shapes") != null) shapes.addAll((List<String>) recipe.get("Shapes"));
recipes.put("Amount", recipe.getInteger("Amount")); recipes.put("Shape", shapes);
recipes.put("Ingredients", ingredients); recipes.put("Amount", recipe.getInteger("Amount"));
recipes.put("Ingredients", ingredients);
}
item.put("Name", name); item.put("Name", name);
item.put("Material", Material.matchMaterial(doc.getString("Material"))); item.put("Material", Material.matchMaterial(doc.getString("Material")));
item.put("Type", doc.getString("Type")); item.put("Type", doc.getString("Type"));

View file

@ -1,26 +1,40 @@
package me.night.nullvalkyrie.enums; package me.night.nullvalkyrie.enums;
import org.bukkit.Material;
public enum Items { public enum Items {
COAL("Coal", 27), ETERNALSTARE("Eternal Stare", 29, Rarity.LEGENDARY, Material.COAL), // legendary charm
IRON("Iron", 23), MORNINGTEA("Morning Tea", 28, Rarity.EPIC, Material.IRON_INGOT), // epic emote
GOLD("Gold", 20), PARACHUTE("Parachute - Doomed Chorus", 11, Rarity.EPIC, Material.GOLD_INGOT), // epic parachute
LAPIS("Lapis", 14), RALLYCAR("Rally Car - Doomed Chorus", 10, Rarity.EPIC, Material.REDSTONE), //epic backpack
REDSTONE("Redstone", 10), WORLDAFLAME("World Aflame", 6.5, Rarity.LEGENDARY, Material.LAPIS_LAZULI), // legendary background
EMERALD("Emerald", 6), MOLOTOVCOTAIL("Molotov Cotail - Soul Flame", 5.5, Rarity.EPIC, Material.COPPER_INGOT), // epic throwable
QUARTZ("Quartz", 4), KATANA("Katana - Silent Echo", 4.67, Rarity.EPIC, Material.EMERALD), // epic melee
OBSIDIAN("Obsidian", 3), DLQ33("DL Q33 - Doomed Chorus", 4, Rarity.EPIC, Material.QUARTZ), // epic gun
DIAMOND("Diamond", 2), DAME("Dame - Shot Caller", 1.25, Rarity.EPIC, Material.DIAMOND), // character epic
NETHERITE("Netherite", 1); KILO141("Kilo 141 - Demonsong", 0.08, Rarity.LEGENDARY, Material.NETHERITE_INGOT); // weapon legendary
private final String name; private final String name;
private final double weight; private final double weight;
private final Rarity rarity;
private final Material material;
Items(String name, double weight) {
Items(String name, double weight, Rarity rarity, Material material) {
this.name = name; this.name = name;
this.weight = weight; this.weight = weight;
this.rarity = rarity;
this.material = material;
}
public static Items getByName(String name) {
for (Items item : Items.values()) {
if (item.getName().equalsIgnoreCase(name)) {
return item;
}
}
return null;
} }
public String getName() { public String getName() {
return name; return name;
} }
@ -28,4 +42,12 @@ public enum Items {
public double getWeight() { public double getWeight() {
return weight; return weight;
} }
public Rarity getRarity() {
return rarity;
}
public Material getMaterial() {
return material;
}
} }

View file

@ -88,7 +88,7 @@ public class CustomItemEvents implements Listener {
if (weaponMeta != null) { if (weaponMeta != null) {
PersistentDataContainer container = weaponMeta.getPersistentDataContainer(); PersistentDataContainer container = weaponMeta.getPersistentDataContainer();
NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo"); NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
int ammo = container.get(ammoKey, PersistentDataType.INTEGER); int ammo = container.get(ammoKey, PersistentDataType.INTEGER) != null ? container.get(ammoKey, PersistentDataType.INTEGER) : 0;
container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1); container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1);
int max = container.get(CustomItemManager.keys.get(name + ".max"), PersistentDataType.INTEGER); int max = container.get(CustomItemManager.keys.get(name + ".max"), PersistentDataType.INTEGER);
weapon.setItemMeta(weaponMeta); weapon.setItemMeta(weaponMeta);

View file

@ -89,12 +89,15 @@ public class CustomItemManager {
} }
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
HashMap<String, Object> recipes = (HashMap<String, Object>) weapon.get("Recipes"); HashMap<String, Object> recipes = (HashMap<String, Object>) weapon.get("Recipes");
List<String> shapes = (List<String>) recipes.get("Shape"); if (recipes.get("Shape") != null) {
HashMap<String, String> ind = (HashMap<String, String>) recipes.get("Ingredients"); List<String> shapes = (List<String>) recipes.get("Shape");
HashMap<Character, Material> indgredients = new HashMap<>(); HashMap<String, String> ind = (HashMap<String, String>) recipes.get("Ingredients");
for (String i : ind.keySet()) HashMap<Character, Material> indgredients = new HashMap<>();
indgredients.put(i.charAt(0), Material.matchMaterial(ind.get(i))); for (String i : ind.keySet())
setItemRecipe((String) weapon.get("Name"), item, shapes, indgredients, (int) recipes.get("Amount")); indgredients.put(i.charAt(0), Material.matchMaterial(ind.get(i)));
setItemRecipe((String) weapon.get("Name"), item, shapes, indgredients, (int) recipes.get("Amount"));
}
return item; return item;
} }

View file

@ -0,0 +1,75 @@
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;
public abstract class GUIManager {
public static Inventory GUI;
private boolean close;
public abstract void UI(Player player);
public void init(int size, String title) {
GUI = Bukkit.createInventory(null, size, title);
}
public void setCloseButton(boolean boo) {
if (boo) {
close = true;
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);
} else close = false;
}
public void setFrame(boolean boo, Material... frame) {
if (boo) {
ItemStack frames = new ItemStack(frame[0]);
switch (GUI.getSize()) {
case 27 -> {
if (close) {
for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26})
GUI.setItem(i, frames);
} else {
for (int i : new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26})
GUI.setItem(i, frames);
}
}
case 36 -> {
if (close) {
for (int i : new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35})
GUI.setItem(i, frames);
} else {
for (int i : new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35})
GUI.setItem(i, frames);
}
}
case 45 -> {
if (close) {
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, frames);
} else {
for (int i : new int[]{0, 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, frames);
}
}
case 54 -> {
if (close) {
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, frames);
} else {
for (int i : new int[]{0, 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, frames);
}
}
}
}
}
}

View file

@ -1,16 +1,34 @@
package me.night.nullvalkyrie.ui.inventory; package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.enums.Items;
import me.night.nullvalkyrie.util.RandomCollection;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
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;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class InventoryListener implements Listener { public class InventoryListener implements Listener {
RandomCollection<String> randomCollection;
public InventoryListener() {
randomCollection = new RandomCollection<>();
for (Items e : Items.values()) {
randomCollection.add(e.getWeight(), e.getName());
}
}
@EventHandler @EventHandler
public void onClick(InventoryClickEvent e) { public void onClick(InventoryClickEvent e) {
if (e.getInventory().equals(Menu.GUI) && e.getCurrentItem() != null) { if (e.getCurrentItem() == null) return;
if (e.getView().getTitle().equals(Menu.title)) {
e.setCancelled(true); e.setCancelled(true);
Player player = (Player) e.getWhoClicked(); Player player = (Player) e.getWhoClicked();
switch (e.getRawSlot()) { switch (e.getRawSlot()) {
@ -32,12 +50,108 @@ public class InventoryListener implements Listener {
} }
player.closeInventory(); player.closeInventory();
} }
if (e.getInventory().equals(Shop.GUI) && e.getCurrentItem() != null) { if (e.getView().getTitle().equals(Shop.title)) {
e.setCancelled(true); e.setCancelled(true);
Player player = (Player) e.getWhoClicked(); Player player = (Player) e.getWhoClicked();
if (e.getRawSlot() == 0) { if (e.getRawSlot() == 0) {
player.closeInventory(); player.closeInventory();
} }
} }
if (e.getView().getTitle().equals(LuckyDraw.title)) {
e.setCancelled(true);
Player player = (Player) e.getWhoClicked();
if (e.getRawSlot() == 0) {
player.closeInventory();
} else if (e.getRawSlot() == 22) {
List<String> colors = List.of("WHITE", "ORANGE", "MAGENTA", "LIGHT_BLUE", "YELLOW", "LIME", "PINK", "GRAY", "LIGHT_GRAY", "CYAN", "PURPLE", "BLUE", "BROWN", "GREEN", "RED", "BLACK");
List<String> slot1 = new ArrayList<>(colors);
List<String> slot2 = new ArrayList<>(colors);
List<String> slot3 = new ArrayList<>(colors);
List<String> slot4 = new ArrayList<>(colors);
List<String> slot5 = new ArrayList<>(colors);
List<String> slot6 = new ArrayList<>(colors);
List<String> slot7 = new ArrayList<>(colors);
List<String> slot8 = new ArrayList<>(colors);
Collections.shuffle(slot1);
Collections.shuffle(slot2);
Collections.shuffle(slot3);
Collections.shuffle(slot4);
Collections.shuffle(slot5);
Collections.shuffle(slot6);
Collections.shuffle(slot7);
Collections.shuffle(slot8);
int[] slots = new int[]{11, 13, 15, 20, 24, 29, 31, 33};
new BukkitRunnable() {
int i = 0;
int ii = 0;
int time = 0;
@Override
public void run() {
if (colors.size() - 1 <= i) i = 0;
if (ii == 8) ii = 0;
if (time == 20) {
cancel();
return;
}
for (int slot : slots) {
if (slot == 11) {
ItemStack item = new ItemStack(Material.valueOf(slot1.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 13) {
ItemStack item = new ItemStack(Material.valueOf(slot2.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 15) {
ItemStack item = new ItemStack(Material.valueOf(slot3.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 20) {
ItemStack item = new ItemStack(Material.valueOf(slot4.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 24) {
ItemStack item = new ItemStack(Material.valueOf(slot5.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 29) {
ItemStack item = new ItemStack(Material.valueOf(slot6.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 31) {
ItemStack item = new ItemStack(Material.valueOf(slot7.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
if (slot == 33) {
ItemStack item = new ItemStack(Material.valueOf(slot8.get(i) + "_STAINED_GLASS_PANE"), 1);
LuckyDraw.GUI.setItem(slot, item);
}
}
i++;
ii++;
time++;
}
}.runTaskTimer(Main.getPlugin(Main.class), 1L, 5L);
new BukkitRunnable() {
@Override
public void run() {
for (int slot : slots) {
LuckyDraw.GUI.setItem(slot, new ItemStack(Material.AIR));
}
String s = randomCollection.getRandom();
randomCollection.remove(s);
Items it = Items.getByName(s);
ItemStack item = new ItemStack(it.getMaterial(), 1);
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
meta.setDisplayName(ChatColor.GOLD + it.getName());
meta.setLore(List.of(it.getRarity().getDisplay()));
item.setItemMeta(meta);
player.getInventory().addItem(item);
}
}.runTaskLater(Main.getPlugin(Main.class), 5L * 20L);
}
}
} }
} }

View file

@ -0,0 +1,39 @@
package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.enums.Items;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class LuckyDraw extends GUIManager {
public static final String title = ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "X Lucky Draw";
@Override
public void UI(Player player) {
init(45, title);
setCloseButton(true);
setFrame(true, Material.BLUE_STAINED_GLASS_PANE);
int[] slots = new int[]{10, 12, 14, 16, 28, 30, 32, 34, 19, 25};
int count = 0;
for (Items name : Items.values()) {
ItemStack item = new ItemStack(name.getMaterial());
ItemMeta meta = item.getItemMeta();
if (meta == null) return;
meta.setDisplayName(ChatColor.GOLD + name.getName());
meta.setLore(List.of(name.getRarity().getDisplay()));
item.setItemMeta(meta);
GUI.setItem(slots[count], item);
count++;
}
ItemStack roll = new ItemStack(Material.ARROW);
ItemMeta meta = roll.getItemMeta();
if (meta == null) return;
meta.setLore(List.of("Press to roll!"));
roll.setItemMeta(meta);
GUI.setItem(22, roll);
player.openInventory(GUI);
}
}

View file

@ -1,23 +1,23 @@
package me.night.nullvalkyrie.ui.inventory; package me.night.nullvalkyrie.ui.inventory;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays; import java.util.Arrays;
public class Menu { public class Menu extends GUIManager {
public static Inventory GUI; public static final String title = ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu";
@Override
public void UI(Player player) { public void UI(Player player) {
GUI = Bukkit.createInventory(player, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); init(45, title);
setCloseButton(true);
setFrame(true, Material.BLUE_STAINED_GLASS_PANE);
ItemStack KYS = new ItemStack(Material.WOODEN_SWORD); ItemStack KYS = new ItemStack(Material.WOODEN_SWORD);
ItemMeta KYSmeta = KYS.getItemMeta(); ItemMeta KYSmeta = KYS.getItemMeta();
if (KYSmeta == null) return;
KYSmeta.setDisplayName(ChatColor.RED + "KILL YOURSELF WHEN???"); KYSmeta.setDisplayName(ChatColor.RED + "KILL YOURSELF WHEN???");
KYSmeta.setLore(Arrays.asList(ChatColor.GRAY + "KYS", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); KYSmeta.setLore(Arrays.asList(ChatColor.GRAY + "KYS", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON"));
KYS.setItemMeta(KYSmeta); KYS.setItemMeta(KYSmeta);
@ -25,6 +25,7 @@ public class Menu {
ItemStack home = new ItemStack(Material.MAP); ItemStack home = new ItemStack(Material.MAP);
ItemMeta homemeta = home.getItemMeta(); ItemMeta homemeta = home.getItemMeta();
if (homemeta == null) return;
homemeta.setDisplayName(ChatColor.BLUE + "Teleport to home"); 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")); homemeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to teleport back to home", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON"));
home.setItemMeta(homemeta); home.setItemMeta(homemeta);
@ -32,22 +33,12 @@ public class Menu {
ItemStack chest = new ItemStack(Material.ENDER_CHEST); ItemStack chest = new ItemStack(Material.ENDER_CHEST);
ItemMeta chestmeta = chest.getItemMeta(); ItemMeta chestmeta = chest.getItemMeta();
if (chestmeta == null) return;
chestmeta.setDisplayName(ChatColor.GREEN + "Open your chest"); chestmeta.setDisplayName(ChatColor.GREEN + "Open your chest");
chestmeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to open the chest", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON")); chestmeta.setLore(Arrays.asList(ChatColor.GRAY + "Click to open the chest", ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON"));
chest.setItemMeta(chestmeta); chest.setItemMeta(chestmeta);
GUI.setItem(24, chest); 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); player.openInventory(GUI);
} }
} }

View file

@ -2,11 +2,9 @@ package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.database.MinerDataManager; import me.night.nullvalkyrie.database.MinerDataManager;
import me.night.nullvalkyrie.entities.miners.CryptoMiner; import me.night.nullvalkyrie.entities.miners.CryptoMiner;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -15,35 +13,30 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
public class Miner { public class Miner extends GUIManager {
public static Inventory GUI; public static String title = ChatColor.DARK_AQUA + "Crypto Miners";
@Override
public void UI(Player player) { public void UI(Player player) {
GUI = Bukkit.createInventory(null, 45, ChatColor.DARK_AQUA + "Crypto Miners"); init(45, title);
ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); setCloseButton(true);
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}) { setFrame(true, Material.BLUE_STAINED_GLASS_PANE);
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[] 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; int counter = 0;
for (CryptoMiner c : MinerDataManager.getMiners().values()) { for (CryptoMiner c : MinerDataManager.getMiners().values()) {
if (counter <= 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()); if (itemMeta != null) {
List<String> lore = new ArrayList<>(); itemMeta.setDisplayName(c.getName());
lore.add("Level: " + c.getLevel()); List<String> lore = new ArrayList<>();
lore.add("Rate: " + c.getRate()); lore.add("Level: " + c.getLevel());
lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(c.getLastclaim()))); lore.add("Rate: " + c.getRate());
itemMeta.setLore(lore); lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(c.getLastclaim())));
item.setItemMeta(itemMeta); itemMeta.setLore(lore);
GUI.setItem(a[counter], item); item.setItemMeta(itemMeta);
counter++; GUI.setItem(a[counter], item);
counter++;
}
} }
player.openInventory(GUI); player.openInventory(GUI);
} }

View file

@ -2,30 +2,23 @@ package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.database.ShopDataManager; import me.night.nullvalkyrie.database.ShopDataManager;
import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.items.CustomItemManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
public class Shop { public class Shop extends GUIManager {
public static Inventory GUI; public static final String title = ChatColor.GREEN + "7-Eleven 24/7";
@Override
public void UI(Player player) { public void UI(Player player) {
GUI = Bukkit.createInventory(null, 54, ChatColor.GREEN + "7-Eleven 24/7"); init(54, title);
ItemStack frame = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); setCloseButton(true);
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}) setFrame(true, Material.GREEN_STAINED_GLASS_PANE);
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(); 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[] 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; int counter = 0;
@ -33,7 +26,8 @@ public class Shop {
if (counter <= 20) { if (counter <= 20) {
ItemStack item = CustomItemManager.produceItem(c).clone(); ItemStack item = CustomItemManager.produceItem(c).clone();
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
List<String> lore = itemMeta.getLore(); if (itemMeta == null) return;
List<String> lore = itemMeta.getLore() == null ? new ArrayList<>() : itemMeta.getLore();
lore.add("Price (BIN): " + list.get(c)); lore.add("Price (BIN): " + list.get(c));
itemMeta.setLore(lore); itemMeta.setLore(lore);
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);