SHARE
TWEET

Untitled

a guest Jun 15th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.thauandev.habilidades;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.GameMode;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.block.Block;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.EventPriority;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.entity.PlayerDeathEvent;
  18. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  19. import org.bukkit.event.player.PlayerInteractEntityEvent;
  20. import org.bukkit.event.player.PlayerInteractEvent;
  21. import org.bukkit.event.player.PlayerQuitEvent;
  22. import org.bukkit.inventory.ItemStack;
  23. import org.bukkit.inventory.meta.ItemMeta;
  24. import org.bukkit.potion.PotionEffect;
  25. import org.bukkit.potion.PotionEffectType;
  26.  
  27. import me.thauandev.API.CooldownAPI;
  28. import me.thauandev.API.KitAPI;
  29. import me.thauandev.configuração.cfGrupo;
  30. import me.thauandev.main.Main;
  31.  
  32.  
  33. public class Gladiator implements Listener{
  34.  
  35.  
  36. public boolean generateGlass = true;
  37.  
  38. public static ArrayList<Player> noExecut = new ArrayList<>();
  39.   public static HashMap<String, Location> oldl = new HashMap<String, Location>();
  40.   public static HashMap<String, String> fighting = new HashMap<String, String>();
  41.   public HashMap<Integer, ArrayList<Location>> blocks = new HashMap<Integer, ArrayList<Location>>();
  42.   public static HashMap<Player, Location> localizacao = new HashMap<Player, Location>();
  43.   public static HashMap<Location, Block> bloco = new HashMap<Location, Block>();
  44.   public HashMap<Integer, String[]> players = new HashMap<Integer, String[]>();
  45.   public HashMap<String, Integer> tasks = new HashMap<String, Integer>();
  46.   int nextID = 0;
  47.   public static int id1;
  48.   public static int id2;
  49.  
  50.  
  51.   @SuppressWarnings({ "static-access" })
  52. @EventHandler
  53.   public void OnGladiat0orKit(PlayerInteractEntityEvent event) {
  54.     final Player p = event.getPlayer();
  55.     if ((event.getRightClicked() instanceof Player)){
  56.       final Player r = (Player)event.getRightClicked();
  57.       if (p.getItemInHand().getType() == Material.IRON_FENCE && KitAPI.getKit(p) == "Gladiator"){
  58.            
  59.       }
  60.       if (p.getItemInHand().getType() == Material.IRON_FENCE && KitAPI.getKit(p) == "Gladiator" && !CooldownAPI.Cooldown.containsKey(p.getName())){
  61.         event.setCancelled(true);
  62.         Location loc = new Location(p.getWorld(), p.getLocation().getBlockX(), p.getLocation().getBlockY() + 200, p.getLocation().getBlockZ());
  63.         this.localizacao.put(p, loc);
  64.         this.localizacao.put(r, loc);
  65.         Location loc2 = new Location(p.getWorld(), p.getLocation().getBlockX() + 8, p.getLocation().getBlockY() + 203, p.getLocation().getBlockZ() + 8);
  66.         Location loc3 = new Location(p.getWorld(), p.getLocation().getBlockX() - 8, p.getLocation().getBlockY() + 203, p.getLocation().getBlockZ() - 8);
  67.         if ((fighting.containsKey(p.getName())) || (fighting.containsKey(r.getName())))
  68.         {
  69.           event.setCancelled(true);
  70.           return;
  71.         }
  72.         Integer currentID = Integer.valueOf(this.nextID);
  73.         this.nextID += 1;
  74.         ArrayList<String> list = new ArrayList<String>();
  75.         list.add(p.getName());
  76.         list.add(r.getName());
  77.         this.players.put(currentID, (String[])list.toArray(new String[1]));
  78.         this.oldl.put(p.getName(), p.getLocation());
  79.         this.oldl.put(r.getName(), r.getLocation());
  80.         if (this.generateGlass)
  81.         {
  82.           List<Location> cuboid = new ArrayList<Location>();
  83.           cuboid.clear();
  84.           int bY;
  85.           for (int bX = -10; bX <= 10; bX++) {
  86.             for (int bZ = -10; bZ <= 10; bZ++) {
  87.               for (bY = -1; bY <= 10; bY++)
  88.               {
  89.                 Block b = loc.clone().add(bX, bY, bZ).getBlock();
  90.                 if (!b.isEmpty())
  91.                 {
  92.                   event.setCancelled(true);
  93.                   p.sendMessage(Main.Name + "Este local possúe blocos em cima de você, portanto o §bGladitor§f não poderá ser usado aqui.");
  94.                   return;
  95.                 }
  96.                 if (bY == 10) {
  97.                   cuboid.add(loc.clone().add(bX, bY, bZ));
  98.                 } else if (bY == -1) {
  99.                   cuboid.add(loc.clone().add(bX, bY, bZ));
  100.                 } else if ((bX == -10) || (bZ == -10) || (bX == 10) || (bZ == 10)) {
  101.                   cuboid.add(loc.clone().add(bX, bY, bZ));
  102.                 }
  103.               }
  104.             }
  105.           }
  106.           for (Location loc1 : cuboid)
  107.           {
  108.             loc1.getBlock().setType(Material.STAINED_GLASS);
  109.             this.bloco.put(loc1, loc1.getBlock());
  110.           }
  111.           loc2.setYaw(135.0F);
  112.           p.teleport(loc2);
  113.           loc3.setYaw(-45.0F);
  114.           r.teleport(loc3);
  115.           p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 110, 5));
  116.           r.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 110, 5));
  117.           p.getInventory().remove(Material.IRON_FENCE);
  118.           r.getInventory().remove(Material.IRON_FENCE);
  119.          p.sendMessage(Main.Name + "Você puxou o jogador §b" + r.getName() + " §fpara uma batalha.");
  120.        
  121.           noExecut.add(p);
  122.           noExecut.add(r);
  123.           fighting.put(p.getName(), r.getName());
  124.           fighting.put(r.getName(), p.getName());
  125.           this.id2 = Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable()
  126.           {
  127.             public void run()
  128.             {
  129.               if ((Gladiator.fighting.containsKey(p.getName())) && (((String)Gladiator.fighting.get(p.getName())).equalsIgnoreCase(r.getName())) && (Gladiator.fighting.containsKey(r.getName())) && (((String)Gladiator.fighting.get(r.getName())).equalsIgnoreCase(p.getName())))
  130.               {
  131.               }
  132.             }
  133.           }, 2400L);
  134.           this.id1 = Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable()
  135.           {
  136.             public void run()
  137.             {
  138.               if ((Gladiator.fighting.containsKey(p.getName())) && (((String)Gladiator.fighting.get(p.getName())).equalsIgnoreCase(r.getName())) && (Gladiator.fighting.containsKey(r.getName())) && (((String)Gladiator.fighting.get(r.getName())).equalsIgnoreCase(p.getName())))
  139.               {
  140.                 Gladiator.fighting.remove(p.getName());
  141.                 Gladiator.fighting.remove(r.getName());
  142.                 noExecut.remove(p);
  143.                 noExecut.remove(r);
  144.                 p.teleport((Location)Gladiator.this.oldl.get(p.getName()));
  145.                 r.teleport((Location)Gladiator.this.oldl.get(r.getName()));
  146.                 Gladiator.this.oldl.remove(p.getName());
  147.                 Gladiator.this.oldl.remove(r.getName());
  148.                 Location loc = (Location)Gladiator.this.localizacao.get(p);
  149.                 List<Location> cuboid = new ArrayList<Location>();
  150.                 int bY;
  151.                 for (int bX = -10; bX <= 10; bX++) {
  152.                   for (int bZ = -10; bZ <= 10; bZ++) {
  153.                     for (bY = -1; bY <= 10; bY++) {
  154.                       if (bY == 10) {
  155.                         cuboid.add(loc.clone().add(bX, bY, bZ));
  156.                       } else if (bY == -1) {
  157.                         cuboid.add(loc.clone().add(bX, bY, bZ));
  158.                       } else if ((bX == -10) || (bZ == -10) || (bX == 10) || (bZ == 10)) {
  159.                         cuboid.add(loc.clone().add(bX, bY, bZ));
  160.                       }
  161.                     }
  162.                   }
  163.                 }
  164.                 for (Location loc1 : cuboid)
  165.                 {
  166.                   loc1.getBlock().setType(Material.AIR);
  167.                   ((Block)Gladiator.this.bloco.get(loc1)).setType(Material.AIR);
  168.                 }
  169.               }
  170.             }
  171.           }, 100000L);
  172.         }
  173.       }
  174.     }
  175.   }
  176.   @EventHandler
  177.   public void onPlayerInteractGlad(PlayerInteractEvent e)
  178.   {
  179.     Player p = e.getPlayer();
  180.     if ((p.getItemInHand().getType() == Material.IRON_FENCE) || (KitAPI.getKit(p) == "Gladiator"))
  181.     {
  182.       e.setCancelled(true);
  183.       p.updateInventory();
  184.       return;
  185.     }
  186.   }
  187.   @EventHandler(priority=EventPriority.MONITOR)
  188.   public void onPlyaerInteract(final PlayerInteractEvent e)
  189.   {
  190.     if ((e.getAction() == Action.LEFT_CLICK_BLOCK) && (e.getClickedBlock().getType() == Material.GLASS) && (e.getPlayer().getGameMode() != GameMode.CREATIVE) && (fighting.containsKey(e.getPlayer().getName()))){
  191.       e.setCancelled(true);
  192.       e.getClickedBlock().setType(Material.GLASS);
  193.       Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getPlugin(), new Runnable()
  194.       {
  195.         public void run()
  196.         {
  197.           if (Gladiator.fighting.containsKey(e.getPlayer().getName())) {
  198.             e.getClickedBlock().setType(Material.GLASS);
  199.           }
  200.         }
  201.       }, 30L);
  202.     }
  203.   }
  204. @SuppressWarnings("static-access")
  205. @EventHandler(priority=EventPriority.HIGHEST)
  206.   public void onPlayerLeft(PlayerQuitEvent e)
  207.   {
  208.     Player p = e.getPlayer();
  209.     if (fighting.containsKey(p.getName()))
  210.     {
  211.       Player t = Bukkit.getServer().getPlayer((String)fighting.get(p.getName()));
  212.       fighting.remove(t.getName());
  213.       fighting.remove(p.getName());
  214.       noExecut.remove(p);
  215.       noExecut.remove(t);
  216.         ItemStack Item = new ItemStack(Material.IRON_FENCE);
  217.         ItemMeta kItem = Item.getItemMeta();
  218.         kItem.setDisplayName("§bGladiator");
  219.         Item.setItemMeta(kItem);
  220.        
  221.       fighting.remove(t.getName());
  222.       fighting.remove(p.getName());
  223.       noExecut.remove(p);
  224.       noExecut.remove(t);
  225.         if(KitAPI.getKit(p) == "Gladiator"){
  226.             p.getInventory().setItem(1, Item);
  227.         }
  228.         if(KitAPI.getKit(t) == "Gladiator"){
  229.             t.getInventory().setItem(1, Item);
  230.         }
  231.       Location old = (Location)this.oldl.get(t.getName());
  232.       t.teleport(old);
  233.       Bukkit.getScheduler().cancelTask(this.id1);
  234.       Bukkit.getScheduler().cancelTask(this.id2);
  235.       t.removePotionEffect(PotionEffectType.WITHER);
  236.       Location loc = (Location)this.localizacao.get(p);
  237.       List<Location> cuboid = new ArrayList<Location>();
  238.       int bY;
  239.       for (int bX = -10; bX <= 10; bX++) {
  240.         for (int bZ = -10; bZ <= 10; bZ++) {
  241.           for (bY = -1; bY <= 10; bY++) {
  242.             if (bY == 10) {
  243.               cuboid.add(loc.clone().add(bX, bY, bZ));
  244.             } else if (bY == -1) {
  245.               cuboid.add(loc.clone().add(bX, bY, bZ));
  246.             } else if ((bX == -10) || (bZ == -10) || (bX == 10) || (bZ == 10)) {
  247.               cuboid.add(loc.clone().add(bX, bY, bZ));
  248.             }
  249.           }
  250.         }
  251.       }
  252.       for (Location loc1 : cuboid)
  253.       {
  254.         loc1.getBlock().setType(Material.AIR);
  255.         ((Block)this.bloco.get(loc1)).setType(Material.AIR);
  256.       }
  257.       for (Location loc1 : cuboid)
  258.       {
  259.         loc1.getBlock().setType(Material.AIR);
  260.         ((Block)this.bloco.get(loc1)).setType(Material.AIR);
  261.       }
  262.       for (Location loc1 : cuboid)
  263.       {
  264.         loc1.getBlock().setType(Material.AIR);
  265.         ((Block)this.bloco.get(loc1)).setType(Material.AIR);
  266.       }
  267.     }
  268.   }
  269.  
  270.   @SuppressWarnings("static-access")
  271. @EventHandler(priority=EventPriority.HIGHEST)
  272.   public void onDeathGladiator(PlayerDeathEvent e)
  273.   {
  274.     Player p = e.getEntity();
  275.     if (fighting.containsKey(p.getName())){
  276.       Player k = Bukkit.getServer().getPlayer((String)fighting.get(p.getName()));
  277.       Location old = (Location)this.oldl.get(p.getName());
  278.       k.teleport(old);
  279.       Bukkit.getScheduler().cancelTask(this.id1);
  280.       Bukkit.getScheduler().cancelTask(this.id2);
  281.       k.removePotionEffect(PotionEffectType.WITHER);
  282.       k.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100, 10));
  283.      
  284.         ItemStack Item = new ItemStack(Material.IRON_FENCE);
  285.         ItemMeta kItem = Item.getItemMeta();
  286.         kItem.setDisplayName("§7➳ §a§lGladiator" + KitAPI.getKit(p));
  287.         Item.setItemMeta(kItem);
  288.        
  289.       fighting.remove(k.getName());
  290.       fighting.remove(p.getName());
  291.       noExecut.remove(p);
  292.       noExecut.remove(k);
  293.         if(KitAPI.getKit(p) == "Gladiator"){
  294.             p.getInventory().setItem(1, Item);
  295.         }
  296.         if(KitAPI.getKit(k) == "Gladiator"){
  297.             k.getInventory().setItem(1, Item);
  298.         }
  299.       Location loc = (Location)this.localizacao.get(p);
  300.       List<Location> cuboid = new ArrayList<Location>();
  301.       cuboid.clear();
  302.       int bY;
  303.       for (int bX = -10; bX <= 10; bX++) {
  304.         for (int bZ = -10; bZ <= 10; bZ++) {
  305.           for (bY = -1; bY <= 10; bY++) {
  306.             if (bY == 10) {
  307.               cuboid.add(loc.clone().add(bX, bY, bZ));
  308.             } else if (bY == -1) {
  309.               cuboid.add(loc.clone().add(bX, bY, bZ));
  310.             } else if ((bX == -10) || (bZ == -10) || (bX == 10) || (bZ == 10)) {
  311.               cuboid.add(loc.clone().add(bX, bY, bZ));
  312.             }
  313.           }
  314.         }
  315.       }
  316.       for (Location loc1 : cuboid)
  317.       {
  318.         loc1.getBlock().setType(Material.AIR);
  319.         if (this.bloco.containsKey(loc1)) {
  320.           ((Block)this.bloco.get(loc1)).setType(Material.AIR);
  321.         }
  322.       }
  323.       return;
  324.     }
  325.   }
  326.     @EventHandler
  327.     public void processocommand(PlayerCommandPreprocessEvent e){
  328.         Player p = e.getPlayer();
  329.         if(noExecut.contains(p)){
  330.             if(e.getMessage().toLowerCase().startsWith("/spawn") && (e.getMessage().toLowerCase().startsWith("/warp"))&& (e.getMessage().toLowerCase().startsWith("/warps"))) {
  331.            
  332.                     e.setCancelled(true);
  333.                     p.sendMessage(Main.Name + "Você está em uma batalha de §bGladiator§f, portanto não poderá usar comandos.");
  334.                 }
  335.             }
  336.         }
  337.  
  338. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top