Guest User

KitPvPAssist source

a guest
Feb 27th, 2015
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.au2001.KitPvPAssist;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import net.milkbowl.vault.Vault;
  6. import net.milkbowl.vault.economy.Economy;
  7. import net.milkbowl.vault.permission.Permission;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.command.Command;
  12. import org.bukkit.command.CommandSender;
  13. import org.bukkit.entity.Damageable;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.event.EventHandler;
  16. import org.bukkit.event.EventPriority;
  17. import org.bukkit.event.Listener;
  18. import org.bukkit.event.entity.PlayerDeathEvent;
  19. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  20. import org.bukkit.event.player.PlayerJoinEvent;
  21. import org.bukkit.event.player.PlayerRespawnEvent;
  22. import org.bukkit.plugin.java.JavaPlugin;
  23. import org.bukkit.potion.PotionEffect;
  24.  
  25. public class Main extends JavaPlugin implements Listener {
  26.  
  27.     public void onEnable () {
  28.         saveDefaultConfig();
  29.         Bukkit.getPluginManager().registerEvents(this, this);
  30.     }
  31.    
  32.     @SuppressWarnings("deprecation")
  33.     @EventHandler
  34.     public void onPlayerJoin (PlayerJoinEvent event) {
  35.         if (event.getPlayer().getFirstPlayed() == event.getPlayer().getLastPlayed()) {
  36.             event.getPlayer().getInventory().clear();
  37.             event.getPlayer().updateInventory();
  38.             if (!event.getPlayer().hasPermission(getConfig().getString("kitPermission"))) {
  39.                 if (Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault) {
  40.                     if (Bukkit.getServicesManager().getRegistration(Permission.class) != null) {
  41.                         Permission perms = Bukkit.getServicesManager().getRegistration(Permission.class).getProvider();
  42.                         perms.playerAdd(event.getPlayer(), getConfig().getString("kitPermission"));
  43.                         Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  44.                         perms.playerRemove(event.getPlayer(), getConfig().getString("kitPermission"));
  45.                         return;
  46.                     }
  47.                 }
  48.             }
  49.             Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  50.         }
  51.         event.getPlayer().teleport(Bukkit.getWorld(getConfig().getString("respawnWorld")).getSpawnLocation());
  52.     }
  53.    
  54.     @SuppressWarnings("deprecation")
  55.     @EventHandler
  56.     public void onPlayerRespawn (PlayerRespawnEvent event) {
  57.         event.setRespawnLocation(Bukkit.getWorld(getConfig().getString("respawnWorld")).getSpawnLocation());
  58.         event.getPlayer().getInventory().clear();
  59.         event.getPlayer().updateInventory();
  60.         if (!event.getPlayer().hasPermission(getConfig().getString("kitPermission"))) {
  61.             if (Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault) {
  62.                 if (Bukkit.getServicesManager().getRegistration(Permission.class) != null) {
  63.                     Permission perms = Bukkit.getServicesManager().getRegistration(Permission.class).getProvider();
  64.                     perms.playerAdd(event.getPlayer(), getConfig().getString("kitPermission"));
  65.                     Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  66.                     perms.playerRemove(event.getPlayer(), getConfig().getString("kitPermission"));
  67.                     return;
  68.                 }
  69.             }
  70.         }
  71.         Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  72.     }
  73.    
  74.     @EventHandler
  75.     public void onPlayerDeath (PlayerDeathEvent event) {
  76.         if (!getConfig().getBoolean("dropItems")) {
  77.             event.getEntity().getInventory().clear();
  78.             event.setKeepInventory(true);
  79.         }
  80.         if (!getConfig().getBoolean("dropExp")) {
  81.             event.getEntity().setExp(0);
  82.             event.getEntity().setLevel(0);
  83.             event.setKeepLevel(true);
  84.         }
  85.         if (Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault) {
  86.             if (Bukkit.getServicesManager().getRegistration(Economy.class) != null) {
  87.                 Economy econ = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
  88.                 econ.depositPlayer(event.getEntity(), getConfig().getDouble("moneyOnDeath"));
  89.                 if (event.getEntity().getKiller() != null)
  90.                     econ.depositPlayer(event.getEntity().getKiller(), getConfig().getDouble("moneyOnKill"));
  91.             }
  92.         }
  93.         if (event.getEntity().getKiller() != null) {
  94.             event.getEntity().getKiller().sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("killMessage")));
  95.             event.getEntity().getKiller().setHealth(((Damageable) event.getEntity().getKiller()).getMaxHealth());
  96.             event.getEntity().getKiller().setFoodLevel(20);
  97.             for (PotionEffect effect : event.getEntity().getKiller().getActivePotionEffects())
  98.                 event.getEntity().getKiller().removePotionEffect(effect.getType());
  99.         }
  100.     }
  101.    
  102.     @SuppressWarnings("deprecation")
  103.     public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
  104.         if (args.length == 1) {
  105.             Player victim = Bukkit.getPlayer(args[0]);
  106.             if (victim != null) {
  107.                 if (sender instanceof Player) {
  108.                     victim.damage(((Damageable) victim).getHealth(), (Player) sender);
  109.                     sender.sendMessage(ChatColor.GREEN + "You killed " + victim.getDisplayName() + ChatColor.GREEN + " with your hands!");
  110.                 } else {
  111.                     victim.damage(((Damageable) victim).getHealth());
  112.                     sender.sendMessage(ChatColor.GREEN + "You killed " + victim.getDisplayName() + ChatColor.GREEN + "! Even a ninja wouldn't have saw you.");
  113.                 }
  114.             } else {
  115.                 sender.sendMessage(ChatColor.RED + "Error: This player doesn't exist!");
  116.             }
  117.         } else {
  118.             sender.sendMessage(ChatColor.RED + "Usage: /kill <player>");
  119.         }
  120.         return false;
  121.     }
  122.    
  123.     @SuppressWarnings("deprecation")
  124.     @EventHandler(priority=EventPriority.HIGHEST)
  125.     public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event) {
  126.         if (event.getPlayer().hasPermission("essentials.kill")) {
  127.             ArrayList<String> commands = new ArrayList<String>();
  128.             if (commands.contains(event.getMessage().split(" ")[0].toLowerCase())) {
  129.                 if (event.getMessage().split(" ").length >= 2) {
  130.                     Player victim = Bukkit.getPlayer(event.getMessage().split(" ")[1]);
  131.                     if (victim != null && victim.isOnline()) {
  132.                         victim.damage(((Damageable) victim).getHealth(), event.getPlayer());
  133.                         event.setCancelled(true);
  134.                         event.setMessage("");
  135.                     }
  136.                 }
  137.             }
  138.         }
  139.     }
  140.    
  141. }
RAW Paste Data