Advertisement
Superloup10

Untitled

Sep 11th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.29 KB | None | 0 0
  1. package net.minecraft.command;
  2.  
  3. import com.google.common.collect.Maps;
  4. import com.google.common.io.Files;
  5. import com.google.gson.GsonBuilder;
  6. import com.google.gson.JsonElement;
  7. import com.mojang.brigadier.CommandDispatcher;
  8. import com.mojang.brigadier.arguments.ArgumentType;
  9. import com.mojang.brigadier.builder.ArgumentBuilder;
  10. import com.mojang.brigadier.builder.LiteralArgumentBuilder;
  11. import com.mojang.brigadier.builder.RequiredArgumentBuilder;
  12. import com.mojang.brigadier.exceptions.CommandSyntaxException;
  13. import com.mojang.brigadier.tree.CommandNode;
  14. import com.mojang.brigadier.tree.RootCommandNode;
  15. import java.io.File;
  16. import java.io.IOException;
  17. import java.nio.charset.StandardCharsets;
  18. import java.util.Map;
  19. import net.minecraft.command.arguments.ArgumentTypes;
  20. import net.minecraft.command.arguments.SuggestionProviders;
  21. import net.minecraft.command.impl.AdvancementCommand;
  22. import net.minecraft.command.impl.BanCommand;
  23. import net.minecraft.command.impl.BanIpCommand;
  24. import net.minecraft.command.impl.BanListCommand;
  25. import net.minecraft.command.impl.BossBarCommand;
  26. import net.minecraft.command.impl.ClearCommand;
  27. import net.minecraft.command.impl.CloneCommand;
  28. import net.minecraft.command.impl.DataPackCommand;
  29. import net.minecraft.command.impl.DeOpCommand;
  30. import net.minecraft.command.impl.DebugCommand;
  31. import net.minecraft.command.impl.DefaultGameModeCommand;
  32. import net.minecraft.command.impl.DifficultyCommand;
  33. import net.minecraft.command.impl.EffectCommand;
  34. import net.minecraft.command.impl.EnchantCommand;
  35. import net.minecraft.command.impl.ExecuteCommand;
  36. import net.minecraft.command.impl.ExperienceCommand;
  37. import net.minecraft.command.impl.FillCommand;
  38. import net.minecraft.command.impl.FunctionCommand;
  39. import net.minecraft.command.impl.GameModeCommand;
  40. import net.minecraft.command.impl.GameRuleCommand;
  41. import net.minecraft.command.impl.GiveCommand;
  42. import net.minecraft.command.impl.HelpCommand;
  43. import net.minecraft.command.impl.KickCommand;
  44. import net.minecraft.command.impl.KillCommand;
  45. import net.minecraft.command.impl.ListCommand;
  46. import net.minecraft.command.impl.LocateCommand;
  47. import net.minecraft.command.impl.MeCommand;
  48. import net.minecraft.command.impl.MessageCommand;
  49. import net.minecraft.command.impl.OpCommand;
  50. import net.minecraft.command.impl.PardonCommand;
  51. import net.minecraft.command.impl.PardonIpCommand;
  52. import net.minecraft.command.impl.ParticleCommand;
  53. import net.minecraft.command.impl.PlaySoundCommand;
  54. import net.minecraft.command.impl.PublishCommand;
  55. import net.minecraft.command.impl.RecipeCommand;
  56. import net.minecraft.command.impl.ReloadCommand;
  57. import net.minecraft.command.impl.ReplaceItemCommand;
  58. import net.minecraft.command.impl.SaveAllCommand;
  59. import net.minecraft.command.impl.SaveOffCommand;
  60. import net.minecraft.command.impl.SaveOnCommand;
  61. import net.minecraft.command.impl.SayCommand;
  62. import net.minecraft.command.impl.ScoreboardCommand;
  63. import net.minecraft.command.impl.SeedCommand;
  64. import net.minecraft.command.impl.SetBlockCommand;
  65. import net.minecraft.command.impl.SetIdleTimeoutCommand;
  66. import net.minecraft.command.impl.SetWorldSpawnCommand;
  67. import net.minecraft.command.impl.SpawnPointCommand;
  68. import net.minecraft.command.impl.SpreadPlayersCommand;
  69. import net.minecraft.command.impl.StopCommand;
  70. import net.minecraft.command.impl.StopSoundCommand;
  71. import net.minecraft.command.impl.SummonCommand;
  72. import net.minecraft.command.impl.TagCommand;
  73. import net.minecraft.command.impl.TeamCommand;
  74. import net.minecraft.command.impl.TeleportCommand;
  75. import net.minecraft.command.impl.TellRawCommand;
  76. import net.minecraft.command.impl.TimeCommand;
  77. import net.minecraft.command.impl.TitleCommand;
  78. import net.minecraft.command.impl.TriggerCommand;
  79. import net.minecraft.command.impl.WeatherCommand;
  80. import net.minecraft.command.impl.WhitelistCommand;
  81. import net.minecraft.command.impl.WorldBorderCommand;
  82. import net.minecraft.command.impl.data.DataCommand;
  83. import net.minecraft.entity.player.EntityPlayerMP;
  84. import net.minecraft.network.play.server.SPacketCommandList;
  85. import net.minecraft.util.text.ITextComponent;
  86. import net.minecraft.util.text.TextComponentString;
  87. import net.minecraft.util.text.TextComponentTranslation;
  88. import net.minecraft.util.text.TextComponentUtils;
  89. import net.minecraft.util.text.TextFormatting;
  90. import net.minecraft.util.text.event.ClickEvent;
  91. import net.minecraft.util.text.event.HoverEvent;
  92. import org.apache.logging.log4j.LogManager;
  93. import org.apache.logging.log4j.Logger;
  94.  
  95. public class Commands {
  96.    private static final Logger field_197061_a = LogManager.getLogger();
  97.    private final CommandDispatcher<CommandSource> field_197062_b = new CommandDispatcher<CommandSource>();
  98.  
  99.    public Commands(boolean p_i49161_1_) {
  100.       AdvancementCommand.func_198199_a(this.field_197062_b);
  101.       ExecuteCommand.func_198378_a(this.field_197062_b);
  102.       BossBarCommand.func_201413_a(this.field_197062_b);
  103.       ClearCommand.func_198243_a(this.field_197062_b);
  104.       CloneCommand.func_198265_a(this.field_197062_b);
  105.       DataCommand.func_198937_a(this.field_197062_b);
  106.       DataPackCommand.func_198299_a(this.field_197062_b);
  107.       DebugCommand.func_198330_a(this.field_197062_b);
  108.       DefaultGameModeCommand.func_198340_a(this.field_197062_b);
  109.       DifficultyCommand.func_198344_a(this.field_197062_b);
  110.       EffectCommand.func_198353_a(this.field_197062_b);
  111.       MeCommand.func_198364_a(this.field_197062_b);
  112.       EnchantCommand.func_202649_a(this.field_197062_b);
  113.       ExperienceCommand.func_198437_a(this.field_197062_b);
  114.       FillCommand.func_198465_a(this.field_197062_b);
  115.       FunctionCommand.func_198476_a(this.field_197062_b);
  116.       GameModeCommand.func_198482_a(this.field_197062_b);
  117.       GameRuleCommand.func_198487_a(this.field_197062_b);
  118.       GiveCommand.func_198494_a(this.field_197062_b);
  119.       HelpCommand.func_198510_a(this.field_197062_b);
  120.       KickCommand.func_198514_a(this.field_197062_b);
  121.       KillCommand.func_198518_a(this.field_197062_b);
  122.       ListCommand.func_198522_a(this.field_197062_b);
  123.       LocateCommand.func_198528_a(this.field_197062_b);
  124.       MessageCommand.func_198537_a(this.field_197062_b);
  125.       ParticleCommand.func_198563_a(this.field_197062_b);
  126.       PlaySoundCommand.func_198572_a(this.field_197062_b);
  127.       PublishCommand.func_198581_a(this.field_197062_b);
  128.       ReloadCommand.func_198597_a(this.field_197062_b);
  129.       RecipeCommand.func_198589_a(this.field_197062_b);
  130.       ReplaceItemCommand.func_198602_a(this.field_197062_b);
  131.       SayCommand.func_198625_a(this.field_197062_b);
  132.       ScoreboardCommand.func_198647_a(this.field_197062_b);
  133.       SeedCommand.func_198671_a(this.field_197062_b);
  134.       SetBlockCommand.func_198684_a(this.field_197062_b);
  135.       SpawnPointCommand.func_198695_a(this.field_197062_b);
  136.       SetWorldSpawnCommand.func_198702_a(this.field_197062_b);
  137.       SpreadPlayersCommand.func_198716_a(this.field_197062_b);
  138.       StopSoundCommand.func_198730_a(this.field_197062_b);
  139.       SummonCommand.func_198736_a(this.field_197062_b);
  140.       TagCommand.func_198743_a(this.field_197062_b);
  141.       TeamCommand.func_198771_a(this.field_197062_b);
  142.       TeleportCommand.func_198809_a(this.field_197062_b);
  143.       TellRawCommand.func_198818_a(this.field_197062_b);
  144.       TimeCommand.func_198823_a(this.field_197062_b);
  145.       TitleCommand.func_198839_a(this.field_197062_b);
  146.       TriggerCommand.func_198852_a(this.field_197062_b);
  147.       WeatherCommand.func_198862_a(this.field_197062_b);
  148.       WorldBorderCommand.func_198894_a(this.field_197062_b);
  149.       if (p_i49161_1_) {
  150.          BanIpCommand.func_198220_a(this.field_197062_b);
  151.          BanListCommand.func_198229_a(this.field_197062_b);
  152.          BanCommand.func_198235_a(this.field_197062_b);
  153.          DeOpCommand.func_198321_a(this.field_197062_b);
  154.          OpCommand.func_198541_a(this.field_197062_b);
  155.          PardonCommand.func_198547_a(this.field_197062_b);
  156.          PardonIpCommand.func_198553_a(this.field_197062_b);
  157.          SaveAllCommand.func_198611_a(this.field_197062_b);
  158.          SaveOffCommand.func_198617_a(this.field_197062_b);
  159.          SaveOnCommand.func_198621_a(this.field_197062_b);
  160.          SetIdleTimeoutCommand.func_198690_a(this.field_197062_b);
  161.          StopCommand.func_198725_a(this.field_197062_b);
  162.          WhitelistCommand.func_198873_a(this.field_197062_b);
  163.       }
  164.  
  165.       this.field_197062_b.findAmbiguities((p_201302_1_, p_201302_2_, p_201302_3_, p_201302_4_) -> {
  166.          field_197061_a.warn("Ambiguity between arguments {} and {} with inputs: {}", this.field_197062_b.getPath(p_201302_2_), this.field_197062_b.getPath(p_201302_3_), p_201302_4_);
  167.       });
  168.       this.field_197062_b.setConsumer((p_197058_0_, p_197058_1_, p_197058_2_) -> {
  169.          ((CommandSource)p_197058_0_.getSource()).func_197038_a(p_197058_0_, p_197058_1_, p_197058_2_);
  170.       });
  171.    }
  172.  
  173.    public void func_200378_a(File p_200378_1_) {
  174.       try {
  175.          Files.write((new GsonBuilder()).setPrettyPrinting().create().toJson((JsonElement)ArgumentTypes.func_200388_a(this.field_197062_b, this.field_197062_b.getRoot())), p_200378_1_, StandardCharsets.UTF_8);
  176.       } catch (IOException ioexception) {
  177.          field_197061_a.error("Couldn't write out command tree!", (Throwable)ioexception);
  178.       }
  179.  
  180.    }
  181.  
  182.    public int func_197059_a(CommandSource p_197059_1_, String p_197059_2_) {
  183.       String s = p_197059_2_;
  184.       if (p_197059_2_.startsWith("/")) {
  185.          p_197059_2_ = p_197059_2_.substring(1);
  186.       }
  187.  
  188.       p_197059_1_.func_197028_i().profiler.startSection(p_197059_2_);
  189.  
  190.       try {
  191.          try {
  192.             int lvt_4_3_ = this.field_197062_b.execute(p_197059_2_, p_197059_1_);
  193.             return lvt_4_3_;
  194.          } catch (CommandException commandexception) {
  195.             p_197059_1_.func_197021_a(commandexception.func_197003_a());
  196.             byte b1 = 0;
  197.             return b1;
  198.          } catch (CommandSyntaxException commandsyntaxexception) {
  199.             p_197059_1_.func_197021_a(TextComponentUtils.func_202465_a(commandsyntaxexception.getRawMessage()));
  200.             if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
  201.                int k = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
  202.                ITextComponent itextcomponent1 = (new TextComponentString("")).func_211708_a(TextFormatting.GRAY).func_211710_a((p_211705_1_) -> {
  203.                   p_211705_1_.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, s));
  204.                });
  205.                if (k > 10) {
  206.                   itextcomponent1.appendText("...");
  207.                }
  208.  
  209.                itextcomponent1.appendText(commandsyntaxexception.getInput().substring(Math.max(0, k - 10), k));
  210.                if (k < commandsyntaxexception.getInput().length()) {
  211.                   ITextComponent itextcomponent2 = (new TextComponentString(commandsyntaxexception.getInput().substring(k))).func_211709_a(new TextFormatting[]{TextFormatting.RED, TextFormatting.UNDERLINE});
  212.                   itextcomponent1.appendSibling(itextcomponent2);
  213.                }
  214.  
  215.                itextcomponent1.appendSibling((new TextComponentTranslation("command.context.here", new Object[0])).func_211709_a(new TextFormatting[]{TextFormatting.RED, TextFormatting.ITALIC}));
  216.                p_197059_1_.func_197021_a(itextcomponent1);
  217.             }
  218.          } catch (Exception exception) {
  219.             TextComponentString textcomponentstring = new TextComponentString(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage());
  220.             ITextComponent itextcomponent = textcomponentstring;
  221.             if (field_197061_a.isDebugEnabled()) {
  222.                StackTraceElement[] astacktraceelement = exception.getStackTrace();
  223.  
  224.                for(int j = 0; j < Math.min(astacktraceelement.length, 3); ++j) {
  225.                   itextcomponent.appendText("\n\n").appendText(astacktraceelement[j].getMethodName()).appendText("\n ").appendText(astacktraceelement[j].getFileName()).appendText(":").appendText(String.valueOf(astacktraceelement[j].getLineNumber()));
  226.                }
  227.             }
  228.  
  229.             p_197059_1_.func_197021_a((new TextComponentTranslation("command.failed", new Object[0])).func_211710_a((p_211704_1_) -> {
  230.                p_211704_1_.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, itextcomponent));
  231.             }));
  232.             byte b2 = 0;
  233.             return b2;
  234.          }
  235.  
  236.          byte b0 = 0;
  237.          return b0;
  238.       } finally {
  239.          p_197059_1_.func_197028_i().profiler.endSection();
  240.       }
  241.    }
  242.  
  243.    public void func_197051_a(EntityPlayerMP p_197051_1_) {
  244.       Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> map = Maps.<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>>newHashMap();
  245.       RootCommandNode<ISuggestionProvider> rootcommandnode = new RootCommandNode<ISuggestionProvider>();
  246.       map.put(this.field_197062_b.getRoot(), rootcommandnode);
  247.       this.func_197052_a(this.field_197062_b.getRoot(), rootcommandnode, p_197051_1_.func_195051_bN(), map);
  248.       p_197051_1_.connection.sendPacket(new SPacketCommandList(rootcommandnode));
  249.    }
  250.  
  251.    private void func_197052_a(CommandNode<CommandSource> p_197052_1_, CommandNode<ISuggestionProvider> p_197052_2_, CommandSource p_197052_3_, Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> p_197052_4_) {
  252.       for(CommandNode<CommandSource> commandnode : p_197052_1_.getChildren()) {
  253.          if (commandnode.canUse(p_197052_3_)) {
  254.             ArgumentBuilder<ISuggestionProvider, ?> argumentbuilder = (ArgumentBuilder)commandnode.createBuilder();
  255.             argumentbuilder.requires((p_197060_0_) -> {
  256.                return true;
  257.             });
  258.             if (argumentbuilder.getCommand() != null) {
  259.                argumentbuilder.executes((p_197053_0_) -> {
  260.                   return 0;
  261.                });
  262.             }
  263.  
  264.             if (argumentbuilder instanceof RequiredArgumentBuilder) {
  265.                RequiredArgumentBuilder<ISuggestionProvider, ?> requiredargumentbuilder = (RequiredArgumentBuilder)argumentbuilder;
  266.                if (requiredargumentbuilder.getSuggestionsProvider() != null) {
  267.                   requiredargumentbuilder.suggests(SuggestionProviders.func_197496_b(requiredargumentbuilder.getSuggestionsProvider()));
  268.                }
  269.             }
  270.  
  271.             if (argumentbuilder.getRedirect() != null) {
  272.                argumentbuilder.redirect(p_197052_4_.get(argumentbuilder.getRedirect()));
  273.             }
  274.  
  275.             CommandNode<ISuggestionProvider> commandnode1 = argumentbuilder.build();
  276.             p_197052_4_.put(commandnode, commandnode1);
  277.             p_197052_2_.addChild(commandnode1);
  278.             if (!commandnode.getChildren().isEmpty()) {
  279.                this.func_197052_a(commandnode, commandnode1, p_197052_3_, p_197052_4_);
  280.             }
  281.          }
  282.       }
  283.  
  284.    }
  285.  
  286.    public static LiteralArgumentBuilder<CommandSource> func_197057_a(String p_197057_0_) {
  287.       return LiteralArgumentBuilder.<CommandSource>literal(p_197057_0_);
  288.    }
  289.  
  290.    public static <T> RequiredArgumentBuilder<CommandSource, T> func_197056_a(String p_197056_0_, ArgumentType<T> p_197056_1_) {
  291.       return RequiredArgumentBuilder.<CommandSource, T>argument(p_197056_0_, p_197056_1_);
  292.    }
  293.  
  294.    public CommandDispatcher<CommandSource> func_197054_a() {
  295.       return this.field_197062_b;
  296.    }
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement