Search in sources :

Example 96 with LiteralText

use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.

the class NotificationsCommand method showNotifications.

public static int showNotifications(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    List<Text> notifs = PlayerUtils.getUnreadPingsFor(src.getPlayer());
    if (!notifs.isEmpty()) {
        MutableText response = new LiteralText("You have " + notifs.size() + " unread message" + (notifs.size() != 1 ? "s" : "") + ":").formatted(Formatting.GREEN);
        for (Text notif : notifs) {
            response.append(new LiteralText("\n- ").formatted(Formatting.WHITE).append(notif));
        }
        src.sendFeedback(response, false);
        notifs.clear();
        return 1;
    } else {
        src.sendFeedback(new LiteralText("You have no unread messages.").formatted(Formatting.GREEN), false);
        return 0;
    }
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 97 with LiteralText

use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.

the class GroupCommand method removePlayerGroup.

private static int removePlayerGroup(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    String group = StringArgumentType.getString(ctx, "groupname");
    ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
    List<String> groups = PlayerUtils.getPingGroupsOf(player);
    if (!GROUPNAME_PATTERN.asPredicate().test(group))
        throw INVALID_GROUPNAME.create();
    if (groups.stream().noneMatch(x -> x.equalsIgnoreCase(group)))
        throw NOT_IN_GROUP_OTHER.create(player);
    groups.removeIf(x -> x.equalsIgnoreCase(group));
    if (!NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), group, false))
        ServerNetworkLogic.removePossibleName(src.getMinecraftServer().getPlayerManager(), group);
    src.sendFeedback(new LiteralText("Removed player ").formatted(Formatting.RED).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).append(" from group ").append(new LiteralText(group).formatted(Formatting.YELLOW)).append(new LiteralText(".")), true);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 98 with LiteralText

use of net.minecraft.text.LiteralText in project pingspam by BasiqueEvangelist.

the class PingIgnoreCommand method listIgnoredPlayers.

private static int listIgnoredPlayers(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    ServerPlayerEntity player = src.getPlayer();
    List<UUID> ignoredPlayers = PlayerUtils.getIgnoredPlayersOf(player);
    if (ignoredPlayers.isEmpty()) {
        src.sendFeedback(new LiteralText("You are not ignoring any players.").formatted(Formatting.GREEN), false);
        return 0;
    }
    StringBuilder contentBuilder = new StringBuilder();
    int count = 0;
    for (UUID ignoredPlayerUuid : ignoredPlayers) {
        contentBuilder.append("\n - ").append(OfflineNameCache.INSTANCE.getNameFromUUID(ignoredPlayerUuid));
        count++;
    }
    src.sendFeedback(new LiteralText("You are ignoring " + count + " player(s):").formatted(Formatting.GREEN).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.AQUA)), false);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) UUID(java.util.UUID) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 99 with LiteralText

use of net.minecraft.text.LiteralText in project quilt-standard-libraries by QuiltMC.

the class ChannelScreen method init.

@Override
protected void init() {
    this.s2cButton = this.addDrawableChild(new ButtonWidget(this.width / 2 - 55, 5, 50, 20, new LiteralText("S2C"), this::toS2C, (button, matrices, mouseX, mouseY) -> {
        this.renderTooltip(matrices, new LiteralText("Packets this client can receive"), mouseX, mouseY);
    }));
    this.c2sButton = this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, 5, 50, 20, new LiteralText("C2S"), this::toC2S, (button, matrices, mouseX, mouseY) -> {
        this.renderTooltip(matrices, new LiteralText("Packets the server can receive"), mouseX, mouseY);
    }));
    this.closeButton = this.addDrawableChild(new ButtonWidget(this.width / 2 - 60, this.height - 25, 120, 20, new LiteralText("Close"), button -> this.onClose()));
    this.channelList = this.addDrawable(new ChannelList(this.client, this.width, this.height - 60, 30, this.height - 30, this.textRenderer.fontHeight + 2));
}
Also used : ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) LiteralText(net.minecraft.text.LiteralText)

Example 100 with LiteralText

use of net.minecraft.text.LiteralText in project quilt-standard-libraries by QuiltMC.

the class NetworkingChannelTest method registerChannel.

private static int registerChannel(CommandContext<ServerCommandSource> context, ServerPlayerEntity executor) throws CommandSyntaxException {
    final Identifier channel = getIdentifier(context, "channel");
    if (ServerPlayNetworking.getReceived(executor).contains(channel)) {
        throw new SimpleCommandExceptionType(new LiteralText(String.format("Cannot register channel %s twice for server player", channel))).create();
    }
    ServerPlayNetworking.registerReceiver(executor.networkHandler, channel, (server, player, handler, buf, sender) -> {
        System.out.printf("Received packet on channel %s%n", channel);
    });
    context.getSource().sendFeedback(new LiteralText(String.format("Registered channel %s for %s", channel, executor.getEntityName())), false);
    return 1;
}
Also used : IdentifierArgumentType.getIdentifier(net.minecraft.command.argument.IdentifierArgumentType.getIdentifier) Identifier(net.minecraft.util.Identifier) SimpleCommandExceptionType(com.mojang.brigadier.exceptions.SimpleCommandExceptionType) LiteralText(net.minecraft.text.LiteralText)

Aggregations

LiteralText (net.minecraft.text.LiteralText)249 Text (net.minecraft.text.Text)63 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)51 ItemStack (net.minecraft.item.ItemStack)37 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)34 TranslatableText (net.minecraft.text.TranslatableText)32 MutableText (net.minecraft.text.MutableText)28 BaseText (net.minecraft.text.BaseText)26 NbtCompound (net.minecraft.nbt.NbtCompound)24 HoverEvent (net.minecraft.text.HoverEvent)24 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)23 Screen (net.minecraft.client.gui.screen.Screen)21 ClickEvent (net.minecraft.text.ClickEvent)20 MatrixStack (net.minecraft.client.util.math.MatrixStack)19 Formatting (net.minecraft.util.Formatting)19 Items (net.minecraft.item.Items)18 Inject (org.spongepowered.asm.mixin.injection.Inject)18 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)17 List (java.util.List)16 Identifier (net.minecraft.util.Identifier)15