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;
})));
}
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;
})));
}
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;
})));
}
Aggregations