Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.63 KB | None | 0 0
  1. package br.com.battlecraft.kitpvp.kits;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.Sound;
  12. import org.bukkit.block.Block;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.EventPriority;
  16. import org.bukkit.event.Listener;
  17. import org.bukkit.event.player.PlayerInteractEntityEvent;
  18. import org.bukkit.inventory.ItemStack;
  19. import org.bukkit.potion.PotionEffect;
  20. import org.bukkit.potion.PotionEffectType;
  21.  
  22. import br.com.battlecraft.kitpvp.BukkitMain;
  23. import br.com.battlecraft.kitpvp.api.KitAPI;
  24. import br.com.battlecraft.kitpvp.api.TittleAPI;
  25. import br.com.battlecraft.kitpvp.warps.Spawn.SpawnItens;
  26. import br.com.battlecraft.kitpvp.warps.Spawn.SpawnWarpListener;
  27.  
  28. public final class Gladiator implements Listener {
  29.  
  30. public static final void showPlayer(final Player one, final Player two) {
  31. while (inFight.get(one.getName()) == two.getName() && inFight.get(two.getName()) == one.getName()) {
  32. one.showPlayer(two);
  33. two.showPlayer(one);
  34. }
  35. }
  36.  
  37. public static final void setGladiatorKit(final Player bp) {
  38. PvP.defaultItens(bp);
  39. KitAPI.setKit(bp, "Gladiator");
  40. bp.getInventory().setItem(0, new ItemStack(Material.DIAMOND_SWORD));
  41. bp.getInventory().setItem(1, SpawnItens.newItem(Material.IRON_FENCE, "§3§lGladiator", 1, (byte) 0));
  42. bp.sendMessage("§3§lKIT§f Você selecionou o kit §b§lGladiator");
  43. TittleAPI.sendTittle(bp, "§bKit Gladiator");
  44. TittleAPI.sendSubTittle(bp, "§fescolhido com sucesso!");
  45. bp.playSound(bp.getLocation(), Sound.LEVEL_UP, 2.0F, 1.0F);
  46. }
  47.  
  48. public static final HashMap<String, String> inFight = new HashMap<>();
  49. public static final HashMap<String, Location> oldLocation = new HashMap<>();
  50. public static final HashMap<String, List<Location>> blocks = new HashMap<>();
  51.  
  52. @EventHandler(priority = EventPriority.MONITOR)
  53. public final void onGladiator(final PlayerInteractEntityEvent e) {
  54. final Player bp = e.getPlayer();
  55. if (e.getRightClicked() instanceof Player) {
  56. final Player toGlad = (Player) e.getRightClicked();
  57. if (KitAPI.getKit(bp) == "Gladiator" && bp.getItemInHand().getType() == Material.IRON_FENCE) {
  58. if (inFight.containsKey(bp.getName())) {
  59. return;
  60. }
  61. if (SpawnWarpListener.onWarpSpawnProtection.contains(toGlad)) {
  62. bp.sendMessage("§3§lGLADIATOR§f Este jogador esta com proteçao de spawn.");
  63. return;
  64. }
  65. newGladiatorArena(bp, toGlad, bp.getLocation());
  66. }
  67. }
  68. }
  69.  
  70. public static int id = 0;
  71.  
  72. @SuppressWarnings("deprecation")
  73. public static final Object newGladiatorArena(final Player p1, final Player p2, final Location loc) {
  74. if (id > 15) {
  75. id = 0;
  76. }
  77. id++;
  78. double x = loc.getX();
  79. double y = loc.getY();
  80. double z = loc.getZ();
  81. Location loc1 = new Location(p1.getWorld(), x, y + 120, z);
  82. Location loc2 = new Location(p1.getWorld(), x, y + 120, z + 8);
  83. Location loc3 = new Location(p1.getWorld(), x - 8, y + 120, z - 8);
  84. loc1.getWorld().refreshChunk(loc1.getChunk().getX(), loc1.getChunk().getZ());
  85.  
  86. final List<Location> location = new ArrayList<Location>();
  87. location.clear();
  88. for (int blockX = -10; blockX <= 10; blockX++) {
  89. for (int blockZ = -10; blockZ <= 10; blockZ++) {
  90. for (int blockY = -1; blockY <= 10; blockY++) {
  91. Block b = loc1.clone().add(blockX, blockY, blockZ).getBlock();
  92. if (!b.isEmpty()) {
  93. Random random = new Random();
  94. x = random.nextInt(500);
  95. z = random.nextInt(500);
  96. Location newLoc = new Location(p1.getWorld(), loc1.getBlockX() + x, 120, loc1.getBlockZ() + z);
  97. return newGladiatorArena(p1, p2, newLoc);
  98. }
  99. if (blockY == 10) {
  100. location.add(loc1.clone().add(blockX, blockY, blockZ));
  101. } else if (blockY == -1) {
  102. location.add(loc1.clone().add(blockX, blockY, blockZ));
  103. } else if ((blockX == -10) || (blockZ == -10) || (blockX == 10) || (blockZ == 10)) {
  104. location.add(loc1.clone().add(blockX, blockY, blockZ));
  105. }
  106. }
  107. }
  108. }
  109. for (Location arena : location) {
  110. arena.getBlock().setTypeIdAndData(95, (byte) id, true);
  111. }
  112. oldLocation.put(p1.getName(), p1.getLocation());
  113. oldLocation.put(p2.getName(), p2.getLocation());
  114. blocks.put(p1.getName(), location);
  115. blocks.put(p2.getName(), location);
  116. inFight.put(p1.getName(), p2.getName());
  117. inFight.put(p2.getName(), p1.getName());
  118. loc2.setYaw(135.0F);
  119. p1.teleport(new Location(p1.getWorld(), loc2.getX() + 8, loc2.getY() + 1, loc2.getZ() + 1));
  120. loc3.setYaw(-45.0F);
  121. p2.teleport(new Location(p2.getWorld(), loc3.getX() + 1.20, loc3.getY() + 1, loc1.getZ() + -8.5));
  122.  
  123. p1.sendMessage("§3§lGLADIATOR§f Voce desafiou o player §b§l" + p2.getName() + "§f para uma batalha 1v1!");
  124. p2.sendMessage("§3§lGLADIATOR§f Voce foi desafiado pelo player " + p1.getName() + "§f para uma batalha 1v1!");
  125. showPlayer(p1, p2);
  126.  
  127. Bukkit.getScheduler().scheduleSyncDelayedTask(BukkitMain.getPlugin(), new Runnable() {
  128. @Override
  129. public void run() {
  130. if (blocks.containsKey(p1.getName()) && blocks.containsKey(p2.getName())) {
  131. if (blocks.get(p1.getName()) == location && blocks.get(p2.getName()) == location
  132. && inFight.get(p1.getName()) == p2.getName() && inFight.get(p2.getName()) == p1.getName()) {
  133. p1.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 10000, 2));
  134. p2.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 10000, 2));
  135. }
  136. }
  137. }
  138. }, 2400L);
  139. Bukkit.getScheduler().scheduleSyncDelayedTask(BukkitMain.getPlugin(), new Runnable() {
  140. @Override
  141. public void run() {
  142. if (blocks.containsKey(p1.getName()) && blocks.containsKey(p2.getName())) {
  143. if (blocks.get(p1.getName()) == location && blocks.get(p2.getName()) == location
  144. && inFight.get(p1.getName()) == p2.getName() && inFight.get(p2.getName()) == p1.getName()) {
  145. p1.teleport(oldLocation.get(p1.getName()));
  146. p2.teleport(oldLocation.get(p2.getName()));
  147. for (PotionEffect pot : p1.getActivePotionEffects()) {
  148. p1.removePotionEffect(pot.getType());
  149. }
  150. for (PotionEffect pot : p2.getActivePotionEffects()) {
  151. p2.removePotionEffect(pot.getType());
  152. }
  153. for (Location loc : blocks.get(p1.getName())) {
  154. loc.getBlock().setType(Material.AIR);
  155. }
  156. for (Location loc : blocks.get(p2.getName())) {
  157. loc.getBlock().setType(Material.AIR);
  158. }
  159. blocks.remove(p1.getName());
  160. inFight.remove(p1.getName());
  161. oldLocation.remove(p1.getName());
  162. blocks.remove(p2.getName());
  163. inFight.remove(p2.getName());
  164. oldLocation.remove(p2.getName());
  165.  
  166. p1.sendMessage("§3§lGLADIATOR§f Nao houve vencedores! Voce foi teleportado para onde estava.");
  167. p2.sendMessage("§3§lGLADIATOR§f Nao houve vencedores! Voce foi teleportado para onde estava.");
  168. }
  169. }
  170. }
  171. }, 3600L);
  172. return null;
  173. }
  174.  
  175. public static final void resetGladiatorByKill(final Player winner, final Player loser) {
  176. for (int i = 1; i < 5; i++) {
  177. winner.teleport(oldLocation.get(winner.getName()));
  178. }
  179. for (int i = 1; i < 5; i++) {
  180. loser.teleport(oldLocation.get(loser.getName()));
  181. }
  182. for (PotionEffect pot : winner.getActivePotionEffects()) {
  183. winner.removePotionEffect(pot.getType());
  184. }
  185. for (PotionEffect pot : loser.getActivePotionEffects()) {
  186. loser.removePotionEffect(pot.getType());
  187. }
  188. for (Location loc : blocks.get(winner.getName())) {
  189. loc.getBlock().setType(Material.AIR);
  190. }
  191. for (Location loc : blocks.get(loser.getName())) {
  192. loc.getBlock().setType(Material.AIR);
  193. }
  194. blocks.remove(winner.getName());
  195. inFight.remove(winner.getName());
  196. oldLocation.remove(winner.getName());
  197. blocks.remove(loser.getName());
  198. inFight.remove(loser.getName());
  199. oldLocation.remove(loser.getName());
  200.  
  201. winner.sendMessage("§3§lGLADIATOR§f Voce venceu a batalha contra §b§l" + loser.getName());
  202. loser.sendMessage("§3§lGLADIATOR§f Voce perdeu a batalha contra §b§l" + winner.getName());
  203. }
  204.  
  205. public static final void resetGladiatorByScreenshare(final Player winner, final Player loser) {
  206. for (int i = 1; i < 5; i++) {
  207. winner.teleport(oldLocation.get(winner.getName()));
  208. }
  209. for (PotionEffect pot : winner.getActivePotionEffects()) {
  210. winner.removePotionEffect(pot.getType());
  211. }
  212. for (PotionEffect pot : loser.getActivePotionEffects()) {
  213. loser.removePotionEffect(pot.getType());
  214. }
  215. for (Location loc : blocks.get(winner.getName())) {
  216. loc.getBlock().setType(Material.AIR);
  217. }
  218. for (Location loc : blocks.get(loser.getName())) {
  219. loc.getBlock().setType(Material.AIR);
  220. }
  221. blocks.remove(winner.getName());
  222. inFight.remove(winner.getName());
  223. oldLocation.remove(winner.getName());
  224. blocks.remove(loser.getName());
  225. inFight.remove(loser.getName());
  226. oldLocation.remove(loser.getName());
  227.  
  228. winner.sendMessage("§c" + loser.getName() + " foi puxado para screenshare.");
  229. }
  230.  
  231. public static final void resetGladiatorByTpAll(final Player winner, final Player loser) {
  232. for (PotionEffect pot : winner.getActivePotionEffects()) {
  233. winner.removePotionEffect(pot.getType());
  234. }
  235. for (PotionEffect pot : loser.getActivePotionEffects()) {
  236. loser.removePotionEffect(pot.getType());
  237. }
  238. for (Location loc : blocks.get(winner.getName())) {
  239. loc.getBlock().setType(Material.AIR);
  240. }
  241. for (Location loc : blocks.get(loser.getName())) {
  242. loc.getBlock().setType(Material.AIR);
  243. }
  244. blocks.remove(winner.getName());
  245. inFight.remove(winner.getName());
  246. oldLocation.remove(winner.getName());
  247. blocks.remove(loser.getName());
  248. inFight.remove(loser.getName());
  249. oldLocation.remove(loser.getName());
  250. }
  251.  
  252. public static final void resetGladiatorByQuit(final Player winner, final Player loser) {
  253. for (int i = 1; i < 5; i++) {
  254. winner.teleport(oldLocation.get(winner.getName()));
  255. }
  256. for (PotionEffect pot : winner.getActivePotionEffects()) {
  257. winner.removePotionEffect(pot.getType());
  258. }
  259. for (PotionEffect pot : loser.getActivePotionEffects()) {
  260. loser.removePotionEffect(pot.getType());
  261. }
  262. for (Location loc : blocks.get(winner.getName())) {
  263. loc.getBlock().setType(Material.AIR);
  264. }
  265. for (Location loc : blocks.get(loser.getName())) {
  266. loc.getBlock().setType(Material.AIR);
  267. }
  268. blocks.remove(winner.getName());
  269. inFight.remove(winner.getName());
  270. oldLocation.remove(winner.getName());
  271. blocks.remove(loser.getName());
  272. inFight.remove(loser.getName());
  273. oldLocation.remove(loser.getName());
  274.  
  275. winner.sendMessage("§3§lGLADIATOR§f O player §b§l" + loser.getName() + "§f deslogou.");
  276. }
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement