当前位置: 首页>>代码示例>>Java>>正文


Java TextActions类代码示例

本文整理汇总了Java中org.spongepowered.api.text.action.TextActions的典型用法代码示例。如果您正苦于以下问题:Java TextActions类的具体用法?Java TextActions怎么用?Java TextActions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextActions类属于org.spongepowered.api.text.action包,在下文中一共展示了TextActions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    List<Camera> cams = new ArrayList<>(plugin.getCameras().values());
    cams.removeIf((cam)-> !cam.canUseCamera(src));

    Iterable<Text> texts = cams.parallelStream().map((cam)->
            plugin.translations.CAMERA_LIST_ITEM.apply(cam.templateVariables())
            .onHover(TextActions.showText(
                    plugin.translations.CAMERA_LIST_ITEM_HOVER.apply(cam.templateVariables()).build()
            ))
            .onClick(TextActions.runCommand("/camera view " + cam.getId())).build()
    ).collect(Collectors.toList());

    PaginationList.builder()
            .title(plugin.translations.CAMERA_LIST_TITLE)
            .contents(texts)
            .sendTo(src);

    return CommandResult.success();
}
 
开发者ID:Lergin,项目名称:Vigilate,代码行数:21,代码来源:ListCamerasCommand.java

示例2: execute

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	long time = (long) args.getOne("time").get();
	long before = new Date().getTime() - time;
	
	if (src instanceof Player) {
		Text text = Text.of(TextColors.BLUE, "[AS] ", TextColors.RED, 
				"This operation will remove log entries from the database! Are you sure? ",
				Text.builder("<Yes, proceed!>").color(TextColors.GOLD)
						.onClick(TextActions.executeCallback(cbs -> {
							doPurge(cbs, before);
						}
				)));
		src.sendMessage(text);
	} else {
		doPurge(src, before);
	}
	return CommandResult.success();
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:20,代码来源:CommandPurge.java

示例3: timeAgoToString

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
public static Text timeAgoToString(long time) {
	long current = new Date().getTime();
	long diff = current - time;
	
	if (diff < 0)
		return Text.of("Near future");
	
	Text hoverText = Text.of(TextColors.DARK_AQUA, "Minutes: ", TextColors.AQUA, (diff % HOUR) / MINUTE);
	if (diff >= HOUR) {
		hoverText = Text.of(TextColors.DARK_AQUA, "Hours: ", TextColors.AQUA, (diff % DAY) / HOUR, Text.NEW_LINE, hoverText);
		if (diff >= DAY) {
			hoverText = Text.of(TextColors.DARK_AQUA, "Days: ", TextColors.AQUA, diff / DAY, Text.NEW_LINE, hoverText);
		}
	}
	
	float hours = diff / (float) HOUR;
	return Text.builder(String.format(Locale.ROOT, "%.2fh", hours))
			.color(TextColors.AQUA)
			.onHover(TextActions.showText(hoverText))
			.build();
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:22,代码来源:TimeUtils.java

示例4: installMessageButton

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
private void installMessageButton(ActivePlayerChatView view) {
    UUID playerId = view.getPlayer().getUniqueId();
    view.getPlayerList().addAddon(player -> {
        UUID otherId = player.getUniqueId();
        Text.Builder builder = Text.builder("Message");
        if (!otherId.equals(playerId)) {
            if (this.privateView.containsKey(otherId)) {
                builder.onClick(Utils.execClick(() -> newPrivateMessage(playerId, otherId)))
                        .onHover(TextActions.showText(Text.of("Send a private message")))
                        .color(TextColors.BLUE).style(TextStyles.UNDERLINE);
            } else {
                builder.color(TextColors.GRAY)
                        .onHover(TextActions.showText(Text.of("This player doesn't have Chat UI enabled")));
            }

        } else {
            builder.color(TextColors.GRAY)
                    .onHover(TextActions.showText(Text.of("Cannot send message to yourself")));
        }
        return builder.build();
    });
}
 
开发者ID:simon816,项目名称:ChatUI,代码行数:23,代码来源:PrivateMessageFeature.java

示例5: formatCustomEmoji

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
/**
 * @param texts The message that may contain custom emoji
 * @param config  The mention config to be used for formatting
 * @return The final message with custom emoji formatted
 */
private static List<Text> formatCustomEmoji(List<Text> texts, ChannelMinecraftEmojiConfig config) {
    for(Text text : texts){
        String serialized = TextSerializers.FORMATTING_CODE.serialize(text);
        Matcher matcher = customEmoji.matcher(serialized);
        while (matcher.find()) {
            String name = matcher.group(1);
            String id = matcher.group(2);

            Text.Builder builder = TextSerializers.FORMATTING_CODE.deserialize(config.template.replace("%n", name)).toBuilder();

            if (config.allowLink) {
                try {
                    builder = builder.onClick(TextActions.openUrl(new URL("https://cdn.discordapp.com/emojis/" + id + ".png")));
                } catch (MalformedURLException ignored) { }
            }

            if (StringUtils.isNotBlank(config.hoverTemplate))
                builder = builder.onHover(TextActions.showText(Text.of(config.hoverTemplate)));
            texts = replaceMention(texts, "<:"+name+":"+id+">", builder);
        }
    }
    return texts;
}
 
开发者ID:nguyenquyhy,项目名称:DiscordBridge,代码行数:29,代码来源:TextUtil.java

示例6: getValueFormat

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
@Override
public Text getValueFormat(EntityTemplateFlagValue value) {
	if (value.getKeys().isEmpty()) {
		return EAMessages.FLAG_MAP_EMPTY.getText();
	}
	
	List<Text> groups = new ArrayList<Text>();
	for (String group : value.getKeys()) {
		List<Text> entities = new ArrayList<Text>();
		for (EntityTemplate entity : this.groups.get(group)) {
			entities.add(EAMessages.FLAG_MAP_HOVER.getFormat().toText("{value}", entity.getId()));
		}
		groups.add(EAMessages.FLAG_MAP_GROUP.getFormat().toText("{group}", group).toBuilder()
			.onHover(TextActions.showText(Text.joinWith(Text.of("\n"), entities)))
			.build());
	}
	
	return Text.joinWith(EAMessages.FLAG_MAP_JOIN.getText(), groups);
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:20,代码来源:EntityTemplateFlag.java

示例7: help

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
@Override
public Text help(final CommandSource source) {
	boolean walk = source.hasPermission(EEPermissions.SPEED_WALK.get());
	boolean fly = source.hasPermission(EEPermissions.SPEED_FLY.get());
	
	Builder build = Text.builder("/" + this.getName());
	
	if (walk || fly) {
		if (walk && fly) {
			build.append(Text.of(" [" + EAMessages.ARGS_SPEED.getString() + "] [walk|fly]"));
		} else if (fly) {
			build.append(Text.of(" [" + EAMessages.ARGS_SPEED.getString() + "] [fly]"));
		} else if (walk) {
			build.append(Text.of(" [" + EAMessages.ARGS_SPEED.getString() + "] [walk]"));
		}
		
		if(source.hasPermission(EEPermissions.SPEED_OTHERS.get())) {
			build.append(Text.of(" [" + EAMessages.ARGS_USER.getString() + "]"));
		}
	}
	
	return build.onClick(TextActions.suggestCommand("/" + this.getName() + " "))
				.color(TextColors.RED)
				.build();
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:26,代码来源:EESpeed.java

示例8: commandSanctions

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
private CompletableFuture<Boolean> commandSanctions(final CommandSource staff) {
	List<Text> list = new ArrayList<Text>();
	this.plugin.getSanctionService().getAllReasons().forEach(reason -> {
		list.add(ESMessages.SANCTIONS_LIST_LINE.getFormat().toText(
					"{name}", reason.getName(),
					"{count}", String.valueOf(reason.getLevels().size()))
			.toBuilder()
			.onClick(TextActions.runCommand("/sanctions \"" + reason.getName() + "\""))
			.onHover(TextActions.showText(ESMessages.SANCTIONS_LIST_LINE_HOVER.getFormat()
				.toText("{name}", reason.getName())))
			.build());
	});
	
	if (list.isEmpty()) {
		list.add(ESMessages.SANCTIONS_LIST_EMPTY.getText());
	}
	
	this.plugin.getEverAPI().getManagerService().getEPagination().sendTo(
			ESMessages.SANCTIONS_LIST_TITLE.getText().toBuilder()
				.onClick(TextActions.runCommand("/sanctions"))
				.build(), 
			list, staff);
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverSanctions,代码行数:25,代码来源:ESSanctions.java

示例9: command

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
private CompletableFuture<Boolean> command(final CommandSource player) throws EMessageException {
	List<Text> list = new ArrayList<Text>();
	
	this.plugin.getService().getDescriptions().stream()
		.sorted((o1, o2) -> o1.getId().compareTo(o2.getId()))
		.forEachOrdered(permission -> {
			Text description = permission.getDescription().orElse(Text.of());
			
			list.add(EPMessages.DESCRIPTION_LINE.getFormat()
					.toText("{permission}", this.getButtonDescription(permission.getId(), description),
							"{description}", description));
		});
	
	this.plugin.getEverAPI().getManagerService().getEPagination().sendTo(
			EPMessages.DESCRIPTION_TITLE.getText()
				.toBuilder()
				.onClick(TextActions.runCommand("/" + this.getName()))
				.build(), 
			list, player);
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:22,代码来源:EPDescription.java

示例10: commandMsgConsole

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
private CompletableFuture<Boolean> commandMsgConsole(final EPlayer player, final CommandSource receive, final String message) {
	Map<Pattern, EReplace<?>> replaces = new HashMap<Pattern, EReplace<?>>();
	replaces.put(Pattern.compile("\\{message}"), EReplace.of(message));
	
	player.sendMessage(EEMessages.MSG_CONSOLE_SEND.getFormat().toText(replaces)
				.toBuilder()
				.onHover(TextActions.showText(EEMessages.MSG_CONSOLE_SEND_HOVER.getFormat().toText(replaces)))
				.onClick(TextActions.suggestCommand("/msg " + EEMsg.CONSOLE + " "))
				.build());
	
	replaces.putAll(player.getReplaces());
	receive.sendMessage(EEMessages.MSG_PLAYER_RECEIVE.getFormat().toText(replaces)
				.toBuilder()
				.onHover(TextActions.showText(EEMessages.MSG_PLAYER_RECEIVE_HOVER.getFormat().toText(replaces)))
				.onClick(TextActions.suggestCommand("/msg " + player.getName() + " "))
				.build());
	
	player.setReplyTo(EEMsg.CONSOLE);
	this.plugin.getEssentials().getConsole().setReplyTo(player.getIdentifier());
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:22,代码来源:EEMsg.java

示例11: execute

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Collection<UserPermission> users = Users.getUsers();
    PaginationList.builder()
            .title(Text.of("Web-API users"))
            .contents(users.stream().map(u -> {
                Text editUser = Text.builder("[Change pw]")
                        .color(TextColors.YELLOW)
                        .onClick(TextActions.suggestCommand("/webapi users changepw " + u.getUsername() + " "))
                        .build();

                Text rmvUser = Text.builder(" [Remove]")
                        .color(TextColors.RED)
                        .onClick(TextActions.suggestCommand("/webapi users remove " + u.getUsername()))
                        .build();

                return Text.builder(u.getUsername() + " ").append(editUser, rmvUser).build();
            }).collect(Collectors.toList()))
            .sendTo(src);
    return CommandResult.success();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:22,代码来源:CmdUserList.java

示例12: execute

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
/**
 * Callback for the execution of a command.
 *
 * @param src  The commander who is executing this command
 * @param args The parsed command arguments for this command
 * @return the result of executing this command
 * @throws CommandException If a user-facing error occurs while executing this command
 */
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (!(src instanceof Player))
		return execServer(src, args);

	HashMap<Player, UUID> deleteQueue = Maps.newHashMap();
	Player player = (Player) src;

	if (args.hasAny(ALL)) {
		player.sendMessage(Text.of(
			TextColors.GOLD, "Are you sure you want to unload all? ",
			TextColors.GREEN, Text.builder("Yes ").onClick(TextActions.executeCallback(unloadAll(player))),
			TextColors.RED, Text.builder("No").onClick(TextActions
				.executeCallback(s -> player.sendMessage(Text.of(TextColors.GREEN, "Unload All Cancelled."))))
		));
		return CommandResult.success();
	}

	dataStore.getPlayerRegions(player).forEach(region ->
		region.getChunks().forEach(chunk -> {
				if (player.getLocation().getChunkPosition().equals(chunk.getPosition())) {
					region.unForceChunks();
					region.invalidateTicket();
					deleteQueue.put(player, region.getUniqueId());
					player.sendMessage(Text.of(TextColors.GREEN, "Successfully removed loaded region"));
				}
			}
		));

	// Delete all the regions queued to be deleted
	deleteQueue.forEach((owner, regionId) -> dataStore.deletePlayerRegion(owner, regionId));

	return CommandResult.success();
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:42,代码来源:CommandUnload.java

示例13: formatHelpText

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
private static Text formatHelpText(String command, String description, Text extendedDescription) {
    return Text.of(Text.builder(command)
        .color(TextColors.GREEN)
        .onClick(TextActions.suggestCommand(command))
        .onHover(TextActions.showText(extendedDescription))
        .build(),Text.of(TextColors.GRAY, " - ", description));
}
 
开发者ID:ichorpowered,项目名称:iplog,代码行数:8,代码来源:HelpCommand.java

示例14: execute

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    String id = args.<String>getOne("id").orElseThrow(() -> new CommandException(Text.of("No Camera Id")));

    Location<World> location;

    if(src instanceof Player){
        location = args.<Location<World>>getOne("location").orElse(((Player) src).getLocation());
    }else{
        location = args.<Location<World>>getOne("location").orElseThrow(() -> new CommandException(Text.of("No Location")));
    }

    Camera camera = new Camera(location, id);

    Optional<String> name = args.getOne("name");

    if(name.isPresent()){
        camera.setName(Text.of(name.get()));
    }

    Optional<String> permission = args.getOne("permission");

    if(permission.isPresent()){
        camera.setPermission(permission.get());
    }

    plugin.getCameras().put(id, camera);
    plugin.getConfig().saveCameras();

    src.sendMessage(plugin.translations.CAMERA_CREATED, camera.templateVariables());

    if(camera.canUseCamera(src)){
        src.sendMessage(plugin.translations.CAMERA_CREATED_HAS_PERMISSIONS.apply(camera.templateVariables())
                .onClick(TextActions.runCommand("/vigilate view " + camera.getId())).build());
    }

    return CommandResult.success();
}
 
开发者ID:Lergin,项目名称:Vigilate,代码行数:39,代码来源:CreateCameraCommand.java

示例15: showPage

import org.spongepowered.api.text.action.TextActions; //导入依赖的package包/类
public void showPage(Player p, int page) {
	if (lines.isEmpty()) {
		p.sendMessage(Text.of(TextColors.DARK_AQUA, "[AS] ", TextColors.GRAY, "No results at this location..."));
		return;
	}
	
	int linesPerPage = LookupResultManager.instance().getLinesPerPage();
	int pages = getPages(linesPerPage);
	if (page > pages) {
		p.sendMessage(Text.of(TextColors.DARK_AQUA, "[AS] ", TextColors.RED, "Page number exceeds amount of pages (max ", pages, ")"));
		return;
	}
	
	lastPage = page;
	
	Text text = Text.of(TextColors.DARK_AQUA, "[AS] ", TextColors.YELLOW, "Showing results, page ", page, "/", pages);
	for (int i = (page - 1) * linesPerPage; i < page * linesPerPage && i < lines.size(); ++i) {
		LookupLine line = lines.get(i);
		Text hover = Text.builder(line.toString())
				.color(TextColors.GOLD)
				.onHover(TextActions.showText(line.getHoverText()))
				.build();
		text = Text.of(text, Text.NEW_LINE, TimeUtils.timeAgoToString(line.getTime()),
				TextColors.DARK_AQUA, " - ", hover);
	}
	p.sendMessage(text);
}
 
开发者ID:Karanum,项目名称:AdamantineShield,代码行数:28,代码来源:LookupResult.java


注:本文中的org.spongepowered.api.text.action.TextActions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。