package org.royaldev.thehumanity.commands.impl.ping.subcommands; import org.jetbrains.annotations.NotNull; import org.kitteh.irc.client.library.element.User; import org.kitteh.irc.client.library.event.channel.ChannelMessageEvent; import org.royaldev.thehumanity.TheHumanity; import org.royaldev.thehumanity.commands.impl.ping.PingListSubcommand; import org.royaldev.thehumanity.ping.PingRegistry; import xyz.cardstock.cardstock.commands.CallInfo; import xyz.cardstock.cardstock.commands.Command; import java.util.List; import java.util.Optional; @Command( name = "remove", description = "Removes yourself from the registry.", aliases = {"r", "unregister"} ) public class RemoveSubcommand extends PingListSubcommand { private final TheHumanity humanity; public RemoveSubcommand(final TheHumanity humanity) { this.humanity = humanity; } @Override public void onSubcommand(@NotNull final ChannelMessageEvent event, @NotNull final CallInfo ci, @NotNull final List<String> args) { final User u = event.getActor(); final Optional<String> account = u.getAccount(); if (!account.isPresent()) { u.sendNotice("You must be registered with services to use this command."); return; } final PingRegistry pr = this.humanity.getPingRegistry(); if (!pr.hasRegistration(account.get())) { u.sendNotice("You don't have a registration."); return; } final boolean success = pr.removeRegistration(account.get()); u.sendNotice("Registration " + (success ? "" : "could not be ") + "removed for services account " + account.get() + "."); } }