Search in sources :

Example 6 with PowertoolUserDataModule

use of io.github.nucleuspowered.nucleus.modules.powertool.datamodules.PowertoolUserDataModule in project Nucleus by NucleusPowered.

the class TogglePowertoolCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    PowertoolUserDataModule user = Nucleus.getNucleus().getUserDataManager().getUnchecked(src).get(PowertoolUserDataModule.class);
    // If specified - get the key. Else, the inverse of what we have now.
    boolean toggle = args.<Boolean>getOne(toggleKey).orElse(!user.isPowertoolToggled());
    user.setPowertoolToggle(toggle);
    MessageProvider mp = plugin.getMessageProvider();
    src.sendMessage(mp.getTextMessageWithFormat("command.powertool.toggle", mp.getMessageWithFormat(toggle ? "standard.enabled" : "standard.disabled")));
    return CommandResult.success();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) PowertoolUserDataModule(io.github.nucleuspowered.nucleus.modules.powertool.datamodules.PowertoolUserDataModule)

Aggregations

PowertoolUserDataModule (io.github.nucleuspowered.nucleus.modules.powertool.datamodules.PowertoolUserDataModule)6 ItemType (org.spongepowered.api.item.ItemType)5 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)4 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)4 List (java.util.List)4 Player (org.spongepowered.api.entity.living.player.Player)4 Util (io.github.nucleuspowered.nucleus.Util)3 RunAsync (io.github.nucleuspowered.nucleus.internal.annotations.RunAsync)3 NoModifiers (io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers)3 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)3 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)3 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Sponge (org.spongepowered.api.Sponge)3 CommandResult (org.spongepowered.api.command.CommandResult)3 CommandContext (org.spongepowered.api.command.args.CommandContext)3 Text (org.spongepowered.api.text.Text)3 TextColors (org.spongepowered.api.text.format.TextColors)3 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)3