Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
  2. Player entity = (Player) event.getEntity();
  3.  
  4. ItemStack is;
  5. Potion p = null;
  6.  
  7. is = new ItemStack(Material.POTION);
  8.  
  9. // Apply Potion Effect
  10. // [!] Make sure to not apply damage effect
  11. Random ran = new Random();
  12. int ranNum = ran.nextInt(3);
  13.  
  14. if (ranNum == 0) {
  15. p = new Potion(PotionType.INSTANT_DAMAGE, 1);
  16. } else if (ranNum == 1){
  17. p = new Potion(PotionType.SLOWNESS, 1);
  18. } else if (ranNum == 2) {
  19. p = new Potion(PotionType.POISON, 1);
  20. }
  21.  
  22. p.setSplash(true);
  23. p.apply(is);
  24.  
  25. ThrownPotion tp = (ThrownPotion) entity.getWorld().spawnEntity(entity.getLocation(), EntityType.SPLASH_POTION);
  26. tp.setMetadata("player", new FixedMetadataValue(SpecialWeapons.getInstance(), entity.getName()));
  27. tp.setItem(is);
  28. tp.setShooter(entity);
  29. }
  30. }
  31.  
  32. @EventHandler
  33. public void onPotionSplash(PotionSplashEvent event) {
  34. ThrownPotion tp = event.getPotion();
  35.  
  36. for (LivingEntity livingEntityList : event.getAffectedEntities()) {
  37. if (livingEntityList.getType() == EntityType.PLAYER) {
  38. final Player targetPlayer = (Player) livingEntityList;
  39. Player shooterPlayer = (Player) tp.getShooter();
  40.  
  41. if (!(shooterPlayer.getName() == targetPlayer.getName())) {
  42. event.getAffectedEntities().remove(livingEntityList);
  43.  
  44. for (PotionEffect potionEffectList : event.getPotion().getEffects()) {
  45. final PotionEffectType potionEffectType = potionEffectList.getType();
  46.  
  47. new BukkitRunnable() {
  48. public void run() {
  49. targetPlayer.removePotionEffect(potionEffectType);
  50. }
  51. }.runTaskLater(SpecialWeapons.getInstance(), 3L);
  52. }
  53. }
  54. } else {
  55. event.getAffectedEntities().remove(livingEntityList);
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement