56 lines
2.0 KiB
Java
56 lines
2.0 KiB
Java
package net.knarcraft.paidsigns.command;
|
|
|
|
import net.knarcraft.paidsigns.PaidSigns;
|
|
import net.knarcraft.paidsigns.utility.Tokenizer;
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
/**
|
|
* A representation of the command for removing a paid sign
|
|
*/
|
|
public class RemoveCommand implements CommandExecutor {
|
|
|
|
@Override
|
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
|
@NotNull String[] args) {
|
|
if (args.length < 1) {
|
|
return false;
|
|
}
|
|
List<String> arguments = Tokenizer.tokenize(String.join(" ", args));
|
|
String[] input = arguments.get(0).split("\\|");
|
|
short line;
|
|
try {
|
|
line = (short) (Short.parseShort(input[0]) - 1);
|
|
} catch (NumberFormatException exception) {
|
|
sender.sendMessage("Invalid line number given");
|
|
return false;
|
|
}
|
|
String id = String.join("|", (String[]) ArrayUtils.remove(input, 0));
|
|
try {
|
|
if (PaidSigns.getInstance().getSignManager().removePaidSign(id, line)) {
|
|
sender.sendMessage("Successfully removed paid sign");
|
|
} else {
|
|
sender.sendMessage("No matching paid sign was found");
|
|
}
|
|
return true;
|
|
} 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;
|
|
}
|
|
|
|
}
|