Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. package com.gmail.stevenpcc.zpm.Map;
  2.  
  3. import com.gmail.stevenpcc.ZMReboot.ZMRebootAPI;
  4. import com.gmail.stevenpcc.ZMToolKit.Log;
  5. import com.gmail.stevenpcc.ZMToolKit.SystemInfo;
  6. import com.gmail.stevenpcc.ZMToolKit.Util;
  7. import com.gmail.stevenpcc.zpm.Events.MapChangeEvent;
  8. import com.gmail.stevenpcc.zpm.ZombieManic;
  9. import java.util.ArrayList;
  10. import java.util.Collections;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. import org.bukkit.Bukkit;
  15. import org.bukkit.World;
  16. import org.bukkit.entity.Player;
  17.  
  18. public class MapCycler
  19. {
  20. private ZombieManic z;
  21. private String current_file_name;
  22. private List<String> file_names;
  23. private Map<String, GameMap> worlds;
  24.  
  25. public MapCycler() {
  26. this.worlds = new HashMap();
  27.  
  28. this.unloading_world = false;
  29. this.world_iterator = 0;
  30.  
  31.  
  32. this.worlds_played = 0;
  33.  
  34.  
  35. this.z = ZombieManic.getPlugin();
  36.  
  37. loadMapsFromConfig();
  38. this.current_file_name = (String)this.file_names.get(0);
  39.  
  40.  
  41. load();
  42. }
  43. private boolean unloading_world; private int world_iterator; private int unload_world_task_id; private int worlds_played;
  44. public void loadMapsFromConfig() {
  45. this.file_names = this.z.getGameConfig().getMapFiles();
  46. Collections.shuffle(this.file_names);
  47.  
  48.  
  49. if (this.file_names.size() > ZMRebootAPI.getGameLimit()) {
  50. this.file_names.subList(ZMRebootAPI.getGameLimit(), this.file_names.size()).clear();
  51. }
  52.  
  53. for (String file_name : this.file_names) {
  54. this.worlds.put(file_name, this.z.getGameConfig().loadMap(file_name));
  55. }
  56. }
  57.  
  58. public boolean nextMap() {
  59. if (!isUnloading()) {
  60. this.worlds_played++;
  61. Log.info("Loading new world");
  62. Log.info("Worlds Played: " + this.worlds_played);
  63. Log.info(SystemInfo.MemInfo());
  64. this.world_iterator = Util.incrementIterator(this.world_iterator, this.file_names.size());
  65. load();
  66. return true;
  67. }
  68.  
  69. return false;
  70. }
  71.  
  72.  
  73.  
  74. public GameMap getCurrentMap() { return (GameMap)this.worlds.get(this.current_file_name); }
  75.  
  76.  
  77.  
  78. public GameMap getNextMap() { return (GameMap)this.worlds.get(this.file_names.get(Util.incrementIterator(this.world_iterator, this.worlds.size()))); }
  79.  
  80.  
  81. public List<GameMap> getScheduleMaps() {
  82. List<GameMap> cycle = new ArrayList<GameMap>();
  83. for (int i = 0; i < this.file_names.size(); i++) {
  84. cycle.add((GameMap)this.worlds.get(this.file_names.get(i)));
  85. }
  86.  
  87. return cycle;
  88. }
  89.  
  90.  
  91. public List<String> getScheduleFiles() { return this.file_names; }
  92.  
  93.  
  94. public void load() {
  95. this.current_file_name = (String)this.file_names.get(this.world_iterator);
  96. callMapChangeEvent();
  97. getCurrentMap().loadWorld();
  98. }
  99.  
  100.  
  101. public World getCurrentBukkitWorld() { return getCurrentMap().getWorld(); }
  102.  
  103.  
  104.  
  105. public boolean isUnloading() { return this.unloading_world; }
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. public void startUnloadWorldTask(final boolean is_rebooting) {
  117. this.unloading_world = true;
  118. this.unload_world_task_id = this.z.getServer().getScheduler().scheduleSyncRepeatingTask(this.z, new Runnable()
  119. {
  120. public void run()
  121. {
  122. if (MapCycler.this.getCurrentMap().unloadWorld()) {
  123. Log.info("World unloaded");
  124. Bukkit.getScheduler().cancelTask(MapCycler.this.unload_world_task_id);
  125. MapCycler.this.unloading_world = false;
  126. if (!is_rebooting) {
  127. MapCycler.this.nextMap();
  128. }
  129. } else {
  130.  
  131. Log.info("WORLD NOT UNLOADED!! Will try again."); byte b; int i; Player[] arrayOfPlayer;
  132. for (i = arrayOfPlayer = Bukkit.getServer().getOnlinePlayers().length, b = 0; b < i; ) { Player player = arrayOfPlayer[b];
  133. if (player.getLocation().getWorld().getName() == MapCycler.this.current_file_name)
  134. player.kickPlayer("Sorry, but you were stopping the world from unloading. Log back in.");
  135. b++; }
  136.  
  137. }
  138. }
  139. }40L, 20L);
  140. }
  141.  
  142.  
  143. private void callMapChangeEvent() { Bukkit.getServer().getPluginManager().callEvent(new MapChangeEvent(this)); }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement