Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package WarZ.Food;
- import org.bukkit.ChatColor;
- import org.bukkit.Effect;
- import org.bukkit.Material;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Damageable;
- import org.bukkit.entity.Player;
- import org.bukkit.entity.Snowball;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityDamageByEntityEvent;
- import org.bukkit.event.entity.ProjectileHitEvent;
- import org.bukkit.event.player.PlayerCommandPreprocessEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerQuitEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.util.BlockIterator;
- public class Main
- extends JavaPlugin
- implements Listener
- {
- @EventHandler
- public void onInteract(PlayerInteractEvent e)
- {
- Player p = e.getPlayer();
- Action a = e.getAction();
- ItemStack hand = p.getItemInHand();
- if (((a == Action.RIGHT_CLICK_AIR) || (a == Action.RIGHT_CLICK_BLOCK)) &&
- (isFood(hand.getType())) &&
- (!Cooldown.isInCooldown(p.getUniqueId(), "food")))
- {
- Cooldown cd = new Cooldown(p.getUniqueId(), "food", 1);
- cd.start();
- if (hand.getType() == Material.INK_SACK) {
- handleInkSac(p, hand);
- } else if (hand.getType() == Material.COOKED_FISH) {
- handleFish(p, hand);
- } else if (hand.getType() == Material.GOLDEN_APPLE) {
- handleGoldenApple(p, hand);
- } else if (hand.getType() == Material.SUGAR) {
- handleSugar(p, hand);
- }
- }
- }
- @SuppressWarnings("deprecation")
- public void handleInkSac(Player p, ItemStack i)
- {
- System.out.println("handle inc sack");
- Damageable d = p;
- if (i.getData().getData() == 4)
- {
- dropEgg(p);
- p.getWorld().playSound(p.getLocation(), Sound.EAT, 1.0F, 1.0F);
- if (i.getAmount() > 1)
- {
- if (p.getHealth() >= 15.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 15) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 5);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 5.0D);
- if (p.getFoodLevel() >= 15) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 5);
- }
- }
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- if (p.getHealth() >= 15.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 15) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 5);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 5.0D);
- if (p.getFoodLevel() >= 15) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 5);
- }
- }
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- if (i.getData().getData() == 14)
- {
- dropEgg(p);
- p.getWorld().playSound(p.getLocation(), Sound.EAT, 1.0F, 1.0F);
- if (i.getAmount() > 1)
- {
- if (p.getHealth() >= 19.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 19) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 1);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 1.0D);
- if (p.getFoodLevel() >= 19) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 1);
- }
- }
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- if (p.getHealth() >= 19.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 19) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 1);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 1.0D);
- if (p.getFoodLevel() >= 19) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 1);
- }
- }
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- if (i.getData().getData() == 11)
- {
- dropEgg(p);
- p.getWorld().playSound(p.getLocation(), Sound.EAT, 1.0F, 1.0F);
- if (i.getAmount() > 1)
- {
- if (p.getHealth() >= 13.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 13) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 7);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 7.0D);
- if (p.getFoodLevel() >= 13) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 7);
- }
- }
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- if (p.getHealth() >= 13.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 13) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 7);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 7.0D);
- if (p.getFoodLevel() >= 13) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 7);
- }
- }
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- if (i.getData().getData() == 15)
- {
- dropEgg(p);
- p.getWorld().playSound(p.getLocation(), Sound.EAT, 1.0F, 1.0F);
- if (i.getAmount() > 1)
- {
- d.setHealth(20.0D);
- p.setFoodLevel(20);
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- d.setHealth(20.0D);
- p.setFoodLevel(20);
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- }
- public void handleFish(Player p, ItemStack i)
- {
- Damageable d = p;
- dropEgg(p);
- p.getWorld().playSound(p.getLocation(), Sound.EAT, 1.0F, 1.0F);
- if (i.getAmount() > 1)
- {
- if (p.getHealth() >= 12.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 12) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 8);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 8.0D);
- if (p.getFoodLevel() >= 12) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 8);
- }
- }
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- if (p.getHealth() >= 12.0D)
- {
- d.setHealth(20.0D);
- if (p.getFoodLevel() >= 12) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 8);
- }
- }
- else
- {
- d.setHealth(d.getHealth() + 8.0D);
- if (p.getFoodLevel() >= 12) {
- p.setFoodLevel(20);
- } else {
- p.setFoodLevel(p.getFoodLevel() + 8);
- }
- }
- p.getInventory().remove(p.getItemInHand());
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- public void handleGoldenApple(Player p, ItemStack i)
- {
- p.getWorld().playSound(p.getLocation(), Sound.EAT, 1.0F, 1.0F);
- if (!Cooldown.isInCooldown(p.getUniqueId(), "food_apple"))
- {
- Cooldown cd = new Cooldown(p.getUniqueId(), "food_apple", 10);
- cd.start();
- p.removePotionEffect(PotionEffectType.ABSORPTION);
- p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 100, 2), true);
- if (i.getAmount() > 1)
- {
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- p.getInventory().remove(p.getItemInHand());
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- }
- public void handleSugar(Player p, ItemStack i)
- {
- if (!Cooldown.isInCooldown(p.getUniqueId(), "food_sugar"))
- {
- Cooldown cd = new Cooldown(p.getUniqueId(), "food_sugar", 5);
- cd.start();
- p.getWorld().playSound(p.getLocation(), Sound.BURP, 1.0F, 1.0F);
- p.sendMessage(ChatColor.GRAY + "*You feel a sugar rush*");
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 100, 0), true);
- if (i.getAmount() > 1)
- {
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- p.updateInventory();
- return;
- }
- if (i.getAmount() == 1)
- {
- p.setItemInHand(new ItemStack(Material.AIR));
- p.updateInventory();
- return;
- }
- }
- }
- public boolean isFood(Material m)
- {
- if ((m == Material.INK_SACK) ||
- (m == Material.COOKED_FISH) ||
- (m == Material.GOLDEN_APPLE) ||
- (m == Material.SUGAR)) {
- return true;
- }
- return false;
- }
- private void dropEgg(Player p)
- {
- ItemStack i1 = new ItemStack(Material.EGG);
- ItemMeta i1m = i1.getItemMeta();
- i1m.setDisplayName(ChatColor.DARK_GRAY + "Empty Can");
- i1.setItemMeta(i1m);
- p.getWorld().dropItemNaturally(p.getLocation(), i1);
- }
- @EventHandler
- public void onDamage(EntityDamageByEntityEvent e)
- {
- if ((e.getEntity() instanceof Player))
- {
- Player p = (Player)e.getEntity();
- if (Cooldown.isInCooldown(p.getUniqueId(), "food_apple")) {
- e.setCancelled(true);
- }
- }
- }
- @EventHandler
- public void onCmd(PlayerCommandPreprocessEvent e)
- {
- if (e.getMessage().startsWith("/dfood"))
- {
- e.getPlayer().sendMessage(ChatColor.GREEN + "[dFood] " + ChatColor.GRAY + "is running!");
- e.setCancelled(true);
- }
- }
- @EventHandler
- public void onQuit(PlayerQuitEvent e)
- {
- World w = e.getPlayer().getWorld();
- e.getPlayer().teleport(w.getSpawnLocation());
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void projectileHit(ProjectileHitEvent e)
- {
- if ((e.getEntity() instanceof Snowball))
- {
- BlockIterator iterator = new BlockIterator(e.getEntity().getWorld(), e.getEntity().getLocation().toVector(), e.getEntity().getVelocity().normalize(), 0.0D, 4);
- Block hitBlock = null;
- while (iterator.hasNext())
- {
- hitBlock = iterator.next();
- if (hitBlock.getTypeId() != 0) {
- break;
- }
- }
- if ((hitBlock.getType() == Material.GLASS) || (hitBlock.getType() == Material.THIN_GLASS))
- {
- e.getEntity().getLocation().getWorld().playEffect(hitBlock.getLocation(), Effect.STEP_SOUND, hitBlock.getTypeId());
- hitBlock.setType(Material.AIR);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement