summaryrefslogtreecommitdiff
path: root/src/main/java/net/uomc/mineshaft/resources/commands/RemoveResourceCommand.java
blob: 2fadf27aca1eddca0d3a52bd365dcae46880adf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package net.uomc.mineshaft.resources.commands;

import com.mouldycheerio.dbot.CustomBot;
import com.mouldycheerio.dbot.commands.Command;
import com.mouldycheerio.dbot.commands.CommandDetails;
import com.mouldycheerio.dbot.util.PeelingUtils;

import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.uomc.mineshaft.resources.ResourceManager;

public class RemoveResourceCommand extends ResourceCommand implements Command {

    public RemoveResourceCommand(ResourceManager resourceManager) {
        super(resourceManager);
        setCommandDetails(CommandDetails.hidden("removeItem"));
    }

    @Override
    public void execute(MessageReceivedEvent e, CustomBot op, String[] args) {
        String ownerid = op.getConfig().getString("ownerid");
        if (ownerid.equals(e.getAuthor().getId())) {
            if (args.length > 0) {
                String name = args[0];
                PeelingUtils.askQuestion(e, "Are you sure you want to delete **" + name + "**?\n(warning: all userdata will be lost)\nSend `confirm` to proceed", r -> {
                    if (r.equalsIgnoreCase("confirm")) {
                        boolean removeResource = getResourceManager().removeResource(name);
                        if (removeResource) {
                            op.sendMessage(e, "removed", "removed the item **" + name + "** from the list of items");

                        } else {
                            op.sendMessage(e, "not found", ":x: the item **" + name + "** was not found");
                        }
                    } else {
                        op.sendMessage(e, "cancelled", ":x: operation cancelled");

                    }
                });
            } else {
                op.sendMessage(e, "incorrect usage", ":x: usage: `.removeResource [name]`");
            }
        } else {
            op.sendMessage(e, "missing permissions", ":x: this command is not intended for you");
        }
    }

}