Search in sources :

Example 16 with ServerCommandSource

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

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

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

use of net.minecraft.server.command.ServerCommandSource in project mclogs-fabric by aternosorg.

the class CommandMclogsList method register.

static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    dispatcher.register(literal("mclogs").then(literal("list").requires(source -> source.hasPermissionLevel(2)).executes((context) -> {
        ServerCommandSource source = context.getSource();
        try {
            String[] logs = MclogsFabricLoader.getLogs(context);
            if (logs.length == 0) {
                source.sendFeedback(new LiteralText("No logs available!"), false);
                return 0;
            }
            LiteralText feedback = new LiteralText("Available Logs:");
            for (String log : logs) {
                Style s = Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mclogs share " + log));
                LiteralText tempText = new LiteralText("\n" + log);
                tempText.setStyle(s);
                feedback.append(tempText);
            }
            source.sendFeedback(feedback, false);
            return logs.length;
        } catch (Exception e) {
            MclogsFabricLoader.logger.error("An error occurred when listing your logs.");
            MclogsFabricLoader.logger.error(e);
            LiteralText error = new LiteralText("An error occurred. Check your log for more details.");
            source.sendError(error);
            return -1;
        }
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Style(net.minecraft.text.Style) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ClickEvent(net.minecraft.text.ClickEvent) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) ClickEvent(net.minecraft.text.ClickEvent) Style(net.minecraft.text.Style) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 20 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project LuckPerms by lucko.

the class FabricCommandExecutor method register.

public void register() {
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
        for (String alias : COMMAND_ALIASES) {
            LiteralCommandNode<ServerCommandSource> cmd = literal(alias).executes(this).build();
            ArgumentCommandNode<ServerCommandSource, String> args = argument("args", greedyString()).suggests(this).executes(this).build();
            cmd.addChild(args);
            dispatcher.getRoot().addChild(cmd);
        }
    });
}
Also used : StringArgumentType.greedyString(com.mojang.brigadier.arguments.StringArgumentType.greedyString) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

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