0

Fixed NPE when no challenges are defined

This commit is contained in:
Pepich 2017-02-18 18:31:12 +01:00
parent 32ab517ac7
commit 57767aab0f

View File

@ -13,7 +13,7 @@ import com.redstoner.misc.Main;
import com.redstoner.misc.Utils; import com.redstoner.misc.Utils;
import com.redstoner.modules.Module; import com.redstoner.modules.Module;
@Version(major = 1, minor = 0, revision = 0, compatible = 1) @Version(major = 1, minor = 0, revision = 1, compatible = 1)
public class Challenge implements Module public class Challenge implements Module
{ {
private boolean enabled = false; private boolean enabled = false;
@ -79,7 +79,8 @@ public class Challenge implements Module
Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + challenges.size()); Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + challenges.size());
return true; return true;
} }
Utils.sendMessage(sender, null, "Successfully changed the challenge: &a" + challenges.get(id) + " &7to: &e" + text, '&'); Utils.sendMessage(sender, null,
"Successfully changed the challenge: &a" + challenges.get(id) + " &7to: &e" + text, '&');
challenges.set(id, text); challenges.set(id, text);
saveChallenges(); saveChallenges();
return true; return true;
@ -100,6 +101,11 @@ public class Challenge implements Module
@Command(hook = "challenge") @Command(hook = "challenge")
public boolean challenge(CommandSender sender) public boolean challenge(CommandSender sender)
{ {
if (challenges.size() == 0)
{
Utils.sendErrorMessage(sender, null, "There are no challenges yet!");
return true;
}
int id = (new Random()).nextInt(challenges.size()); int id = (new Random()).nextInt(challenges.size());
Utils.sendMessage(sender, null, challenges.get(id) + "", '&'); Utils.sendMessage(sender, null, challenges.get(id) + "", '&');
return true; return true;