Advertisement
Eller

Untitled

Jan 23rd, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package me.ekits.listeners;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. import me.ekits.main.Main;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.ChatColor;
  11. import org.bukkit.Material;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.entity.ThrownPotion;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.player.PlayerInteractEvent;
  18. import org.bukkit.inventory.ItemStack;
  19. import org.bukkit.potion.Potion;
  20. import org.bukkit.potion.PotionType;
  21.  
  22. public class MageHealingWand implements Listener{
  23.  
  24. Main plugin;
  25. public MageHealingWand(Main instance) {
  26. this.plugin = instance;
  27. }
  28. List<Player> cooldown = new ArrayList<Player>();
  29. @SuppressWarnings("deprecation")
  30. @EventHandler
  31. public void Interact(PlayerInteractEvent e) {
  32. final Player p = e.getPlayer();
  33. Action action = e.getAction();
  34. if(p.getItemInHand().getType() != Material.GOLD_HOE) return;
  35. if(!(cooldown.contains(p)))
  36. {
  37. if(action.equals(Action.RIGHT_CLICK_AIR) || action.equals(Action.RIGHT_CLICK_BLOCK)) {
  38. p.sendMessage(ChatColor.YELLOW + "You have thrown a healing potion!");
  39. // Create a potion type
  40. Potion potion = new Potion(PotionType.REGEN, 1);
  41.  
  42. // Make it a splash potion
  43. potion.setSplash(true);
  44.  
  45. // Set it to an item stack
  46. ItemStack itemStack = new ItemStack(Material.POTION);
  47. potion.apply(itemStack);
  48.  
  49. // Spawn the potion
  50. ThrownPotion thrownPotion = p.launchProjectile(ThrownPotion.class);
  51. thrownPotion.setItem(itemStack);
  52. cooldown.add(p);
  53.  
  54. Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() {
  55.  
  56. public void run() {
  57. cooldown.remove(p);
  58. p.sendMessage(ChatColor.GREEN + "You can heal yourself again!");
  59. }
  60. }, 250L);
  61.  
  62. } else p.sendMessage(ChatColor.RED + "You can't heal yet!");
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement