Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.command;
- import com.google.common.collect.Maps;
- import com.google.common.io.Files;
- import com.google.gson.GsonBuilder;
- import com.google.gson.JsonElement;
- import com.mojang.brigadier.CommandDispatcher;
- import com.mojang.brigadier.arguments.ArgumentType;
- import com.mojang.brigadier.builder.ArgumentBuilder;
- import com.mojang.brigadier.builder.LiteralArgumentBuilder;
- import com.mojang.brigadier.builder.RequiredArgumentBuilder;
- import com.mojang.brigadier.exceptions.CommandSyntaxException;
- import com.mojang.brigadier.tree.CommandNode;
- import com.mojang.brigadier.tree.RootCommandNode;
- import java.io.File;
- import java.io.IOException;
- import java.nio.charset.StandardCharsets;
- import java.util.Map;
- import net.minecraft.command.arguments.ArgumentTypes;
- import net.minecraft.command.arguments.SuggestionProviders;
- import net.minecraft.command.impl.AdvancementCommand;
- import net.minecraft.command.impl.BanCommand;
- import net.minecraft.command.impl.BanIpCommand;
- import net.minecraft.command.impl.BanListCommand;
- import net.minecraft.command.impl.BossBarCommand;
- import net.minecraft.command.impl.ClearCommand;
- import net.minecraft.command.impl.CloneCommand;
- import net.minecraft.command.impl.DataPackCommand;
- import net.minecraft.command.impl.DeOpCommand;
- import net.minecraft.command.impl.DebugCommand;
- import net.minecraft.command.impl.DefaultGameModeCommand;
- import net.minecraft.command.impl.DifficultyCommand;
- import net.minecraft.command.impl.EffectCommand;
- import net.minecraft.command.impl.EnchantCommand;
- import net.minecraft.command.impl.ExecuteCommand;
- import net.minecraft.command.impl.ExperienceCommand;
- import net.minecraft.command.impl.FillCommand;
- import net.minecraft.command.impl.FunctionCommand;
- import net.minecraft.command.impl.GameModeCommand;
- import net.minecraft.command.impl.GameRuleCommand;
- import net.minecraft.command.impl.GiveCommand;
- import net.minecraft.command.impl.HelpCommand;
- import net.minecraft.command.impl.KickCommand;
- import net.minecraft.command.impl.KillCommand;
- import net.minecraft.command.impl.ListCommand;
- import net.minecraft.command.impl.LocateCommand;
- import net.minecraft.command.impl.MeCommand;
- import net.minecraft.command.impl.MessageCommand;
- import net.minecraft.command.impl.OpCommand;
- import net.minecraft.command.impl.PardonCommand;
- import net.minecraft.command.impl.PardonIpCommand;
- import net.minecraft.command.impl.ParticleCommand;
- import net.minecraft.command.impl.PlaySoundCommand;
- import net.minecraft.command.impl.PublishCommand;
- import net.minecraft.command.impl.RecipeCommand;
- import net.minecraft.command.impl.ReloadCommand;
- import net.minecraft.command.impl.ReplaceItemCommand;
- import net.minecraft.command.impl.SaveAllCommand;
- import net.minecraft.command.impl.SaveOffCommand;
- import net.minecraft.command.impl.SaveOnCommand;
- import net.minecraft.command.impl.SayCommand;
- import net.minecraft.command.impl.ScoreboardCommand;
- import net.minecraft.command.impl.SeedCommand;
- import net.minecraft.command.impl.SetBlockCommand;
- import net.minecraft.command.impl.SetIdleTimeoutCommand;
- import net.minecraft.command.impl.SetWorldSpawnCommand;
- import net.minecraft.command.impl.SpawnPointCommand;
- import net.minecraft.command.impl.SpreadPlayersCommand;
- import net.minecraft.command.impl.StopCommand;
- import net.minecraft.command.impl.StopSoundCommand;
- import net.minecraft.command.impl.SummonCommand;
- import net.minecraft.command.impl.TagCommand;
- import net.minecraft.command.impl.TeamCommand;
- import net.minecraft.command.impl.TeleportCommand;
- import net.minecraft.command.impl.TellRawCommand;
- import net.minecraft.command.impl.TimeCommand;
- import net.minecraft.command.impl.TitleCommand;
- import net.minecraft.command.impl.TriggerCommand;
- import net.minecraft.command.impl.WeatherCommand;
- import net.minecraft.command.impl.WhitelistCommand;
- import net.minecraft.command.impl.WorldBorderCommand;
- import net.minecraft.command.impl.data.DataCommand;
- import net.minecraft.entity.player.EntityPlayerMP;
- import net.minecraft.network.play.server.SPacketCommandList;
- import net.minecraft.util.text.ITextComponent;
- import net.minecraft.util.text.TextComponentString;
- import net.minecraft.util.text.TextComponentTranslation;
- import net.minecraft.util.text.TextComponentUtils;
- import net.minecraft.util.text.TextFormatting;
- import net.minecraft.util.text.event.ClickEvent;
- import net.minecraft.util.text.event.HoverEvent;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- public class Commands {
- private static final Logger field_197061_a = LogManager.getLogger();
- private final CommandDispatcher<CommandSource> field_197062_b = new CommandDispatcher<CommandSource>();
- public Commands(boolean p_i49161_1_) {
- AdvancementCommand.func_198199_a(this.field_197062_b);
- ExecuteCommand.func_198378_a(this.field_197062_b);
- BossBarCommand.func_201413_a(this.field_197062_b);
- ClearCommand.func_198243_a(this.field_197062_b);
- CloneCommand.func_198265_a(this.field_197062_b);
- DataCommand.func_198937_a(this.field_197062_b);
- DataPackCommand.func_198299_a(this.field_197062_b);
- DebugCommand.func_198330_a(this.field_197062_b);
- DefaultGameModeCommand.func_198340_a(this.field_197062_b);
- DifficultyCommand.func_198344_a(this.field_197062_b);
- EffectCommand.func_198353_a(this.field_197062_b);
- MeCommand.func_198364_a(this.field_197062_b);
- EnchantCommand.func_202649_a(this.field_197062_b);
- ExperienceCommand.func_198437_a(this.field_197062_b);
- FillCommand.func_198465_a(this.field_197062_b);
- FunctionCommand.func_198476_a(this.field_197062_b);
- GameModeCommand.func_198482_a(this.field_197062_b);
- GameRuleCommand.func_198487_a(this.field_197062_b);
- GiveCommand.func_198494_a(this.field_197062_b);
- HelpCommand.func_198510_a(this.field_197062_b);
- KickCommand.func_198514_a(this.field_197062_b);
- KillCommand.func_198518_a(this.field_197062_b);
- ListCommand.func_198522_a(this.field_197062_b);
- LocateCommand.func_198528_a(this.field_197062_b);
- MessageCommand.func_198537_a(this.field_197062_b);
- ParticleCommand.func_198563_a(this.field_197062_b);
- PlaySoundCommand.func_198572_a(this.field_197062_b);
- PublishCommand.func_198581_a(this.field_197062_b);
- ReloadCommand.func_198597_a(this.field_197062_b);
- RecipeCommand.func_198589_a(this.field_197062_b);
- ReplaceItemCommand.func_198602_a(this.field_197062_b);
- SayCommand.func_198625_a(this.field_197062_b);
- ScoreboardCommand.func_198647_a(this.field_197062_b);
- SeedCommand.func_198671_a(this.field_197062_b);
- SetBlockCommand.func_198684_a(this.field_197062_b);
- SpawnPointCommand.func_198695_a(this.field_197062_b);
- SetWorldSpawnCommand.func_198702_a(this.field_197062_b);
- SpreadPlayersCommand.func_198716_a(this.field_197062_b);
- StopSoundCommand.func_198730_a(this.field_197062_b);
- SummonCommand.func_198736_a(this.field_197062_b);
- TagCommand.func_198743_a(this.field_197062_b);
- TeamCommand.func_198771_a(this.field_197062_b);
- TeleportCommand.func_198809_a(this.field_197062_b);
- TellRawCommand.func_198818_a(this.field_197062_b);
- TimeCommand.func_198823_a(this.field_197062_b);
- TitleCommand.func_198839_a(this.field_197062_b);
- TriggerCommand.func_198852_a(this.field_197062_b);
- WeatherCommand.func_198862_a(this.field_197062_b);
- WorldBorderCommand.func_198894_a(this.field_197062_b);
- if (p_i49161_1_) {
- BanIpCommand.func_198220_a(this.field_197062_b);
- BanListCommand.func_198229_a(this.field_197062_b);
- BanCommand.func_198235_a(this.field_197062_b);
- DeOpCommand.func_198321_a(this.field_197062_b);
- OpCommand.func_198541_a(this.field_197062_b);
- PardonCommand.func_198547_a(this.field_197062_b);
- PardonIpCommand.func_198553_a(this.field_197062_b);
- SaveAllCommand.func_198611_a(this.field_197062_b);
- SaveOffCommand.func_198617_a(this.field_197062_b);
- SaveOnCommand.func_198621_a(this.field_197062_b);
- SetIdleTimeoutCommand.func_198690_a(this.field_197062_b);
- StopCommand.func_198725_a(this.field_197062_b);
- WhitelistCommand.func_198873_a(this.field_197062_b);
- }
- this.field_197062_b.findAmbiguities((p_201302_1_, p_201302_2_, p_201302_3_, p_201302_4_) -> {
- 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_);
- });
- this.field_197062_b.setConsumer((p_197058_0_, p_197058_1_, p_197058_2_) -> {
- ((CommandSource)p_197058_0_.getSource()).func_197038_a(p_197058_0_, p_197058_1_, p_197058_2_);
- });
- }
- public void func_200378_a(File p_200378_1_) {
- try {
- 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);
- } catch (IOException ioexception) {
- field_197061_a.error("Couldn't write out command tree!", (Throwable)ioexception);
- }
- }
- public int func_197059_a(CommandSource p_197059_1_, String p_197059_2_) {
- String s = p_197059_2_;
- if (p_197059_2_.startsWith("/")) {
- p_197059_2_ = p_197059_2_.substring(1);
- }
- p_197059_1_.func_197028_i().profiler.startSection(p_197059_2_);
- try {
- try {
- int lvt_4_3_ = this.field_197062_b.execute(p_197059_2_, p_197059_1_);
- return lvt_4_3_;
- } catch (CommandException commandexception) {
- p_197059_1_.func_197021_a(commandexception.func_197003_a());
- byte b1 = 0;
- return b1;
- } catch (CommandSyntaxException commandsyntaxexception) {
- p_197059_1_.func_197021_a(TextComponentUtils.func_202465_a(commandsyntaxexception.getRawMessage()));
- if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
- int k = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
- ITextComponent itextcomponent1 = (new TextComponentString("")).func_211708_a(TextFormatting.GRAY).func_211710_a((p_211705_1_) -> {
- p_211705_1_.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, s));
- });
- if (k > 10) {
- itextcomponent1.appendText("...");
- }
- itextcomponent1.appendText(commandsyntaxexception.getInput().substring(Math.max(0, k - 10), k));
- if (k < commandsyntaxexception.getInput().length()) {
- ITextComponent itextcomponent2 = (new TextComponentString(commandsyntaxexception.getInput().substring(k))).func_211709_a(new TextFormatting[]{TextFormatting.RED, TextFormatting.UNDERLINE});
- itextcomponent1.appendSibling(itextcomponent2);
- }
- itextcomponent1.appendSibling((new TextComponentTranslation("command.context.here", new Object[0])).func_211709_a(new TextFormatting[]{TextFormatting.RED, TextFormatting.ITALIC}));
- p_197059_1_.func_197021_a(itextcomponent1);
- }
- } catch (Exception exception) {
- TextComponentString textcomponentstring = new TextComponentString(exception.getMessage() == null ? exception.getClass().getName() : exception.getMessage());
- ITextComponent itextcomponent = textcomponentstring;
- if (field_197061_a.isDebugEnabled()) {
- StackTraceElement[] astacktraceelement = exception.getStackTrace();
- for(int j = 0; j < Math.min(astacktraceelement.length, 3); ++j) {
- itextcomponent.appendText("\n\n").appendText(astacktraceelement[j].getMethodName()).appendText("\n ").appendText(astacktraceelement[j].getFileName()).appendText(":").appendText(String.valueOf(astacktraceelement[j].getLineNumber()));
- }
- }
- p_197059_1_.func_197021_a((new TextComponentTranslation("command.failed", new Object[0])).func_211710_a((p_211704_1_) -> {
- p_211704_1_.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, itextcomponent));
- }));
- byte b2 = 0;
- return b2;
- }
- byte b0 = 0;
- return b0;
- } finally {
- p_197059_1_.func_197028_i().profiler.endSection();
- }
- }
- public void func_197051_a(EntityPlayerMP p_197051_1_) {
- Map<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>> map = Maps.<CommandNode<CommandSource>, CommandNode<ISuggestionProvider>>newHashMap();
- RootCommandNode<ISuggestionProvider> rootcommandnode = new RootCommandNode<ISuggestionProvider>();
- map.put(this.field_197062_b.getRoot(), rootcommandnode);
- this.func_197052_a(this.field_197062_b.getRoot(), rootcommandnode, p_197051_1_.func_195051_bN(), map);
- p_197051_1_.connection.sendPacket(new SPacketCommandList(rootcommandnode));
- }
- 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_) {
- for(CommandNode<CommandSource> commandnode : p_197052_1_.getChildren()) {
- if (commandnode.canUse(p_197052_3_)) {
- ArgumentBuilder<ISuggestionProvider, ?> argumentbuilder = (ArgumentBuilder)commandnode.createBuilder();
- argumentbuilder.requires((p_197060_0_) -> {
- return true;
- });
- if (argumentbuilder.getCommand() != null) {
- argumentbuilder.executes((p_197053_0_) -> {
- return 0;
- });
- }
- if (argumentbuilder instanceof RequiredArgumentBuilder) {
- RequiredArgumentBuilder<ISuggestionProvider, ?> requiredargumentbuilder = (RequiredArgumentBuilder)argumentbuilder;
- if (requiredargumentbuilder.getSuggestionsProvider() != null) {
- requiredargumentbuilder.suggests(SuggestionProviders.func_197496_b(requiredargumentbuilder.getSuggestionsProvider()));
- }
- }
- if (argumentbuilder.getRedirect() != null) {
- argumentbuilder.redirect(p_197052_4_.get(argumentbuilder.getRedirect()));
- }
- CommandNode<ISuggestionProvider> commandnode1 = argumentbuilder.build();
- p_197052_4_.put(commandnode, commandnode1);
- p_197052_2_.addChild(commandnode1);
- if (!commandnode.getChildren().isEmpty()) {
- this.func_197052_a(commandnode, commandnode1, p_197052_3_, p_197052_4_);
- }
- }
- }
- }
- public static LiteralArgumentBuilder<CommandSource> func_197057_a(String p_197057_0_) {
- return LiteralArgumentBuilder.<CommandSource>literal(p_197057_0_);
- }
- public static <T> RequiredArgumentBuilder<CommandSource, T> func_197056_a(String p_197056_0_, ArgumentType<T> p_197056_1_) {
- return RequiredArgumentBuilder.<CommandSource, T>argument(p_197056_0_, p_197056_1_);
- }
- public CommandDispatcher<CommandSource> func_197054_a() {
- return this.field_197062_b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement