UnlimitEnergyCommand.java 2.39 KB
Newer Older
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
package emu.grasscutter.command.commands;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamManager;
import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.net.proto.PropChangeReasonOuterClass;
import emu.grasscutter.utils.Position;

import java.util.List;

import static emu.grasscutter.Configuration.GAME_OPTIONS;
import static emu.grasscutter.utils.Language.translate;

@Command(label = "unlimitenergy", usage = "unlimitenergy [on|off|toggle]", aliases = {"ule"}, permission = "player.unlimitenergy", permissionTargeted = "player.unlimitenergy.others", description = "commands.unlimitenergy.description")
public final class UnlimitEnergyCommand implements CommandHandler {

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
        if(!GAME_OPTIONS.energyUsage){
            CommandHandler.sendMessage(sender, translate(sender, "commands.unlimitenergy.config_error"));
            return;
        }
        Boolean status = targetPlayer.getEnergyManager().getEnergyUsage();
        if (args.size() == 1) {
            switch (args.get(0).toLowerCase()) {
                case "on":
                    status = true;
                    break;
                case "off":
                    status = false;
                    break;
                default:
                    status = !status;
                    break;
            }
        }
        EnergyManager energyManager=targetPlayer.getEnergyManager();
        energyManager.setEnergyUsage(!status);
        // if unlimitEnergy is enable , make currentActiveTeam's Avatar full-energy
        if (status) {
            for (EntityAvatar entityAvatar : targetPlayer.getTeamManager().getActiveTeam()) {
                entityAvatar.addEnergy(1000,
                        PropChangeReasonOuterClass.PropChangeReason.PROP_CHANGE_REASON_GM,true);
            }
        }

        CommandHandler.sendMessage(sender, translate(sender, "commands.unlimitenergy.success", (status ? translate(sender, "commands.status.enabled") : translate(sender, "commands.status.disabled")), targetPlayer.getNickname()));
    }
}