Search in sources :

Example 11 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource 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 12 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource 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 13 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource 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 14 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource 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 15 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource 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

ServerCommandSource (net.minecraft.server.command.ServerCommandSource)43 LiteralText (net.minecraft.text.LiteralText)35 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)33 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)14 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)11 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)9 CommandManager.argument (net.minecraft.server.command.CommandManager.argument)9 Extensions (com.kahzerx.kahzerxmod.Extensions)7 GenericExtension (com.kahzerx.kahzerxmod.extensions.GenericExtension)7 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)6 UUID (java.util.UUID)6 CommandManager (net.minecraft.server.command.CommandManager)6 ExtensionSettings (com.kahzerx.kahzerxmod.extensions.ExtensionSettings)5 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)5 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 ExtensionManager (com.kahzerx.kahzerxmod.ExtensionManager)4 GameProfile (com.mojang.authlib.GameProfile)4 ClickEvent (net.minecraft.text.ClickEvent)4 MutableText (net.minecraft.text.MutableText)4