Ghaz-ranka

Untitled

Jun 22nd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. public class Hunger {
  2. private Esinia plugin;
  3. public Config config;
  4. public Hunger(Esinia plugin) {
  5. this.plugin = plugin;
  6. this.config = plugin.config;
  7. }
  8. @Listener
  9. public void onServerStart(GameStartedServerEvent event) {
  10. Task.builder()
  11. .delay(1, TimeUnit.SECONDS)
  12. .interval(1, TimeUnit.SECONDS)
  13. .execute(() -> {
  14. for (Player p : Sponge.getGame().getServer().getOnlinePlayers()) {
  15. int hungerLevel = config.hunger.get(p.getUniqueId()).foodLevel;
  16. double saturationLevel = config.hunger.get(p.getUniqueId()).saturationLevel;
  17. p.offer(Keys.FOOD_LEVEL, hungerLevel);
  18. p.offer(Keys.SATURATION, saturationLevel);
  19. }
  20. })
  21. .submit(plugin);
  22.  
  23. Task.builder()
  24. .delay(300, TimeUnit.SECONDS)
  25. .interval(300, TimeUnit.SECONDS)
  26. .execute(() -> {
  27. for (Player p : Sponge.getGame().getServer().getOnlinePlayers()) {
  28. int hungerLevel = config.hunger.get(p.getUniqueId()).foodLevel;
  29. double saturationLevel = config.hunger.get(p.getUniqueId()).saturationLevel;
  30. if (hungerLevel > 16) {
  31. HungerEntry entry = config.hunger.getOrDefault(p.getUniqueId(), new HungerEntry());
  32. entry.foodLevel = (hungerLevel - 1);
  33. entry.saturationLevel = (hungerLevel -1);
  34. config.hunger.put(p.getUniqueId(), entry);
  35. plugin.saveConfig();
  36. p.offer(Keys.FOOD_LEVEL, (hungerLevel - 1));
  37. p.offer(Keys.SATURATION, (saturationLevel - 1));
  38. }
  39. }
  40. })
  41. .submit(plugin);
  42.  
  43. Task.builder()
  44. .delay(600, TimeUnit.SECONDS)
  45. .interval(600, TimeUnit.SECONDS)
  46. .execute(() -> {
  47. for (Player p : Sponge.getGame().getServer().getOnlinePlayers()) {
  48. int hungerLevel = config.hunger.get(p.getUniqueId()).foodLevel;
  49. double saturationLevel = config.hunger.get(p.getUniqueId()).saturationLevel;
  50. if (hungerLevel <= 16 && hungerLevel > 0) {
  51. HungerEntry entry = config.hunger.getOrDefault(p.getUniqueId(), new HungerEntry());
  52. entry.foodLevel = (hungerLevel - 1);
  53. entry.saturationLevel = (hungerLevel -1);
  54. config.hunger.put(p.getUniqueId(), entry);
  55. plugin.saveConfig();
  56. p.offer(Keys.FOOD_LEVEL, (hungerLevel - 1));
  57. p.offer(Keys.SATURATION, (saturationLevel - 1));
  58. }
  59. }
  60. })
  61. .submit(plugin);
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment