Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.acpsoldier.acpfood;
- import com.acpsoldier.acpfood.AcpFood;
- import thefood.CannedBeans;
- import thefood.CannedFish;
- import thefood.CannedPasta;
- import thefood.GoldenApple;
- import thefood.MountainDew;
- import thefood.Pepsi;
- import thefood.Sugar;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.Sound;
- import org.bukkit.World;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import org.bukkit.scheduler.BukkitScheduler;
- public class FoodManager
- {
- AcpFood acpFood;
- public static CannedBeans cannedBeans;
- public static CannedPasta cannedPasta;
- public static CannedFish cannedFish;
- public static Pepsi pepsi;
- public static MountainDew mountainDew;
- public static Sugar sugar;
- public static GoldenApple goldenApple;
- public FoodManager(AcpFood acpFood)
- {
- this.acpFood = acpFood;
- }
- public static ArrayList<Food> foods = new ArrayList<>();
- public static ArrayList<Player> playersThatCantEat = new ArrayList<>();
- public static ArrayList<Player> appleEaters = new ArrayList<>();
- public static ArrayList<Player> sugarEaters = new ArrayList<>();
- public void setup()
- {
- if (foods.isEmpty())
- {
- cannedBeans = new CannedBeans(this.acpFood);
- cannedPasta = new CannedPasta(this.acpFood);
- cannedFish = new CannedFish(this.acpFood);
- pepsi = new Pepsi(this.acpFood);
- mountainDew = new MountainDew(this.acpFood);
- sugar = new Sugar(this.acpFood);
- goldenApple = new GoldenApple(this.acpFood);
- foods.add(cannedBeans);
- foods.add(cannedPasta);
- foods.add(cannedFish);
- foods.add(pepsi);
- foods.add(mountainDew);
- foods.add(sugar);
- foods.add(goldenApple);
- }
- else
- {
- cannedBeans = new CannedBeans(this.acpFood);
- cannedPasta = new CannedPasta(this.acpFood);
- cannedFish = new CannedFish(this.acpFood);
- pepsi = new Pepsi(this.acpFood);
- mountainDew = new MountainDew(this.acpFood);
- sugar = new Sugar(this.acpFood);
- goldenApple = new GoldenApple(this.acpFood);
- foods.clear();
- foods.add(cannedBeans);
- foods.add(cannedPasta);
- foods.add(cannedFish);
- foods.add(pepsi);
- foods.add(mountainDew);
- foods.add(sugar);
- foods.add(goldenApple);
- }
- this.acpFood.reloadConfiguration();
- }
- @SuppressWarnings("deprecation")
- public void eatFood(final Player p, Food food, AcpFood acpFood)
- {
- if ((!playersThatCantEat.contains(p)) && (p.hasPermission(food.permission)))
- {
- if (p.getHealth() + food.healAmount > 20.0D) {
- p.setHealth(20.0D);
- } else {
- p.setHealth(p.getHealth() + food.healAmount);
- }
- if (p.getFoodLevel() + food.foodAmount > acpFood.maxHunger) {
- p.setFoodLevel(acpFood.maxHunger);
- } else {
- p.setFoodLevel(p.getFoodLevel() + food.foodAmount);
- }
- if (p.getItemInHand().getAmount() == 1)
- {
- p.setItemInHand(new ItemStack(Material.AIR));
- if ((acpFood.autoRefillFood) &&
- (p.hasPermission("acpfood.refill"))) {
- if (p.getInventory().contains(food.getFood().getType(), 1))
- {
- ItemStack newFood = p.getInventory().getItem(p.getInventory().first(food.getFood().getType()));
- p.getInventory().remove(newFood);
- p.setItemInHand(newFood);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', acpFood.autoRefillMessage));
- }
- }
- }
- else
- {
- p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
- }
- if (food.eatMessage.length() > 0) {
- p.sendMessage(ChatColor.translateAlternateColorCodes('&', food.eatMessage));
- }
- World w;
- if (food.playSound) {
- if (acpFood.broadcastFoodSounds)
- {
- w = p.getWorld();
- switch (food.sound)
- {
- case 1:
- w.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
- break;
- case 2:
- w.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1.0F, 1.0F);
- break;
- case 3:
- w.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1.0F, 1.0F);
- break;
- case 4:
- w.playSound(p.getLocation(), Sound.ENTITY_FIREWORK_LAUNCH, 1.0F, 1.5F);
- break;
- case 5:
- w.playSound(p.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, 3.5F);
- break;
- default:
- w.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
- break;
- }
- }
- else
- {
- switch (food.sound)
- {
- case 1:
- p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
- break;
- case 2:
- p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1.0F, 1.0F);
- break;
- case 3:
- p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1.0F, 1.0F);
- break;
- case 4:
- p.playSound(p.getLocation(), Sound.ENTITY_FIREWORK_LAUNCH, 1.0F, 1.5F);
- break;
- case 5:
- p.playSound(p.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, 3.5F);
- break;
- default:
- p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
- }
- }
- }
- switch ((w = food.fileName).hashCode())
- {
- case -1672657533:
- if (w.equals("Golden Apple")) {
- break;
- }
- case 80239894:
- if ((goto == 791) || (!w.equals("Sugar"))) {
- break label791;
- }
- default:
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Sugar.speedTime, Sugar.speedLevel));
- break;
- }
- p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, GoldenApple.invincibilityTime, 0));
- ItemStack iteminHand = p.getItemInHand();
- p.getItemInHand().setType(Material.AIR);
- p.setItemInHand(iteminHand);
- label791:
- playersThatCantEat.add(p);
- BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
- scheduler.scheduleSyncDelayedTask(acpFood, new Runnable()
- {
- public void run()
- {
- FoodManager.playersThatCantEat.remove(p);
- }
- }, acpFood.eatDelay);
- }
- else if (!p.hasPermission(food.permission))
- {
- p.sendMessage(ChatColor.RED + "You don't have permission to eat " + food.fileName + ".");
- }
- }
- public void updateFoodFile(Food food)
- {
- File foodFile = getFoodFile(food);
- FileConfiguration foodData = YamlConfiguration.loadConfiguration(foodFile);
- foodData.set("Settings.DisplayName", food.displayName);
- foodData.set("Settings.HealAmount", Integer.valueOf(food.healAmount));
- foodData.set("Settings.FoodAmount", Integer.valueOf(food.foodAmount));
- foodData.set("Settings.ItemLore", food.itemLore);
- foodData.set("Settings.EatMessage", food.eatMessage);
- foodData.set("Settings.PlaySound", Boolean.valueOf(food.playSound));
- foodData.set("Settings.Sound", Integer.valueOf(food.sound));
- String str;
- switch ((str = food.fileName).hashCode())
- {
- case -1672657533:
- if (str.equals("Golden Apple")) {
- break;
- }
- case 80239894:
- if ((goto 219) && (str.equals("Sugar")))
- {
- foodData.set("Settings.SpeedTime", Integer.valueOf(Sugar.speedTime));
- foodData.set("Settings.SpeedLevel", Integer.valueOf(Sugar.speedLevel));
- break label219;
- foodData.set("Settings.InvincibilityTime", Integer.valueOf(GoldenApple.invincibilityTime));
- foodData.set("Settings.PlayExpireSound", Boolean.valueOf(GoldenApple.playExpireSound));
- }
- break;
- }
- try
- {
- label219:
- foodData.save(foodFile);
- }
- catch (IOException e)
- {
- this.acpFood.getLogger().severe("Failed to edit the '" + food.fileName + "' file. This should never happen. If it does happen, I'm pretty sure it's not my fault! :(");
- e.printStackTrace();
- }
- }
- public File getFoodFile(Food food)
- {
- File dataFolder = ((AcpFood)Bukkit.getPluginManager().getPlugin("AcpFood")).getDataFolder();
- File playerFile = new File(dataFolder + File.separator + "Foods", food.fileName + ".yml");
- return playerFile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement