Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.stevenpcc.zpm.Map;
- import com.gmail.stevenpcc.ZMReboot.ZMRebootAPI;
- import com.gmail.stevenpcc.ZMToolKit.Log;
- import com.gmail.stevenpcc.ZMToolKit.SystemInfo;
- import com.gmail.stevenpcc.ZMToolKit.Util;
- import com.gmail.stevenpcc.zpm.Events.MapChangeEvent;
- import com.gmail.stevenpcc.zpm.ZombieManic;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.bukkit.Bukkit;
- import org.bukkit.World;
- import org.bukkit.entity.Player;
- public class MapCycler
- {
- private ZombieManic z;
- private String current_file_name;
- private List<String> file_names;
- private Map<String, GameMap> worlds;
- public MapCycler() {
- this.worlds = new HashMap();
- this.unloading_world = false;
- this.world_iterator = 0;
- this.worlds_played = 0;
- this.z = ZombieManic.getPlugin();
- loadMapsFromConfig();
- this.current_file_name = (String)this.file_names.get(0);
- load();
- }
- private boolean unloading_world; private int world_iterator; private int unload_world_task_id; private int worlds_played;
- public void loadMapsFromConfig() {
- this.file_names = this.z.getGameConfig().getMapFiles();
- Collections.shuffle(this.file_names);
- if (this.file_names.size() > ZMRebootAPI.getGameLimit()) {
- this.file_names.subList(ZMRebootAPI.getGameLimit(), this.file_names.size()).clear();
- }
- for (String file_name : this.file_names) {
- this.worlds.put(file_name, this.z.getGameConfig().loadMap(file_name));
- }
- }
- public boolean nextMap() {
- if (!isUnloading()) {
- this.worlds_played++;
- Log.info("Loading new world");
- Log.info("Worlds Played: " + this.worlds_played);
- Log.info(SystemInfo.MemInfo());
- this.world_iterator = Util.incrementIterator(this.world_iterator, this.file_names.size());
- load();
- return true;
- }
- return false;
- }
- public GameMap getCurrentMap() { return (GameMap)this.worlds.get(this.current_file_name); }
- public GameMap getNextMap() { return (GameMap)this.worlds.get(this.file_names.get(Util.incrementIterator(this.world_iterator, this.worlds.size()))); }
- public List<GameMap> getScheduleMaps() {
- List<GameMap> cycle = new ArrayList<GameMap>();
- for (int i = 0; i < this.file_names.size(); i++) {
- cycle.add((GameMap)this.worlds.get(this.file_names.get(i)));
- }
- return cycle;
- }
- public List<String> getScheduleFiles() { return this.file_names; }
- public void load() {
- this.current_file_name = (String)this.file_names.get(this.world_iterator);
- callMapChangeEvent();
- getCurrentMap().loadWorld();
- }
- public World getCurrentBukkitWorld() { return getCurrentMap().getWorld(); }
- public boolean isUnloading() { return this.unloading_world; }
- public void startUnloadWorldTask(final boolean is_rebooting) {
- this.unloading_world = true;
- this.unload_world_task_id = this.z.getServer().getScheduler().scheduleSyncRepeatingTask(this.z, new Runnable()
- {
- public void run()
- {
- if (MapCycler.this.getCurrentMap().unloadWorld()) {
- Log.info("World unloaded");
- Bukkit.getScheduler().cancelTask(MapCycler.this.unload_world_task_id);
- MapCycler.this.unloading_world = false;
- if (!is_rebooting) {
- MapCycler.this.nextMap();
- }
- } else {
- Log.info("WORLD NOT UNLOADED!! Will try again."); byte b; int i; Player[] arrayOfPlayer;
- for (i = arrayOfPlayer = Bukkit.getServer().getOnlinePlayers().length, b = 0; b < i; ) { Player player = arrayOfPlayer[b];
- if (player.getLocation().getWorld().getName() == MapCycler.this.current_file_name)
- player.kickPlayer("Sorry, but you were stopping the world from unloading. Log back in.");
- b++; }
- }
- }
- }40L, 20L);
- }
- private void callMapChangeEvent() { Bukkit.getServer().getPluginManager().callEvent(new MapChangeEvent(this)); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement