//
// EVENT
//
public class EventClick implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
if(e.getView().getTitle().equalsIgnoreCase(ChatColor.AQUA + "Custom GUI")) {
Player player = (Player) e.getWhoClicked();
switch(e.getCurrentItem().getType()) {
case TNT:
player.closeInventory();
player.setHealth(0.0);
player.sendMessage("Zabiłeś się! Brawo.");
break;
case BREAD:
player.closeInventory();
player.setFoodLevel(20);
player.sendMessage("Jummy");
break;
case GOLDEN_SWORD:
player.closeInventory();
player.getInventory().addItem(new ItemStack(Material.GOLDEN_SWORD));
player.sendMessage("Miecz");
break;
}
e.setCancelled(true);
}
}
}
//
// TWORZENIE GUI
//
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player player = (Player) sender;
Inventory gui = Bukkit.createInventory(player, 9, ChatColor.AQUA + "Custom GUI");
ItemStack suicide = new ItemStack(Material.TNT);
ItemStack feed = new ItemStack(Material.BREAD);
ItemStack sword = new ItemStack(Material.GOLDEN_SWORD);
ItemStack[] menuItems = {suicide, feed, sword};
ItemMeta suicideMeta = suicide.getItemMeta();
suicideMeta.setDisplayName(ChatColor.RED + "Suicide");
ArrayList<String> suicideLore = new ArrayList<>();
suicideLore.add(ChatColor.GOLD + "Kill yourself");
suicideMeta.setLore(suicideLore);
suicide.setItemMeta(suicideMeta);
ItemMeta feedMeta = feed.getItemMeta();
feedMeta.setDisplayName(ChatColor.GREEN + "Feed");
ArrayList<String> feedLore = new ArrayList<>();
feedLore.add(ChatColor.GOLD + "Feed yourself");
feedMeta.setLore(feedLore);
feed.setItemMeta(feedMeta);
ItemMeta swordMeta = sword.getItemMeta();
swordMeta.setDisplayName(ChatColor.BLUE + "Sword");
ArrayList<String> swordLore = new ArrayList<>();
swordLore.add(ChatColor.GOLD + "Give a sword");
swordMeta.setLore(swordLore);
sword.setItemMeta(swordMeta);
gui.setContents(menuItems);
player.openInventory(gui);
System.out.println();
}
return true;
}