Move map loading into GameCreationManager
This commit is contained in:
parent
582d7ad726
commit
8799d44fd4
@ -137,7 +137,7 @@ public class SetCommand extends CommandBase<ArcadeManager>
|
|||||||
// No particular source specified, we'll use all of them
|
// No particular source specified, we'll use all of them
|
||||||
if (selectedSource == null)
|
if (selectedSource == null)
|
||||||
{
|
{
|
||||||
List<GameType> mapTypes = Arrays.asList(Game.GetWorldHostNames(gameType, gameClass));
|
List<GameType> mapTypes = Arrays.asList(Game.getWorldHostNames(gameType, gameClass));
|
||||||
matchedMaps = matchMaps(mapTypes, mapStr, false);
|
matchedMaps = matchMaps(mapTypes, mapStr, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -252,7 +252,7 @@ public class SetCommand extends CommandBase<ArcadeManager>
|
|||||||
|
|
||||||
private List<GameType> getSources(GameType type, Class<? extends Game> gameClass, String input, boolean isTabCompletion)
|
private List<GameType> getSources(GameType type, Class<? extends Game> gameClass, String input, boolean isTabCompletion)
|
||||||
{
|
{
|
||||||
return matchGameType(input, Game.GetWorldHostNames(type, gameClass), isTabCompletion);
|
return matchGameType(input, Game.getWorldHostNames(type, gameClass), isTabCompletion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> matchMaps(List<GameType> source, String input, boolean isTabCompletion)
|
private List<String> matchMaps(List<GameType> source, String input, boolean isTabCompletion)
|
||||||
@ -417,7 +417,7 @@ public class SetCommand extends CommandBase<ArcadeManager>
|
|||||||
// No particular source specified, we'll use all of them
|
// No particular source specified, we'll use all of them
|
||||||
if (gameSourceStr == null)
|
if (gameSourceStr == null)
|
||||||
{
|
{
|
||||||
List<GameType> mapTypes = Arrays.asList(Game.GetWorldHostNames(gameType, gameClass));
|
List<GameType> mapTypes = Arrays.asList(Game.getWorldHostNames(gameType, gameClass));
|
||||||
return matchMaps(mapTypes, mapStr, true).stream().map(str -> MAP_PREFIX + str).collect(Collectors.toList());
|
return matchMaps(mapTypes, mapStr, true).stream().map(str -> MAP_PREFIX + str).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +157,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
|
|||||||
protected String[] _gameDesc;
|
protected String[] _gameDesc;
|
||||||
|
|
||||||
private PhasedLifetime<GameState> _lifetime = new PhasedLifetime<>();
|
private PhasedLifetime<GameState> _lifetime = new PhasedLifetime<>();
|
||||||
// Map
|
|
||||||
private HashMap<GameType, ArrayList<String>> _files;
|
|
||||||
|
|
||||||
// State
|
// State
|
||||||
private GameState _gameState = GameState.Loading;
|
private GameState _gameState = GameState.Loading;
|
||||||
@ -434,45 +432,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
|
|||||||
|
|
||||||
// Scoreboard
|
// Scoreboard
|
||||||
Scoreboard = new GameScoreboard(this);
|
Scoreboard = new GameScoreboard(this);
|
||||||
|
|
||||||
// Map Select
|
|
||||||
_files = new HashMap<>();
|
|
||||||
for (GameType type : GetWorldHostNames())
|
|
||||||
{
|
|
||||||
_files.put(type, Manager.LoadFiles(type.getName()));
|
|
||||||
}
|
|
||||||
if (Manager.GetGameCreationManager().MapPref != null)
|
|
||||||
{
|
|
||||||
System.out.println("Map Preference: " + Manager.GetGameCreationManager().MapPref);
|
|
||||||
|
|
||||||
HashMap<GameType, ArrayList<String>> matches = new HashMap<>();
|
|
||||||
for (GameType game : _files.keySet())
|
|
||||||
{
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
|
||||||
for (String cur : _files.get(game))
|
|
||||||
{
|
|
||||||
if (cur.replaceAll(" ", "").toLowerCase().contains(Manager.GetGameCreationManager().MapPref.toLowerCase()))
|
|
||||||
{
|
|
||||||
if (Manager.GetGameCreationManager().MapSource == null || game == Manager.GetGameCreationManager().MapSource)
|
|
||||||
{
|
|
||||||
list.add(cur);
|
|
||||||
System.out.print("Map Preference: " + cur);
|
|
||||||
matches.put(game, list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matches.size() > 0)
|
|
||||||
_files = matches;
|
|
||||||
|
|
||||||
Manager.GetGameCreationManager().MapPref = null;
|
|
||||||
Manager.GetGameCreationManager().MapSource = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
System.out.println("Map Preference: None");
|
|
||||||
}
|
|
||||||
WorldData = new WorldData(this);
|
WorldData = new WorldData(this);
|
||||||
|
|
||||||
// Stat Trackers
|
// Stat Trackers
|
||||||
@ -600,22 +559,12 @@ public abstract class Game extends ListenerComponent implements Lifetimed
|
|||||||
_kits = kits;
|
_kits = kits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<GameType, ArrayList<String>> GetFiles()
|
|
||||||
{
|
|
||||||
return _files;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String GetName()
|
public String GetName()
|
||||||
{
|
{
|
||||||
return _gameType.getName();
|
return _gameType.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameType[] GetWorldHostNames()
|
public static GameType[] getWorldHostNames(GameType targetType, Class<? extends Game> gameMode)
|
||||||
{
|
|
||||||
return GetWorldHostNames(GetType(), getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameType[] GetWorldHostNames(GameType targetType, Class<? extends Game> gameMode)
|
|
||||||
{
|
{
|
||||||
GameType[] mapSource = new GameType[]
|
GameType[] mapSource = new GameType[]
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -17,6 +18,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import mineplex.core.common.Pair;
|
||||||
import mineplex.core.common.timing.TimingManager;
|
import mineplex.core.common.timing.TimingManager;
|
||||||
import mineplex.core.common.util.UtilAlg;
|
import mineplex.core.common.util.UtilAlg;
|
||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
@ -37,6 +39,8 @@ import nautilus.game.arcade.managers.voting.types.GameVote;
|
|||||||
public class GameCreationManager implements Listener
|
public class GameCreationManager implements Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final int MAX_ATTEMPTS = 50;
|
||||||
|
|
||||||
final ArcadeManager Manager;
|
final ArcadeManager Manager;
|
||||||
private final VotingManager _votingManager;
|
private final VotingManager _votingManager;
|
||||||
|
|
||||||
@ -47,6 +51,7 @@ public class GameCreationManager implements Listener
|
|||||||
private String _lastMap = "";
|
private String _lastMap = "";
|
||||||
private GameMode _lastMode = null;
|
private GameMode _lastMode = null;
|
||||||
private final List<GameType> _lastGames = new ArrayList<>();
|
private final List<GameType> _lastGames = new ArrayList<>();
|
||||||
|
private Map<GameType, List<String>> _maps;
|
||||||
|
|
||||||
public String MapPref = null;
|
public String MapPref = null;
|
||||||
public GameType MapSource = null;
|
public GameType MapSource = null;
|
||||||
@ -214,7 +219,7 @@ public class GameCreationManager implements Listener
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 50; i++)
|
for (int i = 0; i < MAX_ATTEMPTS; i++)
|
||||||
{
|
{
|
||||||
gameType = UtilAlg.Random(Manager.GetGameList());
|
gameType = UtilAlg.Random(Manager.GetGameList());
|
||||||
ModePref = randomGameMode(gameType);
|
ModePref = randomGameMode(gameType);
|
||||||
@ -227,6 +232,11 @@ public class GameCreationManager implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameType == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Reset Changes
|
//Reset Changes
|
||||||
Manager.GetCreature().SetDisableCustomDrops(false);
|
Manager.GetCreature().SetDisableCustomDrops(false);
|
||||||
Manager.GetDamage().resetConfiguration();
|
Manager.GetDamage().resetConfiguration();
|
||||||
@ -242,11 +252,11 @@ public class GameCreationManager implements Listener
|
|||||||
_lastGames.add(0, gameType);
|
_lastGames.add(0, gameType);
|
||||||
|
|
||||||
boolean setVars = false;
|
boolean setVars = false;
|
||||||
|
Class<? extends Game> gameClass = gameType.getGameClass();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GameMode mode = null;
|
GameMode mode = null;
|
||||||
Class<? extends Game> gameClass = gameType.getGameClass();
|
|
||||||
|
|
||||||
if (ModePref != null)
|
if (ModePref != null)
|
||||||
{
|
{
|
||||||
@ -268,6 +278,9 @@ public class GameCreationManager implements Listener
|
|||||||
gameClass = UtilMath.randomElement(gameType.getGameModes()).getGameClass();
|
gameClass = UtilMath.randomElement(gameType.getGameModes()).getGameClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maps
|
||||||
|
loadMaps(gameType, gameClass);
|
||||||
|
|
||||||
ModePref = null;
|
ModePref = null;
|
||||||
|
|
||||||
Game game = gameClass.getConstructor(ArcadeManager.class).newInstance(Manager);
|
Game game = gameClass.getConstructor(ArcadeManager.class).newInstance(Manager);
|
||||||
@ -310,6 +323,90 @@ public class GameCreationManager implements Listener
|
|||||||
TimingManager.stop("registerEvents");
|
TimingManager.stop("registerEvents");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadMaps(GameType gameType, Class<? extends Game> gameClass)
|
||||||
|
{
|
||||||
|
_maps = new HashMap<>();
|
||||||
|
|
||||||
|
// Map
|
||||||
|
for (GameType type : Game.getWorldHostNames(gameType, gameClass))
|
||||||
|
{
|
||||||
|
_maps.put(type, Manager.LoadFiles(type.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MapPref != null)
|
||||||
|
{
|
||||||
|
System.out.println("Map Preference: " + MapPref);
|
||||||
|
|
||||||
|
Map<GameType, List<String>> matches = new HashMap<>();
|
||||||
|
|
||||||
|
for (Entry<GameType, List<String>> entry : _maps.entrySet())
|
||||||
|
{
|
||||||
|
GameType entryType = entry.getKey();
|
||||||
|
List<String> maps = entry.getValue();
|
||||||
|
List<String> matchList = new ArrayList<>();
|
||||||
|
|
||||||
|
maps.forEach(map ->
|
||||||
|
{
|
||||||
|
if (map.replace(" ", "").toLowerCase().contains(MapPref.toLowerCase()))
|
||||||
|
{
|
||||||
|
if (MapSource == null || entryType == MapSource)
|
||||||
|
{
|
||||||
|
matchList.add(map);
|
||||||
|
System.out.print("Map Preference: " + map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
matches.put(entryType, matchList);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matches.isEmpty())
|
||||||
|
{
|
||||||
|
_maps = matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapPref = null;
|
||||||
|
MapSource = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("Map Preference: None");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pair<GameType, String> getMapFile()
|
||||||
|
{
|
||||||
|
GameType gameType = null;
|
||||||
|
String selectedMap = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_ATTEMPTS; i++)
|
||||||
|
{
|
||||||
|
int gameTypeIndex = UtilMath.r(_maps.size());
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (GameType mapType : _maps.keySet())
|
||||||
|
{
|
||||||
|
if (index++ == gameTypeIndex)
|
||||||
|
{
|
||||||
|
gameType = mapType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedMap = UtilAlg.Random(_maps.get(gameType));
|
||||||
|
|
||||||
|
// Not the last map
|
||||||
|
if (!selectedMap.equals(_lastMap))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastMap = selectedMap;
|
||||||
|
|
||||||
|
return Pair.create(gameType, selectedMap);
|
||||||
|
}
|
||||||
|
|
||||||
private GameMode randomGameMode(GameType type)
|
private GameMode randomGameMode(GameType type)
|
||||||
{
|
{
|
||||||
ArrayList<String> modes = Manager.GetServerConfig().GameModeList;
|
ArrayList<String> modes = Manager.GetServerConfig().GameModeList;
|
||||||
|
@ -378,6 +378,10 @@ public abstract class LobbyManager implements Listener
|
|||||||
|
|
||||||
_manager.getMineplexGameManager().clearKitNPCs();
|
_manager.getMineplexGameManager().clearKitNPCs();
|
||||||
|
|
||||||
|
// Remove Old Kits
|
||||||
|
getKitBlocks().forEach(Block::setType);
|
||||||
|
getKitBlocks().clear();
|
||||||
|
|
||||||
//Remove Old Ents
|
//Remove Old Ents
|
||||||
getTeams().keySet().forEach(Entity::remove);
|
getTeams().keySet().forEach(Entity::remove);
|
||||||
getTeams().clear();
|
getTeams().clear();
|
||||||
|
@ -222,9 +222,6 @@ public class NewGameLobbyManager extends LobbyManager
|
|||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
.forEach(Entity::remove);
|
.forEach(Entity::remove);
|
||||||
|
|
||||||
getKitBlocks().forEach(Block::setType);
|
|
||||||
getKitBlocks().clear();
|
|
||||||
|
|
||||||
List<Kit> kitList = Lists.newArrayList(game.GetKits()).stream()
|
List<Kit> kitList = Lists.newArrayList(game.GetKits()).stream()
|
||||||
.filter(kit -> !(kit instanceof NullKit))
|
.filter(kit -> !(kit instanceof NullKit))
|
||||||
.filter(kit -> kit.GetAvailability() != KitAvailability.Hide)
|
.filter(kit -> kit.GetAvailability() != KitAvailability.Hide)
|
||||||
|
@ -9,7 +9,6 @@ import org.bukkit.DyeColor;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Sheep;
|
import org.bukkit.entity.Sheep;
|
||||||
|
|
||||||
@ -20,7 +19,6 @@ import mineplex.core.common.util.UtilAlg;
|
|||||||
import mineplex.core.common.util.UtilEnt;
|
import mineplex.core.common.util.UtilEnt;
|
||||||
import mineplex.core.common.util.UtilWorld;
|
import mineplex.core.common.util.UtilWorld;
|
||||||
import mineplex.core.game.kit.KitAvailability;
|
import mineplex.core.game.kit.KitAvailability;
|
||||||
import mineplex.core.newnpc.NPC;
|
|
||||||
|
|
||||||
import nautilus.game.arcade.ArcadeManager;
|
import nautilus.game.arcade.ArcadeManager;
|
||||||
import nautilus.game.arcade.GameType;
|
import nautilus.game.arcade.GameType;
|
||||||
@ -98,14 +96,6 @@ public class LegacyGameLobbyManager extends LobbyManager
|
|||||||
writeTeamLine("Select", 0, 159, (byte) 15);
|
writeTeamLine("Select", 0, 159, (byte) 15);
|
||||||
writeTeamLine("Team", 1, 159, (byte) 4);
|
writeTeamLine("Team", 1, 159, (byte) 4);
|
||||||
|
|
||||||
//Remove Old Ents
|
|
||||||
getTeams().keySet().forEach(Entity::remove);
|
|
||||||
getTeams().clear();
|
|
||||||
|
|
||||||
//Remove Blocks
|
|
||||||
getTeamBlocks().forEach(Block::setType);
|
|
||||||
getTeamBlocks().clear();
|
|
||||||
|
|
||||||
//Smash
|
//Smash
|
||||||
if (game.HideTeamSheep)
|
if (game.HideTeamSheep)
|
||||||
{
|
{
|
||||||
@ -168,10 +158,6 @@ public class LegacyGameLobbyManager extends LobbyManager
|
|||||||
writeKitLine("Select", 0, 159, (byte) 15);
|
writeKitLine("Select", 0, 159, (byte) 15);
|
||||||
writeKitLine("Kit", 1, 159, (byte) 4);
|
writeKitLine("Kit", 1, 159, (byte) 4);
|
||||||
|
|
||||||
//Remove Blocks
|
|
||||||
getKitBlocks().forEach(Block::setType);
|
|
||||||
getKitBlocks().clear();
|
|
||||||
|
|
||||||
//Display
|
//Display
|
||||||
List<Kit> kits = Lists.newArrayList();
|
List<Kit> kits = Lists.newArrayList();
|
||||||
for (Kit kit : game.GetKits())
|
for (Kit kit : game.GetKits())
|
||||||
|
@ -1,25 +1,5 @@
|
|||||||
package nautilus.game.arcade.world;
|
package nautilus.game.arcade.world;
|
||||||
|
|
||||||
import com.mineplex.spigot.ChunkPreLoadEvent;
|
|
||||||
|
|
||||||
import mineplex.core.common.util.FileUtil;
|
|
||||||
import mineplex.core.common.util.MapUtil;
|
|
||||||
import mineplex.core.common.util.UtilMath;
|
|
||||||
import mineplex.core.common.util.UtilServer;
|
|
||||||
import mineplex.core.common.util.WorldUtil;
|
|
||||||
import mineplex.core.common.util.ZipUtil;
|
|
||||||
import mineplex.core.common.util.worldgen.WorldGenCleanRoom;
|
|
||||||
import mineplex.core.common.api.enderchest.EnderchestWorldLoader;
|
|
||||||
import mineplex.core.common.timing.TimingManager;
|
|
||||||
import nautilus.game.arcade.GameType;
|
|
||||||
import nautilus.game.arcade.game.Game;
|
|
||||||
import nautilus.game.arcade.game.games.uhc.UHC;
|
|
||||||
import org.bukkit.Difficulty;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.spigotmc.SpigotConfig;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@ -28,18 +8,37 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
|
import org.spigotmc.SpigotConfig;
|
||||||
|
|
||||||
|
import mineplex.core.common.Pair;
|
||||||
|
import mineplex.core.common.api.enderchest.EnderchestWorldLoader;
|
||||||
|
import mineplex.core.common.timing.TimingManager;
|
||||||
|
import mineplex.core.common.util.FileUtil;
|
||||||
|
import mineplex.core.common.util.MapUtil;
|
||||||
|
import mineplex.core.common.util.UtilMath;
|
||||||
|
import mineplex.core.common.util.WorldUtil;
|
||||||
|
import mineplex.core.common.util.ZipUtil;
|
||||||
|
import mineplex.core.common.util.worldgen.WorldGenCleanRoom;
|
||||||
|
|
||||||
|
import nautilus.game.arcade.GameType;
|
||||||
|
import nautilus.game.arcade.game.Game;
|
||||||
|
import nautilus.game.arcade.game.games.uhc.UHC;
|
||||||
|
|
||||||
public class WorldData
|
public class WorldData
|
||||||
{
|
{
|
||||||
public Game Host;
|
|
||||||
|
|
||||||
public int Id = -1;
|
public final Game Host;
|
||||||
|
private final int Id;
|
||||||
|
|
||||||
public String File = null;
|
public String File = null;
|
||||||
public String Folder = null;
|
private String Folder = null;
|
||||||
|
|
||||||
public World World;
|
public World World;
|
||||||
public int MinX = 0;
|
public int MinX = 0;
|
||||||
@ -55,9 +54,9 @@ public class WorldData
|
|||||||
|
|
||||||
public GameType Game = null;
|
public GameType Game = null;
|
||||||
|
|
||||||
public HashMap<String, ArrayList<Location>> SpawnLocs = new LinkedHashMap<String, ArrayList<Location>>();
|
public final Map<String, ArrayList<Location>> SpawnLocs = new LinkedHashMap<>();
|
||||||
private HashMap<String, ArrayList<Location>> DataLocs = new LinkedHashMap<String, ArrayList<Location>>();
|
private final Map<String, ArrayList<Location>> DataLocs = new LinkedHashMap<>();
|
||||||
private HashMap<String, ArrayList<Location>> CustomLocs = new LinkedHashMap<String, ArrayList<Location>>();
|
private final Map<String, ArrayList<Location>> CustomLocs = new LinkedHashMap<>();
|
||||||
private final Map<String, String> _dataEntries = new LinkedHashMap<>();
|
private final Map<String, String> _dataEntries = new LinkedHashMap<>();
|
||||||
|
|
||||||
public WorldData(Game game)
|
public WorldData(Game game)
|
||||||
@ -74,27 +73,24 @@ public class WorldData
|
|||||||
final WorldData worldData = this;
|
final WorldData worldData = this;
|
||||||
GetFile();
|
GetFile();
|
||||||
|
|
||||||
UtilServer.getServer().getScheduler().runTaskAsynchronously(Host.Manager.getPlugin(), new Runnable()
|
Host.getArcadeManager().runAsync(() ->
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
//Unzip
|
//Unzip
|
||||||
if (Host instanceof UHC) {
|
if (Host instanceof UHC)
|
||||||
|
{
|
||||||
boolean uhcLoaded = loadUHCMap(); // attempt to load from enderchest
|
boolean uhcLoaded = loadUHCMap(); // attempt to load from enderchest
|
||||||
if (!uhcLoaded)
|
if (!uhcLoaded)
|
||||||
{
|
{
|
||||||
// failsafe on normal UHC map
|
// failsafe on normal UHC map
|
||||||
worldData.UnzipWorld();
|
worldData.UnzipWorld();
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
worldData.UnzipWorld();
|
worldData.UnzipWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load World Data Sync
|
Host.getArcadeManager().runSync(() ->
|
||||||
UtilServer.getServer().getScheduler().runTask(Host.Manager.getPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
{
|
||||||
TimingManager.start("WorldData loading world.");
|
TimingManager.start("WorldData loading world.");
|
||||||
|
|
||||||
@ -112,19 +108,7 @@ public class WorldData
|
|||||||
//Load World Data
|
//Load World Data
|
||||||
worldData.LoadWorldConfig();
|
worldData.LoadWorldConfig();
|
||||||
TimingManager.stop("WorldData loading WorldConfig.");
|
TimingManager.stop("WorldData loading WorldConfig.");
|
||||||
|
|
||||||
/*
|
|
||||||
TimingManager.start("WinEffect Room Builder.");
|
|
||||||
|
|
||||||
Location loc = GetRandomXZ().add(1000, 0, 1000);
|
|
||||||
loc.setY(200);
|
|
||||||
worldData.Host.WinEffectManager.prepareSetup(loc);
|
|
||||||
|
|
||||||
TimingManager.stop("WinEffect Room Builder.");
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +126,8 @@ public class WorldData
|
|||||||
worldLoader.loadMap("uhc", GetFolder());
|
worldLoader.loadMap("uhc", GetFolder());
|
||||||
SpigotConfig.config.set("world-settings." + GetFolder() + ".view-distance", UHC.VIEW_DISTANCE);
|
SpigotConfig.config.set("world-settings." + GetFolder() + ".view-distance", UHC.VIEW_DISTANCE);
|
||||||
success = true;
|
success = true;
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
attempt++;
|
attempt++;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -157,58 +142,14 @@ public class WorldData
|
|||||||
return Game;
|
return Game;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String GetFile()
|
private String GetFile()
|
||||||
{
|
{
|
||||||
if (File == null)
|
if (File == null)
|
||||||
{
|
{
|
||||||
GameType game = null;
|
Pair<GameType, String> mapFile = Host.getArcadeManager().GetGameCreationManager().getMapFile();
|
||||||
int gameRandom = UtilMath.r(Host.GetFiles().size());
|
Game = mapFile.getLeft();
|
||||||
int i = 0;
|
File = mapFile.getRight();
|
||||||
for(GameType type : Host.GetFiles().keySet())
|
|
||||||
{
|
|
||||||
if(i == gameRandom)
|
|
||||||
{
|
|
||||||
game = type;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
Game = game;
|
|
||||||
int map;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
map = UtilMath.r(Host.GetFiles().get(game).size());
|
|
||||||
} catch (IllegalArgumentException e)
|
|
||||||
{
|
|
||||||
System.out.println("No maps found!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
File = Host.GetFiles().get(game).get(map);
|
|
||||||
|
|
||||||
//Don't allow repeat maps.
|
|
||||||
if (Host.GetFiles().get(game).size() > 1)
|
|
||||||
{
|
|
||||||
while (File.equals(Host.Manager.GetGameCreationManager().GetLastMap()))
|
|
||||||
{
|
|
||||||
GameType _game = null;
|
|
||||||
int _gameRandom = UtilMath.r(Host.GetFiles().size());
|
|
||||||
int _i = 0;
|
|
||||||
for(GameType _type : Host.GetFiles().keySet())
|
|
||||||
{
|
|
||||||
if(_i == _gameRandom)
|
|
||||||
{
|
|
||||||
_game = _type;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_i++;
|
|
||||||
}
|
|
||||||
int _map = UtilMath.r(Host.GetFiles().get(game).size());
|
|
||||||
File = Host.GetFiles().get(_game).get(_map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Host.Manager.GetGameCreationManager().SetLastMap(File);
|
|
||||||
|
|
||||||
return File;
|
return File;
|
||||||
}
|
}
|
||||||
@ -275,7 +216,7 @@ public class WorldData
|
|||||||
//Spawn Locations
|
//Spawn Locations
|
||||||
else if (tokens[0].equalsIgnoreCase("TEAM_NAME"))
|
else if (tokens[0].equalsIgnoreCase("TEAM_NAME"))
|
||||||
{
|
{
|
||||||
SpawnLocs.put(tokens[1], new ArrayList<Location>());
|
SpawnLocs.put(tokens[1], new ArrayList<>());
|
||||||
currentTeam = SpawnLocs.get(tokens[1]);
|
currentTeam = SpawnLocs.get(tokens[1]);
|
||||||
currentDirection = 0;
|
currentDirection = 0;
|
||||||
}
|
}
|
||||||
@ -299,7 +240,7 @@ public class WorldData
|
|||||||
//Data Locations
|
//Data Locations
|
||||||
else if (tokens[0].equalsIgnoreCase("DATA_NAME"))
|
else if (tokens[0].equalsIgnoreCase("DATA_NAME"))
|
||||||
{
|
{
|
||||||
DataLocs.put(tokens[1], new ArrayList<Location>());
|
DataLocs.put(tokens[1], new ArrayList<>());
|
||||||
currentData = DataLocs.get(tokens[1]);
|
currentData = DataLocs.get(tokens[1]);
|
||||||
}
|
}
|
||||||
else if (tokens[0].equalsIgnoreCase("DATA_LOCS"))
|
else if (tokens[0].equalsIgnoreCase("DATA_LOCS"))
|
||||||
@ -316,7 +257,7 @@ public class WorldData
|
|||||||
//Custom Locations
|
//Custom Locations
|
||||||
else if (tokens[0].equalsIgnoreCase("CUSTOM_NAME"))
|
else if (tokens[0].equalsIgnoreCase("CUSTOM_NAME"))
|
||||||
{
|
{
|
||||||
CustomLocs.put(tokens[1], new ArrayList<Location>());
|
CustomLocs.put(tokens[1], new ArrayList<>());
|
||||||
currentData = CustomLocs.get(tokens[1]);
|
currentData = CustomLocs.get(tokens[1]);
|
||||||
}
|
}
|
||||||
else if (tokens[0].equalsIgnoreCase("CUSTOM_LOCS"))
|
else if (tokens[0].equalsIgnoreCase("CUSTOM_LOCS"))
|
||||||
@ -444,27 +385,6 @@ public class WorldData
|
|||||||
World = null;
|
World = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChunkLoad(ChunkPreLoadEvent event)
|
|
||||||
{
|
|
||||||
if (World == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!event.getWorld().equals(World))
|
|
||||||
return;
|
|
||||||
|
|
||||||
int x = event.getX();
|
|
||||||
int z = event.getZ();
|
|
||||||
|
|
||||||
|
|
||||||
if (x >= MinX >> 4 && x <= MaxX >> 4 && z >= MinZ >> 4 && z <= MaxZ >> 4)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetNewId()
|
public int GetNewId()
|
||||||
{
|
{
|
||||||
File file = new File("GameId.dat");
|
File file = new File("GameId.dat");
|
||||||
@ -527,7 +447,9 @@ public class WorldData
|
|||||||
public ArrayList<Location> GetDataLocs(String data)
|
public ArrayList<Location> GetDataLocs(String data)
|
||||||
{
|
{
|
||||||
if (!DataLocs.containsKey(data))
|
if (!DataLocs.containsKey(data))
|
||||||
return new ArrayList<Location>();
|
{
|
||||||
|
return new ArrayList<>(0);
|
||||||
|
}
|
||||||
|
|
||||||
return DataLocs.get(data);
|
return DataLocs.get(data);
|
||||||
}
|
}
|
||||||
@ -535,17 +457,19 @@ public class WorldData
|
|||||||
public ArrayList<Location> GetCustomLocs(String id)
|
public ArrayList<Location> GetCustomLocs(String id)
|
||||||
{
|
{
|
||||||
if (!CustomLocs.containsKey(id))
|
if (!CustomLocs.containsKey(id))
|
||||||
return new ArrayList<Location>();
|
{
|
||||||
|
return new ArrayList<>(0);
|
||||||
|
}
|
||||||
|
|
||||||
return CustomLocs.get(id);
|
return CustomLocs.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, ArrayList<Location>> GetAllCustomLocs()
|
public Map<String, ArrayList<Location>> GetAllCustomLocs()
|
||||||
{
|
{
|
||||||
return CustomLocs;
|
return CustomLocs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, ArrayList<Location>> GetAllDataLocs()
|
public Map<String, ArrayList<Location>> GetAllDataLocs()
|
||||||
{
|
{
|
||||||
return DataLocs;
|
return DataLocs;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user