Search in sources :

Example 91 with LiteralText

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

the class AliasCommand method removeAlias.

private static int removeAlias(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    String alias = StringArgumentType.getString(ctx, "alias");
    ServerPlayerEntity player = src.getPlayer();
    List<String> aliases = PlayerUtils.getAliasesOf(player);
    if (!ALIAS_PATTERN.asPredicate().test(alias))
        throw INVALID_ALIAS.create();
    if (aliases.stream().noneMatch(x -> x.equalsIgnoreCase(alias)))
        throw NO_SUCH_ALIAS.create();
    aliases.removeIf(x -> x.equalsIgnoreCase(alias));
    if (!NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), alias, false))
        ServerNetworkLogic.removePossibleName(src.getMinecraftServer().getPlayerManager(), alias);
    src.sendFeedback(new LiteralText("Removed alias ").formatted(Formatting.RED).append(new LiteralText('"' + alias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(".")), false);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 92 with LiteralText

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

the class AliasCommand method removePlayerAlias.

private static int removePlayerAlias(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    String alias = StringArgumentType.getString(ctx, "alias");
    ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
    List<String> aliases = PlayerUtils.getAliasesOf(player);
    if (!ALIAS_PATTERN.asPredicate().test(alias))
        throw INVALID_ALIAS.create();
    if (aliases.stream().noneMatch(x -> x.equalsIgnoreCase(alias)))
        throw NO_SUCH_ALIAS_OTHER.create(player);
    aliases.removeIf(x -> x.equalsIgnoreCase(alias));
    if (!NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), alias, false))
        ServerNetworkLogic.removePossibleName(src.getMinecraftServer().getPlayerManager(), alias);
    src.sendFeedback(new LiteralText("Removed alias ").formatted(Formatting.RED).append(new LiteralText('"' + alias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(" from ")).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).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 93 with LiteralText

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

the class AliasCommand method addAliases.

private static int addAliases(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    String newAlias = StringArgumentType.getString(ctx, "alias");
    ServerPlayerEntity player = src.getPlayer();
    List<String> aliases = PlayerUtils.getAliasesOf(player);
    if (!ALIAS_PATTERN.asPredicate().test(newAlias))
        throw INVALID_ALIAS.create();
    if (aliases.stream().anyMatch(x -> x.equalsIgnoreCase(newAlias)))
        throw ALIAS_EXISTS.create();
    if (NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), newAlias, false))
        throw ALIAS_COLLISION.create();
    if (aliases.size() >= ALIAS_LIMIT && !Permissions.check(src, "pingspam.bypass.aliaslimit", 2))
        throw TOO_MANY_ALIASES.create();
    aliases.add(newAlias);
    ServerNetworkLogic.addPossibleName(src.getMinecraftServer().getPlayerManager(), newAlias);
    src.sendFeedback(new LiteralText("Added alias ").formatted(Formatting.GREEN).append(new LiteralText('"' + newAlias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(".")), false);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 94 with LiteralText

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

the class AliasCommand method addPlayerAlias.

private static int addPlayerAlias(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    String newAlias = StringArgumentType.getString(ctx, "alias");
    ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
    List<String> aliases = PlayerUtils.getAliasesOf(player);
    if (!ALIAS_PATTERN.asPredicate().test(newAlias))
        throw INVALID_ALIAS.create();
    if (aliases.stream().anyMatch(x -> x.equalsIgnoreCase(newAlias)))
        throw ALIAS_EXISTS_OTHER.create(player);
    if (NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), newAlias, false))
        throw ALIAS_COLLISION.create();
    if (aliases.size() >= ALIAS_LIMIT && !Permissions.check(src, "pingspam.bypass.aliaslimit", 2))
        throw TOO_MANY_ALIASES.create();
    aliases.add(newAlias);
    ServerNetworkLogic.addPossibleName(src.getMinecraftServer().getPlayerManager(), newAlias);
    src.sendFeedback(new LiteralText("Added alias ").formatted(Formatting.GREEN).append(new LiteralText('"' + newAlias + '"').formatted(Formatting.YELLOW)).append(new LiteralText(" to ")).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).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 95 with LiteralText

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

the class AliasCommand method listAliases.

private static int listAliases(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    ServerPlayerEntity player = src.getPlayer();
    List<String> aliases = PlayerUtils.getAliasesOf(player);
    StringBuilder headerBuilder = new StringBuilder();
    StringBuilder contentBuilder = new StringBuilder();
    headerBuilder.append("You have ");
    headerBuilder.append(aliases.size());
    headerBuilder.append(" alias");
    if (aliases.size() != 1)
        headerBuilder.append("es");
    if (aliases.size() > 0) {
        headerBuilder.append(": ");
        boolean isFirst = true;
        for (String alias : aliases) {
            if (!isFirst)
                contentBuilder.append(", ");
            isFirst = false;
            contentBuilder.append(alias);
        }
    } else {
        headerBuilder.append('.');
    }
    src.sendFeedback(new LiteralText(headerBuilder.toString()).formatted(Formatting.GREEN).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.YELLOW)), false);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Aggregations

LiteralText (net.minecraft.text.LiteralText)430 Text (net.minecraft.text.Text)102 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)78 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)68 TranslatableText (net.minecraft.text.TranslatableText)65 Screen (net.minecraft.client.gui.screen.Screen)61 MatrixStack (net.minecraft.client.util.math.MatrixStack)56 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)50 ItemStack (net.minecraft.item.ItemStack)49 MutableText (net.minecraft.text.MutableText)45 MinecraftClient (net.minecraft.client.MinecraftClient)37 Formatting (net.minecraft.util.Formatting)37 Inject (org.spongepowered.asm.mixin.injection.Inject)34 List (java.util.List)33 TextFieldWidget (net.minecraft.client.gui.widget.TextFieldWidget)33 ArrayList (java.util.ArrayList)32 NbtCompound (net.minecraft.nbt.NbtCompound)32 HoverEvent (net.minecraft.text.HoverEvent)29 Identifier (net.minecraft.util.Identifier)27 TextRenderer (net.minecraft.client.font.TextRenderer)26