Advertisement
Cool_boy21

ShopInventory

May 13th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 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(QuartzDefenders plugin) {
  21.         this.plugin = plugin;
  22.         this.shop = new Shop(plugin);
  23.         Bukkit.getPluginManager().registerEvents(this, plugin);
  24.     }
  25.    
  26.     @EventHandler
  27.     public void onClick(InventoryClickEvent e) {
  28.         if (!(e.getInventory().getName().contains(shop.name))) {
  29.             return;
  30.         }
  31.         Player p = (Player) e.getWhoClicked();
  32.         e.setCancelled(true);
  33.         //GameTeam team = plugin.getGame(p).getTeam(p);
  34.  
  35.         if (e.getCurrentItem() == null
  36.                 || e.getCurrentItem().getType() == Material.STAINED_GLASS
  37.                 || e.getCurrentItem().getType() == Material.AIR
  38.                 || !e.getCurrentItem().hasItemMeta()) {
  39.             p.closeInventory();
  40.             return;
  41.         }
  42.         switch (e.getCurrentItem().getType()) {
  43.             case EXP_BOTTLE:
  44.             Merchant enchants = shop.getSection("enchants", ChatColor.LIGHT_PURPLE + shop.enchantName/*, team*/);
  45.                 p.openMerchant(enchants, true);
  46.                 break;
  47.             case POTION:
  48.             Merchant potions = shop.getSection("potions", ChatColor.AQUA + shop.potionsName/*, team*/);
  49.                 p.openMerchant(potions, true);
  50.                 break;
  51.             case BREAD:
  52.             Merchant food = shop.getSection("food", ChatColor.BLUE + shop.foodName/*, team*/);
  53.                 p.openMerchant(food, true);
  54.                 break;
  55.             case NAME_TAG:
  56.             Merchant other = shop.getSection("other", ChatColor.BLUE + shop.otherName/*, team*/);
  57.                 p.openMerchant(other, true);
  58.                 break;
  59.             case BRICK:
  60.             Merchant blocks = shop.getSection("blocks", ChatColor.GRAY + shop.blocksName/*, team*/);
  61.                 p.openMerchant(blocks, true);
  62.                 break;
  63.             case ARROW:
  64.             Merchant stuff = shop.getSection("stuff", ChatColor.YELLOW + shop.stuffName/*, team*/);
  65.                 p.openMerchant(stuff, true);
  66.                 break;
  67.             case DIAMOND_PICKAXE:
  68.                 Merchant resources = shop.getSection("resources", ChatColor.GREEN + shop.resourcesName/*, team*/);
  69.                 p.openMerchant(resources, true);
  70.                 break;
  71.         }
  72.     }
  73.    
  74.     @EventHandler
  75.     public void shopClick(PlayerInteractEntityEvent e) {
  76.         if(e.getRightClicked() instanceof Villager
  77.                 /*&& e.getRightClicked().getName().contains(shop.name)*/) {
  78.             e.setCancelled(true);
  79.             Player p = e.getPlayer();
  80.             p.openInventory(shop.getInventory());
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement