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