Fixes various bugs in commands
This commit is contained in:
@ -2,10 +2,16 @@ package net.knarcraft.paidsigns.command;
|
||||
|
||||
import net.knarcraft.paidsigns.PaidSigns;
|
||||
import net.knarcraft.paidsigns.container.PaidSign;
|
||||
import net.knarcraft.paidsigns.manager.PaidSignManager;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A representation of the command for removing a condition from a sign
|
||||
*/
|
||||
@ -21,13 +27,33 @@ public class RemoveConditionCommand extends TokenizedCommand {
|
||||
String name = arguments.get(0);
|
||||
short line;
|
||||
try {
|
||||
line = Short.parseShort(arguments.get(1));
|
||||
line = (short) (Short.parseShort(arguments.get(1)) - 1);
|
||||
} catch (NumberFormatException exception) {
|
||||
sender.sendMessage("Invalid line number given");
|
||||
return false;
|
||||
}
|
||||
PaidSign sign = PaidSigns.getInstance().getSignManager().getPaidSign(name);
|
||||
PaidSignManager signManager = PaidSigns.getInstance().getSignManager();
|
||||
PaidSign sign = signManager.getPaidSign(name);
|
||||
if (sign == null) {
|
||||
sender.sendMessage("Invalid sign name given");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sign.getConditions().containsKey(line)) {
|
||||
sender.sendMessage("No condition registered for line " + (line + 1));
|
||||
return false;
|
||||
}
|
||||
|
||||
sign.removeCondition(line);
|
||||
try {
|
||||
signManager.saveSigns();
|
||||
} catch (IOException e) {
|
||||
Logger logger = PaidSigns.getInstance().getLogger();
|
||||
logger.log(Level.SEVERE, "Exception encountered while trying to write to the data file");
|
||||
logger.log(Level.SEVERE, Arrays.toString(e.getStackTrace()));
|
||||
sender.sendMessage("An exception occurred. Please notify the server administrator or check the server log.");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage("Condition removed");
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user