Skip to content

Commit

Permalink
Fix NPE if group / game sign dungeon == null; resolves #419
Browse files Browse the repository at this point in the history
  • Loading branch information
Sataniel98 committed Jun 8, 2018
1 parent 2438149 commit 6a7f543
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
25 changes: 14 additions & 11 deletions src/main/java/de/erethon/dungeonsxl/global/GameSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package de.erethon.dungeonsxl.global;

import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import de.erethon.caliburn.category.Category;
import de.erethon.caliburn.item.VanillaItem;
import de.erethon.commons.chat.MessageUtil;
Expand Down Expand Up @@ -122,39 +120,46 @@ public void save(FileConfiguration config) {
config.set(preString + ".x", startSign.getX());
config.set(preString + ".y", startSign.getY());
config.set(preString + ".z", startSign.getZ());
config.set(preString + ".dungeon", dungeon.getName());
if (dungeon != null) {
config.set(preString + ".dungeon", dungeon.getName());
}
config.set(preString + ".maxGroupsPerGame", maxElements);
}

public boolean onPlayerInteract(Block block, Player player) {
public void onPlayerInteract(Block block, Player player) {
if (DungeonsXL.getInstance().getDWorlds().getGameWorlds().size() >= DungeonsXL.getInstance().getMainConfig().getMaxInstances()) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return true;
return;
}

DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
return true;
return;
}
if (!dGroup.getCaptain().equals(player)) {
MessageUtil.sendMessage(player, DMessage.ERROR_NOT_CAPTAIN.getMessage());
return true;
return;
}

if (Game.getByDGroup(dGroup) != null) {
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GAME.getMessage());
return true;
return;
}

Block topBlock = block.getRelative(0, startSign.getY() - block.getY(), 0);
if (!(topBlock.getState() instanceof Sign)) {
return true;
return;
}

Sign topSign = (Sign) topBlock.getState();

if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_NEW_GAME.getMessage())) {
if (dungeon == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_SIGN_WRONG_FORMAT.getMessage());
return;
}

game = new Game(dGroup);
dGroup.setDungeon(dungeon);
update();
Expand All @@ -163,8 +168,6 @@ public boolean onPlayerInteract(Block block, Player player) {
game.addDGroup(dGroup);
update();
}

return true;
}

/* Statics */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ public void onPortalCreation(PlayerInteractEvent event) {
}
}

/* SUBJECT TO CHANGE */
@Deprecated
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Expand All @@ -207,12 +205,14 @@ public void onInteract(PlayerInteractEvent event) {

if (Category.SIGNS.containsBlock(clickedBlock)) {
GroupSign groupSign = GroupSign.getByBlock(clickedBlock);
if (groupSign != null && groupSign.onPlayerInteract(clickedBlock, player)) {
if (groupSign != null) {
groupSign.onPlayerInteract(clickedBlock, player);
event.setCancelled(true);
}

GameSign gameSign = GameSign.getByBlock(clickedBlock);
if (gameSign != null && gameSign.onPlayerInteract(clickedBlock, player)) {
if (gameSign != null) {
gameSign.onPlayerInteract(clickedBlock, player);
event.setCancelled(true);
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/de/erethon/dungeonsxl/global/GroupSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,32 @@ public void save(FileConfiguration config) {
config.set(preString + ".x", startSign.getX());
config.set(preString + ".y", startSign.getY());
config.set(preString + ".z", startSign.getZ());
config.set(preString + ".dungeon", dungeon.getName());
if (dungeon != null) {
config.set(preString + ".dungeon", dungeon.getName());
}
config.set(preString + ".groupName", groupName);
config.set(preString + ".maxPlayersPerGroup", maxElements);
}

public boolean onPlayerInteract(Block block, Player player) {
public void onPlayerInteract(Block block, Player player) {
if (DGroup.getByPlayer(player) != null) {
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
return true;
return;
}

Block topBlock = block.getRelative(0, startSign.getY() - block.getY(), 0);
if (!(topBlock.getState() instanceof Sign)) {
return true;
return;
}

Sign topSign = (Sign) topBlock.getState();

if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_NEW_GROUP.getMessage())) {
if (dungeon == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_SIGN_WRONG_FORMAT.getMessage());
return;
}

if (groupName != null) {
group = new DGroup(groupName, player, dungeon);
} else {
Expand All @@ -151,8 +158,6 @@ public boolean onPlayerInteract(Block block, Player player) {
group.addPlayer(player);
update();
}

return true;
}

/* Statics */
Expand Down

0 comments on commit 6a7f543

Please sign in to comment.