| 1 | package net.minecraft.command;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 5 | import net.minecraft.network.play.server.S19PacketEntityStatus;
|
| 6 | import net.minecraft.server.MinecraftServer;
|
| 7 | import net.minecraft.util.BlockPos;
|
| 8 | import net.minecraft.util.ChatComponentText;
|
| 9 | import net.minecraft.world.GameRules;
|
| 10 |
|
| 11 | public class CommandGameRule extends CommandBase
|
| 12 | {
|
| 13 | /**
|
| 14 | * Gets the name of the command
|
| 15 | */
|
| 16 | public String getCommandName()
|
| 17 | {
|
| 18 | return "gamerule";
|
| 19 | }
|
| 20 |
|
| 21 | /**
|
| 22 | * Return the required permission level for this command.
|
| 23 | */
|
| 24 | public int getRequiredPermissionLevel()
|
| 25 | {
|
| 26 | return 2;
|
| 27 | }
|
| 28 |
|
| 29 | /**
|
| 30 | * Gets the usage string for the command.
|
| 31 | */
|
| 32 | public String getCommandUsage(ICommandSender sender)
|
| 33 | {
|
| 34 | return "commands.gamerule.usage";
|
| 35 | }
|
| 36 |
|
| 37 | /**
|
| 38 | * Callback when the command is invoked
|
| 39 | */
|
| 40 | public void processCommand(ICommandSender sender, String[] args) throws CommandException
|
| 41 | {
|
| 42 | GameRules gamerules = this.getGameRules();
|
| 43 | String s = args.length > 0 ? args[0] : "";
|
| 44 | String s1 = args.length > 1 ? buildString(args, 1) : "";
|
| 45 |
|
| 46 | switch (args.length)
|
| 47 | {
|
| 48 | case 0:
|
| 49 | sender.addChatMessage(new ChatComponentText(joinNiceString(gamerules.getRules())));
|
| 50 | break;
|
| 51 |
|
| 52 | case 1:
|
| 53 | if (!gamerules.hasRule(s))
|
| 54 | {
|
| 55 | throw new CommandException("commands.gamerule.norule", new Object[] {s});
|
| 56 | }
|
| 57 |
|
| 58 | String s2 = gamerules.getString(s);
|
| 59 | sender.addChatMessage((new ChatComponentText(s)).appendText(" = ").appendText(s2));
|
| 60 | sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, gamerules.getInt(s));
|
| 61 | break;
|
| 62 |
|
| 63 | default:
|
| 64 | if (gamerules.areSameType(s, GameRules.ValueType.BOOLEAN_VALUE) && !"true".equals(s1) && !"false".equals(s1))
|
| 65 | {
|
| 66 | throw new CommandException("commands.generic.boolean.invalid", new Object[] {s1});
|
| 67 | }
|
| 68 |
|
| 69 | gamerules.setOrCreateGameRule(s, s1);
|
| 70 | func_175773_a(gamerules, s);
|
| 71 | notifyOperators(sender, this, "commands.gamerule.success", new Object[0]);
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | public static void func_175773_a(GameRules rules, String p_175773_1_)
|
| 76 | {
|
| 77 | if ("reducedDebugInfo".equals(p_175773_1_))
|
| 78 | {
|
| 79 | byte b0 = (byte)(rules.getBoolean(p_175773_1_) ? 22 : 23);
|
| 80 |
|
| 81 | for (EntityPlayerMP entityplayermp : MinecraftServer.getServer().getConfigurationManager().getPlayerList())
|
| 82 | {
|
| 83 | entityplayermp.playerNetServerHandler.sendPacket(new S19PacketEntityStatus(entityplayermp, b0));
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 | public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos)
|
| 89 | {
|
| 90 | if (args.length == 1)
|
| 91 | {
|
| 92 | return getListOfStringsMatchingLastWord(args, this.getGameRules().getRules());
|
| 93 | }
|
| 94 | else
|
| 95 | {
|
| 96 | if (args.length == 2)
|
| 97 | {
|
| 98 | GameRules gamerules = this.getGameRules();
|
| 99 |
|
| 100 | if (gamerules.areSameType(args[0], GameRules.ValueType.BOOLEAN_VALUE))
|
| 101 | {
|
| 102 | return getListOfStringsMatchingLastWord(args, new String[] {"true", "false"});
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | return null;
|
| 107 | }
|
| 108 | }
|
| 109 |
|
| 110 | /**
|
| 111 | * Return the game rule set this command should be able to manipulate.
|
| 112 | */
|
| 113 | private GameRules getGameRules()
|
| 114 | {
|
| 115 | return MinecraftServer.getServer().worldServerForDimension(0).getGameRules();
|
| 116 | }
|
| 117 | }
|
| 118 |
|