Guest User

KitPvPAssist source

a guest
Feb 27th, 2015
18
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.     @EventHandler
  33.     public void onPlayerJoin (PlayerJoinEvent event) {
  34.         if (!event.getPlayer().hasPlayedBefore()) {
  35.             if (!event.getPlayer().hasPermission(getConfig().getString("kitPermission"))) {
  36.                 if (Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault) {
  37.                     if (Bukkit.getServicesManager().getRegistration(Permission.class) != null) {
  38.                         Permission perms = Bukkit.getServicesManager().getRegistration(Permission.class).getProvider();
  39.                         perms.playerAdd(event.getPlayer(), getConfig().getString("kitPermission"));
  40.                         Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  41.                         perms.playerRemove(event.getPlayer(), getConfig().getString("kitPermission"));
  42.                         return;
  43.                     }
  44.                 }
  45.             }
  46.             Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  47.         }
  48.         event.getPlayer().teleport(Bukkit.getWorld(getConfig().getString("respawnWorld")).getSpawnLocation());
  49.     }
  50.    
  51.     @SuppressWarnings("deprecation")
  52.     @EventHandler
  53.     public void onPlayerRespawn (PlayerRespawnEvent event) {
  54.         event.setRespawnLocation(Bukkit.getWorld(getConfig().getString("respawnWorld")).getSpawnLocation());
  55.         event.getPlayer().getInventory().clear();
  56.         event.getPlayer().updateInventory();
  57.         if (!event.getPlayer().hasPermission(getConfig().getString("kitPermission"))) {
  58.             if (Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault) {
  59.                 if (Bukkit.getServicesManager().getRegistration(Permission.class) != null) {
  60.                     Permission perms = Bukkit.getServicesManager().getRegistration(Permission.class).getProvider();
  61.                     perms.playerAdd(event.getPlayer(), getConfig().getString("kitPermission"));
  62.                     Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  63.                     perms.playerRemove(event.getPlayer(), getConfig().getString("kitPermission"));
  64.                     return;
  65.                 }
  66.             }
  67.         }
  68.         Bukkit.dispatchCommand(event.getPlayer(), getConfig().getString("defaultKitCmd"));
  69.     }
  70.    
  71.     @EventHandler
  72.     public void onPlayerDeath (PlayerDeathEvent event) {
  73.         if (!getConfig().getBoolean("dropItems")) {
  74.             event.getEntity().getInventory().clear();
  75.             event.setKeepInventory(true);
  76.         }
  77.         if (!getConfig().getBoolean("dropExp")) {
  78.             event.getEntity().setExp(0);
  79.             event.getEntity().setLevel(0);
  80.             event.setKeepLevel(true);
  81.         }
  82.         if (Bukkit.getPluginManager().getPlugin("Vault") instanceof Vault) {
  83.             if (Bukkit.getServicesManager().getRegistration(Economy.class) != null) {
  84.                 Economy econ = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
  85.                 econ.depositPlayer(event.getEntity(), getConfig().getDouble("moneyOnDeath"));
  86.                 if (event.getEntity().getKiller() != null)
  87.                     econ.depositPlayer(event.getEntity().getKiller(), getConfig().getDouble("moneyOnKill"));
  88.             }
  89.         }
  90.         if (event.getEntity().getKiller() != null) {
  91.             event.getEntity().getKiller().sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("killMessage").replace("{PLAYER}", event.getEntity().getName())));
  92.             event.getEntity().getKiller().setHealth(((Damageable) event.getEntity().getKiller()).getMaxHealth());
  93.             event.getEntity().getKiller().setFoodLevel(20);
  94.             for (PotionEffect effect : event.getEntity().getKiller().getActivePotionEffects())
  95.                 event.getEntity().getKiller().removePotionEffect(effect.getType());
  96.         }
  97.     }
  98.    
  99.     @SuppressWarnings("deprecation")
  100.     public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
  101.         if (args.length == 1) {
  102.             Player victim = Bukkit.getPlayer(args[0]);
  103.             if (victim != null) {
  104.                 if (sender instanceof Player) {
  105.                     while (!victim.isDead()) victim.damage(((Damageable) victim).getHealth()*10, (Player) sender);
  106.                     sender.sendMessage(ChatColor.GREEN + "You killed " + victim.getDisplayName() + ChatColor.GREEN + " with your hands!");
  107.                 } else {
  108.                     while (!victim.isDead()) victim.damage(((Damageable) victim).getHealth()*10);
  109.                     sender.sendMessage(ChatColor.GREEN + "You killed " + victim.getDisplayName() + ChatColor.GREEN + "! Even a ninja wouldn't have saw you.");
  110.                 }
  111.             } else {
  112.                 sender.sendMessage(ChatColor.RED + "Error: This player doesn't exist!");
  113.             }
  114.         } else {
  115.             sender.sendMessage(ChatColor.RED + "Usage: /kill <player>");
  116.         }
  117.         return false;
  118.     }
  119.    
  120.     @SuppressWarnings("deprecation")
  121.     @EventHandler(priority=EventPriority.HIGHEST)
  122.     public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event) {
  123.         if (event.getPlayer().hasPermission("essentials.kill")) {
  124.             ArrayList<String> commands = new ArrayList<String>();
  125.             if (commands.contains(event.getMessage().split(" ")[0].toLowerCase())) {
  126.                 if (event.getMessage().split(" ").length >= 2) {
  127.                     Player victim = Bukkit.getPlayer(event.getMessage().split(" ")[1]);
  128.                     if (victim != null && victim.isOnline()) {
  129.                         victim.damage(((Damageable) victim).getHealth(), event.getPlayer());
  130.                         event.setCancelled(true);
  131.                         event.setMessage("");
  132.                     }
  133.                 }
  134.             }
  135.         }
  136.     }
  137.    
  138. }
RAW Paste Data