Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.hikings.warzone.listeners;
- import org.bukkit.Effect;
- import org.bukkit.Location;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import com.massivecraft.factions.FPlayer;
- import com.massivecraft.factions.FPlayers;
- import com.sk89q.worldguard.protection.ApplicableRegionSet;
- import com.sk89q.worldguard.protection.flags.DefaultFlag;
- import com.sk89q.worldguard.protection.flags.StateFlag;
- import fr.hikings.warzone.Main;
- public class EntityKill implements Listener {
- private Main main;
- public EntityKill(Main main) {
- this.main = main;
- }
- @EventHandler (ignoreCancelled = true)
- public void onEntityKill(EntityDamageByEntityEvent e) {
- if(e.getEntity() != null && e.getDamager() != null && e.getDamage() > 0) {
- if((e.getEntity() instanceof Player) && (e.getDamager() instanceof Player)) {
- final Player victime = (Player) e.getEntity();
- final Player damager = (Player) e.getDamager();
- if((victime != damager) && main.isActivate ) {
- if(victime.getHealth() - e.getFinalDamage() <= 0) {
- final Location location = e.getEntity().getLocation();
- final Location head = e.getEntity().getLocation().add(0, 1, 0);
- final World world = location.getWorld();
- if(inWarzone(location)) {
- final ApplicableRegionSet set = main.getWorldGuard().getRegionManager(location.getWorld()).getApplicableRegions(location);
- final FPlayer fdamager = FPlayers.getInstance().getByPlayer(damager);
- final FPlayer fvictime = FPlayers.getInstance().getByPlayer(victime);
- if(set.queryState(null, DefaultFlag.PVP) == StateFlag.State.ALLOW) {
- if(fdamager != null && fdamager.hasFaction() && fdamager.getFaction().isNormal()) {
- final String fid = fdamager.getFactionId();
- int points = 1;
- if(main.kill.containsKey(fid)) {
- points += main.kill.get(fid);
- } main.kill.put(fid, points);
- }
- if(fvictime != null && fvictime.hasFaction() && fvictime.getFaction().isNormal()) {
- final String fid = fvictime.getFactionId();
- int points = 1;
- if(main.death.containsKey(fid)) {
- points += main.death.get(fid);
- } main.death.put(fid, points);
- }
- fdamager.sendMessage(" §4§lWarZone §8» §c+100 §4points !");
- world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 10);
- world.playEffect(head, Effect.MOBSPAWNER_FLAMES, 10);
- world.playEffect(head, Effect.EXPLOSION_LARGE, 10);
- world.playSound(location, Sound.EXPLODE, 1, 1);
- }
- }
- }
- }
- }
- }
- }
- private boolean inWarzone(Location location) {
- final int x = location.getBlockX();
- final int z = location.getBlockZ();
- if((x < 400) && x > (-400)) {
- if((z > -400) && (z < 400)) {
- return true;
- }
- } return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement