Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.08 KB | None | 0 0
  1. package me.Nikewade.VallendiaMinigame.Utils;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collection;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import java.util.List;
  8. import java.util.Set;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.Effect;
  12. import org.bukkit.GameMode;
  13. import org.bukkit.Location;
  14. import org.bukkit.Material;
  15. import org.bukkit.Particle;
  16. import org.bukkit.block.Block;
  17. import org.bukkit.block.BlockFace;
  18. import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
  19. import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
  20. import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
  21. import org.bukkit.entity.ArmorStand;
  22. import org.bukkit.entity.Entity;
  23. import org.bukkit.entity.EntityType;
  24. import org.bukkit.entity.LivingEntity;
  25. import org.bukkit.entity.Player;
  26. import org.bukkit.entity.Projectile;
  27. import org.bukkit.entity.Snowball;
  28. import org.bukkit.event.EventHandler;
  29. import org.bukkit.event.Listener;
  30. import org.bukkit.event.block.Action;
  31. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  32. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
  33. import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
  34. import org.bukkit.event.entity.EntityExplodeEvent;
  35. import org.bukkit.event.entity.ProjectileHitEvent;
  36. import org.bukkit.event.player.PlayerInteractEvent;
  37. import org.bukkit.event.player.PlayerMoveEvent;
  38. import org.bukkit.metadata.FixedMetadataValue;
  39. import org.bukkit.potion.PotionEffect;
  40. import org.bukkit.potion.PotionEffectType;
  41. import org.bukkit.scheduler.BukkitRunnable;
  42. import org.bukkit.scheduler.BukkitTask;
  43.  
  44. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  45. import com.sk89q.worldguard.protection.managers.RegionManager;
  46. import com.sk89q.worldguard.protection.regions.ProtectedRegion;
  47.  
  48. import de.slikey.effectlib.effect.SphereEffect;
  49. import me.Nikewade.VallendiaMinigame.VallendiaMinigame;
  50. import me.Nikewade.VallendiaMinigame.Abilities.FlyAbility;
  51. import me.Nikewade.VallendiaMinigame.Events.PlayerItemEvents;
  52. import me.Nikewade.VallendiaMinigame.Graphics.ScoreboardHandler;
  53. import net.minecraft.server.v1_12_R1.Explosion;
  54. import net.minecraft.server.v1_12_R1.PacketPlayOutEntityDestroy;
  55.  
  56. public class AbilityUtils implements Listener {
  57. private static Set<Material> transparentBlocks = null;
  58. private static HashMap<Block, Integer> explosives = new HashMap<>();
  59. public static HashMap<Entity, Integer> explosivesEntities = new HashMap<>();
  60. public static HashMap<LivingEntity, BukkitTask> silenced = new HashMap<>();
  61. public static HashMap<Player, Float> casting = new HashMap<>();
  62. public static HashMap<Player, BukkitTask> castingTask = new HashMap<>();
  63. private static HashMap<Player, BukkitTask> castingTask2 = new HashMap<>();
  64. private static HashMap<String, Double> maxHealth = new HashMap<>();
  65. private static HashMap<Projectile, Runnable> arcProjectiles = new HashMap<>();
  66. private static HashMap<LivingEntity, Integer> handleDamage = new HashMap<>();
  67. private static HashMap<Player, SphereEffect> castingParticles = new HashMap<>();
  68. static int castingHealthPercent = 70;
  69.  
  70.  
  71. //If the player already has a potion effect, this will add the existing effects duration to the new one.
  72. public static void addPotionDuration(LivingEntity e, PotionEffectType p, int amplifier, int duration )
  73. {
  74. if(!e.hasPotionEffect(p))
  75. {
  76. e.addPotionEffect(new PotionEffect(p, duration, amplifier));
  77. return;
  78. }
  79. int existingAmp = e.getPotionEffect(p).getAmplifier();
  80. int existingDuration = e.getPotionEffect(p).getDuration();
  81.  
  82. if(existingAmp < amplifier)
  83. {
  84. e.removePotionEffect(p);
  85. e.addPotionEffect(new PotionEffect(p, duration, existingAmp + amplifier));
  86. }
  87.  
  88. if(existingAmp > amplifier)
  89. {
  90. e.removePotionEffect(p);
  91. e.addPotionEffect(new PotionEffect(p, existingDuration, existingAmp + amplifier));
  92. }
  93.  
  94. if(existingAmp == amplifier)
  95. {
  96. if(existingDuration > duration)
  97. {
  98. e.removePotionEffect(p);
  99. e.addPotionEffect(new PotionEffect(p, existingDuration, existingAmp));
  100. }else
  101. {
  102. e.removePotionEffect(p);
  103. e.addPotionEffect(new PotionEffect(p, duration, existingAmp));
  104. }
  105. }
  106. }
  107.  
  108.  
  109. public static boolean partyCheck(Player p1, Player p2)
  110. {
  111. if(!getPlayerParty(p1).isEmpty() || !getPlayerParty(p2).isEmpty())
  112. {
  113. if(getPlayerParty(p1).equalsIgnoreCase(getPlayerParty(p2)))
  114. {
  115. return true;
  116. }
  117. }
  118. return false;
  119.  
  120. }
  121.  
  122. public static String getPlayerParty(Player p)
  123. {
  124. return VallendiaMinigame.getInstance().parties.getPartyPlayer(p.getUniqueId()).getPartyName();
  125. }
  126.  
  127.  
  128.  
  129. public static boolean runPassive(Player p, Player p2)
  130. {
  131. //Checking for party
  132. if(p2 != null)
  133. {
  134. if(partyCheck(p,p2))
  135. {
  136. return false;
  137. }
  138. }
  139.  
  140. RegionManager regionManager = VallendiaMinigame.getInstance().worldguard.getRegionManager(p.getWorld());
  141. ApplicableRegionSet set = regionManager.getApplicableRegions(p.getLocation());
  142.  
  143. for (ProtectedRegion region : set) {
  144.  
  145. if (region != null){
  146.  
  147. if(region.getId().equalsIgnoreCase("minigamespawn"))
  148. {
  149. return false;
  150. }
  151.  
  152. }
  153.  
  154. }
  155. return true;
  156. }
  157.  
  158.  
  159.  
  160.  
  161. public static LivingEntity getTarget(Player p, int range)
  162. {
  163.  
  164. if(p.hasPotionEffect(PotionEffectType.BLINDNESS))
  165. {
  166. p.sendMessage(Utils.Colorate("&8&l You have to be able to see to do that!"));
  167. return null;
  168. }
  169. if (p.getLocation().getBlockY() > p.getLocation().getWorld().getMaxHeight()) {
  170. return null;
  171. }
  172. try
  173. {
  174. List lineOfSight = p.getLineOfSight(AbilityUtils.transparentBlocks, range);
  175. }
  176. catch (IllegalStateException e)
  177. {
  178. return null;
  179. }
  180. Set<Location> locs = new HashSet();
  181. for (Block block : p.getLineOfSight(AbilityUtils.transparentBlocks, range))
  182. {
  183. locs.add(block.getRelative(BlockFace.UP).getLocation());
  184. locs.add(block.getLocation());
  185. locs.add(block.getRelative(BlockFace.DOWN).getLocation());
  186. }
  187. List<Block> lineOfSight = null;
  188. List<Entity> nearbyEntities = p.getNearbyEntities(range, range, range);
  189. for (Entity entity : nearbyEntities) {
  190. if (((entity instanceof LivingEntity)) && (!entity.isDead()) && (((LivingEntity)entity).getHealth() != 0.0D) &&
  191. (locs.contains(entity.getLocation().getBlock().getLocation())) && !(entity instanceof ArmorStand)) {
  192.  
  193. if(entity instanceof Player)
  194. {
  195. Player player = (Player) entity;
  196.  
  197. //In party
  198. if(partyCheck(player, p))
  199. {
  200. p.sendMessage(Utils.Colorate("&8&l Target not found."));
  201. return null;
  202. }
  203.  
  204. if(!(player.getGameMode() == GameMode.SURVIVAL) && !(player.getGameMode() == GameMode.ADVENTURE))
  205. {
  206. p.sendMessage(Utils.Colorate("&8&l Target not found."));
  207. return null;
  208. }
  209. }
  210.  
  211. if ((!(entity instanceof Player)) || (p.canSee((Player)entity))) {
  212. return (LivingEntity)entity;
  213. }
  214. }
  215. }
  216. p.sendMessage(Utils.Colorate("&8&l Target not found."));
  217. return null;
  218. }
  219.  
  220.  
  221.  
  222.  
  223. public static LivingEntity getHealingTarget(Player p, int range)
  224. {
  225.  
  226. if(p.hasPotionEffect(PotionEffectType.BLINDNESS))
  227. {
  228. p.sendMessage(Utils.Colorate("&8&l You have to be able to see to do that!"));
  229. return null;
  230. }
  231. if (p.getLocation().getBlockY() > p.getLocation().getWorld().getMaxHeight()) {
  232. return null;
  233. }
  234. try
  235. {
  236. List lineOfSight = p.getLineOfSight(AbilityUtils.transparentBlocks, range);
  237. }
  238. catch (IllegalStateException e)
  239. {
  240. return null;
  241. }
  242. Set<Location> locs = new HashSet();
  243. for (Block block : p.getLineOfSight(AbilityUtils.transparentBlocks, range))
  244. {
  245. locs.add(block.getRelative(BlockFace.UP).getLocation());
  246. locs.add(block.getLocation());
  247. locs.add(block.getRelative(BlockFace.DOWN).getLocation());
  248. }
  249. List<Block> lineOfSight = null;
  250. List<Entity> nearbyEntities = p.getNearbyEntities(range, range, range);
  251. for (Entity entity : nearbyEntities) {
  252. if (((entity instanceof LivingEntity)) && (!entity.isDead()) && (((LivingEntity)entity).getHealth() != 0.0D) &&
  253. (locs.contains(entity.getLocation().getBlock().getLocation())) && !(entity instanceof ArmorStand)) {
  254.  
  255. if(entity instanceof Player)
  256. {
  257. Player player = (Player) entity;
  258.  
  259. //Not in party
  260. if(!partyCheck((Player)entity, p))
  261. {
  262. p.sendMessage(Utils.Colorate("&8&l Target not found."));
  263. return null;
  264. }
  265.  
  266. if(!(player.getGameMode() == GameMode.SURVIVAL) && !(player.getGameMode() == GameMode.ADVENTURE))
  267. {
  268. p.sendMessage(Utils.Colorate("&8&l Target not found."));
  269. return null;
  270. }
  271. }
  272.  
  273. if ((!(entity instanceof Player)) || (p.canSee((Player)entity))) {
  274. return (LivingEntity)entity;
  275. }
  276. }
  277. }
  278. p.sendMessage(Utils.Colorate("&8&l Target not found."));
  279. return null;
  280. }
  281.  
  282.  
  283.  
  284.  
  285. public static List<Block> getLine(Player p, int range)
  286. {
  287. List<Block> lineOfSight = null;
  288. if (p.getLocation().getBlockY() > p.getLocation().getWorld().getMaxHeight()) {
  289. return null;
  290. }
  291. try
  292. {
  293. lineOfSight = p.getLineOfSight(AbilityUtils.transparentBlocks, range);
  294. }
  295. catch (IllegalStateException e)
  296. {
  297. return null;
  298. }
  299. Set<Location> locs = new HashSet();
  300. int x = 0;
  301. for (Block block : p.getLineOfSight(AbilityUtils.transparentBlocks, range))
  302. {
  303. if(x >= range)
  304. {
  305. locs.add(block.getRelative(BlockFace.UP).getLocation());
  306. locs.add(block.getLocation());
  307. locs.add(block.getRelative(BlockFace.DOWN).getLocation());
  308. }
  309. }
  310. return lineOfSight;
  311. }
  312.  
  313.  
  314.  
  315.  
  316. public static Collection<Entity> getAoeTargets(Player originplayer, Location loc, double Radiusx, double Radiusy, double Radiusz)
  317. {
  318. Collection<Entity> nearbyEntities = new ArrayList<Entity>();
  319. for(Entity entity : loc.getWorld().getNearbyEntities(loc, Radiusx, Radiusy, Radiusz))
  320. {
  321. if(entity instanceof LivingEntity && !(entity == originplayer) && !(entity instanceof ArmorStand))
  322. {
  323. if(entity instanceof Player)
  324. {
  325. Player entityplayer = (Player) entity;
  326.  
  327.  
  328. //In party
  329. if(partyCheck(entityplayer, originplayer))
  330. {
  331. continue;
  332. }
  333.  
  334. if(!(entityplayer.getGameMode() == GameMode.SURVIVAL) && !(entityplayer.getGameMode() == GameMode.ADVENTURE))
  335. {
  336. continue;
  337. }
  338. }
  339. nearbyEntities.add(entity);
  340. continue;
  341. }
  342. }
  343. return nearbyEntities;
  344.  
  345. }
  346.  
  347.  
  348.  
  349.  
  350. public static Collection<Entity> getHealingAoeTargets(Player originplayer, Location loc, double Radiusx, double Radiusy, double Radiusz)
  351. {
  352. Collection<Entity> nearbyEntities = new ArrayList<Entity>();
  353. for(Entity entity : loc.getWorld().getNearbyEntities(loc, Radiusx, Radiusy, Radiusz))
  354. {
  355. if(entity instanceof LivingEntity && !(entity == originplayer) && !(entity instanceof ArmorStand))
  356. {
  357. if(entity instanceof Player)
  358. {
  359. Player entityplayer = (Player) entity;
  360.  
  361.  
  362. //Not in party
  363. if(!partyCheck(originplayer, entityplayer))
  364. {
  365. continue;
  366. }
  367.  
  368. if(!(entityplayer.getGameMode() == GameMode.SURVIVAL) && !(entityplayer.getGameMode() == GameMode.ADVENTURE))
  369. {
  370. continue;
  371. }
  372. }
  373. nearbyEntities.add(entity);
  374. continue;
  375. }
  376. }
  377. return nearbyEntities;
  378.  
  379. }
  380.  
  381.  
  382.  
  383.  
  384.  
  385. public static void addBlocks()
  386. {
  387. transparentBlocks = new HashSet(42);
  388. transparentBlocks.add(Material.AIR);
  389. transparentBlocks.add(Material.CARPET);
  390. transparentBlocks.add(Material.CROPS);
  391. transparentBlocks.add(Material.DEAD_BUSH);
  392. transparentBlocks.add(Material.DETECTOR_RAIL);
  393. transparentBlocks.add(Material.DIODE_BLOCK_OFF);
  394. transparentBlocks.add(Material.DIODE_BLOCK_ON);
  395. transparentBlocks.add(Material.DIODE);
  396. transparentBlocks.add(Material.FENCE_GATE);
  397. transparentBlocks.add(Material.FLOWER_POT);
  398. transparentBlocks.add(Material.LADDER);
  399. transparentBlocks.add(Material.LEVER);
  400. transparentBlocks.add(Material.LONG_GRASS);
  401. transparentBlocks.add(Material.DOUBLE_PLANT);
  402. transparentBlocks.add(Material.NETHER_WARTS);
  403. transparentBlocks.add(Material.PORTAL);
  404. transparentBlocks.add(Material.POWERED_RAIL);
  405. transparentBlocks.add(Material.RAILS);
  406. transparentBlocks.add(Material.RED_ROSE);
  407. transparentBlocks.add(Material.REDSTONE_COMPARATOR_OFF);
  408. transparentBlocks.add(Material.REDSTONE_COMPARATOR_ON);
  409. transparentBlocks.add(Material.REDSTONE_COMPARATOR);
  410. transparentBlocks.add(Material.REDSTONE_TORCH_OFF);
  411. transparentBlocks.add(Material.REDSTONE_TORCH_ON);
  412. transparentBlocks.add(Material.REDSTONE_WIRE);
  413. transparentBlocks.add(Material.SAPLING);
  414. transparentBlocks.add(Material.SIGN_POST);
  415. transparentBlocks.add(Material.SIGN);
  416. transparentBlocks.add(Material.SNOW);
  417. transparentBlocks.add(Material.STATIONARY_LAVA);
  418. transparentBlocks.add(Material.STATIONARY_WATER);
  419. transparentBlocks.add(Material.STONE_BUTTON);
  420. transparentBlocks.add(Material.STONE_PLATE);
  421. transparentBlocks.add(Material.SUGAR_CANE_BLOCK);
  422. transparentBlocks.add(Material.TORCH);
  423. transparentBlocks.add(Material.TRIPWIRE);
  424. transparentBlocks.add(Material.VINE);
  425. transparentBlocks.add(Material.WALL_SIGN);
  426. transparentBlocks.add(Material.WATER_LILY);
  427. transparentBlocks.add(Material.WATER);
  428. transparentBlocks.add(Material.WEB);
  429. transparentBlocks.add(Material.WOOD_BUTTON);
  430. transparentBlocks.add(Material.WOOD_PLATE);
  431. transparentBlocks.add(Material.YELLOW_FLOWER);
  432.  
  433. }
  434.  
  435.  
  436. //Makes and explosion and stores it so you can set its damage.. The damageSubtraction is what we subtract from the normal explosion damage.
  437. public static void explode(Location loc, Entity explodeAs, int power, int damage, boolean setFires, boolean terrainDamage, boolean particles) {
  438. Explosion explosion = new Explosion(((CraftWorld)loc.getWorld()).
  439. getHandle(), ((CraftEntity)explodeAs).getHandle(), loc.getX(),
  440. loc.getY(), loc.getZ(), (float)power, setFires, terrainDamage);
  441. explosives.put(loc.getBlock(), damage);
  442. explosivesEntities.put(explodeAs, damage);
  443. explosion.a();
  444. explosion.a(true);
  445. if (particles) {
  446. loc.getWorld().playEffect(loc, Effect.EXPLOSION_HUGE, power);
  447. }
  448.  
  449. loc.getBlock().setMetadata(explodeAs.getName(), new FixedMetadataValue(VallendiaMinigame.getInstance(), loc.getBlock()));
  450. }
  451.  
  452.  
  453. public static void silenceAbilities(LivingEntity e, int seconds, String ability)
  454. {
  455. if(silenced.containsKey(e))
  456. {
  457. silenced.remove(e);
  458. }
  459.  
  460. if(e instanceof Player )
  461. {
  462. Player p = (Player) e;
  463. if(casting.containsKey(p))
  464. {
  465. removeCast(p);
  466. Language.sendDefaultMessage(p, "Your casting was interrupted.");
  467. }
  468. }
  469.  
  470. BukkitTask task = new BukkitRunnable() {
  471. @Override
  472. public void run() {
  473. if(silenced.containsKey(e))
  474. {
  475. silenced.remove(e);
  476. Language.sendAbilityUseMessage(e, "Your abilities are no longer silenced.", ability);
  477. }
  478. }
  479. }.runTaskLater(VallendiaMinigame.getInstance(), seconds*20L);
  480.  
  481. silenced.put(e, task);
  482. }
  483.  
  484.  
  485. public static void removeSilence(LivingEntity e)
  486. {
  487. if(silenced.containsKey(e))
  488. {
  489. silenced.remove(e);
  490. }
  491. }
  492.  
  493.  
  494. public static boolean castAbility(Player p, int seconds, Runnable run)
  495. {
  496. if(!casting.containsKey(p))
  497. {
  498. casting.put(p, p.getWalkSpeed());
  499. }else
  500. {
  501. Language.sendDefaultMessage(p, "You are already casting!");
  502. return false;
  503. }
  504.  
  505. p.setWalkSpeed((float) 0.07);
  506. SphereEffect se = new SphereEffect(VallendiaMinigame.getInstance().effectmanager);
  507. se.setEntity(p);
  508. se.disappearWithOriginEntity = true;
  509. se.infinite();
  510. se.particle = Particle.ENCHANTMENT_TABLE;
  511. se.radius = 0.4;
  512. se.particles = 1;
  513. se.yOffset = -0.4;
  514. se.particleOffsetZ = (float) 0.4;
  515. se.speed = (float) 0;
  516. se.start();
  517. castingParticles.put(p, se);
  518.  
  519.  
  520. BukkitTask task2 = new BukkitRunnable() {
  521. int x = seconds;
  522. @Override
  523. public void run() {
  524. if(casting.containsKey(p))
  525. {
  526. p.sendTitle(Utils.Colorate("&3&lCasting " + x), null, 0, 21, 0);
  527. x--;
  528. }else this.cancel();
  529. }
  530. }.runTaskTimer(VallendiaMinigame.getInstance(), 0, 20L);
  531.  
  532. BukkitTask task = new BukkitRunnable() {
  533. @Override
  534. public void run() {
  535. if(casting.containsKey(p))
  536. {
  537. removeCast(p);
  538. run.run();
  539. }
  540. }
  541. }.runTaskLater(VallendiaMinigame.getInstance(), seconds*20L);
  542. castingTask.put(p, task);
  543. castingTask2.put(p, task2);
  544.  
  545.  
  546.  
  547. return true;
  548. }
  549.  
  550.  
  551.  
  552.  
  553. public static void removeCast(Player p)
  554. {
  555. if(casting.containsKey(p))
  556. {
  557. p.setWalkSpeed(casting.get(p));
  558. casting.remove(p);
  559. castingTask.get(p).cancel();
  560. castingTask.remove(p);
  561. castingTask2.get(p).cancel();
  562. castingTask2.remove(p);
  563. castingParticles.get(p).cancel();
  564. castingParticles.remove(p);
  565. }
  566. }
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573. public static Listener getListener() {
  574. return new Listener() {
  575.  
  576. @EventHandler
  577. public void onExplode(EntityExplodeEvent e)
  578. {
  579. if(explosives.containsKey(e.getLocation().getBlock()))
  580. {
  581. e.setYield(0);
  582. for (Block b : new ArrayList<Block>(e.blockList()))
  583. {
  584.  
  585. if((b.getType() == Material.TORCH) || (b.getType() == Material.REDSTONE_TORCH_ON) || (b.getType() == Material.REDSTONE_TORCH_OFF) || (b.getType() == Material.BANNER)|| (b.getType() == Material.STANDING_BANNER)|| (b.getType() == Material.WALL_BANNER) || (b.getType() == Material.FLOWER_POT) || (b.getType() == Material.ITEM_FRAME) || (b.getType() == Material.PAINTING))
  586. {
  587. e.blockList().remove(b);
  588. continue;
  589. }
  590.  
  591. Utils.regenBlock(b, 30);
  592. b.setType(Material.AIR);
  593. }
  594. }
  595. }
  596.  
  597.  
  598. @EventHandler
  599. public void onEntityExplode(EntityExplodeEvent e)
  600. {
  601. if(explosivesEntities.containsKey(e.getEntity()))
  602. {
  603. explosivesEntities.remove(e.getEntity());
  604. }
  605. }
  606.  
  607. @EventHandler
  608. public void onDamage(EntityDamageByEntityEvent e)
  609. {
  610.  
  611. if(e.getEntity() instanceof ArmorStand)
  612. {
  613. return;
  614. }
  615. if(explosivesEntities.containsKey(e.getDamager()))
  616. {
  617. if(e.getDamager() instanceof Player && e.getCause() == DamageCause.ENTITY_EXPLOSION)
  618. {
  619. e.setDamage(0);
  620. e.setDamage(DamageModifier.ARMOR, (explosivesEntities.get(e.getDamager())));
  621. explosivesEntities.remove(e.getDamager());
  622. }
  623. }
  624.  
  625. if(e.getEntity() instanceof Player && casting.containsKey(e.getEntity()))
  626. {
  627. Player p = (Player) e.getEntity();
  628. double currentHealth = p.getHealth() - e.getFinalDamage();
  629. double lowestHealth = p.getMaxHealth() * Utils.getPercentHigherOrLower(castingHealthPercent, false);
  630. if(currentHealth <= lowestHealth)
  631. {
  632. removeCast((Player) e.getEntity());
  633. Language.sendDefaultMessage((Player) e.getEntity(), "Your casting was interrupted.");
  634. }
  635. }
  636.  
  637. if(handleDamage.containsKey(e.getEntity()))
  638. {
  639. e.setDamage(0);
  640. e.setDamage(DamageModifier.ARMOR, handleDamage.get(e.getEntity()));
  641. handleDamage.remove(e.getEntity());
  642. }
  643. }
  644.  
  645. @EventHandler
  646. public void onMove(PlayerMoveEvent e)
  647. {
  648.  
  649. if(casting.containsKey(e.getPlayer()) &&
  650. !FlyAbility.enabled.contains(e.getPlayer()))
  651. {
  652. if(e.getTo().getY() > e.getFrom().getY() && !e.getPlayer().isOnGround())
  653. {
  654. e.setCancelled(true);
  655. }
  656. }
  657. }
  658.  
  659. @EventHandler
  660. public void leftClick(PlayerInteractEvent e)
  661. {
  662. if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK)
  663. {
  664. if(casting.containsKey(e.getPlayer()))
  665. {
  666. if(PlayerItemEvents.casting.containsKey(e.getPlayer()))
  667. {
  668. PlayerItemEvents.casting.get(e.getPlayer()).cancel();
  669. PlayerItemEvents.casting.remove(e.getPlayer());
  670. }
  671. AbilityUtils.removeCast(e.getPlayer());
  672. Language.sendDefaultMessage(e.getPlayer(), "You stop casting.");
  673. }
  674. }
  675. }
  676.  
  677. @EventHandler
  678. public void projectileHit(ProjectileHitEvent e)
  679. {
  680. if(e.getEntityType() == EntityType.SNOWBALL && e.getEntity().getShooter() instanceof Player && arcProjectiles.containsKey(e.getEntity()))
  681. {
  682. arcProjectiles.get(e.getEntity()).run();
  683. }
  684. }
  685.  
  686.  
  687. };
  688. }
  689.  
  690.  
  691. public static void healEntity(LivingEntity p, double amount)
  692. {
  693. if(p.getHealth() + amount >= p.getMaxHealth())
  694. {
  695. p.setHealth(p.getMaxHealth());
  696. }else p.setHealth(p.getHealth() + amount);
  697.  
  698.  
  699. p.getWorld().spawnParticle(Particle.HEART, p.getLocation().add(0, 0.4, 0.4), 5);
  700. p.getWorld().spawnParticle(Particle.HEART, p.getLocation().add(0, 0.4, 0), 5);
  701. p.getWorld().spawnParticle(Particle.HEART, p.getLocation().add(0.4, 0.4, 0), 5);
  702. if(p instanceof Player)
  703. {
  704. ScoreboardHandler.updateMaxHealth((Player) p);
  705. }
  706. }
  707.  
  708. public static void damageEntity(LivingEntity target, LivingEntity damager, int amount)
  709. {
  710. handleDamage.put(target, amount);
  711. target.damage(amount, damager);
  712. }
  713.  
  714.  
  715. public static void setMaxHealth(Player p, double amount, String ability)
  716. {
  717. double healthAdded = amount - p.getMaxHealth();
  718. p.setMaxHealth(amount);
  719. if(!maxHealth.containsKey(p.toString()+ability))
  720. {
  721. maxHealth.put(p.toString()+ability, healthAdded);
  722. }
  723. ScoreboardHandler.updateMaxHealth(p);
  724. }
  725.  
  726. public static void resetMaxHealth(Player p, String ability)
  727. {
  728.  
  729. if(maxHealth.containsKey(p.toString()+ability))
  730. {
  731. p.setMaxHealth(p.getMaxHealth() - maxHealth.get(p.toString()+ability));
  732. maxHealth.remove(p.toString()+ability);
  733. }
  734. ScoreboardHandler.updateMaxHealth(p);
  735. }
  736.  
  737. public static void resetAllMaxHealth(Player p)
  738. {
  739. for(String s : maxHealth.keySet())
  740. {
  741. if(s.contains(p.toString()))
  742. {
  743. p.setMaxHealth(p.getMaxHealth() - maxHealth.get(s));
  744. maxHealth.remove(s);
  745. ScoreboardHandler.updateMaxHealth(p);
  746. }
  747. }
  748. }
  749.  
  750.  
  751.  
  752. public static void arcParticle(LivingEntity e, de.slikey.effectlib.Effect effect, double velocity, Runnable run)
  753. {
  754. Snowball ball = e.launchProjectile(Snowball.class);
  755. ball.setSilent(true);
  756. ball.setVelocity(ball.getVelocity().multiply(velocity));
  757. arcProjectiles.put(ball, run);
  758.  
  759. BukkitTask task = new BukkitRunnable() {
  760. @Override
  761. public void run() {
  762. if(ball.isDead())
  763. {
  764. this.cancel();
  765. }
  766.  
  767. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
  768. PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ball.getEntityId());
  769. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
  770. }
  771.  
  772. }
  773. }.runTaskTimer(VallendiaMinigame.getInstance(), 0, 1);
  774.  
  775. effect.setEntity(ball);
  776. effect.start();
  777. }
  778.  
  779.  
  780. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement