/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.CommandDispatcher * com.mojang.brigadier.builder.LiteralArgumentBuilder * com.mojang.brigadier.context.CommandContext */ package net.minecraft.server.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.minecraft.world.level.gamerules.GameRule; import net.minecraft.world.level.gamerules.GameRuleTypeVisitor; import net.minecraft.world.level.gamerules.GameRules; public class GameRuleCommand { public static void register(CommandDispatcher dispatcher, CommandBuildContext context) { final LiteralArgumentBuilder base = (LiteralArgumentBuilder)Commands.literal("gamerule").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)); new GameRules(context.enabledFeatures()).visitGameRuleTypes(new GameRuleTypeVisitor(){ @Override public void visit(GameRule gameRule) { LiteralArgumentBuilder rule = Commands.literal(gameRule.id()); base.then(((LiteralArgumentBuilder)rule.executes(c -> GameRuleCommand.queryRule((CommandSourceStack)c.getSource(), gameRule))).then(Commands.argument("value", gameRule.argument()).executes(c -> GameRuleCommand.setRule((CommandContext)c, gameRule)))); } }); dispatcher.register(base); } private static int setRule(CommandContext context, GameRule gameRule) { CommandSourceStack source = (CommandSourceStack)context.getSource(); Object value = context.getArgument("value", gameRule.valueClass()); source.getLevel().getGameRules().set(gameRule, value, ((CommandSourceStack)context.getSource()).getServer()); source.sendSuccess(() -> Component.translatable("commands.gamerule.set", gameRule.id(), gameRule.serialize(value)), true); return gameRule.getCommandResult(value); } private static int queryRule(CommandSourceStack source, GameRule gameRule) { Object value = source.getLevel().getGameRules().get(gameRule); source.sendSuccess(() -> Component.translatable("commands.gamerule.query", gameRule.id(), gameRule.serialize(value)), false); return gameRule.getCommandResult(value); } }