aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/djtheredstoner/perspectivemod/PerspectiveModCommand.java
blob: 3eae96acfac95a5729d6bb56d7468e281c3819e2 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package me.djtheredstoner.perspectivemod;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatComponentText;

import java.util.Collections;
import java.util.List;

public class PerspectiveModCommand extends CommandBase {

    private final String PREFIX = "§c[§6Perspective Mod§c] §r";

    @Override
    public String getCommandName() {
        return "perspectivemod";
    }

    @Override
    public List<String> getCommandAliases() {
        return Collections.singletonList("pmod");
    }

    @Override
    public String getCommandUsage(ICommandSender sender) {
        return "§6Perspective Mod Help\n" +
            "§b/pmod <enable|disable> §7- Enables or disables the mod.\n" +
            "§b/pmod mode <hold|toggle> §7- Changes the mode.\n" +
            "§7Edit the keybind in the minecraft controls menu.";
    }

    @Override
    public void processCommand(ICommandSender sender, String[] args) throws CommandException {
        if (args.length > 0 && args.length < 3) {
            String arg = args[0];
            if (arg.equalsIgnoreCase("enable")) {
                PerspectiveMod.config.modEnabled = true;

                sendMessage(sender, "§bMod §aEnabled§b.");
            } else if (arg.equalsIgnoreCase("disable")) {
                PerspectiveMod.config.modEnabled = false;

                sendMessage(sender, "§bMod §cDisabled§b.");
            } else if (arg.equalsIgnoreCase("mode")) {
                if (args.length == 2) {
                    String mode = args[1];
                    if (mode.equalsIgnoreCase("hold")) {
                        PerspectiveMod.config.holdMode = true;

                        sendMessage(sender, "§bMode set to hold.");
                    } else if (mode.equalsIgnoreCase("toggle")) {
                        PerspectiveMod.config.holdMode = false;

                        sendMessage(sender, "§bMode set to toggle.");
                    } else {
                        sendMessage(sender, "§cInvalid mode. Valid mode are hold and toggle.");
                    }
                } else {
                    sendMessage(sender, "§cYou must specify a mode. Valid Modes are hold and toggle.");
                }
            } else {
                sendHelp(sender);
            }
        } else {
            sendHelp(sender);
        }
    }

    @Override
    public int getRequiredPermissionLevel() {
        return -1;
    }

    private void sendHelp(ICommandSender sender) {
        sendMessage(sender, getCommandUsage(sender), false);
    }

    private void sendMessage(ICommandSender sender, String message, boolean addPrefix) {
        sender.addChatMessage(new ChatComponentText((addPrefix ? PREFIX : "") + message));
    }

    private void sendMessage(ICommandSender sender, String message) {
        sendMessage(sender, message, true);
    }
}