0

Fixed counting/error messages

This commit is contained in:
Pepich 2017-02-18 18:41:36 +01:00
parent 323abffb5e
commit 0481ed52fe

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 = 1, compatible = 1) @Version(major = 1, minor = 0, revision = 2, compatible = 1)
public class Challenge implements Module public class Challenge implements Module
{ {
private boolean enabled = false; private boolean enabled = false;
@ -60,9 +60,14 @@ public class Challenge implements Module
@Command(hook = "delchallenge") @Command(hook = "delchallenge")
public boolean delChallenge(CommandSender sender, int id) public boolean delChallenge(CommandSender sender, int id)
{ {
if (challenges.size() == 0)
{
Utils.sendErrorMessage(sender, null, "There are no challenges yet!");
return true;
}
if (id < 0 || id >= challenges.size()) if (id < 0 || id >= challenges.size())
{ {
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() - 1));
return true; return true;
} }
Utils.sendMessage(sender, null, "Successfully deleted the challenge: " + challenges.remove(id), '&'); Utils.sendMessage(sender, null, "Successfully deleted the challenge: " + challenges.remove(id), '&');
@ -74,9 +79,14 @@ public class Challenge implements Module
@Command(hook = "setchallenge") @Command(hook = "setchallenge")
public boolean setChallenge(CommandSender sender, int id, String text) public boolean setChallenge(CommandSender sender, int id, String text)
{ {
if (challenges.size() == 0)
{
Utils.sendErrorMessage(sender, null, "There are no challenges yet!");
return true;
}
if (id < 0 || id >= challenges.size()) if (id < 0 || id >= challenges.size())
{ {
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() - 1));
return true; return true;
} }
Utils.sendMessage(sender, null, Utils.sendMessage(sender, null,
@ -89,6 +99,11 @@ public class Challenge implements Module
@Command(hook = "challengeid") @Command(hook = "challengeid")
public boolean challengeId(CommandSender sender, int id) public boolean challengeId(CommandSender sender, int id)
{ {
if (challenges.size() == 0)
{
Utils.sendErrorMessage(sender, null, "There are no challenges yet!");
return true;
}
if (id < 0 || id >= challenges.size()) if (id < 0 || id >= challenges.size())
{ {
Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + (challenges.size() - 1)); Utils.sendErrorMessage(sender, null, "The ID must be at least 0 and at most " + (challenges.size() - 1));
@ -114,6 +129,11 @@ public class Challenge implements Module
@Command(hook = "listchallenges") @Command(hook = "listchallenges")
public boolean listChallenges(CommandSender sender, int page) public boolean listChallenges(CommandSender sender, int page)
{ {
if (challenges.size() == 0)
{
Utils.sendErrorMessage(sender, null, "There are no challenges yet!");
return true;
}
page = page - 1; page = page - 1;
int start = page * 10; int start = page * 10;
int end = start + 10; int end = start + 10;