From 37312c5e746549cf8a8c141a17f517aad73cc77a Mon Sep 17 00:00:00 2001 From: ImproperIssues Date: Sat, 22 Jul 2023 19:26:32 -0700 Subject: [PATCH] ranks gui --- .../events/InteractionListener.java | 2 +- .../ogredupealias/plugin/ItemPresets.java | 55 ++++++++++++++++++- .../plugin/custom/gui/CustomGui.java | 9 ++- .../plugin/custom/gui/CustomGuis.java | 51 +++++++++++++++++ 4 files changed, 111 insertions(+), 6 deletions(-) diff --git a/src/main/java/fun/ogre/ogredupealias/events/InteractionListener.java b/src/main/java/fun/ogre/ogredupealias/events/InteractionListener.java index 4d7cbd9..dcaaf5e 100644 --- a/src/main/java/fun/ogre/ogredupealias/events/InteractionListener.java +++ b/src/main/java/fun/ogre/ogredupealias/events/InteractionListener.java @@ -15,7 +15,7 @@ public class InteractionListener implements Listener { @EventHandler public void onClick(PlayerInteractEvent e) { try { - e.getPlayer().openInventory(CustomGuis.EXAMPLE.getInventory()); + e.getPlayer().openInventory(CustomGuis.RANKS.getInventory()); this.processTable(e); NetSkyBlade.handleNetskyBlade(e); diff --git a/src/main/java/fun/ogre/ogredupealias/plugin/ItemPresets.java b/src/main/java/fun/ogre/ogredupealias/plugin/ItemPresets.java index c0e9c85..b979f8b 100644 --- a/src/main/java/fun/ogre/ogredupealias/plugin/ItemPresets.java +++ b/src/main/java/fun/ogre/ogredupealias/plugin/ItemPresets.java @@ -13,8 +13,6 @@ public abstract class ItemPresets { private static final ItemFactory factory = Bukkit.getItemFactory(); - public static ItemStack TROLL_SWORD = factory.createItemStack("wooden_sword{Enchantments:[],HideFlags:127,PublicUniVaultValues:[{\"univault:from\":\"Plugin made by ImproperIssues, visit https://github.com/ItziSpyder/UniVault\"}],Unbreakable:1b,display:{Lore:['{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gray\",\"text\":\"- No I\\'m not joking, it\"}],\"text\":\"\"}','{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gray\",\"text\":\" really is real!\"}],\"text\":\"\"}','{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gray\",\"text\":\"- Don\\'t believe me? Search it up yourself!\"}],\"text\":\"\"}','{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gray\",\"text\":\" \"},{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gray\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://google.com/search?q=what+is+the+penis+joke\"},\"text\":\"https://google.com/search?q=what+is+the+penis+joke\"}],\"text\":\"\"}'],Name:'{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":false,\"color\":\"gray\",\"text\":\"(\"},{\"italic\":false,\"color\":\"gold\",\"text\":\"The Penis Joke is Real\"},{\"italic\":false,\"color\":\"gray\",\"text\":\") \"},{\"italic\":false,\"color\":\"dark_gray\",\"text\":\"(real)\"}],\"text\":\"\"}'}}"); - public static ItemStack LEGENDARY_HELMET = factory.createItemStack("netherite_helmet{Enchantments:[{id:\"minecraft:aqua_affinity\",lvl:1},{id:\"minecraft:mending\",lvl:1},{id:\"minecraft:protection\",lvl:6},{id:\"minecraft:respiration\",lvl:5},{id:\"minecraft:thorns\",lvl:3},{id:\"minecraft:unbreaking\",lvl:10}],display:{Name:'{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":true,\"color\":\"light_purple\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"dark_purple\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"yellow\",\"text\":\"... \"},{\"bold\":true,\"italic\":false,\"obfuscated\":false,\"color\":\"dark_aqua\",\"text\":\"Chill Shades \"},{\"bold\":false,\"italic\":false,\"obfuscated\":true,\"color\":\"yellow\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"dark_purple\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"light_purple\",\"text\":\"...\"}],\"text\":\"\"}'}}"); public static ItemStack LEGENDARY_CHESTPLATE = factory.createItemStack("netherite_chestplate{Enchantments:[{id:\"minecraft:mending\",lvl:1},{id:\"minecraft:protection\",lvl:6},{id:\"minecraft:thorns\",lvl:3},{id:\"minecraft:unbreaking\",lvl:10}],display:{Name:'{\"extra\":[{\"bold\":false,\"italic\":false,\"underlined\":false,\"strikethrough\":false,\"obfuscated\":true,\"color\":\"light_purple\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"dark_purple\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"yellow\",\"text\":\"... \"},{\"bold\":true,\"italic\":false,\"obfuscated\":false,\"color\":\"dark_aqua\",\"text\":\"Hawiian Shirt \"},{\"bold\":false,\"italic\":false,\"obfuscated\":true,\"color\":\"yellow\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"dark_purple\",\"text\":\"...\"},{\"italic\":false,\"obfuscated\":true,\"color\":\"light_purple\",\"text\":\"...\"}],\"text\":\"\"}'}}"); @@ -170,4 +168,57 @@ public abstract class ItemPresets { .customModelData(1111) .build(); + public static ItemStack BLANK = ItemBuilder.create() + .material(Material.LIGHT_GRAY_STAINED_GLASS_PANE) + .name(" ") + .build(); + + public static ItemStack RANK_KING = ItemBuilder.create() + .material(Material.MAGENTA_WOOL) + .name(Text.color("&5&lKing")) + .lore(Text.color("&7Click this to change")) + .lore(Text.color("&7your rank to")) + .lore(Text.color("&7➥ &5&lKING")) + .build(); + + public static ItemStack RANK_QUEEN = ItemBuilder.create() + .material(Material.RED_WOOL) + .name(Text.color("&c&lQueen")) + .lore(Text.color("&7Click this to change")) + .lore(Text.color("&7your rank to")) + .lore(Text.color("&7➥ &c&lQUEEN")) + .build(); + + public static ItemStack RANK_ROOK = ItemBuilder.create() + .material(Material.ORANGE_WOOL) + .name(Text.color("&6&lRook")) + .lore(Text.color("&7Click this to change")) + .lore(Text.color("&7your rank to")) + .lore(Text.color("&7➥ &6&lROOK")) + .build(); + + public static ItemStack RANK_BISHOP = ItemBuilder.create() + .material(Material.LIME_WOOL) + .name(Text.color("&a&lBishop")) + .lore(Text.color("&7Click this to change")) + .lore(Text.color("&7your rank to")) + .lore(Text.color("&7➥ &a&lBISHOP")) + .build(); + + public static ItemStack RANK_KNIGHT = ItemBuilder.create() + .material(Material.LIGHT_BLUE_WOOL) + .name(Text.color("&b&lKnight")) + .lore(Text.color("&7Click this to change")) + .lore(Text.color("&7your rank to")) + .lore(Text.color("&7➥ &b&lKNIGHT")) + .build(); + + public static ItemStack RANK_CONFIRM_BUTTON = ItemBuilder.create() + .material(Material.BARRIER) + .name(Text.color("&eSet Rank?")) + .lore(" ") + .lore(Text.color("&7Yes, select!")) + .lore(" ") + .build(); + } diff --git a/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGui.java b/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGui.java index efb5c0f..683951b 100644 --- a/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGui.java +++ b/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGui.java @@ -3,6 +3,7 @@ package fun.ogre.ogredupealias.plugin.custom.gui; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -69,9 +70,11 @@ public class CustomGui { } public void onInventoryClick(InventoryClickEvent event) { - mainAction.onClick(event); - if (slotActions.containsKey(event.getSlot())) { - slotActions.get(event.getSlot()).onClick(event); + if (!event.isCancelled() && event.getClickedInventory() != null && event.getClickedInventory().getType() != InventoryType.PLAYER) { + mainAction.onClick(event); + if (slotActions.containsKey(event.getSlot())) { + slotActions.get(event.getSlot()).onClick(event); + } } } diff --git a/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGuis.java b/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGuis.java index a1fa85e..e6b1cc6 100644 --- a/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGuis.java +++ b/src/main/java/fun/ogre/ogredupealias/plugin/custom/gui/CustomGuis.java @@ -1,6 +1,11 @@ package fun.ogre.ogredupealias.plugin.custom.gui; +import fun.ogre.ogredupealias.plugin.ItemPresets; +import fun.ogre.ogredupealias.utils.ServerUtils; +import fun.ogre.ogredupealias.utils.Text; import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public final class CustomGuis { @@ -26,5 +31,51 @@ public final class CustomGuis { }) .build(); // Completes the build, returns a CustomGUI!! + public static final CustomGui RANKS = CustomGui.create() + .title(Text.color("&8| &b&lRank Customization &8|")) + .size(27) + .onDefine(inv -> { + ItemStack fill = ItemPresets.BLANK; + while (inv.firstEmpty() != -1) { + inv.setItem(inv.firstEmpty(), fill); + } + }) + .defineMain(event -> event.setCancelled(true)) + .define(16, ItemPresets.RANK_CONFIRM_BUTTON, event -> { + switch (event.getCurrentItem().getType()) { + case MAGENTA_WOOL -> ServerUtils.dispatch("say king"); + case RED_WOOL -> ServerUtils.dispatch("say queen"); + case ORANGE_WOOL -> ServerUtils.dispatch("say rook"); + case LIME_WOOL -> ServerUtils.dispatch("say bishop"); + case LIGHT_BLUE_WOOL -> ServerUtils.dispatch("say knight"); + } + event.getWhoClicked().closeInventory(); + }) + .define(10, ItemPresets.RANK_KING, event -> { + Player p = (Player)event.getWhoClicked(); + p.playSound(p, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 0.2F); + event.getClickedInventory().getItem(16).setType(event.getCurrentItem().getType()); + }) + .define(11, ItemPresets.RANK_QUEEN, event -> { + Player p = (Player)event.getWhoClicked(); + p.playSound(p, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 0.4F); + event.getClickedInventory().getItem(16).setType(event.getCurrentItem().getType()); + }) + .define(12, ItemPresets.RANK_ROOK, event -> { + Player p = (Player)event.getWhoClicked(); + p.playSound(p, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 0.6F); + event.getClickedInventory().getItem(16).setType(event.getCurrentItem().getType()); + }) + .define(13, ItemPresets.RANK_BISHOP, event -> { + Player p = (Player)event.getWhoClicked(); + p.playSound(p, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 0.8F); + event.getClickedInventory().getItem(16).setType(event.getCurrentItem().getType()); + }) + .define(14, ItemPresets.RANK_KNIGHT, event -> { + Player p = (Player)event.getWhoClicked(); + p.playSound(p, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 1.0F); + event.getClickedInventory().getItem(16).setType(event.getCurrentItem().getType()); + }) + .build(); }