net.kyori.text.TextComponent Java Examples

The following examples show how to use net.kyori.text.TextComponent. 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: CommandClaimInfo.java    From GriefDefender with MIT License 7 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 #2
Source File: PrettyPaginatedResult.java    From PGM with 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 #3
Source File: ListCommand.java    From PGM with 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 #4
Source File: Carried.java    From PGM with 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 #5
Source File: Core.java    From PGM with 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 #6
Source File: SignUtil.java    From GriefDefender with 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 #7
Source File: EconomyUtil.java    From GriefDefender with 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 #8
Source File: SignUtil.java    From GriefDefender with 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 #9
Source File: GriefDefenderPlugin.java    From GriefDefender with 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 #10
Source File: CommandRestoreNature.java    From GriefDefender with 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 #11
Source File: GDClaimManager.java    From GriefDefender with 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 #12
Source File: ClaimOptionBase.java    From GriefDefender with 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 #13
Source File: ChatDispatcher.java    From PGM with 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 #14
Source File: FreeForAllCommand.java    From PGM with 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 #15
Source File: ComponentConfigSerializer.java    From GriefDefender with 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 #16
Source File: FreeForAllMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Component getReason() {
  if (players == 1) {
    return TranslatableComponent.of(
        "join.wait.singular", TextComponent.of(String.valueOf(players), TextColor.AQUA));
  } else {
    return TranslatableComponent.of(
        "join.wait.plural", TextComponent.of(String.valueOf(players), TextColor.AQUA));
  }
}
 
Example #17
Source File: ChatCaptureUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public Component createRecordChatComponent(Player player, GDClaim claim, GDPlayerData playerData, String command, Component returnComponent) {
    final Component chatSettings = TextComponent.builder()
                .append(TextComponent.builder()
                        .append(whiteOpenBracket)
                        .append("RECORD-CHAT").color(TextColor.GOLD).append(whiteCloseBracket)
                        .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createChatSettingsConsumer(player, claim, command, returnComponent))))
                        .hoverEvent(HoverEvent.showText(TextComponent.of("Click here to see recorded chat.")))
                        .build())
                .append(TextComponent.builder()
                        .append(" ")
                        .append(getRecordChatClickableInfoText(player, claim, MessageCache.getInstance().CLAIMINFO_UI_CLICK_TOGGLE, playerData.isRecordingChat() ? TextComponent.of("ON", TextColor.GREEN) : TextComponent.of("OFF", TextColor.RED), command))
                        .build())
                .build();
    return chatSettings;
}
 
Example #18
Source File: VirtualAudience.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
default void sendWarning(Component message) {
  sendMessage(
      TextComponent.of(" \u26a0 ", TextColor.YELLOW)
          .append(message.colorIfAbsent(TextColor.RED)));
  playSound(new Sound("note.bass", 1f, 0.75f));
}
 
Example #19
Source File: Team.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Component getName(NameStyle style) {
  if (componentName == null) {
    this.componentName = TextComponent.of(getNameLegacy(), TextFormatter.convert(getColor()));
  }
  return componentName;
}
 
Example #20
Source File: CommandGDVersion.java    From GriefDefender with MIT License 5 votes vote down vote up
@CommandAlias("gdversion")
@Description("Displays GriefDefender's version information.")
@Subcommand("version")
public void execute(CommandSender src) {

    Component gpVersion = TextComponent.builder("")
            .append(GriefDefenderPlugin.GD_TEXT)
            .append("Running ")
            .append("GriefDefender " + GriefDefenderPlugin.IMPLEMENTATION_VERSION, TextColor.AQUA)
            .build();
    Component bukkitVersion = TextComponent.builder("")
            .append(GriefDefenderPlugin.GD_TEXT)
            .append("Running ")
            .append(Bukkit.getVersion(), TextColor.YELLOW)
            .build();

    String permissionPlugin = Bukkit.getPluginManager().getPlugin("LuckPerms").getDescription().getFullName();
    Component permVersion = TextComponent.builder("")
            .append(GriefDefenderPlugin.GD_TEXT)
            .append("Running ")
            .append(permissionPlugin, TextColor.GREEN)
            .build();
    TextAdapter.sendComponent(src, TextComponent.builder("")
            .append(gpVersion)
            .append("\n")
            .append(bukkitVersion)
            .append("\n")
            .append(permVersion)
            .build());
}
 
Example #21
Source File: MapCommand.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private @Nullable Component formatContribution(Contributor contributor) {
  Component componentName = contributor.getName(NameStyle.FANCY);
  if (contributor.getContribution() == null) return componentName;
  return TextComponent.builder()
      .append(componentName)
      .append(" - ", TextColor.GRAY)
      .append(contributor.getContribution(), TextColor.GRAY, TextDecoration.ITALIC)
      .build();
}
 
Example #22
Source File: BanCategory.java    From GriefDefender with MIT License 5 votes vote down vote up
public void addItemBan(String id, Component reason) {
    if (id == null) {
        return;
    }
    if (reason == null) {
        reason = TextComponent.empty();
    }
    if (!id.contains(":")) {
        id = "minecraft:" + id;
    }
    this.items.put(id, reason);
}
 
Example #23
Source File: CommandHelper.java    From GriefDefender with MIT License 5 votes vote down vote up
public static Component getClickableText(CommandSender src, GDClaim claim, Subject subject, Set<Context> contexts, Flag flag, Tristate flagValue, MenuType type) {
    TextComponent.Builder textBuilder = TextComponent.builder(flagValue.toString().toLowerCase())
            .hoverEvent(HoverEvent.showText(TextComponent.builder("")
                    .append(MessageStorage.MESSAGE_DATA.getMessage(MessageStorage.CLAIMLIST_UI_CLICK_TOGGLE_VALUE,
                            ImmutableMap.of("type", type.name().toLowerCase())))
                    .append("\n")
                    .append(UIHelper.getPermissionMenuTypeHoverText(type)).build()))
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(createFlagConsumer(src, claim, subject, contexts, flag, flagValue, type))));
    return textBuilder.build();
}
 
Example #24
Source File: MapPoll.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private Component getMapChatComponent(MatchPlayer viewer, MapInfo map, boolean winner) {
  boolean voted = votes.get(map).contains(viewer.getId());

  return TextComponent.builder()
      .append("[")
      .append(voted ? SYMBOL_VOTED : SYMBOL_IGNORE, voted ? TextColor.GREEN : TextColor.DARK_RED)
      .append(
          TextComponent.of(" ").decoration(TextDecoration.BOLD, !voted)) // Fix 1px symbol diff
      .append("" + countVotes(votes.get(map)), TextColor.YELLOW)
      .append("] ")
      .append(
          map.getStyledName(
              winner ? MapNameStyle.HIGHLIGHT_WITH_AUTHORS : MapNameStyle.COLOR_WITH_AUTHORS))
      .build();
}
 
Example #25
Source File: CommandClaimFarewell.java    From GriefDefender with MIT License 5 votes vote down vote up
@CommandAlias("claimfarewell")
@Description("Sets the farewell message of your claim.")
@Syntax("<message>|clear")
@Subcommand("claim farewell")
public void execute(Player player, String message) {
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    if (claim.allowEdit(player) != null) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().PERMISSION_EDIT_CLAIM);
        return;
    }

    TextComponent farewell = LegacyComponentSerializer.legacy().deserialize(message, '&');
    if (farewell == TextComponent.empty() || farewell.content().equals("clear")) {
        claim.getInternalClaimData().setFarewell(null);
    } else {
        claim.getInternalClaimData().setFarewell(farewell);
    }
    claim.getInternalClaimData().setRequiresSave(true);
    claim.getInternalClaimData().save();
    Component resultMessage = null;
    if (!claim.getInternalClaimData().getFarewell().isPresent()) {
        resultMessage = MessageCache.getInstance().CLAIM_FAREWELL_CLEAR;
    } else {
        resultMessage = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_FAREWELL,
                ImmutableMap.of(
                "farewell", farewell));
    }
    TextAdapter.sendComponent(player, resultMessage);
}
 
Example #26
Source File: CommandHelper.java    From GriefDefender with MIT License 5 votes vote down vote up
public static Consumer<CommandSender> createFlagConsumer(CommandSender src, GDClaim claim, Subject subject, Set<Context> contexts, Flag flag, Tristate flagValue, MenuType flagType) {
    return consumer -> {
        Tristate newValue = Tristate.UNDEFINED;
        if (flagValue == Tristate.TRUE) {
            newValue = Tristate.FALSE;
        } else if (flagValue == Tristate.UNDEFINED) {
            newValue = Tristate.TRUE;
        }

        Component flagTypeText = TextComponent.empty();
        if (flagType == MenuType.OVERRIDE) {
            flagTypeText = TextComponent.of("OVERRIDE", TextColor.RED);
        } else if (flagType == MenuType.DEFAULT) {
            flagTypeText = TextComponent.of("DEFAULT", TextColor.LIGHT_PURPLE);
        } else if (flagType == MenuType.CLAIM) {
            flagTypeText = TextComponent.of("CLAIM", TextColor.GOLD);
        }

        Set<Context> newContexts = new HashSet<>(contexts);
        PermissionUtil.getInstance().setPermissionValue(GriefDefenderPlugin.DEFAULT_HOLDER, flag, newValue, newContexts);
        TextAdapter.sendComponent(src, TextComponent.builder("")
                .append("Set ", TextColor.GREEN)
                .append(flagTypeText)
                .append(" permission ")
                .append(flag.getName().toLowerCase(), TextColor.AQUA)
                .append("\n to ", TextColor.GREEN)
                .append(getClickableText(src, (GDClaim) claim, subject, newContexts, flag, newValue, flagType).color(TextColor.LIGHT_PURPLE))
                .append(" for ", TextColor.GREEN)
                .append(subject.getFriendlyName(), TextColor.GOLD).build());
    };
}
 
Example #27
Source File: GDFlag.java    From GriefDefender with 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 #28
Source File: CommandClaimName.java    From GriefDefender with MIT License 5 votes vote down vote up
@CommandAlias("claimname")
@Syntax("<name>|clear")
@Description("Sets the name of your claim.")
@Subcommand("claim name")
public void execute(Player player, String name) {
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    final Component result = claim.allowEdit(player);
    if (result != null) {
        GriefDefenderPlugin.sendMessage(player, result);
        return;
    }

    if (!player.hasPermission(GDPermissions.USE_RESERVED_CLAIM_NAMES)) {
        final GriefDefenderConfig<?> activeConfig = GriefDefenderPlugin.getActiveConfig(player.getWorld().getUID());
        for (String str : activeConfig.getConfig().claim.reservedClaimNames) {
            if (FilenameUtils.wildcardMatch(name, str)) {
                GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().CLAIM_RESERVED_NAME);
                return;
            }
        }
    }

    final TextComponent text = LegacyComponentSerializer.legacy().deserialize(name, '&');
    if (text == TextComponent.empty() || text.content().equals("clear")) {
        claim.getInternalClaimData().setName(null);
    } else {
        claim.getInternalClaimData().setName(text);
    }
    claim.getInternalClaimData().setRequiresSave(true);
    claim.getInternalClaimData().save();
    final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_NAME,
            ImmutableMap.of(
            "name", text));
    GriefDefenderPlugin.sendMessage(player, message);
}
 
Example #29
Source File: ClaimOptionBase.java    From GriefDefender with MIT License 5 votes vote down vote up
private void appendContexts(TextComponent.Builder builder, Set<Context> contexts) {
    // check source/target
    Component source = null;
    Component target = null;
    final Component whiteOpenBracket = TextComponent.of("[", TextColor.WHITE);
    final Component whiteCloseBracket = TextComponent.of("]", TextColor.WHITE);
    for (Context context : contexts) {
        if (context.getKey().equals(ContextKeys.SOURCE)) {
            source = TextComponent.builder()
                        .append(whiteOpenBracket)
                        .append("s", TextColor.GREEN)
                        .append("=", TextColor.WHITE)
                        .append(context.getValue().replace("minecraft:", ""), TextColor.GOLD)
                        .append(whiteCloseBracket)
                        .hoverEvent(HoverEvent.showText(MessageCache.getInstance().LABEL_SOURCE))
                        .build();
            builder.append(" ").append(source);
        } else if (context.getKey().equals(ContextKeys.TARGET)) {
            target = TextComponent.builder()
                    .append(whiteOpenBracket)
                    .append("t", TextColor.GREEN)
                    .append("=", TextColor.WHITE)
                    .append(context.getValue().replace("minecraft:", ""), TextColor.GOLD)
                    .append(whiteCloseBracket)
                    .hoverEvent(HoverEvent.showText(MessageCache.getInstance().LABEL_TARGET))
                    .build();
            builder.append(" ").append(target);
        }
    }
}
 
Example #30
Source File: CommandHelper.java    From GriefDefender with MIT License 5 votes vote down vote up
public static Consumer<CommandSource> createReturnClaimListConsumer(CommandSource src, String arguments) {
    return consumer -> {
        Component claimListReturnCommand = TextComponent.builder("")
                .append("\n[")
                .append(MessageCache.getInstance().CLAIMLIST_UI_RETURN_CLAIMSLIST.color(TextColor.AQUA))
                .append("]\n", TextColor.WHITE)
            .clickEvent(ClickEvent.runCommand(GDCallbackHolder.getInstance().createCallbackRunCommand(CommandHelper.createCommandConsumer(src, "/claimslist", arguments)))).build();
        TextAdapter.sendComponent(src, claimListReturnCommand);
    };
}