the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 83 lines 2.4 kB view raw
1/* 2package net.minecraft.commands.common; 3 4import net.minecraft.commands.BaseCommand; 5import net.minecraft.commands.CommandSender; 6import net.minecraft.commands.exceptions.UsageException; 7import net.minecraft.network.chat.ChatMessageComponent; 8import net.minecraft.server.MinecraftServer; 9import net.minecraft.world.level.GameRules; 10 11import java.util.List; 12 13public class GameRuleCommand extends BaseCommand { 14 @Override 15 public String getName() { 16 return "gamerule"; 17 } 18 19 @Override 20 public int getPermissionLevel() { 21 return LEVEL_GAMEMASTERS; 22 } 23 24 25 @Override 26 public String getUsage(CommandSender source) { 27 return "commands.gamerule.usage"; 28 } 29 30 @Override 31 public void execute(CommandSender source, String[] args) { 32 if (args.length == 2) { 33 String rule = args[0]; 34 String value = args[1]; 35 36 GameRules rules = getRules(); 37 38 if (rules.contains(rule)) { 39 rules.set(rule, value); 40 logAdminAction(source, "commands.gamerule.success"); 41 } else { 42 logAdminAction(source, "commands.gamerule.norule", rule); 43 } 44 45 return; 46 } else if (args.length == 1) { 47 String rule = args[0]; 48 GameRules rules = getRules(); 49 50 if (rules.contains(rule)) { 51 String value = rules.get(rule); 52 source.sendMessage(ChatMessageComponent.forPlainText(rule).addPlainText(" = ").addPlainText(value)); 53 } else { 54 logAdminAction(source, "commands.gamerule.norule", rule); 55 } 56 57 return; 58 } else if (args.length == 0) { 59 GameRules rules = getRules(); 60 source.sendMessage(ChatMessageComponent.forPlainText(joinStrings(rules.getRuleNames()))); 61 return; 62 } 63 64 throw new UsageException("commands.gamerule.usage"); 65 } 66 67 @Override 68 public List<String> matchArguments(CommandSender source, String[] args) { 69 if (args.length == 1) { 70 return matchArguments(args, getRules().getRuleNames()); 71 } else if (args.length == 2) { 72 return matchArguments(args, "true", "false"); 73 } 74 75 return null; 76 } 77 78 private GameRules getRules() { 79 return MinecraftServer.getInstance().getLevel(0).getGameRules(); 80 } 81} 82 83*/