Search in sources :

Example 26 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.

the class GroupCommand method listPlayerGroups.

private static int listPlayerGroups(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
    List<String> groups = PlayerUtils.getPingGroupsOf(player);
    StringBuilder headerBuilder = new StringBuilder();
    StringBuilder contentBuilder = new StringBuilder();
    headerBuilder.append(" is in ");
    headerBuilder.append(groups.size());
    headerBuilder.append(" ping group");
    if (groups.size() != 1)
        headerBuilder.append("s");
    if (groups.size() > 0) {
        headerBuilder.append(": ");
        boolean isFirst = true;
        for (String group : groups) {
            if (!isFirst)
                contentBuilder.append(", ");
            isFirst = false;
            contentBuilder.append(group);
        }
    } else {
        headerBuilder.append('.');
    }
    src.sendFeedback(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA).append(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)

Example 27 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.

the class GroupCommand method addPlayerGroup.

private static int addPlayerGroup(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    String newGroup = StringArgumentType.getString(ctx, "groupname");
    ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
    List<String> groups = PlayerUtils.getPingGroupsOf(player);
    if (!GROUPNAME_PATTERN.asPredicate().test(newGroup))
        throw INVALID_GROUPNAME.create();
    if (groups.stream().anyMatch(x -> x.equalsIgnoreCase(newGroup)))
        throw IN_GROUP_OTHER.create(player);
    if (NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), newGroup, true))
        throw NAME_COLLISION.create();
    groups.add(newGroup);
    ServerNetworkLogic.addPossibleName(src.getMinecraftServer().getPlayerManager(), newGroup);
    src.sendFeedback(new LiteralText("Added player ").formatted(Formatting.GREEN).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).append(" to group ").append(new LiteralText(newGroup).formatted(Formatting.YELLOW).append(".")), true);
    return 0;
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 28 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.

the class GroupCommand method listOwnGroups.

private static int listOwnGroups(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    ServerPlayerEntity player = src.getPlayer();
    List<String> pingGroups = PlayerUtils.getPingGroupsOf(player);
    StringBuilder headerBuilder = new StringBuilder();
    StringBuilder contentBuilder = new StringBuilder();
    headerBuilder.append("You are in ");
    headerBuilder.append(pingGroups.size());
    headerBuilder.append(" ping group");
    if (pingGroups.size() != 1)
        headerBuilder.append("s");
    if (pingGroups.size() > 0) {
        headerBuilder.append(": ");
        boolean isFirst = true;
        for (String pingGroup : pingGroups) {
            if (!isFirst)
                contentBuilder.append(", ");
            isFirst = false;
            contentBuilder.append(pingGroup);
        }
    } 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)

Example 29 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.

the class PingIgnoreCommand method removeIgnoredPlayer.

private static int removeIgnoredPlayer(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    Collection<GameProfile> removedPlayers = GameProfileArgumentType.getProfileArgument(ctx, "player");
    ServerPlayerEntity player = src.getPlayer();
    List<UUID> ignoredPlayers = PlayerUtils.getIgnoredPlayersOf(player);
    StringBuilder playersBuilder = new StringBuilder();
    boolean isFirst = true;
    for (GameProfile removedPlayer : removedPlayers) {
        if (!isFirst)
            playersBuilder.append(", ");
        isFirst = false;
        playersBuilder.append(removedPlayer.getName());
        if (!ignoredPlayers.contains(removedPlayer.getId())) {
            throw PLAYER_NOT_IGNORED.create();
        }
        ignoredPlayers.remove(removedPlayer.getId());
    }
    src.sendFeedback(new LiteralText("You are no longer ignoring ").formatted(Formatting.GREEN).append(new LiteralText(playersBuilder.toString()).formatted(Formatting.AQUA)).append("."), false);
    return 0;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) UUID(java.util.UUID) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 30 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.

the class PingIgnoreCommand method addIgnoredPlayer.

private static int addIgnoredPlayer(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
    ServerCommandSource src = ctx.getSource();
    Collection<GameProfile> playersToIgnore = GameProfileArgumentType.getProfileArgument(ctx, "player");
    ServerPlayerEntity player = src.getPlayer();
    List<UUID> ignoredPlayers = PlayerUtils.getIgnoredPlayersOf(player);
    StringBuilder playersBuilder = new StringBuilder();
    boolean isFirst = true;
    for (GameProfile playerToIgnore : playersToIgnore) {
        if (!isFirst)
            playersBuilder.append(", ");
        isFirst = false;
        playersBuilder.append(playerToIgnore.getName());
        if (ignoredPlayers.contains(playerToIgnore.getId())) {
            throw PLAYER_ALREADY_IGNORED.create();
        }
        ignoredPlayers.add(playerToIgnore.getId());
    }
    src.sendFeedback(new LiteralText("You are now ignoring ").formatted(Formatting.RED).append(new LiteralText(playersBuilder.toString()).formatted(Formatting.AQUA)).append(new LiteralText(".")), false);
    return 0;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) UUID(java.util.UUID) 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