Advertisement
Guest User

Help

a guest
Jan 3rd, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.91 KB | None | 0 0
  1. package com.acpsoldier.acpfood;
  2.  
  3. import com.acpsoldier.acpfood.AcpFood;
  4. import thefood.CannedBeans;
  5. import thefood.CannedFish;
  6. import thefood.CannedPasta;
  7. import thefood.GoldenApple;
  8. import thefood.MountainDew;
  9. import thefood.Pepsi;
  10. import thefood.Sugar;
  11. import java.io.File;
  12. import java.io.IOException;
  13. import java.util.ArrayList;
  14. import java.util.logging.Logger;
  15. import org.bukkit.Bukkit;
  16. import org.bukkit.ChatColor;
  17. import org.bukkit.Material;
  18. import org.bukkit.Server;
  19. import org.bukkit.Sound;
  20. import org.bukkit.World;
  21. import org.bukkit.configuration.file.FileConfiguration;
  22. import org.bukkit.configuration.file.YamlConfiguration;
  23. import org.bukkit.entity.Player;
  24. import org.bukkit.inventory.ItemStack;
  25. import org.bukkit.inventory.PlayerInventory;
  26. import org.bukkit.plugin.PluginManager;
  27. import org.bukkit.potion.PotionEffect;
  28. import org.bukkit.potion.PotionEffectType;
  29. import org.bukkit.scheduler.BukkitScheduler;
  30.  
  31. public class FoodManager
  32. {
  33.   AcpFood acpFood;
  34.   public static CannedBeans cannedBeans;
  35.   public static CannedPasta cannedPasta;
  36.   public static CannedFish cannedFish;
  37.   public static Pepsi pepsi;
  38.   public static MountainDew mountainDew;
  39.   public static Sugar sugar;
  40.   public static GoldenApple goldenApple;
  41.  
  42.   public FoodManager(AcpFood acpFood)
  43.   {
  44.     this.acpFood = acpFood;
  45.   }
  46.  
  47.   public static ArrayList<Food> foods = new ArrayList<>();
  48.   public static ArrayList<Player> playersThatCantEat = new ArrayList<>();
  49.   public static ArrayList<Player> appleEaters = new ArrayList<>();
  50.   public static ArrayList<Player> sugarEaters = new ArrayList<>();
  51.  
  52.   public void setup()
  53.   {
  54.     if (foods.isEmpty())
  55.     {
  56.       cannedBeans = new CannedBeans(this.acpFood);
  57.       cannedPasta = new CannedPasta(this.acpFood);
  58.       cannedFish = new CannedFish(this.acpFood);
  59.       pepsi = new Pepsi(this.acpFood);
  60.       mountainDew = new MountainDew(this.acpFood);
  61.       sugar = new Sugar(this.acpFood);
  62.       goldenApple = new GoldenApple(this.acpFood);
  63.      
  64.       foods.add(cannedBeans);
  65.       foods.add(cannedPasta);
  66.       foods.add(cannedFish);
  67.       foods.add(pepsi);
  68.       foods.add(mountainDew);
  69.       foods.add(sugar);
  70.       foods.add(goldenApple);
  71.     }
  72.     else
  73.     {
  74.       cannedBeans = new CannedBeans(this.acpFood);
  75.       cannedPasta = new CannedPasta(this.acpFood);
  76.       cannedFish = new CannedFish(this.acpFood);
  77.       pepsi = new Pepsi(this.acpFood);
  78.       mountainDew = new MountainDew(this.acpFood);
  79.       sugar = new Sugar(this.acpFood);
  80.       goldenApple = new GoldenApple(this.acpFood);
  81.      
  82.       foods.clear();
  83.       foods.add(cannedBeans);
  84.       foods.add(cannedPasta);
  85.       foods.add(cannedFish);
  86.       foods.add(pepsi);
  87.       foods.add(mountainDew);
  88.       foods.add(sugar);
  89.       foods.add(goldenApple);
  90.     }
  91.     this.acpFood.reloadConfiguration();
  92.   }
  93.  
  94.   @SuppressWarnings("deprecation")
  95. public void eatFood(final Player p, Food food, AcpFood acpFood)
  96.   {
  97.     if ((!playersThatCantEat.contains(p)) && (p.hasPermission(food.permission)))
  98.     {
  99.       if (p.getHealth() + food.healAmount > 20.0D) {
  100.         p.setHealth(20.0D);
  101.       } else {
  102.         p.setHealth(p.getHealth() + food.healAmount);
  103.       }
  104.       if (p.getFoodLevel() + food.foodAmount > acpFood.maxHunger) {
  105.         p.setFoodLevel(acpFood.maxHunger);
  106.       } else {
  107.         p.setFoodLevel(p.getFoodLevel() + food.foodAmount);
  108.       }
  109.       if (p.getItemInHand().getAmount() == 1)
  110.       {
  111.         p.setItemInHand(new ItemStack(Material.AIR));
  112.         if ((acpFood.autoRefillFood) &&
  113.           (p.hasPermission("acpfood.refill"))) {
  114.           if (p.getInventory().contains(food.getFood().getType(), 1))
  115.           {
  116.             ItemStack newFood = p.getInventory().getItem(p.getInventory().first(food.getFood().getType()));
  117.             p.getInventory().remove(newFood);
  118.             p.setItemInHand(newFood);
  119.            
  120.             p.sendMessage(ChatColor.translateAlternateColorCodes('&', acpFood.autoRefillMessage));
  121.           }
  122.         }
  123.       }
  124.       else
  125.       {
  126.         p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
  127.       }
  128.       if (food.eatMessage.length() > 0) {
  129.         p.sendMessage(ChatColor.translateAlternateColorCodes('&', food.eatMessage));
  130.       }
  131.       World w;
  132.       if (food.playSound) {
  133.         if (acpFood.broadcastFoodSounds)
  134.         {
  135.           w = p.getWorld();
  136.           switch (food.sound)
  137.           {
  138.           case 1:
  139.             w.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
  140.             break;
  141.           case 2:
  142.             w.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1.0F, 1.0F);
  143.             break;
  144.           case 3:
  145.             w.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1.0F, 1.0F);
  146.             break;
  147.           case 4:
  148.             w.playSound(p.getLocation(), Sound.ENTITY_FIREWORK_LAUNCH, 1.0F, 1.5F);
  149.             break;
  150.           case 5:
  151.             w.playSound(p.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, 3.5F);
  152.             break;
  153.           default:
  154.             w.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
  155.            
  156.             break;
  157.           }
  158.         }
  159.         else
  160.         {
  161.           switch (food.sound)
  162.           {
  163.           case 1:
  164.             p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
  165.             break;
  166.           case 2:
  167.             p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EAT, 1.0F, 1.0F);
  168.             break;
  169.           case 3:
  170.             p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_DRINK, 1.0F, 1.0F);
  171.             break;
  172.           case 4:
  173.             p.playSound(p.getLocation(), Sound.ENTITY_FIREWORK_LAUNCH, 1.0F, 1.5F);
  174.             break;
  175.           case 5:
  176.             p.playSound(p.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, 3.5F);
  177.             break;
  178.           default:
  179.             p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_BURP, 1.0F, 1.0F);
  180.           }
  181.         }
  182.       }
  183.       switch ((w = food.fileName).hashCode())
  184.       {
  185.       case -1672657533:
  186.         if (w.equals("Golden Apple")) {
  187.           break;
  188.         }
  189.       case 80239894:
  190.         if ((goto == 791) || (!w.equals("Sugar"))) {
  191.           break label791;
  192.         }
  193.       default:
  194.         p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Sugar.speedTime, Sugar.speedLevel));
  195.         break;
  196.       }
  197.       p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, GoldenApple.invincibilityTime, 0));
  198.       ItemStack iteminHand = p.getItemInHand();
  199.       p.getItemInHand().setType(Material.AIR);
  200.       p.setItemInHand(iteminHand);
  201.       label791:
  202.       playersThatCantEat.add(p);
  203.       BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
  204.       scheduler.scheduleSyncDelayedTask(acpFood, new Runnable()
  205.       {
  206.         public void run()
  207.         {
  208.           FoodManager.playersThatCantEat.remove(p);
  209.         }
  210.       }, acpFood.eatDelay);
  211.     }
  212.     else if (!p.hasPermission(food.permission))
  213.     {
  214.       p.sendMessage(ChatColor.RED + "You don't have permission to eat " + food.fileName + ".");
  215.     }
  216.   }
  217.  
  218.   public void updateFoodFile(Food food)
  219.   {
  220.     File foodFile = getFoodFile(food);
  221.     FileConfiguration foodData = YamlConfiguration.loadConfiguration(foodFile);
  222.    
  223.     foodData.set("Settings.DisplayName", food.displayName);
  224.     foodData.set("Settings.HealAmount", Integer.valueOf(food.healAmount));
  225.     foodData.set("Settings.FoodAmount", Integer.valueOf(food.foodAmount));
  226.     foodData.set("Settings.ItemLore", food.itemLore);
  227.     foodData.set("Settings.EatMessage", food.eatMessage);
  228.     foodData.set("Settings.PlaySound", Boolean.valueOf(food.playSound));
  229.     foodData.set("Settings.Sound", Integer.valueOf(food.sound));
  230.     String str;
  231.     switch ((str = food.fileName).hashCode())
  232.     {
  233.     case -1672657533:
  234.       if (str.equals("Golden Apple")) {
  235.         break;
  236.       }
  237.     case 80239894:
  238.       if ((goto 219) && (str.equals("Sugar")))
  239.       {
  240.         foodData.set("Settings.SpeedTime", Integer.valueOf(Sugar.speedTime));
  241.         foodData.set("Settings.SpeedLevel", Integer.valueOf(Sugar.speedLevel));
  242.         break label219;
  243.         foodData.set("Settings.InvincibilityTime", Integer.valueOf(GoldenApple.invincibilityTime));
  244.         foodData.set("Settings.PlayExpireSound", Boolean.valueOf(GoldenApple.playExpireSound));
  245.       }
  246.       break;
  247.     }
  248.     try
  249.     {
  250.       label219:
  251.       foodData.save(foodFile);
  252.     }
  253.     catch (IOException e)
  254.     {
  255.       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! :(");
  256.       e.printStackTrace();
  257.     }
  258.   }
  259.  
  260.   public File getFoodFile(Food food)
  261.   {
  262.     File dataFolder = ((AcpFood)Bukkit.getPluginManager().getPlugin("AcpFood")).getDataFolder();
  263.     File playerFile = new File(dataFolder + File.separator + "Foods", food.fileName + ".yml");
  264.     return playerFile;
  265.   }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement