Search in sources :

Example 1 with ClientCommandManager.literal

use of net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal in project EarthMCEssentials by EarthMC-Stats.

the class NearbyCommand method register.

public static void register() {
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("nearby").executes(c -> {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null)
            return -1;
        Formatting headingFormatting = Formatting.byName(instance().getConfig().nearby.headingTextColour.name());
        Formatting textFormatting = Formatting.byName(instance().getConfig().nearby.playerTextColour.name());
        MsgUtils.sendPlayer("text_nearby_header", false, headingFormatting, false);
        for (int i = 0; i < instance().getNearbyPlayers().size(); i++) {
            JsonObject currentPlayer = instance().getNearbyPlayers().get(i).getAsJsonObject();
            JsonElement xElement = currentPlayer.get("x");
            JsonElement zElement = currentPlayer.get("z");
            if (xElement == null || zElement == null)
                continue;
            int distance = Math.abs(xElement.getAsInt() - (int) client.player.getX()) + Math.abs(zElement.getAsInt() - (int) client.player.getZ());
            String prefix = "";
            if (instance().getConfig().nearby.showRank) {
                if (!currentPlayer.has("town"))
                    prefix = new TranslatableText("text_nearby_rank_townless").toString();
                else
                    prefix = "(" + currentPlayer.get("rank").getAsString() + ") ";
            }
            MsgUtils.sendPlayer(prefix + currentPlayer.get("name").getAsString() + ": " + distance + "m", false, textFormatting, false);
        }
        return 1;
    }).then(ClientCommandManager.literal("refresh").executes(c -> {
        instance().scheduler().stop();
        instance().scheduler().start();
        MsgUtils.sendPlayer("msg_nearby_refresh", false, Formatting.AQUA, true);
        return 1;
    })).then(ClientCommandManager.literal("clear").executes(c -> {
        instance().setNearbyPlayers(new JsonArray());
        MsgUtils.sendPlayer("msg_nearby_clear", false, Formatting.AQUA, true);
        return 1;
    })));
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) Formatting(net.minecraft.util.Formatting) TranslatableText(net.minecraft.text.TranslatableText) EarthMCEssentials(net.emc.emce.EarthMCEssentials) MsgUtils(net.emc.emce.utils.MsgUtils) MinecraftClient(net.minecraft.client.MinecraftClient) EarthMCEssentials.instance(net.emc.emce.EarthMCEssentials.instance) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) TranslatableText(net.minecraft.text.TranslatableText) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) MinecraftClient(net.minecraft.client.MinecraftClient) Formatting(net.minecraft.util.Formatting) JsonObject(com.google.gson.JsonObject)

Example 2 with ClientCommandManager.literal

use of net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal in project mineclub-expanded by Blobanium.

the class CommandParser method registerCommand.

public static void registerCommand() {
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("mcex").executes(context -> {
        context.getSource().sendFeedback(Text.Serializer.fromJson("[\"\",{\"text\":\"Mineclub Expanded\\n\"},{\"text\":\"Click here to see the full set of commands\",\"color\":\"light_purple\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://github.com/Blobanium/mineclub-expanded/wiki/List-Of-Commands\"}}]"));
        return 0;
    }));
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("mcex").then(ClientCommandManager.literal("getminingvalue").executes(context -> {
        context.getSource().sendFeedback(new LiteralText(GetMiningValue.miningValueResponseString(false)));
        return 0;
    })));
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("mcex").then(ClientCommandManager.literal("getminingvalue").then(ClientCommandManager.literal("deatiled").executes(context -> {
        context.getSource().sendFeedback(new LiteralText(GetMiningValue.miningValueResponseString(true)));
        return 0;
    }))));
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("mcex").then(ClientCommandManager.literal("yourmom").executes(context -> {
        context.getSource().sendFeedback(new LiteralText("No your mom."));
        return 0;
    })));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) GetMiningValue(io.github.blobanium.mineclubexpanded.util.command.commnads.GetMiningValue) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) LiteralText(net.minecraft.text.LiteralText)

Example 3 with ClientCommandManager.literal

use of net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal in project EarthMCEssentials by EarthMC-Stats.

the class TownlessCommand method register.

public static void register() {
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("townless").executes(TownlessCommand::run).then(ClientCommandManager.literal("inviteAll").executes(c -> {
        if (MinecraftClient.getInstance().player == null)
            return -1;
        if (ModUtils.isConnectedToEMC()) {
            StringBuilder townlessString = new StringBuilder();
            for (String townlessPlayer : instance().getTownless()) {
                if (("/towny:town invite " + townlessString + " " + townlessPlayer).length() > 256)
                    break;
                else
                    townlessString.append(townlessPlayer).append(" ");
            }
            MsgUtils.sendChat("/towny:town invite " + townlessString);
            MsgUtils.sendPlayer("msg_townless_sent", false, Formatting.AQUA, true, instance().getTownless().size());
        } else
            MsgUtils.sendPlayer("msg_townless_invite_err", false, Formatting.RED, true);
        return 1;
    })).then(ClientCommandManager.literal("revokeAll").executes(c -> {
        if (MinecraftClient.getInstance().player == null)
            return -1;
        if (ModUtils.isConnectedToEMC()) {
            StringBuilder townlessString = new StringBuilder();
            for (String townlessPlayer : instance().getTownless()) {
                if (("/towny:town invite -" + townlessString + " " + townlessPlayer).length() > 256)
                    break;
                else
                    townlessString.append("-").append(townlessPlayer).append(" ");
            }
            MsgUtils.sendChat("/towny:town invite " + townlessString);
            MsgUtils.sendPlayer("msg_townless_revoked", false, Formatting.AQUA, true, instance().getTownless().size());
        } else
            MsgUtils.sendPlayer("msg_townless_revoke_err", false, Formatting.RED, true);
        return 1;
    })).then(ClientCommandManager.literal("refresh").executes(c -> {
        EarthMCAPI.getTownless().thenAccept(instance()::setTownlessResidents);
        MsgUtils.sendPlayer("msg_townless_refresh", false, Formatting.AQUA, true);
        return 1;
    })).then(ClientCommandManager.literal("clear").executes(c -> {
        instance().setTownlessResidents(new JsonArray());
        MsgUtils.sendPlayer("msg_townless_clear", false, Formatting.AQUA, true);
        return 1;
    })));
}
Also used : JsonArray(com.google.gson.JsonArray) Formatting(net.minecraft.util.Formatting) CommandContext(com.mojang.brigadier.context.CommandContext) FabricClientCommandSource(net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource) MsgUtils(net.emc.emce.utils.MsgUtils) MinecraftClient(net.minecraft.client.MinecraftClient) EarthMCEssentials.instance(net.emc.emce.EarthMCEssentials.instance) EarthMCAPI(net.emc.emce.utils.EarthMCAPI) ModUtils(net.emc.emce.utils.ModUtils) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) JsonArray(com.google.gson.JsonArray)

Aggregations

ClientCommandManager (net.fabricmc.fabric.api.client.command.v1.ClientCommandManager)3 JsonArray (com.google.gson.JsonArray)2 EarthMCEssentials.instance (net.emc.emce.EarthMCEssentials.instance)2 MsgUtils (net.emc.emce.utils.MsgUtils)2 MinecraftClient (net.minecraft.client.MinecraftClient)2 Formatting (net.minecraft.util.Formatting)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 GetMiningValue (io.github.blobanium.mineclubexpanded.util.command.commnads.GetMiningValue)1 EarthMCEssentials (net.emc.emce.EarthMCEssentials)1 EarthMCAPI (net.emc.emce.utils.EarthMCAPI)1 ModUtils (net.emc.emce.utils.ModUtils)1 FabricClientCommandSource (net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource)1 LiteralText (net.minecraft.text.LiteralText)1 Text (net.minecraft.text.Text)1 TranslatableText (net.minecraft.text.TranslatableText)1