Ghaz-ranka

Untitled

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