mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +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;
|
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.category.Category;
|
||||||
import de.erethon.caliburn.item.VanillaItem;
|
import de.erethon.caliburn.item.VanillaItem;
|
||||||
import de.erethon.commons.chat.MessageUtil;
|
import de.erethon.commons.chat.MessageUtil;
|
||||||
@ -122,39 +120,46 @@ public class GameSign extends JoinSign {
|
|||||||
config.set(preString + ".x", startSign.getX());
|
config.set(preString + ".x", startSign.getX());
|
||||||
config.set(preString + ".y", startSign.getY());
|
config.set(preString + ".y", startSign.getY());
|
||||||
config.set(preString + ".z", startSign.getZ());
|
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);
|
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()) {
|
if (DungeonsXL.getInstance().getDWorlds().getGameWorlds().size() >= DungeonsXL.getInstance().getMainConfig().getMaxInstances()) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DGroup dGroup = DGroup.getByPlayer(player);
|
DGroup dGroup = DGroup.getByPlayer(player);
|
||||||
if (dGroup == null) {
|
if (dGroup == null) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
if (!dGroup.getCaptain().equals(player)) {
|
if (!dGroup.getCaptain().equals(player)) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_NOT_CAPTAIN.getMessage());
|
MessageUtil.sendMessage(player, DMessage.ERROR_NOT_CAPTAIN.getMessage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Game.getByDGroup(dGroup) != null) {
|
if (Game.getByDGroup(dGroup) != null) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GAME.getMessage());
|
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GAME.getMessage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block topBlock = block.getRelative(0, startSign.getY() - block.getY(), 0);
|
Block topBlock = block.getRelative(0, startSign.getY() - block.getY(), 0);
|
||||||
if (!(topBlock.getState() instanceof Sign)) {
|
if (!(topBlock.getState() instanceof Sign)) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sign topSign = (Sign) topBlock.getState();
|
Sign topSign = (Sign) topBlock.getState();
|
||||||
|
|
||||||
if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_NEW_GAME.getMessage())) {
|
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);
|
game = new Game(dGroup);
|
||||||
dGroup.setDungeon(dungeon);
|
dGroup.setDungeon(dungeon);
|
||||||
update();
|
update();
|
||||||
@ -163,8 +168,6 @@ public class GameSign extends JoinSign {
|
|||||||
game.addDGroup(dGroup);
|
game.addDGroup(dGroup);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Statics */
|
/* Statics */
|
||||||
|
@ -192,8 +192,6 @@ public class GlobalProtectionListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SUBJECT TO CHANGE */
|
|
||||||
@Deprecated
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
@ -207,12 +205,14 @@ public class GlobalProtectionListener implements Listener {
|
|||||||
|
|
||||||
if (Category.SIGNS.containsBlock(clickedBlock)) {
|
if (Category.SIGNS.containsBlock(clickedBlock)) {
|
||||||
GroupSign groupSign = GroupSign.getByBlock(clickedBlock);
|
GroupSign groupSign = GroupSign.getByBlock(clickedBlock);
|
||||||
if (groupSign != null && groupSign.onPlayerInteract(clickedBlock, player)) {
|
if (groupSign != null) {
|
||||||
|
groupSign.onPlayerInteract(clickedBlock, player);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSign gameSign = GameSign.getByBlock(clickedBlock);
|
GameSign gameSign = GameSign.getByBlock(clickedBlock);
|
||||||
if (gameSign != null && gameSign.onPlayerInteract(clickedBlock, player)) {
|
if (gameSign != null) {
|
||||||
|
gameSign.onPlayerInteract(clickedBlock, player);
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,25 +121,32 @@ public class GroupSign extends JoinSign {
|
|||||||
config.set(preString + ".x", startSign.getX());
|
config.set(preString + ".x", startSign.getX());
|
||||||
config.set(preString + ".y", startSign.getY());
|
config.set(preString + ".y", startSign.getY());
|
||||||
config.set(preString + ".z", startSign.getZ());
|
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 + ".groupName", groupName);
|
||||||
config.set(preString + ".maxPlayersPerGroup", maxElements);
|
config.set(preString + ".maxPlayersPerGroup", maxElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPlayerInteract(Block block, Player player) {
|
public void onPlayerInteract(Block block, Player player) {
|
||||||
if (DGroup.getByPlayer(player) != null) {
|
if (DGroup.getByPlayer(player) != null) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
MessageUtil.sendMessage(player, DMessage.ERROR_LEAVE_GROUP.getMessage());
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block topBlock = block.getRelative(0, startSign.getY() - block.getY(), 0);
|
Block topBlock = block.getRelative(0, startSign.getY() - block.getY(), 0);
|
||||||
if (!(topBlock.getState() instanceof Sign)) {
|
if (!(topBlock.getState() instanceof Sign)) {
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sign topSign = (Sign) topBlock.getState();
|
Sign topSign = (Sign) topBlock.getState();
|
||||||
|
|
||||||
if (topSign.getLine(0).equals(DMessage.SIGN_GLOBAL_NEW_GROUP.getMessage())) {
|
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) {
|
if (groupName != null) {
|
||||||
group = new DGroup(groupName, player, dungeon);
|
group = new DGroup(groupName, player, dungeon);
|
||||||
} else {
|
} else {
|
||||||
@ -151,8 +158,6 @@ public class GroupSign extends JoinSign {
|
|||||||
group.addPlayer(player);
|
group.addPlayer(player);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Statics */
|
/* Statics */
|
||||||
|
Loading…
Reference in New Issue
Block a user