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);
}
Aggregations