From c99dbcfa6cc822b036ef51a938ce448b308de094 Mon Sep 17 00:00:00 2001 From: night0721 Date: Mon, 4 Jul 2022 00:07:27 +0100 Subject: [PATCH] Added WitherChest, Interactive GUI --- .../java/com/night/nullvalkyrie/Main.java | 1 + .../com/night/nullvalkyrie/MenuListener.java | 37 +++++++++++++++++++ .../com/night/nullvalkyrie/WitherChest.java | 9 +++++ .../nullvalkyrie/commands/MenuCommand.java | 4 +- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/night/nullvalkyrie/MenuListener.java create mode 100644 src/main/java/com/night/nullvalkyrie/WitherChest.java diff --git a/src/main/java/com/night/nullvalkyrie/Main.java b/src/main/java/com/night/nullvalkyrie/Main.java index ee01f4d..a0b5616 100644 --- a/src/main/java/com/night/nullvalkyrie/Main.java +++ b/src/main/java/com/night/nullvalkyrie/Main.java @@ -40,6 +40,7 @@ public final class Main extends JavaPlugin implements Listener { BarStyle.SEGMENTED_12 ); Bukkit.getPluginManager().registerEvents(this, this); + Bukkit.getPluginManager().registerEvents(new MenuListener(), this); } @EventHandler diff --git a/src/main/java/com/night/nullvalkyrie/MenuListener.java b/src/main/java/com/night/nullvalkyrie/MenuListener.java new file mode 100644 index 0000000..398feb2 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/MenuListener.java @@ -0,0 +1,37 @@ +package com.night.nullvalkyrie; + +import com.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 { + + @EventHandler + public void onClick(InventoryClickEvent e) { + if(e.getInventory().equals(MenuCommand.inv) && e.getCurrentItem() != null) { + e.setCancelled(true); + Player player = (Player) e.getWhoClicked(); + switch (e.getRawSlot()) { + case 0: + break; + case 20: + player.setHealth(0); + player.sendMessage(ChatColor.RED + "又做兵 抵死"); + break; + case 22: + break; + case 24: + player.closeInventory(); + player.openInventory(WitherChest.witherchest); + return; + default: + return; + } + + + player.closeInventory(); + } + } +} diff --git a/src/main/java/com/night/nullvalkyrie/WitherChest.java b/src/main/java/com/night/nullvalkyrie/WitherChest.java new file mode 100644 index 0000000..8039fc6 --- /dev/null +++ b/src/main/java/com/night/nullvalkyrie/WitherChest.java @@ -0,0 +1,9 @@ +package com.night.nullvalkyrie; + +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/com/night/nullvalkyrie/commands/MenuCommand.java b/src/main/java/com/night/nullvalkyrie/commands/MenuCommand.java index f3d90ae..71fd57c 100644 --- a/src/main/java/com/night/nullvalkyrie/commands/MenuCommand.java +++ b/src/main/java/com/night/nullvalkyrie/commands/MenuCommand.java @@ -14,11 +14,13 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.Arrays; public class MenuCommand implements CommandExecutor { + public static Inventory inv = Bukkit.createInventory(null, 45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(sender instanceof Player) { Player player = (Player) sender; - Inventory inv = Bukkit.createInventory(player,45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); + inv = Bukkit.createInventory(player,45, ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Valkyrie Menu"); ItemStack KYS = new ItemStack(Material.WOODEN_SWORD); ItemMeta KYSmeta = KYS.getItemMeta();