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,19 +8,38 @@ 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;
|
||||||
|
|
||||||
public class WorldData
|
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 Game Host;
|
|
||||||
|
public final Game Host;
|
||||||
public int Id = -1;
|
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;
|
||||||
public int MinZ = 0;
|
public int MinZ = 0;
|
||||||
@ -49,82 +48,67 @@ public class WorldData
|
|||||||
|
|
||||||
public int MinY = -1;
|
public int MinY = -1;
|
||||||
public int MaxY = 256;
|
public int MaxY = 256;
|
||||||
|
|
||||||
public String MapName = "Null";
|
public String MapName = "Null";
|
||||||
public String MapAuthor = "Null";
|
public String MapAuthor = "Null";
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
Host = game;
|
Host = game;
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
Id = GetNewId();
|
Id = GetNewId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
if (Host instanceof UHC)
|
||||||
{
|
{
|
||||||
//Unzip
|
boolean uhcLoaded = loadUHCMap(); // attempt to load from enderchest
|
||||||
if (Host instanceof UHC) {
|
if (!uhcLoaded)
|
||||||
boolean uhcLoaded = loadUHCMap(); // attempt to load from enderchest
|
|
||||||
if (!uhcLoaded)
|
|
||||||
{
|
|
||||||
// failsafe on normal UHC map
|
|
||||||
worldData.UnzipWorld();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
|
// failsafe on normal UHC map
|
||||||
worldData.UnzipWorld();
|
worldData.UnzipWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load World Data Sync
|
|
||||||
UtilServer.getServer().getScheduler().runTask(Host.Manager.getPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
TimingManager.start("WorldData loading world.");
|
|
||||||
|
|
||||||
WorldCreator creator = new WorldCreator(GetFolder());
|
|
||||||
creator.generator(new WorldGenCleanRoom());
|
|
||||||
World = WorldUtil.LoadWorld(creator);
|
|
||||||
|
|
||||||
|
|
||||||
TimingManager.stop("WorldData loading world.");
|
|
||||||
|
|
||||||
World.setDifficulty(Difficulty.HARD);
|
|
||||||
World.setGameRuleValue("showDeathMessages", "false");
|
|
||||||
|
|
||||||
TimingManager.start("WorldData loading WorldConfig.");
|
|
||||||
//Load World Data
|
|
||||||
worldData.LoadWorldConfig();
|
|
||||||
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.");
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
worldData.UnzipWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
Host.getArcadeManager().runSync(() ->
|
||||||
|
{
|
||||||
|
TimingManager.start("WorldData loading world.");
|
||||||
|
|
||||||
|
WorldCreator creator = new WorldCreator(GetFolder());
|
||||||
|
creator.generator(new WorldGenCleanRoom());
|
||||||
|
World = WorldUtil.LoadWorld(creator);
|
||||||
|
|
||||||
|
|
||||||
|
TimingManager.stop("WorldData loading world.");
|
||||||
|
|
||||||
|
World.setDifficulty(Difficulty.HARD);
|
||||||
|
World.setGameRuleValue("showDeathMessages", "false");
|
||||||
|
|
||||||
|
TimingManager.start("WorldData loading WorldConfig.");
|
||||||
|
//Load World Data
|
||||||
|
worldData.LoadWorldConfig();
|
||||||
|
TimingManager.stop("WorldData loading WorldConfig.");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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();
|
||||||
@ -151,78 +136,34 @@ public class WorldData
|
|||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GameType GetGame()
|
protected GameType GetGame()
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetFolder()
|
public String GetFolder()
|
||||||
{
|
{
|
||||||
if (Folder == null)
|
if (Folder == null)
|
||||||
{
|
{
|
||||||
Folder = "Game" + Id + "_" + GetGame().getName() + "_" + GetFile();
|
Folder = "Game" + Id + "_" + GetGame().getName() + "_" + GetFile();
|
||||||
}
|
}
|
||||||
return Folder;
|
return Folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UnzipWorld()
|
protected void UnzipWorld()
|
||||||
{
|
{
|
||||||
TimingManager.start("UnzipWorld creating folders");
|
TimingManager.start("UnzipWorld creating folders");
|
||||||
String folder = GetFolder();
|
String folder = GetFolder();
|
||||||
@ -230,38 +171,38 @@ public class WorldData
|
|||||||
new File(folder + java.io.File.separator + "region").mkdir();
|
new File(folder + java.io.File.separator + "region").mkdir();
|
||||||
new File(folder + java.io.File.separator + "data").mkdir();
|
new File(folder + java.io.File.separator + "data").mkdir();
|
||||||
TimingManager.stop("UnzipWorld creating folders");
|
TimingManager.stop("UnzipWorld creating folders");
|
||||||
|
|
||||||
TimingManager.start("UnzipWorld UnzipToDirectory");
|
TimingManager.start("UnzipWorld UnzipToDirectory");
|
||||||
ZipUtil.UnzipToDirectory("../../update/maps/" + GetGame().getName() + "/" + GetFile() + ".zip", folder);
|
ZipUtil.UnzipToDirectory("../../update/maps/" + GetGame().getName() + "/" + GetFile() + ".zip", folder);
|
||||||
TimingManager.stop("UnzipWorld UnzipToDirectory");
|
TimingManager.stop("UnzipWorld UnzipToDirectory");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadWorldConfig()
|
public void LoadWorldConfig()
|
||||||
{
|
{
|
||||||
//Load Track Data
|
//Load Track Data
|
||||||
String line = null;
|
String line = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileInputStream fstream = new FileInputStream(GetFolder() + java.io.File.separator + "WorldConfig.dat");
|
FileInputStream fstream = new FileInputStream(GetFolder() + java.io.File.separator + "WorldConfig.dat");
|
||||||
DataInputStream in = new DataInputStream(fstream);
|
DataInputStream in = new DataInputStream(fstream);
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||||
|
|
||||||
ArrayList<Location> currentTeam = null;
|
ArrayList<Location> currentTeam = null;
|
||||||
ArrayList<Location> currentData = null;
|
ArrayList<Location> currentData = null;
|
||||||
|
|
||||||
int currentDirection = 0;
|
int currentDirection = 0;
|
||||||
|
|
||||||
while ((line = br.readLine()) != null)
|
while ((line = br.readLine()) != null)
|
||||||
{
|
{
|
||||||
String[] tokens = line.split(":");
|
String[] tokens = line.split(":");
|
||||||
|
|
||||||
if (tokens.length < 2)
|
if (tokens.length < 2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (tokens[0].length() == 0)
|
if (tokens[0].length() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//Name & Author
|
//Name & Author
|
||||||
if (tokens[0].equalsIgnoreCase("MAP_NAME"))
|
if (tokens[0].equalsIgnoreCase("MAP_NAME"))
|
||||||
{
|
{
|
||||||
@ -271,11 +212,11 @@ public class WorldData
|
|||||||
{
|
{
|
||||||
MapAuthor = tokens[1];
|
MapAuthor = tokens[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
//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;
|
||||||
}
|
}
|
||||||
@ -285,51 +226,51 @@ public class WorldData
|
|||||||
}
|
}
|
||||||
else if (tokens[0].equalsIgnoreCase("TEAM_SPAWNS"))
|
else if (tokens[0].equalsIgnoreCase("TEAM_SPAWNS"))
|
||||||
{
|
{
|
||||||
for (int i=1 ; i<tokens.length ; i++)
|
for (int i = 1; i < tokens.length; i++)
|
||||||
{
|
{
|
||||||
Location loc = StrToLoc(tokens[i]);
|
Location loc = StrToLoc(tokens[i]);
|
||||||
if (loc == null) continue;
|
if (loc == null) continue;
|
||||||
|
|
||||||
loc.setYaw(currentDirection);
|
loc.setYaw(currentDirection);
|
||||||
|
|
||||||
currentTeam.add(loc);
|
currentTeam.add(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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"))
|
||||||
{
|
{
|
||||||
for (int i=1 ; i<tokens.length ; i++)
|
for (int i = 1; i < tokens.length; i++)
|
||||||
{
|
{
|
||||||
Location loc = StrToLoc(tokens[i]);
|
Location loc = StrToLoc(tokens[i]);
|
||||||
if (loc == null) continue;
|
if (loc == null) continue;
|
||||||
|
|
||||||
currentData.add(loc);
|
currentData.add(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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"))
|
||||||
{
|
{
|
||||||
for (int i=1 ; i<tokens.length ; i++)
|
for (int i = 1; i < tokens.length; i++)
|
||||||
{
|
{
|
||||||
Location loc = StrToLoc(tokens[i]);
|
Location loc = StrToLoc(tokens[i]);
|
||||||
if (loc == null) continue;
|
if (loc == null) continue;
|
||||||
|
|
||||||
currentData.add(loc);
|
currentData.add(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Map Bounds
|
//Map Bounds
|
||||||
else if (tokens[0].equalsIgnoreCase("MIN_X"))
|
else if (tokens[0].equalsIgnoreCase("MIN_X"))
|
||||||
{
|
{
|
||||||
@ -341,7 +282,7 @@ public class WorldData
|
|||||||
{
|
{
|
||||||
System.out.println("World Data Read Error: Invalid MinX [" + tokens[1] + "]");
|
System.out.println("World Data Read Error: Invalid MinX [" + tokens[1] + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (tokens[0].equalsIgnoreCase("MAX_X"))
|
else if (tokens[0].equalsIgnoreCase("MAX_X"))
|
||||||
{
|
{
|
||||||
@ -405,7 +346,7 @@ public class WorldData
|
|||||||
}
|
}
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
|
|
||||||
Host.Manager.GetGameWorldManager().RegisterWorld(this);
|
Host.Manager.GetGameWorldManager().RegisterWorld(this);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -414,58 +355,37 @@ public class WorldData
|
|||||||
System.err.println("Line: " + line);
|
System.err.println("Line: " + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Location StrToLoc(String loc)
|
protected Location StrToLoc(String loc)
|
||||||
{
|
{
|
||||||
String[] coords = loc.split(",");
|
String[] coords = loc.split(",");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new Location(World, Integer.valueOf(coords[0])+0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2])+0.5);
|
return new Location(World, Integer.valueOf(coords[0]) + 0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2]) + 0.5);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
System.out.println("World Data Read Error: Invalid Location String [" + loc + "]");
|
System.out.println("World Data Read Error: Invalid Location String [" + loc + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Uninitialize()
|
public void Uninitialize()
|
||||||
{
|
{
|
||||||
if (World == null)
|
if (World == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Wipe World
|
//Wipe World
|
||||||
MapUtil.UnloadWorld(Host.Manager.getPlugin(), World);
|
MapUtil.UnloadWorld(Host.Manager.getPlugin(), World);
|
||||||
MapUtil.ClearWorldReferences(World.getName());
|
MapUtil.ClearWorldReferences(World.getName());
|
||||||
FileUtil.DeleteFolder(new File(World.getName()));
|
FileUtil.DeleteFolder(new File(World.getName()));
|
||||||
|
|
||||||
World = null;
|
World = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChunkLoad(ChunkPreLoadEvent event)
|
public int GetNewId()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
File file = new File("GameId.dat");
|
File file = new File("GameId.dat");
|
||||||
|
|
||||||
@ -527,36 +447,40 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location GetRandomXZ()
|
public Location GetRandomXZ()
|
||||||
{
|
{
|
||||||
Location loc = new Location(World, 0, 250, 0);
|
Location loc = new Location(World, 0, 250, 0);
|
||||||
|
|
||||||
int xVar = MaxX - MinX;
|
int xVar = MaxX - MinX;
|
||||||
int zVar = MaxZ - MinZ;
|
int zVar = MaxZ - MinZ;
|
||||||
|
|
||||||
loc.setX(MinX + UtilMath.r(xVar));
|
loc.setX(MinX + UtilMath.r(xVar));
|
||||||
loc.setZ(MinZ + UtilMath.r(zVar));
|
loc.setZ(MinZ + UtilMath.r(zVar));
|
||||||
|
|
||||||
@ -567,5 +491,5 @@ public class WorldData
|
|||||||
{
|
{
|
||||||
return _dataEntries.get(key);
|
return _dataEntries.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user