Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.thebukkitarea.inventories;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryAction;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.event.inventory.InventoryCloseEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- /**
- * Created by אביתר on 06/01/2015.
- */
- public class Main extends JavaPlugin implements Listener {
- private List<UUID> users = new ArrayList<UUID>();
- private ItemStack _0 = createItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15, ChatColor.GREEN + "It's good to be back."),
- _8 = createItemStack(Material.BOOK, 1, (short) 0, ChatColor.YELLOW + "THE BUKKIT AREA - 2k15");
- @Override
- public void onEnable() {
- getServer().getPluginManager().registerEvents(this, this);
- }
- private Inventory getInventory() {
- Inventory inv = Bukkit.createInventory(null, 9, "Back to the channel");
- inv.addItem(_0);
- inv.setItem(8, _8);
- // 0, 1, 2, 3, 4, 5, 6, 7, 8
- return inv;
- }
- private ItemStack createItemStack(Material material, int amount, short durability, String name) {
- ItemStack stack = new ItemStack(material, amount, durability);
- ItemMeta meta = stack.getItemMeta();
- meta.setDisplayName(ChatColor.RESET + name);
- stack.setItemMeta(meta);
- return stack;
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- if (sender instanceof Player) {
- Player player = (Player) sender;
- if (!users.contains(player.getUniqueId())) {
- users.add(player.getUniqueId());
- }
- player.openInventory(getInventory());
- }
- return true;
- }
- @EventHandler
- public void onInventoryClick(InventoryClickEvent event) {
- if (event.getWhoClicked() instanceof Player) {
- Player player = (Player) event.getWhoClicked();
- if (!users.contains(player.getUniqueId())) {
- return;
- }
- if (event.getCurrentItem() != null) {
- ItemStack current = event.getCurrentItem();
- event.setCancelled(true);
- if (current.equals(_0) && event.getSlot() == 0);
- else if (current.equals(_8) && event.getSlot() == 8);
- else {
- event.setCancelled(false);
- }
- }
- }
- }
- @EventHandler
- public void onInventoryClose(InventoryCloseEvent event) {
- if (event.getPlayer() instanceof Player) {
- Player player = (Player) event.getPlayer();
- if (users.contains(player.getUniqueId())) {
- users.remove(player.getUniqueId());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement