Search in sources :

Example 46 with Command

use of org.cubeengine.butler.parametric.Command in project modules-extra by CubeEngine.

the class ChatCommands method nick.

@Command(desc = "Changes your display name")
public void nick(CommandSource context, @Label("<name>|-reset") String name, @Optional Player player) {
    // TODO this only works when ChatFormat uses {DISPLAYNAME}
    if (player == null) {
        if (!(context instanceof Player)) {
            // console has no data / displayname
            i18n.send(context, NEGATIVE, "You cannot change the consoles display name");
            return;
        }
        player = ((Player) context);
    }
    if (!context.equals(player) && !context.hasPermission(module.perms().COMMAND_NICK_OTHER.getId())) {
        i18n.send(context, NEGATIVE, "You are not allowed to change the nickname of another player!");
        return;
    }
    if ("-r".equalsIgnoreCase(name) || "-reset".equalsIgnoreCase(name)) {
        DisplayNameData display = player.getOrCreate(DisplayNameData.class).get();
        display.displayName().set(Text.of(context.getName()));
        player.offer(display);
        i18n.send(context, POSITIVE, "Display name reset to {user}", context);
        return;
    }
    if (name.length() >= 3 && name.length() <= 16 && Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(name).isPresent() && !context.hasPermission(module.perms().COMMAND_NICK_OFOTHER.getId())) {
        i18n.send(context, NEGATIVE, "This name has been taken by another player!");
        return;
    }
    i18n.send(context, POSITIVE, "Display name changed from {user} to {user}", context, name);
    DisplayNameData display = player.getOrCreate(DisplayNameData.class).get();
    display.displayName().set(ChatFormat.fromLegacy(name, '&'));
    player.offer(display);
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) DisplayNameData(org.spongepowered.api.data.manipulator.mutable.DisplayNameData) Command(org.cubeengine.butler.parametric.Command)

Aggregations

Command (org.cubeengine.butler.parametric.Command)46 World (org.spongepowered.api.world.World)18 ContainerCommand (org.cubeengine.libcube.service.command.ContainerCommand)14 ConversationCommand (org.cubeengine.libcube.service.command.conversation.ConversationCommand)14 IMarketSignData (org.cubeengine.module.signmarket.data.IMarketSignData)14 ImmutableMarketSignData (org.cubeengine.module.signmarket.data.ImmutableMarketSignData)14 MarketSignData (org.cubeengine.module.signmarket.data.MarketSignData)14 Player (org.spongepowered.api.entity.living.player.Player)11 Alias (org.cubeengine.butler.alias.Alias)10 Restricted (org.cubeengine.butler.filter.Restricted)9 PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)5 ItemStack (org.spongepowered.api.item.inventory.ItemStack)5 Language (de.cubeisland.engine.i18n.language.Language)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 BlockRayHit (org.spongepowered.api.util.blockray.BlockRayHit)4 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)3 Text (org.spongepowered.api.text.Text)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 IOException (java.io.IOException)2