Fix end NPE; resolves #177

This commit is contained in:
Daniel Saukel 2016-12-20 20:06:05 +01:00
parent ac4c807da6
commit b8bf2659d7
14 changed files with 79 additions and 62 deletions

View File

@ -8,6 +8,6 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
</project> </project>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
<build> <build>
<resources> <resources>

View File

@ -97,9 +97,10 @@ public class PlayCommand extends BRCommand {
} }
if (dGroup.getMapName() == null) { if (dGroup.getMapName() == null) {
dGroup.setMapName(mapName);
if (multiFloor) { if (multiFloor) {
dGroup.setDungeonName(identifier); dGroup.setDungeon(plugin.getDungeons().getByName(identifier));
} else {
dGroup.setDungeon(mapName);
} }
} else { } else {

View File

@ -18,7 +18,11 @@ package io.github.dre2n.dungeonsxl.dungeon;
import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DungeonConfig; import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/** /**
* Represents a dungeon. * Represents a dungeon.
@ -31,19 +35,22 @@ public class Dungeon {
private String name; private String name;
private DungeonConfig config; private DungeonConfig config;
private DResourceWorld map;
/**
* Real dungeon
*/
public Dungeon(File file) { public Dungeon(File file) {
this.name = file.getName().replaceAll(".yml", ""); this.name = file.getName().replaceAll(".yml", "");
this.config = new DungeonConfig(file); this.config = new DungeonConfig(file);
} }
public Dungeon(String name) { /**
this.name = name; * Artificial dungeon
*/
File file = new File(DungeonsXL.DUNGEONS, name + ".yml"); public Dungeon(DResourceWorld resource) {
if (file.exists()) { name = resource.getName();
this.config = new DungeonConfig(file); map = resource;
}
} }
/** /**
@ -67,6 +74,34 @@ public class Dungeon {
return config != null; return config != null;
} }
/**
* @return
* the floors of the dungeon
*/
public List<DResourceWorld> getFloors() {
if (isMultiFloor()) {
return config.getFloors();
} else {
return new ArrayList<>(Arrays.asList(map));
}
}
/**
* @return
* the SFD map / start floor
*/
public DResourceWorld getMap() {
return map;
}
/**
* @param map
* the SFD map / start floor to set
*/
public void setMap(DResourceWorld map) {
this.map = map;
}
/** /**
* @return false if there are setup errors * @return false if there are setup errors
*/ */
@ -74,4 +109,15 @@ public class Dungeon {
return config.getStartFloor() != null && config.getEndFloor() != null; return config.getStartFloor() != null && config.getEndFloor() != null;
} }
/* Statics */
/**
* @param name
* the name of the dungeon
* @return
* the file. Might not exist
*/
public static File getFileFromName(String name) {
return new File(DungeonsXL.DUNGEONS, name + ".yml");
}
} }

View File

@ -76,7 +76,7 @@ public class Dungeons {
* @return the Dungeon that has the name * @return the Dungeon that has the name
*/ */
public Dungeon loadDungeon(String name) { public Dungeon loadDungeon(String name) {
Dungeon dungeon = new Dungeon(name); Dungeon dungeon = new Dungeon(Dungeon.getFileFromName(name));
dungeons.add(dungeon); dungeons.add(dungeon);
return dungeon; return dungeon;
} }

View File

@ -513,8 +513,7 @@ public class GameSign extends GlobalProtection {
if (topSign.getLine(0).equals(NEW_GAME)) { if (topSign.getLine(0).equals(NEW_GAME)) {
Game game = new Game(dGroup); Game game = new Game(dGroup);
dGroup.setDungeonName(gameSign.dungeonName); dGroup.setDungeon(gameSign.dungeonName == null ? gameSign.mapName : gameSign.dungeonName);
dGroup.setMapName(gameSign.mapName);
gameSign.games[column] = game; gameSign.games[column] = game;
gameSign.update(); gameSign.update();

View File

@ -509,9 +509,9 @@ public class DGamePlayer extends DInstancePlayer {
if (getDGroup() != null) { if (getDGroup() != null) {
if (!dGroup.isEmpty()) { if (!dGroup.isEmpty()) {
if (dGroup.finishIfMembersFinished()) { /*if (dGroup.finishIfMembersFinished()) {
return; return;
} }*/
// Give secure objects to other players // Give secure objects to other players
int i = 0; int i = 0;
@ -787,7 +787,6 @@ public class DGamePlayer extends DInstancePlayer {
Game game = dGroup.getGameWorld().getGame(); Game game = dGroup.getGameWorld().getGame();
dGroup.removeUnplayedFloor(dGroup.getGameWorld().getResource(), false); dGroup.removeUnplayedFloor(dGroup.getGameWorld().getResource(), false);
dGroup.setMapName(newFloor.getName());
DGameWorld gameWorld = null; DGameWorld gameWorld = null;
if (newFloor != null) { if (newFloor != null) {

View File

@ -58,8 +58,6 @@ public class DGroup {
private List<UUID> players = new ArrayList<>(); private List<UUID> players = new ArrayList<>();
private List<UUID> invitedPlayers = new ArrayList<>(); private List<UUID> invitedPlayers = new ArrayList<>();
private Dungeon dungeon; private Dungeon dungeon;
private String dungeonName;
private String mapName;
private List<DResourceWorld> unplayedFloors = new ArrayList<>(); private List<DResourceWorld> unplayedFloors = new ArrayList<>();
private DGameWorld gameWorld; private DGameWorld gameWorld;
private boolean playing; private boolean playing;
@ -115,13 +113,13 @@ public class DGroup {
dungeon = plugin.getDungeons().getByName(identifier); dungeon = plugin.getDungeons().getByName(identifier);
if (multiFloor && dungeon != null) { if (multiFloor && dungeon != null) {
dungeonName = dungeon.getName(); // Real dungeon
mapName = dungeon.getConfig().getStartFloor().getName();
unplayedFloors = dungeon.getConfig().getFloors(); unplayedFloors = dungeon.getConfig().getFloors();
} else { } else {
mapName = identifier; // Artificial dungeon
dungeon = new Dungeon(identifier); DResourceWorld resource = plugin.getDWorlds().getResourceByName(identifier);
dungeon = new Dungeon(resource);
} }
playing = false; playing = false;
@ -391,13 +389,11 @@ public class DGroup {
public void setDungeon(String name) { public void setDungeon(String name) {
dungeon = plugin.getDungeons().getByName(name); dungeon = plugin.getDungeons().getByName(name);
if (dungeon != null) { if (dungeon != null) {
dungeonName = dungeon.getName();
mapName = dungeon.getConfig().getStartFloor().getName();
unplayedFloors = dungeon.getConfig().getFloors(); unplayedFloors = dungeon.getConfig().getFloors();
} else { } else {
mapName = name; DResourceWorld resource = plugin.getDWorlds().getResourceByName(name);
dungeon = new Dungeon(name); dungeon = new Dungeon(resource);
} }
} }
@ -405,38 +401,14 @@ public class DGroup {
* @return the dungeonName * @return the dungeonName
*/ */
public String getDungeonName() { public String getDungeonName() {
return dungeonName; return dungeon.getName();
}
/**
* Will fail if there is no dungeon with this name.
*
* @param dungeonName
* the dungeonName to set
*/
public void setDungeonName(String dungeonName) {
if (plugin.getDungeons().getByName(name) != null) {
this.dungeonName = dungeonName;
}
} }
/** /**
* @return if the group is playing * @return if the group is playing
*/ */
public String getMapName() { public String getMapName() {
return mapName; return gameWorld == null ? null : gameWorld.getName();
}
/**
* Will fail if there is no resource world with this name.
*
* @param name
* the name to set
*/
public void setMapName(String name) {
if (plugin.getDWorlds().exists(name)) {
mapName = name;
}
} }
/** /**
@ -716,11 +688,11 @@ public class DGroup {
MessageUtil.sendTitleMessage(player, title, subtitle, rules.getTitleFadeIn(), rules.getTitleShow(), rules.getTitleFadeOut()); MessageUtil.sendTitleMessage(player, title, subtitle, rules.getTitleFadeIn(), rules.getTitleShow(), rules.getTitleFadeOut());
} else if (dungeonName != null) { } else if (getDungeonName() != null) {
MessageUtil.sendTitleMessage(player, "&b&l" + dungeonName.replaceAll("_", " "), "&4&l" + mapName.replaceAll("_", " ")); MessageUtil.sendTitleMessage(player, "&b&l" + getDungeonName().replaceAll("_", " "), "&4&l" + getMapName().replaceAll("_", " "));
} else { } else {
MessageUtil.sendTitleMessage(player, "&4&l" + mapName.replaceAll("_", " ")); MessageUtil.sendTitleMessage(player, "&4&l" + getMapName().replaceAll("_", " "));
} }
if (rules.getActionBar() != null) { if (rules.getActionBar() != null) {

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
<build> <build>
<plugins> <plugins>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
<build> <build>
<plugins> <plugins>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
<build> <build>
<plugins> <plugins>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
<build> <build>
<plugins> <plugins>

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>DungeonsXL</name> <name>DungeonsXL</name>
<url>https://dre2n.github.io</url> <url>https://dre2n.github.io</url>

View File

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>io.github.dre2n</groupId> <groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId> <artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version> <version>0.15.3</version>
</parent> </parent>
<build> <build>
<finalName>dungeonsxl-${project.version}${buildNo}</finalName> <finalName>dungeonsxl-${project.version}${buildNo}</finalName>