mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-25 03:55:22 +01:00
Make DSign#getGame() accessible pre ready
This commit is contained in:
parent
ab40ea726f
commit
3ca7017664
@ -156,7 +156,7 @@ public class PlayCommand extends BRCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dGroup.getGameWorld() == null) {
|
if (dGroup.getGameWorld() == null) {
|
||||||
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
|
new Game(dGroup, dGroup.getMapName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dGroup.getGameWorld() == null) {
|
if (dGroup.getGameWorld() == null) {
|
||||||
@ -165,7 +165,6 @@ public class PlayCommand extends BRCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Game(dGroup, dGroup.getGameWorld());
|
|
||||||
if (dGroup.getGameWorld().getLobbyLocation() == null) {
|
if (dGroup.getGameWorld().getLobbyLocation() == null) {
|
||||||
for (Player groupPlayer : dGroup.getPlayers()) {
|
for (Player groupPlayer : dGroup.getPlayers()) {
|
||||||
new DGamePlayer(groupPlayer, dGroup.getGameWorld());
|
new DGamePlayer(groupPlayer, dGroup.getGameWorld());
|
||||||
|
@ -64,8 +64,23 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Game(DGroup dGroup, GameWorld world) {
|
public Game(DGroup dGroup, GameWorld world) {
|
||||||
this(dGroup);
|
dGroups.add(dGroup);
|
||||||
|
started = false;
|
||||||
this.world = world;
|
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) {
|
public Game(DGroup dGroup, GameType type, GameWorld world) {
|
||||||
|
@ -186,7 +186,7 @@ public class DPortal extends GlobalProtection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
target = GameWorld.load(dGroup.getMapName());
|
target = new GameWorld(dGroup.getMapName());
|
||||||
dGroup.setGameWorld(target);
|
dGroup.setGameWorld(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +560,7 @@ public class PlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dGroup.getGameWorld() == null) {
|
if (dGroup.getGameWorld() == null) {
|
||||||
dGroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
|
dGroup.setGameWorld(new GameWorld(DGroup.getByPlayer(player).getMapName()));
|
||||||
dGroup.getGameWorld().setTutorial(true);
|
dGroup.getGameWorld().setTutorial(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public class DMobType {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
// Read Mobs
|
// Read Mobs
|
||||||
EntityType type = EntityType.fromName(config.getString("type"));
|
type = EntityType.fromName(config.getString("type"));
|
||||||
|
|
||||||
// Load MaxHealth
|
// Load MaxHealth
|
||||||
if (config.contains("maxHealth")) {
|
if (config.contains("maxHealth")) {
|
||||||
|
@ -589,7 +589,7 @@ public class DGamePlayer extends DInstancePlayer {
|
|||||||
|
|
||||||
dGroup.removeUnplayedFloor(dGroup.getMapName());
|
dGroup.removeUnplayedFloor(dGroup.getMapName());
|
||||||
dGroup.setMapName(newFloor);
|
dGroup.setMapName(newFloor);
|
||||||
GameWorld gameWorld = GameWorld.load(newFloor);
|
GameWorld gameWorld = new GameWorld(newFloor);
|
||||||
dGroup.setGameWorld(gameWorld);
|
dGroup.setGameWorld(gameWorld);
|
||||||
for (Player player : dGroup.getPlayers()) {
|
for (Player player : dGroup.getPlayers()) {
|
||||||
DGamePlayer dPlayer = getByPlayer(player);
|
DGamePlayer dPlayer = getByPlayer(player);
|
||||||
|
@ -33,6 +33,7 @@ public class ClassesSign extends DSign {
|
|||||||
|
|
||||||
public ClassesSign(Sign sign, GameWorld gameWorld) {
|
public ClassesSign(Sign sign, GameWorld gameWorld) {
|
||||||
super(sign, gameWorld);
|
super(sign, gameWorld);
|
||||||
|
dClass = plugin.getDClasses().getByName(sign.getLine(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getters and setters */
|
/* Getters and setters */
|
||||||
@ -55,8 +56,7 @@ public class ClassesSign extends DSign {
|
|||||||
@Override
|
@Override
|
||||||
public boolean check() {
|
public boolean check() {
|
||||||
String[] lines = getSign().getLines();
|
String[] lines = getSign().getLines();
|
||||||
dClass = plugin.getDClasses().getByName(lines[1]);
|
return plugin.getDClasses().getByName(lines[1]) != null;
|
||||||
return dClass != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +73,6 @@ public class ClassesSign extends DSign {
|
|||||||
getSign().update();
|
getSign().update();
|
||||||
|
|
||||||
getGameWorld().getSignClass().add(getSign());
|
getGameWorld().getSignClass().add(getSign());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +75,7 @@ public class MobSpawnTask extends BukkitRunnable {
|
|||||||
DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob());
|
DMobType mobType = DungeonsXL.getInstance().getDMobTypes().getByName(sign.getMob());
|
||||||
|
|
||||||
if (mobType != null) {
|
if (mobType != null) {
|
||||||
mobType.spawn(GameWorld.getByWorld(world), spawnLoc);
|
mobType.spawn(gameWorld, spawnLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the amount
|
// Set the amount
|
||||||
|
@ -109,6 +109,11 @@ public class GameWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameWorld(String name) {
|
||||||
|
this();
|
||||||
|
load(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
* the Game connected to the GameWorld
|
* the Game connected to the GameWorld
|
||||||
@ -472,20 +477,18 @@ public class GameWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Statics */
|
public void load(String name) {
|
||||||
public static GameWorld load(String name) {
|
|
||||||
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
|
GameWorldLoadEvent event = new GameWorldLoadEvent(name);
|
||||||
plugin.getServer().getPluginManager().callEvent(event);
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(plugin.getDataFolder(), "/maps/" + name);
|
File file = new File(plugin.getDataFolder(), "/maps/" + name);
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
GameWorld gameWorld = new GameWorld();
|
mapName = name;
|
||||||
gameWorld.mapName = name;
|
|
||||||
|
|
||||||
// Unload empty editWorlds
|
// Unload empty editWorlds
|
||||||
for (EditWorld editWorld : plugin.getEditWorlds()) {
|
for (EditWorld editWorld : plugin.getEditWorlds()) {
|
||||||
@ -495,55 +498,52 @@ public class GameWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Config einlesen
|
// 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
|
// 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
|
// 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
|
// Id File
|
||||||
File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name);
|
File idFile = new File("DXL_Game_" + id + "/.id_" + name);
|
||||||
try {
|
try {
|
||||||
idFile.createNewFile();
|
idFile.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id));
|
world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + id));
|
||||||
|
|
||||||
ObjectInputStream os;
|
ObjectInputStream os;
|
||||||
try {
|
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();
|
int length = os.readInt();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
int x = os.readInt();
|
int x = os.readInt();
|
||||||
int y = os.readInt();
|
int y = os.readInt();
|
||||||
int z = os.readInt();
|
int z = os.readInt();
|
||||||
Block block = gameWorld.world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
gameWorld.checkSign(block);
|
checkSign(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
} catch (FileNotFoundException exception) {
|
} 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) {
|
} catch (IOException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return gameWorld;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Statics */
|
||||||
public static GameWorld getByWorld(World world) {
|
public static GameWorld getByWorld(World world) {
|
||||||
for (GameWorld gameWorld : plugin.getGameWorlds()) {
|
for (GameWorld gameWorld : plugin.getGameWorlds()) {
|
||||||
if (gameWorld.getWorld() == null) {
|
if (gameWorld.getWorld() == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user