From 0d9ed022f35dfa6d2a9175fb968342121926be13 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Mon, 16 Feb 2015 15:00:14 -0600 Subject: [PATCH] Only try to jail in a cell if that jail has cells, resolves #51 --- src/main/java/com/graywolf336/jail/beans/Jail.java | 5 +++++ .../jail/command/subcommands/JailCommand.java | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/graywolf336/jail/beans/Jail.java b/src/main/java/com/graywolf336/jail/beans/Jail.java index 10e0607..4937c90 100644 --- a/src/main/java/com/graywolf336/jail/beans/Jail.java +++ b/src/main/java/com/graywolf336/jail/beans/Jail.java @@ -153,6 +153,11 @@ public class Jail { public void removePrisoner(Prisoner p) { this.nocellPrisoners.remove(p.getUUID()); } + + /** Returns if there are any cells or not. */ + public boolean hasCells() { + return !this.cells.isEmpty(); + } /** Adds a cell to the Jail. */ public void addCell(Cell cell, boolean save) { diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java index 3bc2b9d..a8d8e52 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailCommand.java @@ -152,7 +152,14 @@ public class JailCommand implements Command { //If they want just any open cell or automatic jailing in cells is turned on //and a cell wasn't already found, then find try to find a cell - if((params.isAnyCell() || jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICCELL.getPath(), true)) && c == null) { + if(params.isAnyCell() && c == null) { + c = jm.getJail(jailName).getFirstEmptyCell(); + if(c == null) { + //If there wasn't an empty cell, then tell them so. + sender.sendMessage(Lang.NOEMPTYCELLS.get(jailName)); + return true; + } + }else if(jm.getPlugin().getConfig().getBoolean(Settings.AUTOMATICCELL.getPath(), true) && j.hasCells() && c == null) { c = jm.getJail(jailName).getFirstEmptyCell(); if(c == null) { //If there wasn't an empty cell, then tell them so.