Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. package fr.hikings.warzone.listeners;
  2.  
  3. import org.bukkit.Effect;
  4. import org.bukkit.Location;
  5. import org.bukkit.Sound;
  6. import org.bukkit.World;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  11.  
  12. import com.massivecraft.factions.FPlayer;
  13. import com.massivecraft.factions.FPlayers;
  14. import com.sk89q.worldguard.protection.ApplicableRegionSet;
  15. import com.sk89q.worldguard.protection.flags.DefaultFlag;
  16. import com.sk89q.worldguard.protection.flags.StateFlag;
  17.  
  18. import fr.hikings.warzone.Main;
  19.  
  20. public class EntityKill implements Listener {
  21. private Main main;
  22.  
  23. public EntityKill(Main main) {
  24. this.main = main;
  25. }
  26.  
  27. @EventHandler (ignoreCancelled = true)
  28. public void onEntityKill(EntityDamageByEntityEvent e) {
  29. if(e.getEntity() != null && e.getDamager() != null && e.getDamage() > 0) {
  30. if((e.getEntity() instanceof Player) && (e.getDamager() instanceof Player)) {
  31.  
  32. final Player victime = (Player) e.getEntity();
  33. final Player damager = (Player) e.getDamager();
  34.  
  35. if((victime != damager) && main.isActivate ) {
  36.  
  37. if(victime.getHealth() - e.getFinalDamage() <= 0) {
  38. final Location location = e.getEntity().getLocation();
  39. final Location head = e.getEntity().getLocation().add(0, 1, 0);
  40. final World world = location.getWorld();
  41.  
  42.  
  43. if(inWarzone(location)) {
  44. final ApplicableRegionSet set = main.getWorldGuard().getRegionManager(location.getWorld()).getApplicableRegions(location);
  45. final FPlayer fdamager = FPlayers.getInstance().getByPlayer(damager);
  46. final FPlayer fvictime = FPlayers.getInstance().getByPlayer(victime);
  47.  
  48. if(set.queryState(null, DefaultFlag.PVP) == StateFlag.State.ALLOW) {
  49. if(fdamager != null && fdamager.hasFaction() && fdamager.getFaction().isNormal()) {
  50. final String fid = fdamager.getFactionId();
  51.  
  52. int points = 1;
  53. if(main.kill.containsKey(fid)) {
  54. points += main.kill.get(fid);
  55. } main.kill.put(fid, points);
  56. }
  57.  
  58. if(fvictime != null && fvictime.hasFaction() && fvictime.getFaction().isNormal()) {
  59. final String fid = fvictime.getFactionId();
  60.  
  61. int points = 1;
  62. if(main.death.containsKey(fid)) {
  63. points += main.death.get(fid);
  64. } main.death.put(fid, points);
  65. }
  66.  
  67. fdamager.sendMessage(" §4§lWarZone §8» §c+100 §4points !");
  68. world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 10);
  69. world.playEffect(head, Effect.MOBSPAWNER_FLAMES, 10);
  70. world.playEffect(head, Effect.EXPLOSION_LARGE, 10);
  71. world.playSound(location, Sound.EXPLODE, 1, 1);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79.  
  80. private boolean inWarzone(Location location) {
  81. final int x = location.getBlockX();
  82. final int z = location.getBlockZ();
  83.  
  84. if((x < 400) && x > (-400)) {
  85. if((z > -400) && (z < 400)) {
  86. return true;
  87. }
  88. } return false;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement