org.spongepowered.api.text.format.TextStyles Java Examples

The following examples show how to use org.spongepowered.api.text.format.TextStyles. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandHelper.java    From GriefPrevention with MIT License 6 votes vote down vote up
public static Text getClickableText(CommandSource src, Subject subject, String subjectName, Set<Context> contexts, GPClaim claim, String flagPermission, Tristate flagValue, String source, FlagType type) {
    Text onClickText = Text.of("Click here to toggle flag value.");
    boolean hasPermission = true;
    if (type == FlagType.INHERIT) {
        onClickText = Text.of("This flag is inherited from parent claim ", claim.getName().orElse(claim.getFriendlyNameType()), " and ", TextStyles.UNDERLINE, "cannot", TextStyles.RESET, " be changed.");
        hasPermission = false;
    } else if (src instanceof Player) {
        Text denyReason = claim.allowEdit((Player) src);
        if (denyReason != null) {
            onClickText = denyReason;
            hasPermission = false;
        }
    }

    Text.Builder textBuilder = Text.builder()
    .append(Text.of(flagValue.toString().toLowerCase()))
    .onHover(TextActions.showText(Text.of(onClickText, "\n", getFlagTypeHoverText(type))));
    if (hasPermission) {
        textBuilder.onClick(TextActions.executeCallback(createFlagConsumer(src, subject, subjectName, contexts, claim, flagPermission, flagValue, source)));
    }
    return textBuilder.build();
}
 
Example #2
Source File: PrivateMessageFeature.java    From ChatUI with MIT License 6 votes vote down vote up
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();
    });
}
 
Example #3
Source File: WorldsBase.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	ArrayList<String> worlds = EssentialCmds.getEssentialCmds().getGame().getServer().getWorlds().stream().filter(world -> world.getProperties().isEnabled()).map(World::getName).collect(Collectors.toCollection(ArrayList::new));

	PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
	ArrayList<Text> worldText = Lists.newArrayList();

	for (String name : worlds)
	{
		Text item = Text.builder(name)
			.onClick(TextActions.runCommand("/tpworld " + name))
			.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Teleport to world ", TextColors.GOLD, name)))
			.color(TextColors.DARK_AQUA)
			.style(TextStyles.UNDERLINE)
			.build();

		worldText.add(item);
	}

	PaginationList.Builder paginationBuilder = paginationService.builder().contents(worldText).title(Text.of(TextColors.GREEN, "Showing Worlds")).padding(Text.of("-"));
	paginationBuilder.sendTo(src);
}
 
Example #4
Source File: ListHomeExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		Set<Object> homes = Utils.getHomes(player.getUniqueId());

		if (homes.size() == 0)
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must first set a home to list your homes!"));
			return;
		}

		PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
		List<Text> homeText = Lists.newArrayList();

		for (Object home : homes)
		{
			String name = String.valueOf(home);

			Text item = Text.builder(name)
				.onClick(TextActions.runCommand("/home " + name))
				.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Teleport to home ", TextColors.GOLD, name)))
				.color(TextColors.DARK_AQUA)
				.style(TextStyles.UNDERLINE)
				.build();

			homeText.add(item);
		}

		PaginationList.Builder paginationBuilder = paginationService.builder().contents(homeText).title(Text.of(TextColors.GREEN, "Showing Homes")).padding(Text.of("-"));
		paginationBuilder.sendTo(src);
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /homes!"));
	}
}
 
Example #5
Source File: ClaimFlagBase.java    From GriefPrevention with MIT License 5 votes vote down vote up
private static Text getFlagText(String flagPermission, String baseFlag) {
    final String flagSource = GPPermissionHandler.getSourcePermission(flagPermission);
    final String flagTarget = GPPermissionHandler.getTargetPermission(flagPermission);
    Text sourceText = flagSource == null ? null : Text.of(TextColors.WHITE, "source=",TextColors.GREEN, flagSource);
    Text targetText = flagTarget == null ? null : Text.of(TextColors.WHITE, "target=",TextColors.GREEN, flagTarget);
    if (sourceText != null) {
       /* if (targetText != null) {
            sourceText = Text.of(sourceText, "  ");
        } else {*/
            sourceText = Text.of(sourceText, "\n");
        //}
    } else {
        sourceText = Text.of();
    }
    if (targetText != null) {
        targetText = Text.of(targetText);
    } else {
        targetText = Text.of();
    }
    Text baseFlagText = Text.of();
    if (flagSource == null && flagTarget == null) {
        baseFlagText = Text.builder().append(Text.of(TextColors.GREEN, baseFlag.toString(), " "))
            .onHover(TextActions.showText(Text.of(sourceText, targetText))).build();
    } else {
        baseFlagText = Text.builder().append(Text.of(TextStyles.ITALIC, TextColors.YELLOW, baseFlag.toString(), " ", TextStyles.RESET))
                .onHover(TextActions.showText(Text.of(sourceText, targetText))).build();
    }
    final Text baseText = Text.builder().append(Text.of(
            baseFlagText)).build();
            //sourceText,
            //targetText)).build();
    return baseText;
}
 
Example #6
Source File: CommandClaimInfo.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Consumer<CommandSource> createSettingsConsumer(CommandSource src, Claim claim, List<Text> textList, ClaimType type) {
    return settings -> {
        String name = type == ClaimType.TOWN ? "Town Settings" : "Admin Settings";
        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(TextColors.AQUA, name)).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList);
        paginationBuilder.sendTo(src);
    };
}
 
Example #7
Source File: CommandHelper.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Consumer<CommandSource> createBankTransactionsConsumer(CommandSource src, GPClaim claim, boolean checkTown, boolean returnToClaimInfo) {
    return settings -> {
        final String name = "Bank Transactions";
        List<String> bankTransactions = new ArrayList<>(claim.getData().getEconomyData().getBankTransactionLog());
        Collections.reverse(bankTransactions);
        List<Text> textList = new ArrayList<>();
        textList.add(Text.builder().append(Text.of(
                TextColors.WHITE, "\n[", TextColors.AQUA, "Return to bank info", TextColors.WHITE, "]\n"))
            .onClick(TextActions.executeCallback(consumer -> { displayClaimBankInfo(src, claim, checkTown, returnToClaimInfo); })).build());
        Gson gson = new Gson();
        for (String transaction : bankTransactions) {
            GPBankTransaction bankTransaction = gson.fromJson(transaction, GPBankTransaction.class);
            final Duration duration = Duration.between(bankTransaction.timestamp, Instant.now().truncatedTo(ChronoUnit.SECONDS)) ;
            final long s = duration.getSeconds();
            final User user = GriefPreventionPlugin.getOrCreateUser(bankTransaction.source);
            final String timeLeft = String.format("%dh %02dm %02ds", s / 3600, (s % 3600) / 60, (s % 60)) + " ago";
            textList.add(Text.of(getTransactionColor(bankTransaction.type), bankTransaction.type.name(), 
                    TextColors.BLUE, " | ", TextColors.WHITE, bankTransaction.amount, 
                    TextColors.BLUE, " | ", TextColors.GRAY, timeLeft,
                    user == null ? "" : Text.of(TextColors.BLUE, " | ", TextColors.LIGHT_PURPLE, user.getName())));
        }
        textList.add(Text.builder().append(Text.of(
                TextColors.WHITE, "\n[", TextColors.AQUA, "Return to bank info", TextColors.WHITE, "]\n"))
            .onClick(TextActions.executeCallback(CommandHelper.createCommandConsumer(src, "claimbank", ""))).build());
        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(TextColors.AQUA, name)).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList);
        paginationBuilder.sendTo(src);
    };
}
 
Example #8
Source File: CommandHelper.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Consumer<CommandSource> showChildrenList(List<Text> childrenTextList, CommandSource src, Consumer<CommandSource> returnCommand, GPClaim parent) {
    return consumer -> {
        Text claimListReturnCommand = Text.builder().append(Text.of(
                TextColors.WHITE, "\n[", TextColors.AQUA, "Return to claimslist", TextColors.WHITE, "]\n"))
            .onClick(TextActions.executeCallback(returnCommand)).build();

        List<Text> textList = new ArrayList<>();
        textList.add(claimListReturnCommand);
        textList.addAll(childrenTextList);
        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(parent.getName().orElse(parent.getFriendlyNameType()), " Child Claims")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList);
        paginationBuilder.sendTo(src);
    };
}
 
Example #9
Source File: CommandHelper.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static void showClaims(CommandSource src, Set<Claim> claims, int height, boolean visualizeClaims, boolean overlap) {
    final String worldName = src instanceof Player ? ((Player) src).getWorld().getName() : Sponge.getServer().getDefaultWorldName();
    final boolean canListOthers = src.hasPermission(GPPermissions.LIST_OTHER_CLAIMS);
    List<Text> claimsTextList = generateClaimTextList(new ArrayList<Text>(), claims, worldName, null, src, createShowClaimsConsumer(src, claims, height, visualizeClaims), canListOthers, false, overlap);
    if (visualizeClaims && src instanceof Player) {
        Player player = (Player) src;
        final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
        if (claims.size() > 1) {
            if (height != 0) {
                height = playerData.lastValidInspectLocation != null ? playerData.lastValidInspectLocation.getBlockY() : player.getProperty(EyeLocationProperty.class).get().getValue().getFloorY();
            }
            Visualization visualization = Visualization.fromClaims(claims, playerData.optionClaimCreateMode == 1 ? height : player.getProperty(EyeLocationProperty.class).get().getValue().getFloorY(), player.getLocation(), playerData, null);
            visualization.apply(player);
        } else {
            for (Claim claim : claims) {
                final GPClaim gpClaim = (GPClaim) claim;
                gpClaim.getVisualizer().createClaimBlockVisuals(height, player.getLocation(), playerData);
                gpClaim.getVisualizer().apply(player);
            }
        }
    }

    PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
    PaginationList.Builder paginationBuilder = paginationService.builder()
            .title(Text.of(TextColors.RED,"Claim list")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(claimsTextList);
    paginationBuilder.sendTo(src);
}
 
Example #10
Source File: BlacklistBase.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	List<String> blacklistItems = Utils.getBlacklistItems();

	if (blacklistItems.size() == 0)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "There are no blacklisted items!"));
		return CommandResult.success();
	}

	PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
	List<Text> blacklistText = Lists.newArrayList();

	for (String name : blacklistItems)
	{
		Text item = Text.builder(name)
			.color(TextColors.DARK_AQUA)
			.style(TextStyles.UNDERLINE)
			.build();

		blacklistText.add(item);
	}

	PaginationList.Builder paginationBuilder = paginationService.builder().contents(blacklistText).title(Text.of(TextColors.GREEN, "Showing Blacklist")).padding(Text.of("-"));
	paginationBuilder.sendTo(src);

	return CommandResult.success();
}
 
Example #11
Source File: SubjectViewer.java    From ChatUI with MIT License 5 votes vote down vote up
private UIComponent createTopBar() {
    return new UIComponent() {

        @Override
        public void draw(PlayerContext ctx, LineFactory lineFactory) {
            lineFactory.appendNewLine(Text.of(TextStyles.BOLD, TextColors.RED, SubjectViewer.this.activeSubj.getIdentifier()), ctx);
            Text.Builder builder = Text.builder("Parents: ");
            if (SubjectViewer.this.activeSubj.getParents(SubjectViewer.this.activeContext).isEmpty()) {
                builder.append(Text.of("None"));
            }
            for (SubjectReference parent : SubjectViewer.this.activeSubj.getParents(SubjectViewer.this.activeContext)) {
                builder.append(hyperlink(parent.getSubjectIdentifier(), () -> setActive(parent.resolve().join(), false)));
                builder.append(Text.builder("[x]").color(TextColors.RED)
                        .onClick(ExtraUtils.clickAction((Consumer<PlayerChatView>) view -> removeParent(view.getPlayer(), parent),
                                SubjectViewer.this.tab))
                        .build());
                builder.append(Text.of(", "));
            }
            lineFactory.appendNewLine(builder.build(), ctx);
            builder = Text.builder("Current Context: ");
            if (SubjectViewer.this.activeContext.isEmpty()) {
                builder.append(Text.of("global"));
            }
            for (Context context : SubjectViewer.this.activeContext) {
                builder.append(Text.of(context.getKey() + "[" + context.getValue() + "], "));
            }
            lineFactory.appendNewLine(builder.build(), ctx);
        }
    };
}
 
Example #12
Source File: SubjectViewer.java    From ChatUI with MIT License 5 votes vote down vote up
Text hyperlink(String text, Runnable r, String hoverText) {
    Text.Builder b = Text.builder(text).color(TextColors.BLUE).style(TextStyles.UNDERLINE)
            .onClick(ExtraUtils.clickAction(r, this.tab));
    if (hoverText != null) {
        b.onHover(TextActions.showText(Text.of(hoverText)));
    }
    return b.build();
}
 
Example #13
Source File: Window.java    From ChatUI with MIT License 5 votes vote down vote up
private Text createTabButton(int tabIndex) {
    Text.Builder button = getTabs().get(tabIndex).getTitle().toBuilder();
    button.color(TextColors.GREEN);
    if (tabIndex == getActiveIndex()) {
        button.style(TextStyles.BOLD);
    } else {
        button.onClick(ChatUILib.command("settab " + tabIndex));
    }
    return button.build();
}
 
Example #14
Source File: PlayerList.java    From ChatUI with MIT License 5 votes vote down vote up
private void addDefaultAddons(Player player) {
    TextFormat link = TextFormat.of(TextColors.BLUE, TextStyles.UNDERLINE);
    if (player.hasPermission(PERM_KICK)) {
        addAddon(listPlayer -> Text.builder("Kick").format(link).onClick(Utils.execClick(view -> listPlayer.kick())).build());
    }
    if (player.hasPermission(PERM_BAN)) {
        addAddon(listPlayer -> Text.builder("Ban").format(link)
                .onClick(Utils.execClick(view -> Sponge.getServiceManager().provideUnchecked(BanService.class).addBan(Ban.of(listPlayer.getProfile()))))
                .build());
    }
}
 
Example #15
Source File: MailListExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		List<Mail> mail = Utils.getMail(player);

		if (mail.isEmpty())
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You have no new mail!"));
			return;
		}

		PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
		List<Text> mailText = Lists.newArrayList();

		for (Mail newM : mail)
		{
			String name = "New mail from " + newM.getSenderName();
			Text item = Text.builder(name).onClick(TextActions.runCommand("/readmail " + (mail.indexOf(newM)))).onHover(TextActions.showText(Text.of(TextColors.WHITE, "Read mail from ", TextColors.GOLD, newM.getSenderName()))).color(TextColors.DARK_AQUA).style(TextStyles.UNDERLINE).build();

			mailText.add(item);
		}

		PaginationList.Builder paginationBuilder = paginationService.builder().contents(mailText).title(Text.of(TextColors.GREEN, "Showing Mail")).padding(Text.of("-"));
		paginationBuilder.sendTo(src);
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /mailist!"));
	}
}
 
Example #16
Source File: ListCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    CompletableFuture.runAsync(() ->{
        Set<Faction> factionsList = new HashSet<>(super.getPlugin().getFactionLogic().getFactions().values());
        List<Text> helpList = new ArrayList<>();

        Text tagPrefix = getPlugin().getConfiguration().getChatConfig().getFactionStartPrefix();
        Text tagSuffix = getPlugin().getConfiguration().getChatConfig().getFactionEndPrefix();

        for(final Faction faction : factionsList)
        {
            Text tag = Text.builder().append(tagPrefix).append(faction.getTag()).append(tagSuffix, Text.of(" ")).build();

            Text factionHelp = Text.builder()
                    .append(Text.builder()
                            .append(Text.of(TextColors.AQUA, "- ")).append(tag).append(Text.of(faction.getName(), " (", getPlugin().getPowerManager().getFactionPower(faction), "/", getPlugin().getPowerManager().getFactionMaxPower(faction), ")"))
                            .build())
                    .onClick(TextActions.runCommand("/f info " + faction.getName()))
                    .onHover(TextActions.showText(Text.of(TextStyles.ITALIC, TextColors.BLUE, "Click", TextColors.RESET, " for more info...")))
                    .build();

            helpList.add(factionHelp);
        }

        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, Messages.FACTIONS_LIST)).padding(Text.of("-")).contents(helpList);
        paginationBuilder.sendTo(source);
    });
    return CommandResult.success();
}
 
Example #17
Source File: VirtualChestCommandManager.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
private CommandResult processVersionCommand(CommandSource source, CommandContext args) throws CommandException
{
    source.sendMessage(Text.of("================================================================"));
    source.sendMessage(this.translation.take("virtualchest.version.description.title", VERSION));
    source.sendMessage(this.translation.take("virtualchest.version.description.subtitle", SUBTITLE));
    source.sendMessage(Text.of("================================================================"));
    try
    {
        // RFC 3339
        Date releaseDate = RFC3339.parse("@release_date@");
        String gitCommitHash = "@git_hash@";

        source.sendMessage(this.translation
                .take("virtualchest.version.description.line1", releaseDate));
        source.sendMessage(this.translation
                .take("virtualchest.version.description.line2", gitCommitHash));

        Text urlWebsite = Text.builder(WEBSITE_URL)
                .color(TextColors.GREEN).style(TextStyles.BOLD)
                .onClick(TextActions.openUrl(new URL(WEBSITE_URL))).build();
        Text urlGitHub = Text.builder(GITHUB_URL)
                .color(TextColors.GREEN).style(TextStyles.BOLD)
                .onClick(TextActions.openUrl(new URL(GITHUB_URL))).build();

        source.sendMessage(Text.join(this.translation
                .take("virtualchest.version.description.line3", ""), urlWebsite));
        source.sendMessage(Text.join(this.translation
                .take("virtualchest.version.description.line4", ""), urlGitHub));

        source.sendMessage(Text.of("================================================================"));
    }
    catch (MalformedURLException | ParseException e)
    {
        throw new RuntimeException(e);
    }
    return CommandResult.success();
}
 
Example #18
Source File: ListWarpExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Set<Object> warps = Utils.getWarps();

		if (warps.size() == 0)
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No warps set!"));
			return;
		}

		if (warps.size() > 0)
		{
			PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
			List<Text> warpText = Lists.newArrayList();

			for (Object name : warps)
			{
				if (player.hasPermission("essentialcmds.warp.use." + String.valueOf(name)))
				{
					Text item = Text.builder(String.valueOf(name))
						.onClick(TextActions.runCommand("/warp " + String.valueOf(name)))
						.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Warp to ", TextColors.GOLD, String.valueOf(name))))
						.color(TextColors.DARK_AQUA)
						.style(TextStyles.UNDERLINE)
						.build();

					warpText.add(item);
				}
			}

			PaginationList.Builder paginationBuilder = paginationService.builder().contents(warpText).title(Text.of(TextColors.GREEN, "Showing Warps")).padding(Text.of("-"));
			paginationBuilder.sendTo(src);
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "No warps set!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /warps!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /warps!"));
	}
}
 
Example #19
Source File: WorldsBase.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Optional<String> worldName = ctx.<String> getOne("world");
	World world;

	if (worldName.isPresent())
	{
		if (Sponge.getServer().getWorld(worldName.get()).isPresent())
		{
			world = Sponge.getServer().getWorld(worldName.get()).get();
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!"));
			return CommandResult.empty();
		}
	}
	else
	{
		if (src instanceof Player)
		{
			Player player = (Player) src;
			world = player.getWorld();
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /world difficulty!"));
			return CommandResult.empty();
		}
	}

	PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
	ArrayList<Text> gameruleText = Lists.newArrayList();

	for (Entry<String, String> gamerule : world.getGameRules().entrySet())
	{
		Text item = Text.builder(gamerule.getKey())
			.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Value ", TextColors.GOLD, gamerule.getValue())))
			.color(TextColors.DARK_AQUA)
			.style(TextStyles.UNDERLINE)
			.build();

		gameruleText.add(item);
	}

	PaginationList.Builder paginationBuilder = paginationService.builder().contents(gameruleText).title(Text.of(TextColors.GREEN, "Showing Gamerules")).padding(Text.of("-"));
	paginationBuilder.sendTo(src);
	return CommandResult.success();
}
 
Example #20
Source File: CommandClaimInfo.java    From GriefPrevention with MIT License 4 votes vote down vote up
private static void executeAdminSettings(CommandSource src, GPClaim claim) {
    PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
    PaginationList.Builder paginationBuilder = paginationService.builder()
            .title(Text.of(TextColors.AQUA, "Admin Settings")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(generateAdminSettings(src, claim));
    paginationBuilder.sendTo(src);
}
 
Example #21
Source File: CommandClaimPermissionPlayer.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    final String permission = args.<String>getOne("permission").orElse(null);
    if (permission != null && !player.hasPermission(permission)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionAssignWithoutHaving.toText());
        return CommandResult.success();
    }

    final User user = args.<User>getOne("user").orElse(null);
    final String value = args.<String>getOne("value").orElse(null);
    final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimManage
            .apply(ImmutableMap.of(
            "type", claim.getType().name())).build();
    if (claim.isWilderness() && !playerData.canManageWilderness) {
        GriefPreventionPlugin.sendMessage(src, message);
        return CommandResult.success();
    } else if (claim.isAdminClaim() && !playerData.canManageAdminClaims) {
        GriefPreventionPlugin.sendMessage(src, message);
        return CommandResult.success();
    }

    Set<Context> contexts = new HashSet<>();
    contexts.add(claim.getContext());
    if (permission == null || value == null) {
        // display current permissions for user
        List<Object[]> permList = Lists.newArrayList();
        Map<String, Boolean> permissions = user.getSubjectData().getPermissions(contexts);
        for (Map.Entry<String, Boolean> permissionEntry : permissions.entrySet()) {
            Boolean permValue = permissionEntry.getValue();
            Object[] permText = new Object[] { TextColors.GREEN, permissionEntry.getKey(), "  ",
                            TextColors.GOLD, permValue.toString() };
            permList.add(permText);
        }

        List<Text> finalTexts = CommandHelper.stripeText(permList);

        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(TextColors.AQUA, user.getName() + " Permissions")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(finalTexts);
        paginationBuilder.sendTo(src);
        return CommandResult.success();
    }

    Tristate tristateValue = PlayerUtils.getTristateFromString(value);
    if (tristateValue == null) {
        GriefPreventionPlugin.sendMessage(src, Text.of(TextColors.RED, "Invalid value entered. '" + value + "' is not a valid value. Valid values are : true, false, undefined, 1, -1, or 0."));
        return CommandResult.success();
    }

    user.getSubjectData().setPermission(contexts, permission, tristateValue);
    GriefPreventionPlugin.sendMessage(src, Text.of("Set permission ", TextColors.AQUA, permission, TextColors.WHITE, " to ", TextColors.GREEN, tristateValue, TextColors.WHITE, " on user ", TextColors.GOLD, user.getName(), TextColors.WHITE, "."));

    return CommandResult.success();
}
 
Example #22
Source File: CommandClaimPermissionGroup.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    final String permission = args.<String>getOne("permission").orElse(null);
    if (permission != null && !player.hasPermission(permission)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionAssignWithoutHaving.toText());
        return CommandResult.success();
    }

    final String group = args.<String>getOne("group").orElse(null);
    final String value = args.<String>getOne("value").orElse(null);

    if (!PermissionUtils.hasGroupSubject(group)) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.commandGroupInvalid.toText());
        return CommandResult.success();
    }

    final Subject subj = PermissionUtils.getGroupSubject(group);
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimManage
            .apply(ImmutableMap.of(
            "type", claim.getType().name())).build();
    if (claim.isWilderness() && !playerData.canManageWilderness) {
        GriefPreventionPlugin.sendMessage(src, message);
        return CommandResult.success();
    } else if (claim.isAdminClaim() && !playerData.canManageAdminClaims) {
        GriefPreventionPlugin.sendMessage(src, message);
        return CommandResult.success();
    }

    Set<Context> contexts = new HashSet<>();
    contexts.add(claim.getContext());
    if (permission == null || value == null) {
        List<Object[]> permList = Lists.newArrayList();
        Map<String, Boolean> permissions = subj.getSubjectData().getPermissions(contexts);
        for (Map.Entry<String, Boolean> permissionEntry : permissions.entrySet()) {
            Boolean permValue = permissionEntry.getValue();
            Object[] permText = new Object[] { TextColors.GREEN, permissionEntry.getKey(), "  ",
                            TextColors.GOLD, permValue.toString() };
            permList.add(permText);
        }

        List<Text> finalTexts = CommandHelper.stripeText(permList);

        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(TextColors.AQUA, subj.getIdentifier() + " Permissions")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(finalTexts);
        paginationBuilder.sendTo(src);
        return CommandResult.success();
    }

    Tristate tristateValue = PlayerUtils.getTristateFromString(value);
    if (tristateValue == null) {
        GriefPreventionPlugin.sendMessage(src, Text.of(TextColors.RED, "Invalid value entered. '" + value + "' is not a valid value. Valid values are : true, false, undefined, 1, -1, or 0."));
        return CommandResult.success();
    }

    subj.getSubjectData().setPermission(contexts, permission, tristateValue);
    GriefPreventionPlugin.sendMessage(src, Text.of("Set permission ", TextColors.AQUA, permission, TextColors.WHITE, " to ", TextColors.GREEN, tristateValue, TextColors.WHITE, " on group ", TextColors.GOLD, subj.getIdentifier(), TextColors.WHITE, "."));
    return CommandResult.success();
}
 
Example #23
Source File: CommandClaimOptionGroup.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    String option = args.<String>getOne("option").orElse(null);
    if (option != null && !option.startsWith("griefprevention.")) {
        option = "griefprevention." + option;
    }

    final Double value = args.<Double>getOne("value").orElse(null);
    final String group = args.<String>getOne("group").orElse(null);
    final boolean isGlobalOption = GPOptions.GLOBAL_OPTIONS.contains(option);
    // Check if global option
    if (isGlobalOption && !player.hasPermission(GPPermissions.MANAGE_GLOBAL_OPTIONS)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionGlobalOption.toText());
        return CommandResult.success();
    }

    Set<Context> contexts = new HashSet<>();
    final Subject subj = PermissionUtils.getGroupSubject(group);
    if (!isGlobalOption) {
        final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
        final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());

        if (claim.isSubdivision()) {
            GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.commandOptionInvalidClaim.toText());
            return CommandResult.success();
        }
        if (!playerData.canManageOption(player, claim, true)) {
            GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionGroupOption.toText());
            return CommandResult.success();
        }

        if (!PermissionUtils.hasGroupSubject(group)) {
            GriefPreventionPlugin.sendMessage(player,GriefPreventionPlugin.instance.messageData.commandGroupInvalid.toText());
            return CommandResult.success();
        }

        final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimManage
                .apply(ImmutableMap.of(
                "type", claim.getType().name())).build();
        if (claim.isWilderness() && !player.hasPermission(GPPermissions.MANAGE_WILDERNESS)) {
            GriefPreventionPlugin.sendMessage(src, message);
            return CommandResult.success();
        } else if (claim.isAdminClaim() && !player.hasPermission(GPPermissions.COMMAND_ADMIN_CLAIMS)) {
            GriefPreventionPlugin.sendMessage(src, message);
            return CommandResult.success();
        }

        // Validate new value against admin set value
        if (option != null && value != null) {
            Double tempValue = GPOptionHandler.getClaimOptionDouble(player, claim, option, playerData);
            if (tempValue != value) {
                final Text message2 = GriefPreventionPlugin.instance.messageData.commandOptionExceedsAdmin
                        .apply(ImmutableMap.of(
                        "original_value", value,
                        "admin_value", tempValue)).build();
                GriefPreventionPlugin.sendMessage(src, message2);
                return CommandResult.success();
            }
            contexts.add(claim.getContext());
        }
    }

    if (option == null || value == null) {
        List<Object[]> optionList = Lists.newArrayList();
        Map<String, String> options = subj.getSubjectData().getOptions(contexts);
        for (Map.Entry<String, String> optionEntry : options.entrySet()) {
            String optionValue = optionEntry.getValue();
            Object[] optionText = new Object[] { TextColors.GREEN, optionEntry.getKey(), "  ",
                            TextColors.GOLD, optionValue };
            optionList.add(optionText);
        }

        List<Text> finalTexts = CommandHelper.stripeText(optionList);

        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(TextColors.AQUA, subj.getIdentifier() + " Claim Options")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(finalTexts);
        paginationBuilder.sendTo(src);
        return CommandResult.success();
    }

    final String flagOption = option;
    subj.getSubjectData().setOption(contexts, option, value.toString())
        .thenAccept(consumer -> {
            if (consumer.booleanValue()) {
                GriefPreventionPlugin.sendMessage(src, Text.of("Set option ", TextColors.AQUA, flagOption, TextColors.WHITE, " to ", TextColors.GREEN, value, TextColors.WHITE, " on group ", TextColors.GOLD, subj.getIdentifier(), TextColors.WHITE, "."));
            } else {
                GriefPreventionPlugin.sendMessage(src, Text.of(TextColors.RED, "The permission plugin failed to set the option."));
            }
        });
    return CommandResult.success();
}
 
Example #24
Source File: CommandClaimBuy.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    // if economy is disabled, don't do anything
    if (!GriefPreventionPlugin.instance.economyService.isPresent()) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.economyNotInstalled.toText());
        return CommandResult.success();
    }

    Account playerAccount = GriefPreventionPlugin.instance.economyService.get().getOrCreateAccount(player.getUniqueId()).orElse(null);
    if (playerAccount == null) {
        final Text message = GriefPreventionPlugin.instance.messageData.economyUserNotFound
                .apply(ImmutableMap.of(
                "user", player.getName())).build();
        GriefPreventionPlugin.sendMessage(player, message);
        return CommandResult.success();
    }

    Set<Claim> claimsForSale = new HashSet<>();
    GPClaimManager claimManager = GriefPreventionPlugin.instance.dataStore.getClaimWorldManager(player.getWorld().getProperties());
    for (Claim worldClaim : claimManager.getWorldClaims()) {
        if (worldClaim.isWilderness()) {
            continue;
        }
        if (!worldClaim.isAdminClaim() && worldClaim.getEconomyData().isForSale() && worldClaim.getEconomyData().getSalePrice() > -1) {
            claimsForSale.add(worldClaim);
        }
        for (Claim child : worldClaim.getChildren(true)) {
            if (child.isAdminClaim()) {
                continue;
            }
            if (child.getEconomyData().isForSale() && child.getEconomyData().getSalePrice() > -1) {
                claimsForSale.add(child);
            }
        }
    }

    List<Text> claimsTextList = CommandHelper.generateClaimTextList(new ArrayList<Text>(), claimsForSale, player.getWorld().getName(), null, src, CommandHelper.createCommandConsumer(src, "claimbuy", ""), true, false);
    PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
    PaginationList.Builder paginationBuilder = paginationService.builder()
            .title(Text.of(TextColors.AQUA,"Claims for sale")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(claimsTextList);
    paginationBuilder.sendTo(src);
    return CommandResult.success();
}
 
Example #25
Source File: CommandHelper.java    From GriefPrevention with MIT License 4 votes vote down vote up
public static void displayClaimBankInfo(CommandSource src, GPClaim claim, boolean checkTown, boolean returnToClaimInfo) {
    final EconomyService economyService = GriefPreventionPlugin.instance.economyService.orElse(null);
    if (economyService == null) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.economyNotInstalled.toText());
        return;
    }

    if (checkTown && !claim.isInTown()) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.townNotIn.toText());
        return;
    }

    if (!checkTown && (claim.isSubdivision() || claim.isAdminClaim())) {
        return;
    }

    final GPClaim town = claim.getTownClaim();
    Account bankAccount = checkTown ? town.getEconomyAccount().orElse(null) : claim.getEconomyAccount().orElse(null);
    if (bankAccount == null) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.economyVirtualNotSupported.toText());
        return;
    }

    final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getPlayerData(claim.getWorld(), claim.getOwnerUniqueId());
    final double claimBalance = bankAccount.getBalance(economyService.getDefaultCurrency()).doubleValue();
    double taxOwed = -1;
    final double playerTaxRate = GPOptionHandler.getClaimOptionDouble(playerData.getPlayerSubject(), claim, GPOptions.Type.TAX_RATE, playerData);
    if (checkTown) {
        if (!town.getOwnerUniqueId().equals(playerData.playerID)) {
            for (Claim playerClaim : playerData.getInternalClaims()) {
                GPClaim playerTown = (GPClaim) playerClaim.getTown().orElse(null);
                if (!playerClaim.isTown() && playerTown != null && playerTown.getUniqueId().equals(claim.getUniqueId())) {
                    taxOwed += playerTown.getClaimBlocks() * playerTaxRate;
                }
            }
        } else {
            taxOwed = town.getClaimBlocks() * playerTaxRate;
        }
    } else {
        taxOwed = claim.getClaimBlocks() * playerTaxRate;
    }

    final GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(claim.getWorld().getProperties());
    final ZonedDateTime withdrawDate = TaskUtils.getNextTargetZoneDate(activeConfig.getConfig().claim.taxApplyHour, 0, 0);
    Duration duration = Duration.between(Instant.now().truncatedTo(ChronoUnit.SECONDS), withdrawDate.toInstant()) ;
    final long s = duration.getSeconds();
    final String timeLeft = String.format("%d:%02d:%02d", s / 3600, (s % 3600) / 60, (s % 60));
    final Text message = GriefPreventionPlugin.instance.messageData.claimBankInfo
            .apply(ImmutableMap.of(
            "balance", claimBalance,
            "amount", taxOwed,
            "time_remaining", timeLeft,
            "tax_balance", claim.getData().getEconomyData().getTaxBalance())).build();
    Text transactions = Text.builder()
            .append(Text.of(TextStyles.ITALIC, TextColors.AQUA, "Bank Transactions"))
            .onClick(TextActions.executeCallback(createBankTransactionsConsumer(src, claim, checkTown, returnToClaimInfo)))
            .onHover(TextActions.showText(Text.of("Click here to view bank transactions")))
            .build();
    List<Text> textList = new ArrayList<>();
    if (returnToClaimInfo) {
        textList.add(Text.builder().append(Text.of(
                TextColors.WHITE, "\n[", TextColors.AQUA, "Return to claim info", TextColors.WHITE, "]\n"))
            .onClick(TextActions.executeCallback(CommandHelper.createCommandConsumer(src, "claiminfo", ""))).build());
    }
    textList.add(message);
    textList.add(transactions);
    PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
    PaginationList.Builder paginationBuilder = paginationService.builder()
            .title(Text.of(TextColors.AQUA, "Bank Info")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(textList);
    paginationBuilder.sendTo(src);
}
 
Example #26
Source File: CommandHelper.java    From GriefPrevention with MIT License 4 votes vote down vote up
public static Consumer<CommandSource> createTeleportConsumer(CommandSource src, Location<World> location, Claim claim) {
    return teleport -> {
        if (!(src instanceof Player)) {
            // ignore
            return;
        }
        Player player = (Player) src;
        GPClaim gpClaim = (GPClaim) claim;
        GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getPlayerData(player.getWorld(), player.getUniqueId());
        if (!playerData.canIgnoreClaim(gpClaim) && !playerData.canManageAdminClaims) {
            // if not owner of claim, validate perms
            if (!player.getUniqueId().equals(claim.getOwnerUniqueId())) {
                if (!player.hasPermission(GPPermissions.COMMAND_CLAIM_INFO_TELEPORT_OTHERS)) {
                    player.sendMessage(Text.of(TextColors.RED, "You do not have permission to use the teleport feature in this claim.")); 
                    return;
                }
                if (!gpClaim.isUserTrusted(player, TrustType.ACCESSOR)) {
                    if (GriefPreventionPlugin.instance.economyService.isPresent()) {
                        // Allow non-trusted to TP to claims for sale
                        if (!gpClaim.getEconomyData().isForSale()) {
                            player.sendMessage(Text.of(TextColors.RED, "You are not trusted to use the teleport feature in this claim.")); 
                            return;
                        }
                    } else {
                        player.sendMessage(Text.of(TextColors.RED, "You are not trusted to use the teleport feature in this claim.")); 
                        return;
                    }
                }
            } else if (!player.hasPermission(GPPermissions.COMMAND_CLAIM_INFO_TELEPORT_BASE)) {
                player.sendMessage(Text.of(TextColors.RED, "You do not have permission to use the teleport feature in your claim.")); 
                return;
            }
        }

        Location<World> safeLocation = Sponge.getGame().getTeleportHelper().getSafeLocation(location, 64, 16).orElse(null);
        if (safeLocation == null) {
            player.sendMessage(
                    Text.builder().append(Text.of(TextColors.RED, "Location is not safe. "), 
                    Text.builder().append(Text.of(TextColors.GREEN, "Are you sure you want to teleport here?")).onClick(TextActions.executeCallback(createForceTeleportConsumer(player, location))).style(TextStyles.UNDERLINE).build()).build());
        } else {
            player.setLocation(safeLocation);
        }
    };
}
 
Example #27
Source File: CommandClaimOptionPlayer.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    String option = args.<String>getOne("option").orElse(null);
    if (option != null && !option.startsWith("griefprevention.")) {
        option = "griefprevention." + option;
    }

    Double value = args.<Double>getOne("value").orElse(null);
    final User user = args.<User>getOne("user").orElse(null);
    final boolean isGlobalOption = GPOptions.GLOBAL_OPTIONS.contains(option);
    // Check if global option
    if (isGlobalOption && !player.hasPermission(GPPermissions.MANAGE_GLOBAL_OPTIONS)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionGlobalOption.toText());
        return CommandResult.success();
    }

    Set<Context> contexts = new HashSet<>();
    if (!isGlobalOption) {
        final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
        final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());

        if (claim.isSubdivision()) {
            GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.commandOptionInvalidClaim.toText());
            return CommandResult.success();
        }
        if (!playerData.canManageOption(player, claim, false)) {
            GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionPlayerOption.toText());
            return CommandResult.success();
        }

        final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimManage
                .apply(ImmutableMap.of(
                "type", claim.getType().name())).build();
        if (claim.isWilderness() && !player.hasPermission(GPPermissions.MANAGE_WILDERNESS)) {
            GriefPreventionPlugin.sendMessage(src, message);
            return CommandResult.success();
        } else if (claim.isAdminClaim() && !player.hasPermission(GPPermissions.COMMAND_ADMIN_CLAIMS)) {
            GriefPreventionPlugin.sendMessage(src, message);
            return CommandResult.success();
        }

        if (option != null && value != null) {
            // Validate new value against admin set value
            Double tempValue = GPOptionHandler.getClaimOptionDouble(user, claim, option, playerData);
            if (tempValue != value) {
                final Text message2 = GriefPreventionPlugin.instance.messageData.commandOptionExceedsAdmin
                        .apply(ImmutableMap.of(
                        "original_value", value,
                        "admin_value", tempValue)).build();
                GriefPreventionPlugin.sendMessage(src, message2);
                return CommandResult.success();
            }
            contexts.add(claim.getContext());
        }
    }

    if (option == null || value == null) {
        // display current options for user
        List<Object[]> optionList = Lists.newArrayList();
        Map<String, String> options = user.getSubjectData().getOptions(contexts);
        for (Map.Entry<String, String> optionEntry : options.entrySet()) {
            String optionValue = optionEntry.getValue();
            Object[] optionText = new Object[] { TextColors.GREEN, optionEntry.getKey(), "  ",
                            TextColors.GOLD, optionValue };
            optionList.add(optionText);
        }

        List<Text> finalTexts = CommandHelper.stripeText(optionList);

        PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
        PaginationList.Builder paginationBuilder = paginationService.builder()
                .title(Text.of(TextColors.AQUA, user.getName() + " Claim Options")).padding(Text.of(TextStyles.STRIKETHROUGH, "-")).contents(finalTexts);
        paginationBuilder.sendTo(src);
        return CommandResult.success();
    }

    final String flagOption = option;
    final Double newOptionValue = value;
    user.getSubjectData().setOption(contexts, option, newOptionValue.toString())
        .thenAccept(consumer -> {
            if (consumer.booleanValue()) {
                GriefPreventionPlugin.sendMessage(src, Text.of("Set option ", TextColors.AQUA, flagOption, TextColors.WHITE, " to ", TextColors.GREEN, newOptionValue, TextColors.WHITE, " on user ", TextColors.GOLD, user.getName(), TextColors.WHITE, "."));
            } else {
                GriefPreventionPlugin.sendMessage(src, Text.of(TextColors.RED, "The permission plugin failed to set the option."));
            }
        });

    return CommandResult.success();
}
 
Example #28
Source File: NodeBuilder.java    From ChatUI with MIT License 4 votes vote down vote up
private Text getKeyText() {
    return Text.builder(this.key == null ? "[Enter in chat]" : this.key)
            .color(this.key == null ? TextColors.RED : TextColors.GREEN)
            .style(this.key == null ? TextStyles.BOLD : TextStyles.RESET)
            .build();
}
 
Example #29
Source File: NodeBuilder.java    From ChatUI with MIT License 4 votes vote down vote up
@Override
public Text draw(PlayerContext ctx) {
    Text.Builder builder = Text.builder();
    int rem = ctx.height;
    builder.append(Text.of(TextStyles.BOLD, "Create new node"), Text.NEW_LINE);
    builder.append(Text.of("Path: ", TextColors.GREEN, Joiner.on('.').join(this.tab.control.getNode().getPath())), Text.NEW_LINE);
    if (keyRequired()) {
        builder.append(Text.of("Key: ", getKeyText()), Text.NEW_LINE);
        rem -= 1;
    }
    builder.append(Text.of("Value Type: ",
            this.valueTypeName == null ? TextColors.RED : TextColors.GREEN,
            this.valueTypeName == null ? "" : this.valueTypeName), Text.NEW_LINE);
    rem -= 3;
    if (this.valueTypeName == null) {
        rem -= addValueTypes(builder);
    }
    if (!hasKey() || this.valueTypeName == null) {
        builder.append(Text.of("Value: ", TextColors.RED,
                !hasKey() ? "[Waiting for key]" : this.valueTypeName == null ? "[Waiting for value type]" : this.value));
    } else {
        builder.append(Text.of("Value: ", TextColors.GREEN, this.value.toString(), TextColors.WHITE,
                this.valueType != null ? " [Type in chat to change]" : ""));
    }
    for (int i = 0; i < rem - 1; i++) {
        builder.append(Text.NEW_LINE);
    }
    builder.append(Text.builder("[Cancel]").color(TextColors.RED).onClick(onClick(() -> {
        this.tab.nodeBuilder = null;
    })).build());

    if (hasKey() && this.value != null) {
        builder.append(Text.builder(" [Add Node]").color(TextColors.GREEN).onClick(onClick(() -> {
            ConfigurationNode newNode = submitValue();
            this.tab.control.onNodeAdded(newNode);
            this.tab.control.refresh();
            this.tab.nodeBuilder = null;
        })).build());
    }
    return builder.build();
}
 
Example #30
Source File: TextSplitter.java    From ChatUI with MIT License 4 votes vote down vote up
private Format() {
    this.format = TextFormat.of(TextColors.RESET, TextStyles.RESET);
    this.onClick = null;
    this.onHover = null;
    this.onShiftClick = null;
}