Advertisement
Guest User

Troubles Class

a guest
Aug 20th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.28 KB | None | 0 0
  1. package ratedpvp.commands;
  2.  
  3. import java.util.HashSet;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Color;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandExecutor;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.inventory.InventoryClickEvent;
  12. import org.bukkit.inventory.ItemStack;
  13. import net.milkbowl.vault.economy.Economy;
  14. import ratedpvp.RatedPvP;
  15. import ratedpvp.utilities.Item;
  16. import ratedpvp.utilities.ItemBuilder;
  17. import ratedpvp.utilities.Menu;
  18. import ratedpvp.utilities.Vault;
  19.  
  20. public class ShopCmd implements CommandExecutor {
  21.  
  22. private RatedPvP plugin;
  23. private HashSet<String> cdl = new HashSet<String>();
  24. private String sn = ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Shop" + ChatColor.DARK_GRAY + "]: ";
  25. private Economy eco;
  26. public Menu shopMain;
  27. public Menu blocks;
  28. public Menu cb1;
  29. public Menu cb2;
  30. public Menu resources;
  31. public Menu mobdrops;
  32. public Menu potionmats;
  33. public Menu farming;
  34. public Menu food;
  35. public Menu redstone;
  36. public Menu pots;
  37. public Menu spawners;
  38.  
  39. public ShopCmd(RatedPvP plugin) {
  40. this.plugin = plugin;
  41. eco = Vault.economy;
  42. shopMain = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop", 2, plugin.mm);
  43. blocks = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Blocks", 6, plugin.mm);
  44. cb1 = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Color Blocks 1", 6, plugin.mm);
  45. cb2 = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Color Blocks 2", 6, plugin.mm);
  46. resources = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Resources", 6, plugin.mm);
  47. mobdrops = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Mob Drops", 6, plugin.mm);
  48. potionmats = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Potion Materials", 6, plugin.mm);
  49. farming = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Farming", 6, plugin.mm);
  50. food = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Food", 6, plugin.mm);
  51. redstone = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Redstone", 6, plugin.mm);
  52. pots = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Potions", 6, plugin.mm);
  53. spawners = new Menu(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Shop" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + " > Spawners", 6, plugin.mm);
  54.  
  55. shopMenuItem(0, shopMain, Material.COBBLESTONE, "Blocks", blocks);
  56. shopMenuItem(1, shopMain, Material.STAINED_CLAY, "Color Blocks 1", cb1);
  57. shopMenuItem(2, shopMain, Material.HARD_CLAY, "Color Blocks 2", cb2);
  58. shopMenuItem(3, shopMain, Material.DIAMOND, "Resources", resources);
  59. shopMenuItem(4, shopMain, Material.SULPHUR, "Mob Drops", mobdrops);
  60. shopMenuItem(5, shopMain, Material.BREWING_STAND_ITEM, "Potion Materials", potionmats);
  61. shopMenuItem(6, shopMain, Material.WHEAT, "Farming", farming);
  62. shopMenuItem(7, shopMain, Material.COOKED_BEEF, "Food", food);
  63. shopMenuItem(8, shopMain, Material.REDSTONE, "Redstone", redstone);
  64. shopMenuItem(9, shopMain, Material.POTION, "Potions", pots);
  65. shopMenuItem(10, shopMain, Material.MOB_SPAWNER, "Spawners", spawners);
  66.  
  67. shopBSItem(0, shopMain, blocks, Material.COBBLESTONE, "Cobblestone", new ItemBuilder(Material.COBBLESTONE).make(), 64, 150, 1, 0.93, 64, 59.52);
  68. shopBSItem(1, shopMain, blocks, Material.STONE, "Stone", new ItemBuilder(Material.STONE).make(), 64, 175, 1, 0.93, 64, 59.52);
  69. shopBSItem(2, shopMain, blocks, Material.LOG, "Oak Log", new ItemBuilder(Material.LOG).make(), 8, 25, 1, 1.5, 64, 96);
  70. shopBSOItem(3, shopMain, blocks, Material.LOG, 1, "Spruce Log", new ItemBuilder(Material.LOG).data(1).make(), 8, 25, 1, 1.5, 64, 96);
  71. shopBSOItem(4, shopMain, blocks, Material.LOG, 2, "Birch Log", new ItemBuilder(Material.LOG).data(2).make(), 8, 25, 1, 1.5, 64, 96);
  72. shopBSOItem(5, shopMain, blocks, Material.LOG, 3, "Jungle Log", new ItemBuilder(Material.LOG).data(3).make(), 8, 25, 1, 1.5, 64, 96);
  73. shopBSItem(6, shopMain, blocks, Material.LOG_2, "Dark Oak Log", new ItemBuilder(Material.LOG).make(), 8, 25, 1, 1.5, 64, 96);
  74. shopBSOItem(7, shopMain, blocks, Material.LOG_2, 1, "Acacia Log", new ItemBuilder(Material.LOG).data(1).make(), 8, 25, 1, 1.5, 64, 96);
  75. shopBSItem(8, shopMain, blocks, Material.PACKED_ICE, "Packed Ice", new ItemBuilder(Material.PACKED_ICE).make(), 8, 150, 1, 3, 64, 192);
  76. shopBSItem(9, shopMain, blocks, Material.SANDSTONE, "Sand Stone", new ItemBuilder(Material.SANDSTONE).make(), 16, 100, 1, 1, 32, 32);
  77. shopBSOItem(10, shopMain, blocks, Material.SANDSTONE, 1, "Chiseled Sand Stone", new ItemBuilder(Material.SANDSTONE).data(1).make(), 16, 100, 1, 1, 32, 32);
  78. shopBSOItem(11, shopMain, blocks, Material.SANDSTONE, 2, "Smooth Sand Stone", new ItemBuilder(Material.SANDSTONE).data(2).make(), 16, 100, 1, 1, 32, 32);
  79. /*
  80. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  81. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  82. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  83. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  84. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  85. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  86. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , )
  87. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  88. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  89. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  90. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  91. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  92. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  93. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  94. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  95. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  96. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  97. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  98. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  99. shopBSItem(, shopMain, blocks, Material, title + "", player, new ItemBuilder(Material).make(), , , , , , );
  100. */
  101. }
  102.  
  103.  
  104. @Override
  105. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  106. if (sender instanceof Player) {
  107. Player player = (Player) sender;
  108. shopMain.show(player);
  109. return true;
  110. } else {
  111. sender.sendMessage(sn + ChatColor.RED + "You cannot use this from console!");
  112. return true;
  113. }
  114. }
  115.  
  116. public void cooldown(final String player) {
  117. player.toLowerCase();
  118. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  119. public void run() {
  120. cdl.remove(player);
  121. }
  122. }, 10L);
  123. }
  124.  
  125. public void shopBSItem(int slot, Menu main, Menu cat, Material mat, String name, ItemStack i, int a1, double p1, int a2, double p2, int a3, double p3) {
  126. String[] lores = {ChatColor.GREEN + "[L] Buy: $" + p1 + " (" + a1 + ")",
  127. ChatColor.RED + "[R] Sell: $" + p2 + " {" + a2 + ")",
  128. ChatColor.RED + "[R] Sell: $" + p3 + " {" + a3 + ") [SHIFT]"};
  129. cat.setItem(slot, new ItemBuilder(mat).name(ChatColor.WHITE + "" + ChatColor.BOLD + "" + name).lores(lores).make(), new Item() {
  130. @Override
  131. public void clickEvent(InventoryClickEvent event) {
  132. event.setCancelled(true);
  133. Player player = (Player) event.getWhoClicked();
  134. boolean cd = cdl.contains(player.getName().toLowerCase());
  135. if (!cd) {
  136. if (event.isLeftClick()) {
  137. double bal = eco.getBalance(player);
  138. if (bal >= p1) {
  139. i.setAmount(a1);
  140. player.getInventory().addItem(i);
  141. eco.withdrawPlayer(player, p1);
  142. cdl.add(player.getName().toLowerCase());
  143. cooldown(player.getName());
  144. player.updateInventory();
  145. emsg(player, "You have purchased " + a1 + " " + name + " for $" + p1 + "!");
  146. } else {
  147. emsg(player, "You do not have enough money to purchase this!");
  148. }
  149. } else if (event.isRightClick()) {
  150. if (player.getInventory().containsAtLeast(i, a2)) {
  151. i.setAmount(a2);
  152. // Look into this more later \/
  153. player.getInventory().removeItem(i);
  154. eco.depositPlayer(player, p2);
  155. cdl.add(player.getName().toLowerCase());
  156. cooldown(player.getName());
  157. player.updateInventory();
  158. smsg(player, "You have sold " + a2 + " " + name + " for $" + p2 + "!");
  159. } else {
  160. emsg(player, "You do not have enough " + name + " to sell!");
  161. }
  162. } else if (event.isShiftClick()) {
  163. i.setAmount(a3);
  164. // Look into this more later \/
  165. player.getInventory().removeItem(i);
  166. eco.depositPlayer(player, p3);
  167. cdl.add(player.getName().toLowerCase());
  168. cooldown(player.getName());
  169. player.updateInventory();
  170. smsg(player, "You have sold " + a3 + " " + name + " for $" + p3 + "!");
  171. } else if (event.isCancelled()) {
  172. main.show(player);
  173. }
  174. }
  175. }
  176. });
  177. }
  178. public void shopBSOItem(int slot, Menu main, Menu cat, Material mat, int num, String name, ItemStack i, int a1, double p1, int a2, double p2, int a3, double p3) {
  179. String[] lores = {ChatColor.GREEN + "[L] Buy: $" + p1 + " (" + a1 + ")",
  180. ChatColor.RED + "[R] Sell: $" + p2 + " {" + a2 + ")",
  181. ChatColor.RED + "[R] Sell: $" + p3 + " {" + a3 + ") [SHIFT]"};
  182. cat.setItem(slot, new ItemBuilder(mat).data(num).name(ChatColor.WHITE + "" + ChatColor.BOLD + "" + name).lores(lores).make(), new Item() {
  183. @Override
  184. public void clickEvent(InventoryClickEvent event) {
  185. event.setCancelled(true);
  186. Player player = (Player) event.getWhoClicked();
  187. boolean cd = cdl.contains(player.getName().toLowerCase());
  188. if (!cd) {
  189. if (event.isLeftClick()) {
  190. double bal = eco.getBalance(player);
  191. if (bal >= p1) {
  192. i.setAmount(a1);
  193. player.getInventory().addItem(i);
  194. eco.withdrawPlayer(player, p1);
  195. cdl.add(player.getName().toLowerCase());
  196. cooldown(player.getName());
  197. player.updateInventory();
  198. emsg(player, "You have purchased " + a1 + " " + name + " for $" + p1 + "!");
  199. } else {
  200. emsg(player, "You do not have enough money to purchase this!");
  201. }
  202. } else if (event.isRightClick()) {
  203. if (player.getInventory().containsAtLeast(i, a2)) {
  204. i.setAmount(a2);
  205. // Look into this more later \/
  206. player.getInventory().removeItem(i);
  207. eco.depositPlayer(player, p2);
  208. cdl.add(player.getName().toLowerCase());
  209. cooldown(player.getName());
  210. player.updateInventory();
  211. smsg(player, "You have sold " + a2 + " " + name + " for $" + p2 + "!");
  212. } else {
  213. emsg(player, "You do not have enough " + name + " to sell!");
  214. }
  215. } else if (event.isShiftClick()) {
  216. i.setAmount(a3);
  217. // Look into this more later \/
  218. player.getInventory().removeItem(i);
  219. eco.depositPlayer(player, p3);
  220. cdl.add(player.getName().toLowerCase());
  221. cooldown(player.getName());
  222. player.updateInventory();
  223. smsg(player, "You have sold " + a3 + " " + name + " for $" + p3 + "!");
  224. }
  225. }
  226. }
  227. });
  228. }
  229. public void shopBSCItem(int slot, Menu main, Menu cat, Material mat, Color c, String name, ItemStack i, int a1, double p1, int a2, double p2, int a3, double p3) {
  230. String[] lores = {ChatColor.GREEN + "[L] Buy: $" + p1 + " (" + a1 + ")",
  231. ChatColor.RED + "[R] Sell: $" + p2 + " {" + a2 + ")",
  232. ChatColor.RED + "[R] Sell: $" + p3 + " {" + a3 + ") [SHIFT]"};
  233. cat.setItem(slot, new ItemBuilder(mat).name(ChatColor.WHITE + "" + ChatColor.BOLD + "" + name).lores(lores).color(c).make(), new Item() {
  234. @Override
  235. public void clickEvent(InventoryClickEvent event) {
  236. event.setCancelled(true);
  237. Player player = (Player) event.getWhoClicked();
  238. boolean cd = cdl.contains(player.getName().toLowerCase());
  239. if (!cd) {
  240. if (event.isLeftClick()) {
  241. double bal = eco.getBalance(player);
  242. if (bal >= p1) {
  243. i.setAmount(a1);
  244. player.getInventory().addItem(i);
  245. eco.withdrawPlayer(player, p1);
  246. cdl.add(player.getName().toLowerCase());
  247. cooldown(player.getName());
  248. player.updateInventory();
  249. emsg(player, "You have purchased " + a1 + " " + name + " for $" + p1 + "!");
  250. } else {
  251. emsg(player, "You do not have enough money to purchase this!");
  252. }
  253. } else if (event.isRightClick()) {
  254. if (player.getInventory().containsAtLeast(i, a2)) {
  255. i.setAmount(a2);
  256. // Look into this more later \/
  257. player.getInventory().removeItem(i);
  258. eco.depositPlayer(player, p2);
  259. cdl.add(player.getName().toLowerCase());
  260. cooldown(player.getName());
  261. player.updateInventory();
  262. smsg(player, "You have sold " + a2 + " " + name + " for $" + p2 + "!");
  263. } else {
  264. emsg(player, "You do not have enough " + name + " to sell!");
  265. }
  266. } else if (event.isShiftClick()) {
  267. i.setAmount(a3);
  268. // Look into this more later \/
  269. player.getInventory().removeItem(i);
  270. eco.depositPlayer(player, p3);
  271. cdl.add(player.getName().toLowerCase());
  272. cooldown(player.getName());
  273. player.updateInventory();
  274. smsg(player, "You have sold " + a3 + " " + name + " for $" + p3 + "!");
  275. }
  276. }
  277. }
  278. });
  279. }
  280.  
  281. public void shopBItem(int slot, Menu main, Menu cat, Material mat, String name, ItemStack i, int a, double p) {
  282. String[] lores = {ChatColor.GREEN + "[L] Buy: $" + p + " (" + a + ")"};
  283. cat.setItem(slot, new ItemBuilder(mat).name(ChatColor.WHITE + "" + ChatColor.BOLD + "" + name).lores(lores).make(), new Item() {
  284. @Override
  285. public void clickEvent(InventoryClickEvent event) {
  286. event.setCancelled(true);
  287. if (event.isLeftClick()) {
  288. Player player = (Player) event.getWhoClicked();
  289. double bal = eco.getBalance(player);
  290. if (bal >= p) {
  291. i.setAmount(a);
  292. player.getInventory().addItem(i);
  293. eco.withdrawPlayer(player, p);
  294. cdl.add(player.getName().toLowerCase());
  295. cooldown(player.getName());
  296. player.updateInventory();
  297. emsg(player, "You have purchased " + a + " " + name + " for $" + p + "!");
  298. } else {
  299. emsg(player, "You do not have enough money to purchase this!");
  300. }
  301. }
  302. }
  303. });
  304. }
  305.  
  306. public void shopMenuItem(int slot, Menu main, Material mat, String name, Menu next) {
  307. main.setItem(slot, new ItemBuilder(mat).name(ChatColor.WHITE + "" + ChatColor.BOLD + "" + name).make(), new Item() {
  308. @Override
  309. public void clickEvent(InventoryClickEvent event) {
  310. event.setCancelled(true);
  311. Player player = (Player) event.getWhoClicked();
  312. if (event.getClick().isLeftClick()) {
  313. next.show(player);
  314. }
  315. }
  316. });
  317. }
  318.  
  319. public void smsg(Player player, String s) {
  320. player.sendMessage(sn + ChatColor.GREEN + s);
  321. }
  322.  
  323. public void emsg(Player player, String s) {
  324. player.sendMessage(sn + ChatColor.RED + s);
  325. }
  326.  
  327. public void msg(Player player, String s) {
  328. player.sendMessage(sn + ChatColor.GRAY + s);
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement