62 lines
2.1 KiB
Java
62 lines
2.1 KiB
Java
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
|
|
*/
|
|
public class RemoveConditionCommand extends TokenizedCommand {
|
|
|
|
@Override
|
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
super.onCommand(sender, command, label, args);
|
|
if (argumentSize < 2) {
|
|
return false;
|
|
}
|
|
|
|
String name = arguments.get(0);
|
|
short line;
|
|
try {
|
|
line = (short) (Short.parseShort(arguments.get(1)) - 1);
|
|
} catch (NumberFormatException exception) {
|
|
sender.sendMessage("Invalid line number given");
|
|
return false;
|
|
}
|
|
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;
|
|
}
|
|
|
|
}
|