Search in sources :

Example 36 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class DiscordWhitelistExtension method settingsCommand.

@Override
public void settingsCommand(LiteralArgumentBuilder<ServerCommandSource> builder) {
    builder.then(literal("discordRoleID").then(argument("discordRole", LongArgumentType.longArg()).executes(context -> {
        extensionSettings().setDiscordRoleID(LongArgumentType.getLong(context, "discordRoleID"));
        context.getSource().sendFeedback(new LiteralText("[discordRole] > " + extensionSettings().getDiscordRole() + "."), false);
        ExtensionManager.saveSettings();
        return 1;
    })).executes(context -> {
        String help = "Role that gets added to every discord user that !add s.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        context.getSource().sendFeedback(new LiteralText("[discordRole] > " + extensionSettings().getDiscordRole() + "."), false);
        return 1;
    })).then(literal("nPlayers").then(argument("nPlayers", IntegerArgumentType.integer()).executes(context -> {
        extensionSettings().setNPlayers(IntegerArgumentType.getInteger(context, "nPlayers"));
        context.getSource().sendFeedback(new LiteralText("[players] > " + extensionSettings().getNPlayers() + "."), false);
        ExtensionManager.saveSettings();
        return 1;
    })).executes(context -> {
        String help = "Amount of players a discord user can add to the whitelist.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        context.getSource().sendFeedback(new LiteralText("[players] > " + extensionSettings().getNPlayers() + "."), false);
        return 1;
    })).then(literal("whitelistChats").then(literal("add").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
        if (extensionSettings().getWhitelistChats().contains(LongArgumentType.getLong(context, "chatID"))) {
            context.getSource().sendFeedback(new LiteralText("ID already added."), false);
        } else {
            extensionSettings().addWhitelistChatID(LongArgumentType.getLong(context, "chatID"));
            context.getSource().sendFeedback(new LiteralText("ID added."), false);
            ExtensionManager.saveSettings();
        }
        return 1;
    }))).then(literal("remove").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
        if (extensionSettings().getWhitelistChats().contains(LongArgumentType.getLong(context, "chatID"))) {
            extensionSettings().removeWhitelistChatID(LongArgumentType.getLong(context, "chatID"));
            context.getSource().sendFeedback(new LiteralText("ID removed."), false);
            ExtensionManager.saveSettings();
        } else {
            context.getSource().sendFeedback(new LiteralText("This ID doesn't exist."), false);
        }
        return 1;
    }))).then(literal("list").executes(context -> {
        context.getSource().sendFeedback(new LiteralText(extensionSettings().getWhitelistChats().toString()), false);
        return 1;
    })).executes(context -> {
        String help = "ChatIDs where !add, !remove y !list work.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        return 1;
    }));
}
Also used : java.sql(java.sql) LiteralText(net.minecraft.text.LiteralText) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ListCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.ListCommand) DiscordChatUtils(com.kahzerx.kahzerxmod.extensions.discordExtension.utils.DiscordChatUtils) GameProfile(com.mojang.authlib.GameProfile) DiscordListener(com.kahzerx.kahzerxmod.extensions.discordExtension.DiscordListener) TranslatableText(net.minecraft.text.TranslatableText) AddCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.AddCommand) DiscordUtils(com.kahzerx.kahzerxmod.extensions.discordExtension.utils.DiscordUtils) ArrayList(java.util.ArrayList) ExtensionManager(com.kahzerx.kahzerxmod.ExtensionManager) net.minecraft.server(net.minecraft.server) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) RemoveCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.RemoveCommand) GenericExtension(com.kahzerx.kahzerxmod.extensions.GenericExtension) DiscordExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.discordExtension.DiscordExtension) LongArgumentType(com.mojang.brigadier.arguments.LongArgumentType) Extensions(com.kahzerx.kahzerxmod.Extensions) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) UUID(java.util.UUID) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) DiscordCommandsExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.DiscordCommandsExtension) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) ServerQuery(com.kahzerx.kahzerxmod.database.ServerQuery) LiteralText(net.minecraft.text.LiteralText)

Example 37 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class DiscordAdminToolsExtension method settingsCommand.

@Override
public void settingsCommand(LiteralArgumentBuilder<ServerCommandSource> builder) {
    builder.then(literal("adminChats").then(literal("add").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
        if (extensionSettings().getAdminChats().contains(LongArgumentType.getLong(context, "chatID"))) {
            context.getSource().sendFeedback(new LiteralText("ID already added."), false);
        } else {
            extensionSettings().addAdminChatID(LongArgumentType.getLong(context, "chatID"));
            context.getSource().sendFeedback(new LiteralText("ID added."), false);
            ExtensionManager.saveSettings();
        }
        return 1;
    }))).then(literal("remove").then(argument("chatID", LongArgumentType.longArg()).executes(context -> {
        if (extensionSettings().getAdminChats().contains(LongArgumentType.getLong(context, "chatID"))) {
            extensionSettings().removeAdminChatID(LongArgumentType.getLong(context, "chatID"));
            context.getSource().sendFeedback(new LiteralText("ID removed."), false);
            ExtensionManager.saveSettings();
        } else {
            context.getSource().sendFeedback(new LiteralText("This ID doesn't exist."), false);
        }
        return 1;
    }))).then(literal("list").executes(context -> {
        context.getSource().sendFeedback(new LiteralText(extensionSettings().getAdminChats().toString()), false);
        return 1;
    })).executes(context -> {
        String help = "ChatIDs where !ban, !pardon, !exadd and !exremove work.";
        context.getSource().sendFeedback(new LiteralText(help), false);
        return 1;
    }));
}
Also used : ExtensionSettings(com.kahzerx.kahzerxmod.extensions.ExtensionSettings) LiteralText(net.minecraft.text.LiteralText) ExremoveCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.ExremoveCommand) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) DiscordChatUtils(com.kahzerx.kahzerxmod.extensions.discordExtension.utils.DiscordChatUtils) DiscordListener(com.kahzerx.kahzerxmod.extensions.discordExtension.DiscordListener) PardonCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.PardonCommand) DiscordUtils(com.kahzerx.kahzerxmod.extensions.discordExtension.utils.DiscordUtils) ExtensionManager(com.kahzerx.kahzerxmod.ExtensionManager) MinecraftServer(net.minecraft.server.MinecraftServer) MessageAction(net.dv8tion.jda.api.requests.restaction.MessageAction) ExaddCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.ExaddCommand) GenericExtension(com.kahzerx.kahzerxmod.extensions.GenericExtension) DiscordExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.discordExtension.DiscordExtension) LongArgumentType(com.mojang.brigadier.arguments.LongArgumentType) Extensions(com.kahzerx.kahzerxmod.Extensions) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) BanCommand(com.kahzerx.kahzerxmod.extensions.discordExtension.commands.BanCommand) DiscordWhitelistExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.discordWhitelistExtension.DiscordWhitelistExtension) DiscordCommandsExtension(com.kahzerx.kahzerxmod.extensions.discordExtension.DiscordCommandsExtension) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) LiteralText(net.minecraft.text.LiteralText)

Example 38 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class SpawnCommand method register.

public void register(CommandDispatcher<ServerCommandSource> dispatcher, SpawnExtension spawnExtension) {
    dispatcher.register(literal("spawn").requires(server -> spawnExtension.extensionSettings().isEnabled()).executes(context -> {
        SpawnPos pos = spawnExtension.getSpawnPos();
        if (pos.isValidPos()) {
            ServerPlayerEntity player = context.getSource().getPlayer();
            player.teleport(DimUtils.getWorld(pos.getDim(), context.getSource().getServer()), pos.getX(), pos.getY(), pos.getZ(), player.getYaw(), player.getPitch());
        } else {
            context.getSource().sendFeedback(new LiteralText("Not configured yet..."), false);
        }
        return 1;
    }));
    dispatcher.register(literal("setSpawn").requires(server -> spawnExtension.extensionSettings().isEnabled() && server.hasPermissionLevel(2)).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        BlockPos pos = new BlockPos(player.getX(), player.getY(), player.getZ());
        spawnExtension.updateSpawnPos(pos, context.getSource());
        return 1;
    }).then(argument("coords", BlockPosArgumentType.blockPos()).executes(context -> spawnExtension.updateSpawnPos(BlockPosArgumentType.getBlockPos(context, "coords"), context.getSource()))));
}
Also used : LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) BlockPos(net.minecraft.util.math.BlockPos) BlockPosArgumentType(net.minecraft.command.argument.BlockPosArgumentType) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) DimUtils(com.kahzerx.kahzerxmod.utils.DimUtils) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) LiteralText(net.minecraft.text.LiteralText)

Example 39 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project KahzerxMod by otakucraft.

the class ExchangeCommand method register.

public void register(CommandDispatcher<ServerCommandSource> dispatcher, ShopExtension extension) {
    dispatcher.register(literal("exchange").requires(server -> extension.extensionSettings().isEnabled()).then(literal("confirm").then(argument("count", IntegerArgumentType.integer(0)).then(argument("item", StringArgumentType.string()).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        Item item = player.getMainHandStack().getItem();
        String sentItem = StringArgumentType.getString(context, "item");
        int count = player.getMainHandStack().getCount();
        int sentCount = IntegerArgumentType.getInteger(context, "count");
        if (!basicVerify(context, player)) {
            return 1;
        }
        if (count != sentCount || !item.getTranslationKey().equals(sentItem)) {
            context.getSource().sendFeedback(MarkEnum.CROSS.appendMessage("El stack de tu mano ha cambiado!"), false);
            return 1;
        }
        extension.updateFounds(player, Exchange.getValue(item) * count);
        extension.logExchange(player, item, count);
        player.setStackInHand(Hand.MAIN_HAND, new ItemStack(Items.AIR));
        context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Añadidos ").append(MarkEnum.OTAKU_COIN.appendMessage(String.valueOf(Exchange.getValue(item) * count))), false);
        return 1;
    })))).then(literal("abort").then(argument("count", IntegerArgumentType.integer(0)).then(argument("item", StringArgumentType.string()).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        Item item = player.getMainHandStack().getItem();
        String sentItem = StringArgumentType.getString(context, "item");
        int count = player.getMainHandStack().getCount();
        int sentCount = IntegerArgumentType.getInteger(context, "count");
        if (count == sentCount || item.getTranslationKey().equals(sentItem)) {
            context.getSource().sendFeedback(MarkEnum.TICK.appendMessage("Exchange cancelado!"), false);
        }
        return 1;
    })))).executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        Item item = player.getMainHandStack().getItem();
        int count = player.getMainHandStack().getCount();
        if (!basicVerify(context, player)) {
            return 1;
        }
        context.getSource().sendFeedback(MarkEnum.INFO.appendMessage(String.format("Vas a cambiar %d %s por ", count, item.getName().getString())).append(MarkEnum.OTAKU_COIN.appendMessage(String.format("%d", Exchange.getValue(item) * count))), false);
        context.getSource().sendFeedback(MarkEnum.QUESTION.appendMessage("Confirmar exchange? ").append(new LiteralText("[Sí]").styled(style -> style.withColor(Formatting.GREEN).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/exchange confirm %d %s", count, item.getTranslationKey()))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("confirmar exchange"))))).append(new LiteralText(" ").styled(style -> style.withColor(Formatting.WHITE))).append(new LiteralText("[No]").styled(style -> style.withColor(Formatting.DARK_RED).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/exchange abort %d %s", count, item.getTranslationKey()))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("cancelar exchange"))))), false);
        return 1;
    }).then(literal("info").executes(context -> {
        context.getSource().sendFeedback(MarkEnum.OTAKU_COIN.appendMessage("a"), false);
        return 1;
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) ShopExtension(com.kahzerx.kahzerxmod.extensions.shopExtension.ShopExtension) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) CommandContext(com.mojang.brigadier.context.CommandContext) MarkEnum(com.kahzerx.kahzerxmod.utils.MarkEnum) Item(net.minecraft.item.Item) Items(net.minecraft.item.Items) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HoverEvent(net.minecraft.text.HoverEvent) CommandManager.argument(net.minecraft.server.command.CommandManager.argument) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) ItemStack(net.minecraft.item.ItemStack) Formatting(net.minecraft.util.Formatting) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Hand(net.minecraft.util.Hand) IntegerArgumentType(com.mojang.brigadier.arguments.IntegerArgumentType) Item(net.minecraft.item.Item) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 40 with ServerCommandSource

use of net.minecraft.server.command.ServerCommandSource in project carpet-discarpet by replaceitem.

the class DiscarpetCommand method register.

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    dispatcher.register(literal("discarpet").requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)).executes(commandContext -> {
        String version = FabricLoader.getInstance().getModContainer("discarpet").get().getMetadata().getVersion().getFriendlyString();
        MutableText text = new LiteralText("Discarpet version " + version).formatted(Formatting.BLUE);
        text.append("\nFor help, see the ");
        text.append(new LiteralText("documentation").setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/replaceitem/carpet-discarpet/blob/master/docs/Full.md")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to get to the Discarpet documentation"))).withFormatting(Formatting.UNDERLINE).withColor(Formatting.DARK_BLUE)));
        commandContext.getSource().sendFeedback(text, true);
        return 1;
    }).then(literal("list").executes(commandContext -> {
        Set<String> botIDs = Discarpet.discordBots.keySet();
        final LiteralText t;
        if (botIDs.size() == 0) {
            t = (LiteralText) new LiteralText("There are no bots active:\n").formatted(Formatting.RED);
        } else {
            t = (LiteralText) new LiteralText("There are " + botIDs.size() + " bots active\n").formatted(Formatting.GREEN);
        }
        botIDs.forEach(id -> t.append(new LiteralText(id + "\n").formatted(Formatting.BLUE)));
        commandContext.getSource().sendFeedback(t, true);
        return botIDs.size();
    })).then(literal("getInvite").then(CommandManager.argument("id", StringArgumentType.string()).suggests(BOTS).executes(commandContext -> {
        String id = StringArgumentType.getString(commandContext, "id");
        String invite = Discarpet.discordBots.get(id).getInvite();
        Text text = ((new LiteralText("Click here to get the invite link for the bot")).styled((style) -> {
            return style.withColor(Formatting.BLUE).withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, invite)).withHoverEvent(new HoverEvent(net.minecraft.text.HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to open the invite link"))).withInsertion(invite);
        }));
        commandContext.getSource().sendFeedback(text, false);
        return 1;
    }))).then(literal("reload").executes(commandContext -> {
        Discarpet.loadConfig(commandContext.getSource());
        return 1;
    })));
}
Also used : Discarpet(Discarpet.Discarpet) FabricLoader(net.fabricmc.loader.api.FabricLoader) LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Set(java.util.Set) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HoverEvent(net.minecraft.text.HoverEvent) CommandManager(net.minecraft.server.command.CommandManager) CommandSource(net.minecraft.command.CommandSource) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) Style(net.minecraft.text.Style) Formatting(net.minecraft.util.Formatting) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) 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