SHARE
TWEET

Untitled

a guest Jul 20th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.hcfactions.hcf.helpers.listener;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.Location;
  10. import org.bukkit.Sound;
  11. import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.event.EventHandler;
  14. import org.bukkit.event.EventPriority;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.entity.PlayerDeathEvent;
  17. import org.bukkit.event.player.PlayerRespawnEvent;
  18. import org.bukkit.inventory.ItemStack;
  19.  
  20. import com.hcfactions.hcf.Base;
  21. import com.hcfactions.hcf.ConfigurationService;
  22. import com.hcfactions.hcf.factions.faction.struct.Role;
  23. import com.hcfactions.hcf.factions.faction.type.Faction;
  24. import com.hcfactions.hcf.factions.faction.type.PlayerFaction;
  25. import com.hcfactions.hcf.user.FactionUser;
  26. import com.hcfactions.hcf.util.JavaUtils;
  27.  
  28. import ru.tehkode.permissions.bukkit.PermissionsEx;
  29.  
  30. public class DeathListener implements Listener {
  31.    
  32.     public static HashMap<UUID, ItemStack[]> PlayerInventoryContents = new HashMap<UUID, ItemStack[]>();
  33.     public static HashMap<UUID, ItemStack[]> PlayerArmorContents = new HashMap<UUID, ItemStack[]>();
  34.     private static final long BASE_REGEN_DELAY = TimeUnit.MINUTES.toMillis(40L);
  35.     private final Base plugin;
  36.  
  37.     public DeathListener(Base plugin) {
  38.         this.plugin = plugin;
  39.     }
  40.  
  41.     @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
  42.     public void onPlayerDeathKillIncrement(PlayerDeathEvent event) {
  43.         Player killer = event.getEntity().getKiller();
  44.        
  45.         if (killer != null) {
  46.             FactionUser user = this.plugin.getUserManager().getUser(killer.getUniqueId());
  47.             user.setKills(user.getKills() + 1);
  48.         }
  49.  
  50.     }
  51.  
  52.     @EventHandler
  53.     public void onRespawn (PlayerRespawnEvent e, Player p) {
  54.         e.getPlayer().getInventory().clear();
  55.         e.getPlayer().getInventory().setArmorContents(null);
  56.     }
  57.    
  58.     @EventHandler
  59.     public void onDeath(PlayerDeathEvent event) {
  60.         Player p = (Player)event.getEntity().getPlayer();
  61.         p.getWorld().strikeLightningEffect(p.getLocation());
  62.     }
  63.    
  64.     @SuppressWarnings("deprecation")
  65.     @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
  66.     public void onPlayerDeath(PlayerDeathEvent event) {
  67.         Player player = event.getEntity();
  68.         PlayerFaction playerFaction = this.plugin.getFactionManager().getPlayerFaction(player.getUniqueId());
  69.         if (playerFaction != null) {
  70.             Faction factionAt = this.plugin.getFactionManager().getFactionAt(player.getLocation());
  71.             Role role = playerFaction.getMember(player.getUniqueId()).getRole();
  72.             Player killer = event.getEntity().getKiller();
  73.             if ((ConfigurationService.KIT_MAP) == true) {
  74.                 plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
  75.  
  76.                         "cr givekey " + killer.getName() + " Kill 1");
  77.             }
  78.             if ((playerFaction.getDeathsUntilRaidable() >= -5.0D) && (ConfigurationService.KIT_MAP) == false) {
  79.                 playerFaction.setDeathsUntilRaidable(
  80.                         playerFaction.getDeathsUntilRaidable() - factionAt.getDtrLossMultiplier());
  81.                 player.getInventory().clear();
  82.                 playerFaction.setRemainingRegenerationTime(
  83.                         BASE_REGEN_DELAY + playerFaction.getOnlinePlayers().size() * TimeUnit.MINUTES.toMillis(2L));
  84.                 playerFaction.broadcast(ChatColor.YELLOW + "Member Death: " + ConfigurationService.TEAMMATE_COLOUR
  85.                         + role.getAstrix() + player.getName() + ChatColor.YELLOW + ". DTR:" + ChatColor.GRAY + " ["
  86.                         + playerFaction.getDtrColour()
  87.                         + JavaUtils.format(Double.valueOf(playerFaction.getDeathsUntilRaidable())) + ChatColor.WHITE
  88.                         + '/' + ChatColor.WHITE + playerFaction.getMaximumDeathsUntilRaidable() + ChatColor.GRAY
  89.                         + "].");
  90.             } else {
  91.                 playerFaction.broadcast(ChatColor.YELLOW + "Member Death: " + ConfigurationService.TEAMMATE_COLOUR
  92.                         + role.getAstrix() + player.getName() + ChatColor.YELLOW + ". DTR:" + ChatColor.GRAY + " ["
  93.                         + playerFaction.getDtrColour()
  94.                         + JavaUtils.format(Double.valueOf(playerFaction.getDeathsUntilRaidable())) + ChatColor.WHITE
  95.                         + '/' + ChatColor.WHITE + playerFaction.getMaximumDeathsUntilRaidable() + ChatColor.GRAY
  96.                         + "].");
  97.             }
  98.         }
  99.             Integer balance = 0;
  100.             if (plugin.getEconomyManager().getBalance(player.getUniqueId()) > 0) {
  101.                 balance = plugin.getEconomyManager().getBalance(player.getUniqueId()) % 10;
  102.                 String prefix = PermissionsEx.getUser((Player) player).getPrefix().replace("_", " ");
  103.                 if (player.getKiller() instanceof Player) {
  104.                     plugin.getEconomyManager().subtractBalance(player.getUniqueId(), balance);
  105.                     if (balance != 0) {
  106.                         plugin.getEconomyManager().addBalance(player.getKiller().getUniqueId(), balance);
  107.                         player.getKiller()
  108.                                 .sendMessage(ChatColor.GOLD + "You earned " + ChatColor.BOLD + "$"
  109.                                         + balance + ChatColor.GOLD + " for killing " + ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', prefix + player.getName() + ChatColor.GOLD + "."));                       
  110.                     }
  111.                     return;
  112.  
  113.                 }
  114.         }
  115.            
  116.         if (Bukkit.spigot().getTPS()[0] > 15.0D) {
  117.             PlayerInventoryContents.put(player.getUniqueId(), player.getInventory().getContents());
  118.             PlayerArmorContents.put(player.getUniqueId(), player.getInventory().getArmorContents());
  119.             Location location = player.getLocation();
  120.             ((CraftWorld) location.getWorld()).getHandle();
  121.             for (Player target : Bukkit.getOnlinePlayers()) {
  122.                 if (this.plugin.getUserManager().getUser(target.getUniqueId()).isShowLightning()) {
  123.                     target.playSound(target.getLocation(), Sound.AMBIENCE_THUNDER, 1.0F, 1.0F);
  124.                 }
  125.             }
  126.         }
  127.     }
  128. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top