當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。