Advertisement
Guest User

beans

a guest
Nov 27th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. package me.AcpSoldier7.WarZFood;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Material;
  7. import org.bukkit.Sound;
  8. import org.bukkit.command.CommandExecutor;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.block.Action;
  13. import org.bukkit.event.player.PlayerInteractEvent;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. import org.bukkit.scheduler.BukkitScheduler;
  16.  
  17. public class Main extends JavaPlugin implements CommandExecutor, Listener {
  18.  
  19. public void onEnable() {
  20. Bukkit.getPluginManager().registerEvents(this, this);
  21.  
  22. }
  23. public void onDisable() {
  24. //Nothing
  25. }
  26.  
  27. ArrayList<Player> canEat = new ArrayList<Player>();
  28. @SuppressWarnings({ "deprecation"})
  29. @EventHandler
  30. public void onBeans(PlayerInteractEvent e) {
  31. Action a = e.getAction();
  32. final Player p = e.getPlayer();
  33.  
  34. if(a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
  35. if(p.getItemInHand().getType() == Material.getMaterial(351) && p.getItemInHand().getData().getData() == 4){
  36.  
  37. if(!canEat.contains(p)) {
  38. if(p.getHealth() >= 20.0 - 5.0) {
  39. p.setHealth(20.0);
  40. p.getItemInHand().setAmount(p.getItemInHand().getAmount() -1);
  41. p.getWorld().playSound(p.getLocation(), Sound.BURP, 1, 1);
  42. }
  43. else if(p.getHealth() < 20.0) {
  44. p.setHealth(p.getHealth() + 5.0);
  45. p.getItemInHand().setAmount(p.getItemInHand().getAmount() -1);
  46. p.getWorld().playSound(p.getLocation(), Sound.BURP, 1, 1);
  47. }
  48. else if(p.getHealth() == 20.0) {
  49. p.setHealth(20.0);
  50. p.getItemInHand().setAmount(p.getItemInHand().getAmount() -1);
  51. p.getWorld().playSound(p.getLocation(), Sound.BURP, 1, 1);
  52. }
  53. final BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
  54. canEat.add(p);
  55. scheduler.scheduleSyncDelayedTask(this, new Runnable() {
  56. public void run() {
  57. canEat.remove(p);
  58. }
  59. }, 20 * 1); // 20 = one second in ticks.
  60. }
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement