Make DSign#getGame() accessible pre ready

This commit is contained in:
Daniel Saukel 2016-05-15 18:01:51 +02:00
parent ab40ea726f
commit 3ca7017664
9 changed files with 43 additions and 30 deletions

View File

@ -156,7 +156,7 @@ public class PlayCommand extends BRCommand {
}
if (dGroup.getGameWorld() == null) {
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
new Game(dGroup, dGroup.getMapName());
}
if (dGroup.getGameWorld() == null) {
@ -165,7 +165,6 @@ public class PlayCommand extends BRCommand {
return;
}
new Game(dGroup, dGroup.getGameWorld());
if (dGroup.getGameWorld().getLobbyLocation() == null) {
for (Player groupPlayer : dGroup.getPlayers()) {
new DGamePlayer(groupPlayer, dGroup.getGameWorld());

View File

@ -64,8 +64,23 @@ public class Game {
}
public Game(DGroup dGroup, GameWorld world) {
this(dGroup);
dGroups.add(dGroup);
started = false;
this.world = world;
fetchRules();
plugin.getGames().add(this);
}
public Game(DGroup dGroup, String worldName) {
plugin.getGames().add(this);
dGroups.add(dGroup);
started = false;
world = new GameWorld();
dGroup.setGameWorld(world);
fetchRules();
world.load(worldName);
}
public Game(DGroup dGroup, GameType type, GameWorld world) {

View File

@ -186,7 +186,7 @@ public class DPortal extends GlobalProtection {
}
if (target == null) {
target = GameWorld.load(dGroup.getMapName());
target = new GameWorld(dGroup.getMapName());
dGroup.setGameWorld(target);
}

View File

@ -560,7 +560,7 @@ public class PlayerListener implements Listener {
}
if (dGroup.getGameWorld() == null) {
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
dGroup.setGameWorld(new GameWorld(DGroup.getByPlayer(player).getMapName()));
dGroup.getGameWorld().setTutorial(true);
}

View File

@ -83,7 +83,7 @@ public class DMobType {
this.name = name;
// Read Mobs
EntityType type = EntityType.fromName(config.getString("type"));
type = EntityType.fromName(config.getString("type"));
// Load MaxHealth
if (config.contains("maxHealth")) {

View File

@ -589,7 +589,7 @@ public class DGamePlayer extends DInstancePlayer {
dGroup.removeUnplayedFloor(dGroup.getMapName());
dGroup.setMapName(newFloor);
GameWorld gameWorld = GameWorld.load(newFloor);
GameWorld gameWorld = new GameWorld(newFloor);
dGroup.setGameWorld(gameWorld);
for (Player player : dGroup.getPlayers()) {
DGamePlayer dPlayer = getByPlayer(player);

View File

@ -33,6 +33,7 @@ public class ClassesSign extends DSign {
public ClassesSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
dClass = plugin.getDClasses().getByName(sign.getLine(1));
}
/* Getters and setters */
@ -55,8 +56,7 @@ public class ClassesSign extends DSign {
@Override
public boolean check() {
String[] lines = getSign().getLines();
dClass = plugin.getDClasses().getByName(lines[1]);
return dClass != null;
return plugin.getDClasses().getByName(lines[1]) != null;
}
@Override
@ -73,7 +73,6 @@ public class ClassesSign extends DSign {
getSign().update();
getGameWorld().getSignClass().add(getSign());
}
@Override

View File

@ -75,7 +75,7 @@ public class MobSpawnTask extends BukkitRunnable {
DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob());
if (mobType != null) {
mobType.spawn(GameWorld.getByWorld(world), spawnLoc);
mobType.spawn(gameWorld, spawnLoc);
}
// Set the amount

View File

@ -109,6 +109,11 @@ public class GameWorld {
}
}
public GameWorld(String name) {
this();
load(name);
}
/**
* @return
* the Game connected to the GameWorld
@ -472,20 +477,18 @@ public class GameWorld {
}
}
/* Statics */
public static GameWorld load(String name) {
public void load(String name) {
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
return;
}
File file = new File(plugin.getDataFolder(), "/maps/" + name);
if (file.exists()) {
GameWorld gameWorld = new GameWorld();
gameWorld.mapName = name;
mapName = name;
// Unload empty editWorlds
for (EditWorld editWorld : plugin.getEditWorlds()) {
@ -495,55 +498,52 @@ public class GameWorld {
}
// Config einlesen
gameWorld.worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName, "config.yml"));
worldConfig = new WorldConfig(new File(plugin.getDataFolder() + "/maps/" + mapName, "config.yml"));
// Secure Objects
gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects();
secureObjects = worldConfig.getSecureObjects();
if (Bukkit.getWorld("DXL_Game_" + gameWorld.id) == null) {
if (Bukkit.getWorld("DXL_Game_" + id) == null) {
// World
FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id), DungeonsXL.EXCLUDED_FILES);
FileUtil.copyDirectory(file, new File("DXL_Game_" + id), DungeonsXL.EXCLUDED_FILES);
// Id File
File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name);
File idFile = new File("DXL_Game_" + id + "/.id_" + name);
try {
idFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id));
world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + id));
ObjectInputStream os;
try {
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data")));
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + mapName + "/DXLData.data")));
int length = os.readInt();
for (int i = 0; i < length; i++) {
int x = os.readInt();
int y = os.readInt();
int z = os.readInt();
Block block = gameWorld.world.getBlockAt(x, y, z);
gameWorld.checkSign(block);
Block block = world.getBlockAt(x, y, z);
checkSign(block);
}
os.close();
} catch (FileNotFoundException exception) {
plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!");
MessageUtil.log(plugin, "Could not find any sign data for the world \"" + name + "\"!");
} catch (IOException exception) {
exception.printStackTrace();
}
}
return gameWorld;
}
return null;
}
}
/* Statics */
public static GameWorld getByWorld(World world) {
for (GameWorld gameWorld : plugin.getGameWorlds()) {
if (gameWorld.getWorld() == null) {