Skip to content

Commit

Permalink
Fix end NPE; resolves #177
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Dec 20, 2016
1 parent ac4c807 commit b8bf265
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 62 deletions.
2 changes: 1 addition & 1 deletion abstract/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
</project>
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ public void onExecute(String[] args, CommandSender sender) {
}

if (dGroup.getMapName() == null) {
dGroup.setMapName(mapName);
if (multiFloor) {
dGroup.setDungeonName(identifier);
dGroup.setDungeon(plugin.getDungeons().getByName(identifier));
} else {
dGroup.setDungeon(mapName);
}

} else {
Expand Down
60 changes: 53 additions & 7 deletions core/src/main/java/io/github/dre2n/dungeonsxl/dungeon/Dungeon.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DungeonConfig;
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Represents a dungeon.
Expand All @@ -31,19 +35,22 @@ public class Dungeon {

private String name;
private DungeonConfig config;
private DResourceWorld map;

/**
* Real dungeon
*/
public Dungeon(File file) {
this.name = file.getName().replaceAll(".yml", "");
this.config = new DungeonConfig(file);
}

public Dungeon(String name) {
this.name = name;

File file = new File(DungeonsXL.DUNGEONS, name + ".yml");
if (file.exists()) {
this.config = new DungeonConfig(file);
}
/**
* Artificial dungeon
*/
public Dungeon(DResourceWorld resource) {
name = resource.getName();
map = resource;
}

/**
Expand All @@ -67,11 +74,50 @@ public boolean isMultiFloor() {
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
*/
public boolean isSetupCorrect() {
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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<Dungeon> getDungeons() {
* @return the Dungeon that has the name
*/
public Dungeon loadDungeon(String name) {
Dungeon dungeon = new Dungeon(name);
Dungeon dungeon = new Dungeon(Dungeon.getFileFromName(name));
dungeons.add(dungeon);
return dungeon;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ public static boolean playerInteract(Block block, Player player) {

if (topSign.getLine(0).equals(NEW_GAME)) {
Game game = new Game(dGroup);
dGroup.setDungeonName(gameSign.dungeonName);
dGroup.setMapName(gameSign.mapName);
dGroup.setDungeon(gameSign.dungeonName == null ? gameSign.mapName : gameSign.dungeonName);
gameSign.games[column] = game;
gameSign.update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ public void leave(boolean message) {

if (getDGroup() != null) {
if (!dGroup.isEmpty()) {
if (dGroup.finishIfMembersFinished()) {
/*if (dGroup.finishIfMembersFinished()) {
return;
}
}*/

// Give secure objects to other players
int i = 0;
Expand Down Expand Up @@ -787,7 +787,6 @@ public void finishFloor(DResourceWorld specifiedFloor) {
Game game = dGroup.getGameWorld().getGame();

dGroup.removeUnplayedFloor(dGroup.getGameWorld().getResource(), false);
dGroup.setMapName(newFloor.getName());

DGameWorld gameWorld = null;
if (newFloor != null) {
Expand Down
50 changes: 11 additions & 39 deletions core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public class DGroup {
private List<UUID> players = new ArrayList<>();
private List<UUID> invitedPlayers = new ArrayList<>();
private Dungeon dungeon;
private String dungeonName;
private String mapName;
private List<DResourceWorld> unplayedFloors = new ArrayList<>();
private DGameWorld gameWorld;
private boolean playing;
Expand Down Expand Up @@ -115,13 +113,13 @@ public DGroup(String name, Player captain, List<Player> players, String identifi

dungeon = plugin.getDungeons().getByName(identifier);
if (multiFloor && dungeon != null) {
dungeonName = dungeon.getName();
mapName = dungeon.getConfig().getStartFloor().getName();
// Real dungeon
unplayedFloors = dungeon.getConfig().getFloors();

} else {
mapName = identifier;
dungeon = new Dungeon(identifier);
// Artificial dungeon
DResourceWorld resource = plugin.getDWorlds().getResourceByName(identifier);
dungeon = new Dungeon(resource);
}

playing = false;
Expand Down Expand Up @@ -391,52 +389,26 @@ public void setDungeon(Dungeon dungeon) {
public void setDungeon(String name) {
dungeon = plugin.getDungeons().getByName(name);
if (dungeon != null) {
dungeonName = dungeon.getName();
mapName = dungeon.getConfig().getStartFloor().getName();
unplayedFloors = dungeon.getConfig().getFloors();

} else {
mapName = name;
dungeon = new Dungeon(name);
DResourceWorld resource = plugin.getDWorlds().getResourceByName(name);
dungeon = new Dungeon(resource);
}
}

/**
* @return the dungeonName
*/
public String getDungeonName() {
return dungeonName;
}

/**
* 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 dungeon.getName();
}

/**
* @return if the group is playing
*/
public String getMapName() {
return mapName;
}

/**
* 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;
}
return gameWorld == null ? null : gameWorld.getName();
}

/**
Expand Down Expand Up @@ -716,11 +688,11 @@ public void startGame(Game game) {

MessageUtil.sendTitleMessage(player, title, subtitle, rules.getTitleFadeIn(), rules.getTitleShow(), rules.getTitleFadeOut());

} else if (dungeonName != null) {
MessageUtil.sendTitleMessage(player, "&b&l" + dungeonName.replaceAll("_", " "), "&4&l" + mapName.replaceAll("_", " "));
} else if (getDungeonName() != null) {
MessageUtil.sendTitleMessage(player, "&b&l" + getDungeonName().replaceAll("_", " "), "&4&l" + getMapName().replaceAll("_", " "));

} else {
MessageUtil.sendTitleMessage(player, "&4&l" + mapName.replaceAll("_", " "));
MessageUtil.sendTitleMessage(player, "&4&l" + getMapName().replaceAll("_", " "));
}

if (rules.getActionBar() != null) {
Expand Down
2 changes: 1 addition & 1 deletion craftbukkit_1_10_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion craftbukkit_1_11_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion craftbukkit_1_9_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion craftbukkit_1_9_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
<packaging>pom</packaging>
<name>DungeonsXL</name>
<url>https://dre2n.github.io</url>
Expand Down
2 changes: 1 addition & 1 deletion shade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.3-SNAPSHOT</version>
<version>0.15.3</version>
</parent>
<build>
<finalName>dungeonsxl-${project.version}${buildNo}</finalName>
Expand Down

0 comments on commit b8bf265

Please sign in to comment.