Guest User

Untitled

a guest
May 1st, 2014
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package noah.plugins.maxymenu;
  2.  
  3. import java.util.Arrays;
  4.  
  5. import net.milkbowl.vault.economy.Economy;
  6. import net.milkbowl.vault.economy.EconomyResponse;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Material;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.event.EventHandler;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.event.inventory.InventoryClickEvent;
  15. import org.bukkit.inventory.Inventory;
  16. import org.bukkit.inventory.ItemStack;
  17. import org.bukkit.inventory.meta.ItemMeta;
  18. import org.bukkit.plugin.Plugin;
  19. import org.bukkit.plugin.RegisteredServiceProvider;
  20. import org.bukkit.plugin.java.JavaPlugin;
  21.  
  22.  
  23. public class ShopMenuInv extends JavaPlugin implements Listener {
  24.  
  25. private Inventory invShop;
  26. private ItemStack d;
  27.  
  28. public static Economy econ = null;
  29.  
  30. public void onEnable() {
  31. if (!setupEconomy() ) {
  32. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
  33. Bukkit.getServer().getPluginManager().disablePlugin(this);
  34. return;
  35. }
  36.  
  37. System.out.println(econ == null);
  38.  
  39. }
  40.  
  41. public ShopMenuInv(Plugin p) {
  42. invShop = Bukkit.getServer().createInventory(null, 9, "Maxy Shop");
  43.  
  44. d = createItem(ChatColor.BLUE + "Diamond");
  45.  
  46. invShop.setItem(4, d);
  47.  
  48. Bukkit.getServer().getPluginManager().registerEvents(this, p);
  49. }
  50.  
  51. private boolean setupEconomy() {
  52. if (getServer().getPluginManager().getPlugin("Vault") == null) {
  53. return false;
  54. }
  55. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
  56. if (rsp == null) {
  57. return false;
  58. }
  59. econ = rsp.getProvider();
  60. return econ != null;
  61. }
  62.  
  63. private ItemStack createItem(String name) {
  64. ItemStack i = new ItemStack(Material.DIAMOND);
  65. ItemMeta im = i.getItemMeta();
  66.  
  67. im.setDisplayName(name);
  68. im.setLore(Arrays.asList(ChatColor.GREEN + "Buy " + ChatColor.BLUE + "DIAMOND", "" + ChatColor.GREEN + " Price: $110" ));
  69. i.setItemMeta(im);
  70.  
  71. return i;
  72. }
  73.  
  74. public void show(Player p) {
  75. p.openInventory(invShop);
  76. }
  77.  
  78. @EventHandler
  79. public void onInventoryClick(InventoryClickEvent e) {
  80. if (!(e.getInventory().getName().equalsIgnoreCase(invShop.getName()))) return;
  81.  
  82. if(e.getCurrentItem().getItemMeta().getDisplayName().contains("Diamond")) {
  83. Player p = (Player) e.getWhoClicked();
  84.  
  85. if(econ.getBalance(p.getName()) >= 110) {
  86. EconomyResponse r = econ.withdrawPlayer(p.getName(), 110);
  87.  
  88. if (r.transactionSuccess()) {
  89. p.sendMessage(ChatColor.BLUE + "[" + ChatColor.GREEN + "MaxyMenu" + ChatColor.BLUE + "]" + ChatColor.GREEN + "You bought 1 of Diamond for $110");
  90. p.getInventory().addItem(d);
  91.  
  92. } else {
  93. p.sendMessage(ChatColor.BLUE + "[" + ChatColor.GREEN + "MaxyMenu" + ChatColor.BLUE + "]" + ChatColor.RED + "You could not buy 1 of Diamond!");
  94. }
  95.  
  96. } else {
  97. //Do stuff
  98. }
  99.  
  100. e.setCancelled(true);
  101. e.getWhoClicked().closeInventory();
  102.  
  103. }
  104.  
  105. }
  106. }
RAW Paste Data