Java Code Examples for net.kyori.text.TextComponent

The following examples show how to use net.kyori.text.TextComponent. These examples are extracted from open source projects. 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 Project: PGM   Author: PGMDev   File: PrettyPaginatedResult.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Displays a list of items based on the page to an audience
 *
 * @param audience to display data to
 * @param data to display
 * @param page where the data is located
 * @throws CommandException no match exceptions
 */
public void display(Audience audience, List<? extends T> data, int page) throws CommandException {
  if (data.size() == 0) {
    audience.sendMessage(TextComponent.of(formatEmpty()));
    return;
  }

  int maxPages = data.size() / this.resultsPerPage + 1;

  if (data.size() % this.resultsPerPage == 0) {
    maxPages--;
  }

  if (page <= 0 || page > maxPages)
    throw new CommandException("Unknown page selected! " + maxPages + " total pages.");

  StringBuilder message = new StringBuilder(header + "\n");
  for (int i = resultsPerPage * (page - 1);
      i < this.resultsPerPage * page && i < data.size();
      i++) {
    message.append(format(data.get(i), i));
    if (i != (data.size() - 1)) message.append("\n");
  }
  audience.sendMessage(TextComponent.of(message.toString()));
}
 
Example #2
Source Project: GriefDefender   Author: bloodmc   File: SignUtil.java    License: MIT License 6 votes vote down vote up
public static List<Text> createSellSignLines(double price) {
    List<Text> colorLines = new ArrayList<>(4);
    final DecimalFormat format = new DecimalFormat("0.#");
    final TextComponent headerComponent = TextComponent.builder()
                .append("[", TextColor.GRAY)
                .append("GD", TextColor.AQUA)
                .append("-", TextColor.GRAY)
                .append("sell", TextColor.DARK_BLUE)
                .append("]", TextColor.GRAY)
                .build();

    colorLines.add(SpongeUtil.getSpongeText(headerComponent));
    colorLines.add(SpongeUtil.getSpongeText(MessageCache.getInstance().ECONOMY_SIGN_SELL_DESCRIPTION));
    colorLines.add(SpongeUtil.getSpongeText(TextComponent.builder().append("$" + format.format(price), TextColor.RED).build()));
    colorLines.add(SpongeUtil.getSpongeText(MessageCache.getInstance().ECONOMY_SIGN_SELL_FOOTER));
    return colorLines;
}
 
Example #3
Source Project: PGM   Author: PGMDev   File: Core.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Component getTouchMessage(@Nullable ParticipantState toucher, boolean self) {
  // Core has same touch messages as Destroyable
  if (toucher == null) {
    return TranslatableComponent.of(
        "destroyable.touch.owned",
        TextComponent.empty(),
        getComponentName(),
        getOwner().getName());
  } else if (self) {
    return TranslatableComponent.of(
        "destroyable.touch.owned.you",
        TextComponent.empty(),
        getComponentName(),
        getOwner().getName());
  } else {
    return TranslatableComponent.of(
        "destroyable.touch.owned.player",
        toucher.getName(NameStyle.COLOR),
        getComponentName(),
        getOwner().getName());
  }
}
 
Example #4
Source Project: GriefDefender   Author: bloodmc   File: GDClaimManager.java    License: MIT License 6 votes vote down vote up
@Override
public List<Claim> getClaimsByName(String name) {
    List<Claim> claimList = new ArrayList<>();
    for (Claim worldClaim : this.getWorldClaims()) {
        Component claimName = worldClaim.getName().orElse(null);
        if (claimName != null && claimName != TextComponent.empty()) {
            if (PlainComponentSerializer.INSTANCE.serialize(claimName).equalsIgnoreCase(name)) {
                claimList.add(worldClaim);
            }
        }
        // check children
        for (Claim child : ((GDClaim) worldClaim).getChildren(true)) {
            if (child.getUniqueId().toString().equals(name)) {
                claimList.add(child);
            }
        }
    }
    return claimList;
}
 
Example #5
Source Project: GriefDefender   Author: bloodmc   File: ComponentConfigSerializer.java    License: MIT License 6 votes vote down vote up
@Override
public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException {
    if (node.getString() == null || node.getString().isEmpty()) {
        return TextComponent.empty();
    }
    if (node.getString().contains("text=")) {
        // Try sponge data
        StringWriter writer = new StringWriter();

        GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder()
                .setIndent(0)
                .setSink(() -> new BufferedWriter(writer))
                .setHeaderMode(HeaderMode.NONE)
                .build();

        try {
            gsonLoader.save(node);
        } catch (IOException e) {
            throw new ObjectMappingException(e);
        }
        return GsonComponentSerializer.INSTANCE.deserialize(writer.toString());
    }

    return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&');
}
 
Example #6
Source Project: GriefDefender   Author: bloodmc   File: EconomyUtil.java    License: MIT License 6 votes vote down vote up
public void sellCancelConfirmation(CommandSender src, Claim claim, Sign sign) {
    final Player player = (Player) src;
    final GDClaim gdClaim = (GDClaim) claim;
    // check sell access
    if (gdClaim.allowEdit(player) != null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().CLAIM_NOT_YOURS);
        return;
    }

    final Component sellCancelConfirmationText = TextComponent.builder()
            .append("\n[")
            .append(MessageCache.getInstance().LABEL_CONFIRM.color(TextColor.GREEN))
            .append("]\n")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(src, createSellCancelConfirmed(src, claim, sign), true)))
            .build();
    final Component message = TextComponent.builder()
            .append(MessageCache.getInstance().ECONOMY_CLAIM_SALE_CANCEL_CONFIRMATION)
            .append("\n")
            .append(sellCancelConfirmationText)
            .build();
    GriefDefenderPlugin.sendMessage(src, message);
}
 
Example #7
Source Project: PGM   Author: PGMDev   File: ChatDispatcher.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public static void broadcastAdminChatMessage(
    Component message, Match match, Optional<Sound> sound) {
  TextComponent formatted = ADMIN_CHAT_PREFIX.append(message);
  match.getPlayers().stream()
      .filter(AC_FILTER)
      .forEach(
          mp -> {
            // If provided a sound, play if setting allows
            sound.ifPresent(
                s -> {
                  if (canPlaySound(mp)) {
                    mp.playSound(s);
                  }
                });
            mp.sendMessage(formatted);
          });
  Audience.get(Bukkit.getConsoleSender()).sendMessage(formatted);
}
 
Example #8
Source Project: PGM   Author: PGMDev   File: FreeForAllCommand.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"min"},
    desc = "Set the min players on a team",
    usage = "<team> (reset | <min-players>)",
    perms = Permissions.RESIZE)
public void min(Audience audience, Match match, String minPlayers) {
  final FreeForAllMatchModule ffa = getFfa(match);
  if (minPlayers.equalsIgnoreCase("reset")) {
    ffa.setMaxPlayers(null, null);
  } else {
    ffa.setMinPlayers(TextParser.parseInteger(minPlayers, Range.atLeast(0)));
  }

  audience.sendMessage(
      TranslatableComponent.of(
          "match.resize.max",
          TranslatableComponent.of("match.info.players", TextColor.YELLOW),
          TextComponent.of(ffa.getMinPlayers(), TextColor.AQUA)));
}
 
Example #9
Source Project: PGM   Author: PGMDev   File: Carried.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void leaveState() {
  SidebarMatchModule smm = this.flag.getMatch().getModule(SidebarMatchModule.class);
  if (smm != null) smm.stopBlinkingGoal(this.flag);

  this.carrier.showHotbar(TextComponent.empty());

  this.carrier.getInventory().remove(this.flag.getBannerItem());
  this.carrier.getInventory().setHelmet(this.helmetItem);

  this.flag
      .getMatch()
      .getModule(KitMatchModule.class)
      .lockArmorSlot(this.carrier, ArmorType.HELMET, this.helmetLocked);

  Kit kit = this.flag.getDefinition().getDropKit();
  if (kit != null) this.carrier.applyKit(kit, false);
  kit = this.flag.getDefinition().getCarryKit();
  if (kit != null) kit.remove(this.carrier);

  super.leaveState();
}
 
Example #10
Source Project: PGM   Author: PGMDev   File: ListCommand.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
private void sendTeamInfo(
    Audience viewer,
    CommandSender sender,
    Component teamName,
    Collection<MatchPlayer> players,
    int max) {
  Component teamLine =
      TextComponent.builder()
          .append(teamName)
          .append(": ", TextColor.GRAY)
          .append(Integer.toString(getSize(players, false)))
          .append(
              max != -1
                  ? TextComponent.of("/" + Integer.toString(max), TextColor.GRAY)
                  : TextComponent.empty())
          .append(
              getSize(players, true) > 0 && sender.hasPermission(Permissions.STAFF)
                  ? formatVanishCount(players)
                  : TextComponent.empty())
          .build();
  viewer.sendMessage(teamLine);
  if (!players.isEmpty()) {
    viewer.sendMessage(formatNames(players, sender));
  }
}
 
Example #11
Source Project: GriefDefender   Author: bloodmc   File: GriefDefenderPlugin.java    License: MIT License 6 votes vote down vote up
public static void sendMessage(CommandSource src, Component message) {
    if (src == null) {
        return;
    }
    if (NMSUtil.getInstance().isFakePlayer(src)) {
        return;
    }
    if (message == TextComponent.empty() || message == null) {
        return;
    }

    if (src == null) {
        GriefDefenderPlugin.getInstance().getLogger().warn(PlainComponentSerializer.INSTANCE.serialize(message));
    } else {
        TextAdapter.sendComponent(src, message);
    }
}
 
Example #12
Source Project: GriefDefender   Author: bloodmc   File: SignUtil.java    License: MIT License 6 votes vote down vote up
public static void setClaimForSale(Claim claim, Player player, Sign sign, double price) {
    if (claim.isWilderness()) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().ECONOMY_CLAIM_NOT_FOR_SALE);
        return;
    }

    // if not owner of claim, validate perms
    if (((GDClaim) claim).allowEdit(player) != null || !player.hasPermission(GDPermissions.COMMAND_CLAIM_INFO_OTHERS)) {
        TextAdapter.sendComponent(player, MessageCache.getInstance().CLAIM_NOT_YOURS);
        return;
    }

    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_CLAIM_SALE_CONFIRMATION,
            ImmutableMap.of(
            "amount", price));
    GriefDefenderPlugin.sendMessage(player, message);

    final Component saleConfirmationText = TextComponent.builder("")
            .append("\n[")
            .append("Confirm", TextColor.GREEN)
            .append("]\n")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createSaleConfirmationConsumer(player, claim, sign, price))))
            .build();
    GriefDefenderPlugin.sendMessage(player, saleConfirmationText);
}
 
Example #13
Source Project: GriefDefender   Author: bloodmc   File: CommandRestoreNature.java    License: MIT License 6 votes vote down vote up
@CommandAlias("modenature")
@Description("Switches the shovel tool to restoration mode.")
@Subcommand("mode nature")
public void execute(Player player) {
    if (true) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().FEATURE_NOT_AVAILABLE);
        return;
    }

    if (!NMSUtil.getInstance().hasItemInOneHand(player, GriefDefenderPlugin.getInstance().modificationTool)) {
        TextAdapter.sendComponent(player, GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.TOOL_NOT_EQUIPPED,
                ImmutableMap.of("tool", TextComponent.of(GriefDefenderPlugin.getInstance().modificationTool.getName().toLowerCase(), TextColor.GREEN))));
        return;
    }

    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    playerData.shovelMode = ShovelTypes.RESTORE;
    GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().MODE_NATURE);
}
 
Example #14
Source Project: GriefDefender   Author: bloodmc   File: ClaimOptionBase.java    License: MIT License 6 votes vote down vote up
private Component getHoverContextComponent(Set<Context> contexts) {
    if (contexts.isEmpty()) {
        return TextComponent.empty();
    }

    TextComponent.Builder builder = TextComponent.builder()
                .append("\n\nContexts: \n");

    for (Context context : contexts) {
        final String key = context.getKey();
        final String value = context.getValue();
        TextColor keyColor = TextColor.AQUA;
        builder.append(key, keyColor)
                .append("=", TextColor.WHITE)
                .append(value.replace("minecraft:", ""), TextColor.GRAY)
                .append("\n");
    }

    return builder.build();
}
 
Example #15
Source Project: GriefDefender   Author: bloodmc   File: CommandClaimInfo.java    License: MIT License 6 votes vote down vote up
public Component getClickableInfoText(CommandSender src, Claim claim, int titleId, Component infoText) {
    Component onClickText = MessageCache.getInstance().CLAIMINFO_UI_CLICK_TOGGLE;
    boolean hasPermission = true;
    if (src instanceof Player) {
        Component denyReason = ((GDClaim) claim).allowEdit((Player) src);
        if (denyReason != null) {
            onClickText = denyReason;
            hasPermission = false;
        }
    }

    TextComponent.Builder textBuilder = TextComponent.builder()
            .append(infoText)
            .hoverEvent(HoverEvent.showText(onClickText));
    if (hasPermission) {
        textBuilder.clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createClaimInfoConsumer(src, claim, titleId))));
    }
    return textBuilder.build();
}
 
Example #16
Source Project: Geyser   Author: GeyserMC   File: GeyserVelocityCommandExecutor.java    License: MIT License 5 votes vote down vote up
@Override
public void execute(CommandSource source, String[] args) {
    if (args.length > 0) {
        if (getCommand(args[0]) != null) {
            if (!source.hasPermission(getCommand(args[0]).getPermission())) {
                source.sendMessage(TextComponent.of(ChatColor.RED + "You do not have permission to execute this command!"));
                return;
            }
            getCommand(args[0]).execute(new VelocityCommandSender(source), args);
        }
    } else {
        getCommand("help").execute(new VelocityCommandSender(source), args);
    }
}
 
Example #17
Source Project: GriefDefender   Author: bloodmc   File: GDFlagDefinition.java    License: MIT License 5 votes vote down vote up
@Override
public Builder reset() {
    this.enabled = true;
    this.isAdmin = false;
    this.contexts = new HashSet<>();
    this.data = new ArrayList<>();
    this.displayName = "";
    this.groupName = "";
    this.defaultValue = Tristate.UNDEFINED;
    this.description = TextComponent.empty();
    this.subject = GriefDefenderPlugin.DEFAULT_HOLDER;
    return this;
}
 
Example #18
Source Project: GriefDefender   Author: bloodmc   File: GDFlag.java    License: MIT License 5 votes vote down vote up
private Component createDescription() {
    final Component description = GriefDefenderPlugin.getInstance().messageData.getMessage("flag-description-" + this.name.toLowerCase());
    if (description != null) {
        return description;
    }
    return TextComponent.of("Not defined.");
}
 
Example #19
Source Project: GriefDefender   Author: bloodmc   File: UIHelper.java    License: MIT License 5 votes vote down vote up
public static Component getPermissionMenuTypeHoverText(FlagContextHolder flagHolder, MenuType menuType) {
    if (flagHolder.getType() == MenuType.DEFAULT && menuType == MenuType.CLAIM) {
        return TextComponent.builder()
                .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.FLAG_NOT_SET, 
                        ImmutableMap.of("flag", TextComponent.of(flagHolder.getFlag().getName(), TextColor.GREEN),
                                        "value", TextComponent.of(flagHolder.getValue(), TextColor.LIGHT_PURPLE)))).build();
    }

    return getPermissionMenuTypeHoverText(menuType);
}
 
Example #20
Source Project: GriefDefender   Author: bloodmc   File: GDDebugData.java    License: MIT License 5 votes vote down vote up
public void addRecord(String flag, String trust, String source, String target, String location, String user, String contexts, Tristate result) {
    // markdown uses '__' for strong formatting, so underscores must be escaped
    user = user.replace("_", "\\_");
    if (this.records.size() < MAX_LINES) {
        this.records.add("| " + flag + " | " + trust + " | " + source + " | " + target + " | " + location + " | " + user + " | " + contexts + " | " + result + " | ");
    } else {
        TextAdapter.sendComponent(this.source, TextComponent.builder("").append("MAX DEBUG LIMIT REACHED!").append("\n")
                .append("Pasting output...", TextColor.GREEN).build());
        this.pasteRecords();
        this.records.clear();
        GriefDefenderPlugin.getInstance().getDebugUserMap().clear();
        GriefDefenderPlugin.debugActive = false;
        TextAdapter.sendComponent(this.source, TextComponent.builder("").append(GD_TEXT).append("Debug ", TextColor.GRAY).append("OFF", TextColor.RED).build());
    }
}
 
Example #21
Source Project: PGM   Author: PGMDev   File: Dead.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Component getSubtitle() {
  long ticks = ticksUntilRespawn();
  if (ticks > 0) {
    return TranslatableComponent.of(
        spawnRequested ? "death.respawn.confirmed.time" : "death.respawn.unconfirmed.time",
        TextComponent.of(String.format("%.1f", (ticks / (float) 20)), TextColor.AQUA));
  } else {
    return super.getSubtitle();
  }
}
 
Example #22
Source Project: GriefDefender   Author: bloodmc   File: GDClaim.java    License: MIT License 5 votes vote down vote up
public Component getFriendlyNameType(ClaimType claimType, boolean upper) {
    if (claimType == ClaimTypes.ADMIN) {
        if (upper) {
            return TextComponent.of(claimType.getName().toUpperCase(), TextColor.RED);
        }
        return TextComponent.of("Admin", TextColor.RED);
    }

    if (claimType == ClaimTypes.BASIC) {
        if (upper) {
            return TextComponent.of(claimType.getName().toUpperCase(), TextColor.YELLOW);
        }
        return TextComponent.of("Basic", TextColor.YELLOW);
    }

    if (claimType == ClaimTypes.SUBDIVISION) {
        if (upper) {
            return TextComponent.of(claimType.getName().toUpperCase(), TextColor.AQUA);
        }
        return TextComponent.of("Subdivision", TextColor.AQUA);
    }

    if (upper) {
        return TextComponent.of(claimType.getName().toUpperCase(), TextColor.GREEN);
    }
    return TextComponent.of("Town", TextColor.GREEN);
}
 
Example #23
Source Project: PGM   Author: PGMDev   File: MapCommand.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private Component createTagsComponent(Collection<MapTag> tags) {
  checkNotNull(tags);

  Builder result = TextComponent.builder().append(mapInfoLabel("map.info.tags"));
  MapTag[] mapTags = tags.toArray(new MapTag[0]);
  for (int i = 0; i < mapTags.length; i++) {
    if (i != 0) {
      result.append(TextComponent.space());
    }

    String mapTag = mapTags[i].getId();

    Component tag =
        TextComponent.builder()
            .append("#")
            .append(mapTag)
            .clickEvent(ClickEvent.runCommand("/maps -t " + mapTag))
            .hoverEvent(
                HoverEvent.showText(
                    TranslatableComponent.of(
                        "map.info.mapTag.hover",
                        TextColor.GRAY,
                        TextComponent.of(mapTag, TextColor.GOLD))))
            .build();

    result.append(tag);
  }
  return result.color(TextColor.GOLD).build();
}
 
Example #24
Source Project: PGM   Author: PGMDev   File: MatchAnnouncer.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onMatchEnd(final MatchFinishEvent event) {
  Match match = event.getMatch();

  // broadcast match finish message
  for (MatchPlayer viewer : match.getPlayers()) {
    Component title, subtitle = TextComponent.empty();
    if (event.getWinner() == null) {
      title = TranslatableComponent.of("broadcast.gameOver");
    } else {
      title =
          TranslatableComponent.of(
              event.getWinner().isNamePlural()
                  ? "broadcast.gameOver.teamWinners"
                  : "broadcast.gameOver.teamWinner",
              event.getWinner().getName());

      if (event.getWinner() == viewer.getParty()) {
        // Winner
        viewer.playSound(SOUND_MATCH_WIN);
        if (viewer.getParty() instanceof Team) {
          subtitle = TranslatableComponent.of("broadcast.gameOver.teamWon", TextColor.GREEN);
        }
      } else if (viewer.getParty() instanceof Competitor) {
        // Loser
        viewer.playSound(SOUND_MATCH_LOSE);
        if (viewer.getParty() instanceof Team) {
          subtitle = TranslatableComponent.of("broadcast.gameOver.teamLost", TextColor.RED);
        }
      } else {
        // Observer
        viewer.playSound(SOUND_MATCH_WIN);
      }
    }

    viewer.showTitle(title, subtitle, 0, 40, 40);
    viewer.sendMessage(title);
    if (subtitle != null) viewer.sendMessage(subtitle);
  }
}
 
Example #25
Source Project: GriefDefender   Author: bloodmc   File: BanCategory.java    License: MIT License 5 votes vote down vote up
public void addEntityBan(String id, Component reason) {
    if (id == null) {
        return;
    }
    if (reason == null) {
        reason = TextComponent.empty();
    }
    this.entities.put(id, reason);
}
 
Example #26
Source Project: PGM   Author: PGMDev   File: ModerationCommand.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void sendWarning(MatchPlayer target, String reason) {
  Component titleWord = TranslatableComponent.of("misc.warning", TextColor.DARK_RED);
  Component title =
      TextComponent.builder().append(WARN_SYMBOL).append(titleWord).append(WARN_SYMBOL).build();
  Component subtitle = formatPunishmentReason(reason).color(TextColor.GOLD);

  target.showTitle(title, subtitle, 5, 200, 10);
  target.playSound(WARN_SOUND);
}
 
Example #27
Source Project: GriefDefender   Author: bloodmc   File: GriefDefenderPlugin.java    License: MIT License 5 votes vote down vote up
public static void sendMessage(CommandSender source, Component message) {
    if (message == TextComponent.empty() || message == null) {
        return;
    }

    if (source == null) {
        GriefDefenderPlugin.getInstance().getLogger().warning(PlainComponentSerializer.INSTANCE.serialize(message));
    } else {
        TextAdapter.sendComponent(source, message);
    }
}
 
Example #28
Source Project: PGM   Author: PGMDev   File: Mode.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public Mode(
    final MaterialData material,
    final Duration after,
    final @Nullable String name,
    Duration showBefore) {
  this.material = material;
  this.after = after;
  this.name = name;
  this.componentName =
      TextComponent.of(name != null ? name : getPreformattedMaterialName(), TextColor.RED);
  this.showBefore = showBefore;
}
 
Example #29
Source Project: GriefDefender   Author: bloodmc   File: ChatCaptureUtil.java    License: MIT License 5 votes vote down vote up
public List<Component> generateChatSettings(Player player, GDClaim claim, String command, Component returnComponent) {
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    List<Component> textList = new ArrayList<>();
    Component returnToClaimInfo = null;
    if (command.equals("claiminfo")) {
        returnToClaimInfo = TextComponent.builder()
                .append("[")
                .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.UI_CLICK_RETURN_COMMAND, 
                        ImmutableMap.of("command", command)))
                .append("]")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(CommandHelper.createCommandConsumer(player, command, claim.getUniqueId().toString())))).build();
    } else if (command.equals("trustlist")) {
        returnToClaimInfo = TextComponent.builder()
                .append("[")
                .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.UI_CLICK_RETURN_COMMAND, 
                        ImmutableMap.of("command", command)))
                .append("]")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createTrustListConsumer(player, claim, playerData, TrustTypes.NONE, returnComponent)))).build();
    } else {
        returnToClaimInfo = TextComponent.builder()
                .append("[")
                .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.UI_CLICK_RETURN_COMMAND, 
                        ImmutableMap.of("command", command)))
                .append("]")
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(CommandHelper.createCommandConsumer(player, command, "")))).build();
    }
    textList.add(returnToClaimInfo);
    for (Component chatLine : playerData.chatLines) {
        textList.add(chatLine);
    }

    int fillSize = 20 - (textList.size() + 2);
    for (int i = 0; i < fillSize; i++) {
        textList.add(TextComponent.of(" "));
    }
    return textList;
}
 
Example #30
Source Project: GriefDefender   Author: bloodmc   File: LuckPermsProvider.java    License: MIT License 5 votes vote down vote up
public PermissionResult setPermissionValue(GDPermissionHolder holder, String permission, Tristate value, Set<Context> contexts, boolean check, boolean save) {
    DataMutateResult result = null;
    if (check) {
        // If no server context exists, add global
        this.checkServerContext(contexts);
    }
    ImmutableContextSet set = this.getLPContexts(contexts).immutableCopy();
    final Node node = this.luckPermsApi.getNodeBuilderRegistry().forPermission().permission(permission).value(value.asBoolean()).context(set).build();
    final PermissionHolder permissionHolder = this.getLuckPermsHolder(holder);
    if (permissionHolder == null) {
        return new GDPermissionResult(ResultTypes.FAILURE);
    }

    if (value == Tristate.UNDEFINED) {
        result = permissionHolder.data().remove(node);
    } else {
        result = permissionHolder.data().add(node);
    }

    if (result.wasSuccessful()) {
        if (permissionHolder instanceof Group) {
            // If a group is changed, we invalidate all cache
            PermissionHolderCache.getInstance().invalidateAllPermissionCache();
        } else {
            // We need to invalidate cache outside of LP listener so we can guarantee proper result returns
            PermissionHolderCache.getInstance().getOrCreatePermissionCache(holder).invalidateAll();
        }

        if (save) {
            this.savePermissionHolder(permissionHolder);
        }

        return new GDPermissionResult(ResultTypes.SUCCESS, TextComponent.builder().append(result.name()).build());
    }

    return new GDPermissionResult(ResultTypes.FAILURE, TextComponent.builder().append(result.name()).build());
}