Advertisement
Cool_boy21

Untitled

May 13th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.09 KB | None | 0 0
  1. package ua.Coolboy.QuartzDefenders.Shop;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Material;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.entity.Villager;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.inventory.InventoryClickEvent;
  11. import org.bukkit.event.player.PlayerInteractEntityEvent;
  12. import org.bukkit.inventory.Merchant;
  13. import ua.Endertainment.QuartzDefenders.GameTeam;
  14. import ua.Endertainment.QuartzDefenders.QuartzDefenders;
  15.  
  16. public class ShopInventory implements Listener {
  17.     QuartzDefenders plugin;
  18.     Shop shop;
  19.    
  20.     public ShopInventory() {
  21.          Bukkit.getPluginManager().registerEvents(this, plugin);
  22.     }
  23.    
  24.     @EventHandler
  25.     public void onClick(InventoryClickEvent e) {
  26.         if (!(e.getInventory().getName().equalsIgnoreCase(ChatColor.GOLD + shop.name))) {
  27.             return;
  28.         }
  29.         Player p = (Player) e.getWhoClicked();
  30.         e.setCancelled(true);
  31.         GameTeam team = plugin.getGame(p).getTeam(p);
  32.  
  33.         if (e.getCurrentItem() == null
  34.                 || e.getCurrentItem().getType() == Material.STAINED_GLASS
  35.                 || e.getCurrentItem().getType() == Material.AIR
  36.                 || !e.getCurrentItem().hasItemMeta()) {
  37.             p.closeInventory();
  38.             return;
  39.         }
  40.         switch (e.getCurrentItem().getType()) {
  41.             case DIAMOND_PICKAXE:
  42.                 Merchant resources = shop.getSection("resources", ChatColor.GREEN + shop.resourcesName, team);
  43.                 p.openMerchant(resources, true);
  44.                 break;
  45.             case ARROW:
  46.             Merchant stuff = shop.getSection("stuff", ChatColor.YELLOW + shop.stuffName, team);
  47.                 p.openMerchant(stuff, true);
  48.                 break;
  49.             case NAME_TAG:
  50.             Merchant other = shop.getSection("other", ChatColor.BLUE + shop.otherName, team);
  51.                 p.openMerchant(other, true);
  52.                 break;
  53.             case POTION:
  54.             Merchant potions = shop.getSection("potions", ChatColor.AQUA + shop.potionsName, team);
  55.                 p.openMerchant(potions, true);
  56.                 break;
  57.             case EXP_BOTTLE:
  58.             Merchant enchants = shop.getSection("enchants", ChatColor.LIGHT_PURPLE + shop.enchantName, team);
  59.                 p.openMerchant(enchants, true);
  60.                 break;
  61.             case BREAD:
  62.             Merchant food = shop.getSection("food", ChatColor.BLUE + shop.foodName, team);
  63.                 p.openMerchant(food, true);
  64.                 break;
  65.             case BRICK:
  66.             Merchant blocks = shop.getSection("blocks", ChatColor.GRAY + shop.blocksName, team);
  67.                 p.openMerchant(blocks, true);
  68.                 break;
  69.         }
  70.     }
  71.    
  72.     @EventHandler
  73.     public void shopClick(PlayerInteractEntityEvent e) {
  74.         if(e.getRightClicked() instanceof Villager
  75.                 /*&& e.getRightClicked().getName().contains(shop.name)*/) {
  76.             e.setCancelled(true);
  77.             Player p = e.getPlayer();
  78.             p.openInventory(shop.getInventory());
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement