Guest User

Untitled

a guest
Aug 15th, 2013
697
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.JPG.SkyboundCore;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6.  
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.command.Command;
  10. import org.bukkit.command.CommandExecutor;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Arrow;
  13. import org.bukkit.entity.Egg;
  14. import org.bukkit.entity.LivingEntity;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.entity.Projectile;
  17. import org.bukkit.event.EventHandler;
  18. import org.bukkit.event.Listener;
  19. import org.bukkit.event.entity.ProjectileHitEvent;
  20. import org.bukkit.event.entity.ProjectileLaunchEvent;
  21. import org.bukkit.event.player.PlayerMoveEvent;
  22. import org.bukkit.inventory.PlayerInventory;
  23. import org.bukkit.metadata.FixedMetadataValue;
  24.  
  25. public class ExplosiveProjectiles implements CommandExecutor, Listener {
  26. private static final List<String> players = new ArrayList<String>();
  27.  
  28. @Override
  29. public boolean onCommand(CommandSender commandSender, Command cmd, String alias, String[] args) {
  30. if (commandSender instanceof Player) {
  31. Player player = (Player) commandSender;
  32. PlayerInventory inv = player.getInventory();
  33. if (player.hasPermission("skybound.explosivebow") || player.isOp()) {
  34. if (players.contains(player.getName())) {
  35. // They have explosive bow
  36. player.sendMessage(ChatColor.GRAY + "Your arrows will no longer be " + ChatColor.AQUA + "explosive " + ChatColor.GRAY + ".");
  37. players.remove(player.getName());
  38. } else {
  39. player.sendMessage(ChatColor.GRAY + "Your arrows will now be" + ChatColor.AQUA + " explosive " + ChatColor.GRAY + "!");
  40. players.add(player.getName());
  41. }
  42. } else {
  43. commandSender.sendMessage(ChatColor.RED + "You do not have permission to this command!");
  44. }
  45. } else {
  46. commandSender.sendMessage(ChatColor.RED + "This can only be used by in-game players");
  47. }
  48. return true;
  49. }
  50.  
  51. @EventHandler
  52. public void onProjectileShoot(ProjectileLaunchEvent event) {
  53. Projectile projectile = event.getEntity();
  54. LivingEntity shooter = projectile.getShooter();
  55. if (shooter instanceof Player && (projectile instanceof Arrow || projectile instanceof Egg) && players.contains(((Player) shooter).getName())) {
  56. projectile.setMetadata("Explosive", new FixedMetadataValue(Main.getPlugin(), true));
  57. }
  58. }
  59.  
  60. @EventHandler
  61. public void onProjectileHit(ProjectileHitEvent event){
  62. Projectile entity = event.getEntity();
  63. LivingEntity shooter = entity.getShooter();
  64. if (entity.hasMetadata("Explosive")) {
  65. Location loc = entity.getLocation();
  66. entity.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(),10F, false, false);
  67. entity.remove();
  68. }
  69. }
  70. }
RAW Paste Data