Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.List;
- import java.util.Random;
- import org.bukkit.ChatColor;
- import org.bukkit.Effect;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.inventory.InventoryClickEvent;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.InventoryView;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import com.ethan.Kitpvp.Main;
- public class InventoryClick implements Listener {
- private Main main;
- public InventoryClick(Main main) {
- this.main = main;
- }
- @SuppressWarnings({ "deprecation", "static-access" })
- @EventHandler
- public void onInventoryClick(InventoryClickEvent event) {
- try {
- if(!(event.getWhoClicked() instanceof Player)) return;
- Player player = (Player) event.getWhoClicked();
- ItemStack item = event.getCurrentItem();
- Inventory inv = event.getInventory();
- if(inv.getName().equals(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("MenuGuiName")))) {
- if(item.getType() == Material.BARRIER) {
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- event.setCancelled(true);
- player.closeInventory();
- } else if(item.getType() == Material.COMPASS) {
- double worldX = 0;
- double worldY = 0;
- double worldZ = 0;
- String worldXString = "";
- String worldYString = "";
- String worldZString = "";
- String worldWorld = "";
- try {
- worldXString = main.getConfig().getString("WorldSpawnX");
- worldYString = main.getConfig().getString("WorldSpawnY");
- worldZString = main.getConfig().getString("WorldSpawnZ");
- worldWorld = main.getConfig().getString("WorldSpawnWorld");
- if(worldXString.length() >= 1) worldX = main.getConfig().getDouble("WorldSpawnX");
- if(worldYString.length() >= 1) worldY = main.getConfig().getDouble("WorldSpawnY");
- if(worldZString.length() >= 1) worldZ = main.getConfig().getDouble("WorldSpawnZ");
- } catch(Exception e) {
- }
- if(worldXString.length() >= 1 && worldYString.length() >= 1 && worldZString.length() >= 1) {
- Location l = null;
- if(worldWorld.length() >= 1) {
- l = new Location(main.getServer().getWorld(worldWorld), worldX, worldY, worldZ);
- } else {
- l = new Location(player.getWorld(), worldX, worldY, worldZ);
- }
- if(l != null) player.teleport(l);
- } else {
- player.teleport(player.getWorld().getSpawnLocation());
- }
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- event.setCancelled(true);
- player.closeInventory();
- } else if(item.getType() == Material.DIAMOND_SWORD) {
- Inventory Kits = main.helper.kits.openInventory(player);
- player.closeInventory();
- player.openInventory(Kits);
- event.setCancelled(true);
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- } else if(item.getType() == Material.CHEST){
- Inventory Shop = main.helper.shop.openInventory(player);
- player.closeInventory();
- player.openInventory(Shop);
- event.setCancelled(true);
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- } else {
- event.setCancelled(true);
- }
- } else if(inv.getName().equals(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("KitsGuiName")))) {
- for(int i = 1; i < 36; i++) {
- if (!(i < player.getLevel() + 1)) {
- if(item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Kit: " + i)) {
- player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_HURT, 1, 1);
- player.sendMessage(ChatColor.RED + main.getConfig().getString("PlayerDoesNotHaveKit"));
- }
- }
- }
- for(int i = 1; i < player.getLevel() + 1; i++) {
- if(item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Kit: " + i)) {
- File Kitsf = new File("plugins/Kitpvp/Kits.yml");
- YamlConfiguration Kitsyc = YamlConfiguration.loadConfiguration(Kitsf);
- player.getInventory().clear();
- ItemStack[] contents = player.getInventory().getContents();
- List<?> list = Kitsyc.getList("Kit " + i);
- if(list != null) {
- for(int i5 = 0; i5 < list.size(); i5++) {
- contents[i5] = (ItemStack) list.get(i5);
- }
- }
- player.getInventory().setContents(contents);
- File f = new File("plugins/Kitpvp/Players/" + player.getName() + ".yml");
- YamlConfiguration yc = YamlConfiguration.loadConfiguration(f);
- if(main.getConfig().getBoolean("MenuShopEnable")) {
- for(int i3 = 1; i3 < 18; i3++) {
- if(yc.getInt("Special Ability " + i3) == 1) {
- if(i3 == 1) {
- 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));
- }
- if(i3 == 2) {
- 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));
- }
- if(i3 == 3) {
- 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));
- }
- if(i3 == 4) {
- 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));
- }
- if(i3 == 5) {
- 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));
- }
- if(i3 == 6) {
- 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));
- }
- if(i3 == 7) {
- 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));
- }
- if(i3 == 8) {
- 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));
- }
- if(i3 == 9) {
- 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));
- }
- if(i3 == 10) {
- 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));
- }
- if(i3 == 11) {
- 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));
- }
- if(i3 == 12) {
- 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));
- }
- if(i3 == 13) {
- 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));
- }
- if(i3 == 14) {
- 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));
- }
- if(i3 == 15) {
- 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));
- }
- if(i3 == 16) {
- 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));
- }
- if(i3 == 17) {
- 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));
- }
- }
- }
- }
- File Spawnsf = new File("plugins/Kitpvp/Spawns.yml");
- YamlConfiguration Spawnsyc = YamlConfiguration.loadConfiguration(Spawnsf);
- boolean SpawnIsThere = false;
- for(int i2 = 1; i2 < 17; i2++) {
- String CheckX = Spawnsyc.getString("Spawn" + i2 + "X");
- String CheckY = Spawnsyc.getString("Spawn" + i2 + "Y");
- String CheckZ = Spawnsyc.getString("Spawn" + i2 + "Z");
- if(CheckX.length() >= 1 && CheckY.length() >= 1 && CheckZ.length() >= 1) {
- SpawnIsThere = true;
- }
- }
- if(SpawnIsThere) {
- randomSpawn(player);
- if(main.getConfig().getBoolean("HealPlayerWhenTheyEnterArena")) player.setHealth(player.getMaxHealth());
- if(main.getConfig().getBoolean("HealPlayerWhenTheyEnterArena")) player.setFoodLevel(20);
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- File Playerf = new File("plugins/Kitpvp/Players/" + player.getName() + ".yml");
- if(Playerf.exists()) {
- YamlConfiguration Playeryc = YamlConfiguration.loadConfiguration(Playerf);
- Playeryc.set("InPvp", true);
- Playeryc.save(Playerf);
- }
- }
- if(!SpawnIsThere) {
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("NoSpawnLocations")));
- player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_HURT, 1, 1);
- for (PotionEffect effect : player.getActivePotionEffects()) {
- player.removePotionEffect(effect.getType());
- }
- player.getInventory().clear();
- 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));
- }
- event.setCancelled(true);
- }
- }
- if(item.getType() == Material.BARRIER) {
- Inventory Menu = main.helper.menu.openInventory();
- player.closeInventory();
- player.openInventory(Menu);
- event.setCancelled(true);
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- } else {
- event.setCancelled(true);
- }
- } else if(inv.getName().equals(ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("ShopGuiName")))) {
- for(int i = 1; i < 18; i++) {
- if(item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Special Ability: " + i + " | $" + i * 250)) {
- if(main.econ.getBalance(player.getName()) >= i * 250) {
- main.econ.withdrawPlayer(player.getName(), i * 250);
- File f = new File("plugins/Kitpvp/Players/" + player.getName() + ".yml");
- YamlConfiguration yc = YamlConfiguration.loadConfiguration(f);
- yc.save(f);
- yc.set("Special Ability " + i, 1);
- yc.save(f);
- InventoryView Openinv = player.getOpenInventory();
- ItemStack UnlockedAbility = main.helper.NameItem(Material.WOOL, ChatColor.GREEN + "Special Ability: " + i + " | Purchased", 1, 5, null);
- Openinv.setItem(i, UnlockedAbility);
- player.playSound(player.getLocation(), Sound.ENTITY_FIREWORK_BLAST, 1, 1);
- player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 2004);
- } else {
- player.playSound(player.getLocation(), Sound.ENTITY_BLAZE_HURT, 1, 1);
- }
- event.setCancelled(true);
- }
- }
- if(item.getType() == Material.BARRIER) {
- Inventory Menu = main.helper.menu.openInventory();
- player.closeInventory();
- player.openInventory(Menu);
- event.setCancelled(true);
- player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
- } else {
- event.setCancelled(true);
- }
- } else if(inv.getName().equals(player.getInventory().getName())) {
- if(event.isShiftClick()) {
- if(event.getCurrentItem().getData().getItemType().getMaxStackSize() == 1) {
- event.setCancelled(true);
- }
- }
- }
- } catch(Exception e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement