mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-24 19:45:43 +01:00
Fix NPE if group / game sign dungeon == null; resolves #419
This commit is contained in:
parent
2438149bd1
commit
6a7f543c9e
@ -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;
|
||||
@ -122,39 +120,46 @@ public class GameSign extends JoinSign {
|
||||
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();
|
||||
@ -163,8 +168,6 @@ public class GameSign extends JoinSign {
|
||||
game.addDGroup(dGroup);
|
||||
update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
|
@ -192,8 +192,6 @@ public class GlobalProtectionListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/* SUBJECT TO CHANGE */
|
||||
@Deprecated
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@ -207,12 +205,14 @@ public class GlobalProtectionListener implements Listener {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -121,25 +121,32 @@ public class GroupSign extends JoinSign {
|
||||
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 {
|
||||
@ -151,8 +158,6 @@ public class GroupSign extends JoinSign {
|
||||
group.addPlayer(player);
|
||||
update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Statics */
|
||||
|
Loading…
Reference in New Issue
Block a user