Advertisement
Guest User

InventoryClickEvent

a guest
Jun 3rd, 2016
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.06 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.List;
  3. import java.util.Random;
  4.  
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Effect;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.Sound;
  10. import org.bukkit.configuration.file.YamlConfiguration;
  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.InventoryView;
  17. import org.bukkit.inventory.ItemStack;
  18. import org.bukkit.potion.PotionEffect;
  19. import org.bukkit.potion.PotionEffectType;
  20.  
  21. import com.ethan.Kitpvp.Main;
  22.  
  23. public class InventoryClick implements Listener {
  24.  
  25. private Main main;
  26.  
  27. public InventoryClick(Main main) {
  28. this.main = main;
  29. }
  30.  
  31. @SuppressWarnings({ "deprecation", "static-access" })
  32. @EventHandler
  33. public void onInventoryClick(InventoryClickEvent event) {
  34.  
  35. try {
  36.  
  37. if(!(event.getWhoClicked() instanceof Player)) return;
  38.  
  39. Player player = (Player) event.getWhoClicked();
  40. ItemStack item = event.getCurrentItem();
  41.  
  42. Inventory inv = event.getInventory();
  43.  
  44. if(inv.getName().equals(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("MenuGuiName")))) {
  45.  
  46. if(item.getType() == Material.BARRIER) {
  47.  
  48. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  49.  
  50. event.setCancelled(true);
  51. player.closeInventory();
  52.  
  53. } else if(item.getType() == Material.COMPASS) {
  54.  
  55. double worldX = 0;
  56. double worldY = 0;
  57. double worldZ = 0;
  58.  
  59. String worldXString = "";
  60. String worldYString = "";
  61. String worldZString = "";
  62. String worldWorld = "";
  63.  
  64. try {
  65.  
  66. worldXString = main.getConfig().getString("WorldSpawnX");
  67. worldYString = main.getConfig().getString("WorldSpawnY");
  68. worldZString = main.getConfig().getString("WorldSpawnZ");
  69. worldWorld = main.getConfig().getString("WorldSpawnWorld");
  70.  
  71. if(worldXString.length() >= 1) worldX = main.getConfig().getDouble("WorldSpawnX");
  72. if(worldYString.length() >= 1) worldY = main.getConfig().getDouble("WorldSpawnY");
  73. if(worldZString.length() >= 1) worldZ = main.getConfig().getDouble("WorldSpawnZ");
  74.  
  75. } catch(Exception e) {
  76.  
  77. }
  78.  
  79. if(worldXString.length() >= 1 && worldYString.length() >= 1 && worldZString.length() >= 1) {
  80.  
  81. Location l = null;
  82.  
  83. if(worldWorld.length() >= 1) {
  84. l = new Location(main.getServer().getWorld(worldWorld), worldX, worldY, worldZ);
  85. } else {
  86. l = new Location(player.getWorld(), worldX, worldY, worldZ);
  87. }
  88.  
  89. if(l != null) player.teleport(l);
  90.  
  91. } else {
  92. player.teleport(player.getWorld().getSpawnLocation());
  93. }
  94.  
  95. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  96.  
  97. event.setCancelled(true);
  98. player.closeInventory();
  99.  
  100. } else if(item.getType() == Material.DIAMOND_SWORD) {
  101.  
  102. Inventory Kits = main.helper.kits.openInventory(player);
  103.  
  104. player.closeInventory();
  105. player.openInventory(Kits);
  106.  
  107. event.setCancelled(true);
  108.  
  109. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  110.  
  111.  
  112. } else if(item.getType() == Material.CHEST){
  113.  
  114. Inventory Shop = main.helper.shop.openInventory(player);
  115.  
  116. player.closeInventory();
  117. player.openInventory(Shop);
  118.  
  119. event.setCancelled(true);
  120.  
  121. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  122.  
  123. } else {
  124. event.setCancelled(true);
  125. }
  126.  
  127. } else if(inv.getName().equals(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("KitsGuiName")))) {
  128.  
  129. for(int i = 1; i < 36; i++) {
  130. if (!(i < player.getLevel() + 1)) {
  131. if(item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Kit: " + i)) {
  132.  
  133. player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_HURT, 1, 1);
  134. player.sendMessage(ChatColor.RED + main.getConfig().getString("PlayerDoesNotHaveKit"));
  135.  
  136. }
  137. }
  138. }
  139.  
  140. for(int i = 1; i < player.getLevel() + 1; i++) {
  141. if(item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Kit: " + i)) {
  142.  
  143. File Kitsf = new File("plugins/Kitpvp/Kits.yml");
  144. YamlConfiguration Kitsyc = YamlConfiguration.loadConfiguration(Kitsf);
  145.  
  146. player.getInventory().clear();
  147. ItemStack[] contents = player.getInventory().getContents();
  148.  
  149. List<?> list = Kitsyc.getList("Kit " + i);
  150.  
  151. if(list != null) {
  152. for(int i5 = 0; i5 < list.size(); i5++) {
  153. contents[i5] = (ItemStack) list.get(i5);
  154. }
  155. }
  156.  
  157. player.getInventory().setContents(contents);
  158.  
  159. File f = new File("plugins/Kitpvp/Players/" + player.getName() + ".yml");
  160. YamlConfiguration yc = YamlConfiguration.loadConfiguration(f);
  161.  
  162. if(main.getConfig().getBoolean("MenuShopEnable")) {
  163. for(int i3 = 1; i3 < 18; i3++) {
  164. if(yc.getInt("Special Ability " + i3) == 1) {
  165. if(i3 == 1) {
  166. if(main.getConfig().getString("Special Ability 1").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 1").toUpperCase()), Integer.MAX_VALUE, 0));
  167. }
  168. if(i3 == 2) {
  169. if(main.getConfig().getString("Special Ability 2").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 2").toUpperCase()), Integer.MAX_VALUE, 0));
  170. }
  171. if(i3 == 3) {
  172. if(main.getConfig().getString("Special Ability 3").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 3").toUpperCase()), Integer.MAX_VALUE, 0));
  173. }
  174. if(i3 == 4) {
  175. if(main.getConfig().getString("Special Ability 4").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 4").toUpperCase()), Integer.MAX_VALUE, 0));
  176. }
  177. if(i3 == 5) {
  178. if(main.getConfig().getString("Special Ability 5").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 5").toUpperCase()), Integer.MAX_VALUE, 0));
  179. }
  180. if(i3 == 6) {
  181. if(main.getConfig().getString("Special Ability 6").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 6").toUpperCase()), Integer.MAX_VALUE, 0));
  182. }
  183. if(i3 == 7) {
  184. if(main.getConfig().getString("Special Ability 7").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 7").toUpperCase()), Integer.MAX_VALUE, 0));
  185. }
  186. if(i3 == 8) {
  187. if(main.getConfig().getString("Special Ability 8").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 8").toUpperCase()), Integer.MAX_VALUE, 0));
  188. }
  189. if(i3 == 9) {
  190. if(main.getConfig().getString("Special Ability 9").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 9").toUpperCase()), Integer.MAX_VALUE, 1));
  191. }
  192. if(i3 == 10) {
  193. if(main.getConfig().getString("Special Ability 10").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 10").toUpperCase()), Integer.MAX_VALUE, 1));
  194. }
  195. if(i3 == 11) {
  196. if(main.getConfig().getString("Special Ability 11").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 11").toUpperCase()), Integer.MAX_VALUE, 1));
  197. }
  198. if(i3 == 12) {
  199. if(main.getConfig().getString("Special Ability 12").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 12").toUpperCase()), Integer.MAX_VALUE, 1));
  200. }
  201. if(i3 == 13) {
  202. if(main.getConfig().getString("Special Ability 13").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 13").toUpperCase()), Integer.MAX_VALUE, 1));
  203. }
  204. if(i3 == 14) {
  205. if(main.getConfig().getString("Special Ability 14").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 14").toUpperCase()), Integer.MAX_VALUE, 1));
  206. }
  207. if(i3 == 15) {
  208. if(main.getConfig().getString("Special Ability 15").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 15").toUpperCase()), Integer.MAX_VALUE, 1));
  209. }
  210. if(i3 == 16) {
  211. if(main.getConfig().getString("Special Ability 16").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 16").toUpperCase()), Integer.MAX_VALUE, 1));
  212. }
  213. if(i3 == 17) {
  214. if(main.getConfig().getString("Special Ability 17").length() > 1) player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(main.getConfig().getString("Special Ability 17").toUpperCase()), Integer.MAX_VALUE, 1));
  215. }
  216. }
  217. }
  218. }
  219.  
  220. File Spawnsf = new File("plugins/Kitpvp/Spawns.yml");
  221. YamlConfiguration Spawnsyc = YamlConfiguration.loadConfiguration(Spawnsf);
  222.  
  223. boolean SpawnIsThere = false;
  224.  
  225. for(int i2 = 1; i2 < 17; i2++) {
  226.  
  227. String CheckX = Spawnsyc.getString("Spawn" + i2 + "X");
  228. String CheckY = Spawnsyc.getString("Spawn" + i2 + "Y");
  229. String CheckZ = Spawnsyc.getString("Spawn" + i2 + "Z");
  230.  
  231. if(CheckX.length() >= 1 && CheckY.length() >= 1 && CheckZ.length() >= 1) {
  232. SpawnIsThere = true;
  233. }
  234. }
  235.  
  236. if(SpawnIsThere) {
  237.  
  238. randomSpawn(player);
  239.  
  240. if(main.getConfig().getBoolean("HealPlayerWhenTheyEnterArena")) player.setHealth(player.getMaxHealth());
  241. if(main.getConfig().getBoolean("HealPlayerWhenTheyEnterArena")) player.setFoodLevel(20);
  242.  
  243. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  244.  
  245. File Playerf = new File("plugins/Kitpvp/Players/" + player.getName() + ".yml");
  246.  
  247. if(Playerf.exists()) {
  248.  
  249. YamlConfiguration Playeryc = YamlConfiguration.loadConfiguration(Playerf);
  250.  
  251. Playeryc.set("InPvp", true);
  252.  
  253. Playeryc.save(Playerf);
  254.  
  255. }
  256. }
  257.  
  258. if(!SpawnIsThere) {
  259.  
  260. player.sendMessage(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("NoSpawnLocations")));
  261.  
  262. player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_HURT, 1, 1);
  263.  
  264. for (PotionEffect effect : player.getActivePotionEffects()) {
  265.  
  266. player.removePotionEffect(effect.getType());
  267.  
  268. }
  269.  
  270. player.getInventory().clear();
  271. player.getInventory().setItem(main.getConfig().getInt("MenuIconSlot"), main.helper.NameItem(Material.getMaterial(main.getConfig().getString("MenuIconItem")), ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("MenuItemName")), 1, 0, null));
  272.  
  273. }
  274.  
  275. event.setCancelled(true);
  276.  
  277. }
  278. }
  279.  
  280. if(item.getType() == Material.BARRIER) {
  281.  
  282. Inventory Menu = main.helper.menu.openInventory();
  283.  
  284. player.closeInventory();
  285. player.openInventory(Menu);
  286.  
  287. event.setCancelled(true);
  288.  
  289. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  290.  
  291. } else {
  292. event.setCancelled(true);
  293. }
  294. } else if(inv.getName().equals(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("ShopGuiName")))) {
  295.  
  296. for(int i = 1; i < 18; i++) {
  297. if(item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Special Ability: " + i + " | $" + i * 250)) {
  298.  
  299. if(main.econ.getBalance(player.getName()) >= i * 250) {
  300.  
  301. main.econ.withdrawPlayer(player.getName(), i * 250);
  302.  
  303. File f = new File("plugins/Kitpvp/Players/" + player.getName() + ".yml");
  304. YamlConfiguration yc = YamlConfiguration.loadConfiguration(f);
  305.  
  306. yc.save(f);
  307.  
  308. yc.set("Special Ability " + i, 1);
  309.  
  310. yc.save(f);
  311.  
  312. InventoryView Openinv = player.getOpenInventory();
  313.  
  314. ItemStack UnlockedAbility = main.helper.NameItem(Material.WOOL, ChatColor.GREEN + "Special Ability: " + i + " | Purchased", 1, 5, null);
  315.  
  316. Openinv.setItem(i, UnlockedAbility);
  317.  
  318. player.playSound(player.getLocation(), Sound.ENTITY_FIREWORK_BLAST, 1, 1);
  319. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 2004);
  320.  
  321. } else {
  322. player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_HURT, 1, 1);
  323. }
  324.  
  325. event.setCancelled(true);
  326.  
  327. }
  328. }
  329.  
  330. if(item.getType() == Material.BARRIER) {
  331.  
  332. Inventory Menu = main.helper.menu.openInventory();
  333.  
  334. player.closeInventory();
  335. player.openInventory(Menu);
  336.  
  337. event.setCancelled(true);
  338.  
  339. player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
  340.  
  341. } else {
  342. event.setCancelled(true);
  343. }
  344. } else if(inv.getName().equals(player.getInventory().getName())) {
  345.  
  346. if(event.isShiftClick()) {
  347. if(event.getCurrentItem().getData().getItemType().getMaxStackSize() == 1) {
  348. event.setCancelled(true);
  349. }
  350. }
  351. }
  352. } catch(Exception e) {
  353.  
  354. }
  355. }
  356. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement