Implement GameWorldStartEvent

This commit is contained in:
Daniel Saukel 2016-01-10 16:50:45 +01:00
parent 83a2f3058d
commit 89d2f50055

View File

@ -5,6 +5,7 @@ import io.github.dre2n.dungeonsxl.dungeon.Dungeon;
import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig; import io.github.dre2n.dungeonsxl.dungeon.DungeonConfig;
import io.github.dre2n.dungeonsxl.dungeon.WorldConfig; import io.github.dre2n.dungeonsxl.dungeon.WorldConfig;
import io.github.dre2n.dungeonsxl.dungeon.EditWorld; import io.github.dre2n.dungeonsxl.dungeon.EditWorld;
import io.github.dre2n.dungeonsxl.event.gameworld.GameWorldStartGameEvent;
import io.github.dre2n.dungeonsxl.mob.DMob; import io.github.dre2n.dungeonsxl.mob.DMob;
import io.github.dre2n.dungeonsxl.player.DPlayer; import io.github.dre2n.dungeonsxl.player.DPlayer;
import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.requirement.Requirement;
@ -87,6 +88,12 @@ public class GameWorld {
} }
public void startGame() { public void startGame() {
GameWorldStartGameEvent event = new GameWorldStartGameEvent(this);
if (event.isCancelled()) {
return;
}
isPlaying = true; isPlaying = true;
for (DSign dSign : dSigns) { for (DSign dSign : dSigns) {
@ -474,8 +481,9 @@ public class GameWorld {
if ( !file.exists()) { if ( !file.exists()) {
try { try {
file.createNewFile(); file.createNewFile();
} catch (IOException e) {
e.printStackTrace(); } catch (IOException exception) {
exception.printStackTrace();
} }
} }
@ -504,10 +512,10 @@ public class GameWorld {
GameWorld gameWorld = new GameWorld(); GameWorld gameWorld = new GameWorld();
gameWorld.mapName = name; gameWorld.mapName = name;
// Unload empty eworlds // Unload empty editWorlds
for (EditWorld eworld : plugin.getEditWorlds()) { for (EditWorld editWorld : plugin.getEditWorlds()) {
if (eworld.getWorld().getPlayers().isEmpty()) { if (editWorld.getWorld().getPlayers().isEmpty()) {
eworld.delete(); editWorld.delete();
} }
} }
@ -544,10 +552,12 @@ public class GameWorld {
} }
os.close(); os.close();
} catch (FileNotFoundException e) {
e.printStackTrace(); } catch (FileNotFoundException exception) {
} catch (IOException e) { plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!");
e.printStackTrace();
} catch (IOException exception) {
exception.printStackTrace();
} }
return gameWorld; return gameWorld;