mojira.dev
MC-131738

Commands data report creates a server instance for no reason

The commands data report creates a new server instance (along with setting up a ton of other stuff) to create a command tree instance:

(using forge's MCPConfig with 18w22c mappings; the same code is present in 1.13-pre2 though)

public void func_200398_a(DirectoryCache p_200398_1_) throws IOException
    {
        YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
        MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
        GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
        File file1 = new File(this.field_200400_a.func_200391_b().toFile(), "tmp");
        PlayerProfileCache playerprofilecache = new PlayerProfileCache(gameprofilerepository, new File(file1, MinecraftServer.USER_CACHE_FILE.getName()));
        MinecraftServer minecraftserver = new DedicatedServer(file1, DataFixesManager.createFixer(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, playerprofilecache);
        minecraftserver.func_195571_aL().func_200378_a(this.field_200400_a.func_200391_b().resolve("reports/commands.json").toFile());
    }
public void func_200398_a(DirectoryCache p_200398_1_) throws IOException
    {
        YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
        MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
        GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
        File file1 = new File(this.field_200400_a.func_200391_b().toFile(), "tmp");
        PlayerProfileCache playerprofilecache = new PlayerProfileCache(gameprofilerepository, new File(file1, MinecraftServer.USER_CACHE_FILE.getName()));
        MinecraftServer minecraftserver = new DedicatedServer(file1, DataFixesManager.createFixer(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, playerprofilecache);
        minecraftserver.func_195571_aL().func_200378_a(this.field_200400_a.func_200391_b().resolve("reports/commands.json").toFile());
    }

This takes several seconds, while it prepares all the authentication stuff and then the server. However, it could just be replaced with:

public void func_200398_a(DirectoryCache p_200398_1_) throws IOException
    {
        new Commands(true).func_200378_a(this.field_200400_a.func_200391_b().resolve("reports/commands.json").toFile());
    }
public void func_200398_a(DirectoryCache p_200398_1_) throws IOException
    {
        new Commands(true).func_200378_a(this.field_200400_a.func_200391_b().resolve("reports/commands.json").toFile());
    }

which is much faster and simpler. This produces the exact same report (I have tested it), and still detects the ambiguous /teleport commands.


This also causes the dedicated server classes to be included in the client JAR, since they are still referenced.

Comments 3

It appears that the code was further changed in 18w48a to reference a server.properties file, which also isn't needed.

How exactly do you know the changes to the code in the minecraft snapshots?

I've gotten code at reading code without names over the years, but that's not exactly something I can teach. But in this case, it's pretty easy to find the relevant code because there are some strings that don't change: "Command Syntax" and "reports/commands.json". I happened to notice that the code for this report included a reference to server.properties when looking at it (the easiest way for me to check this issue is by looking at the code), and then I just checked previous versions to see when it wasn't present so I knew when the change occurred. Compare:

18w47b

public void a(ga p_a_1_) throws IOException {
      YggdrasilAuthenticationService lvt_2_1_ = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
      MinecraftSessionService lvt_3_1_ = lvt_2_1_.createMinecraftSessionService();
      GameProfileRepository lvt_4_1_ = lvt_2_1_.createProfileRepository();
      File lvt_5_1_ = new File(this.b.b().toFile(), "tmp");
      wg lvt_6_1_ = new wg(lvt_4_1_, new File(lvt_5_1_, MinecraftServer.a.getName()));
      MinecraftServer lvt_7_1_ = new to(lvt_5_1_, yu.a(), lvt_2_1_, lvt_3_1_, lvt_4_1_, lvt_6_1_);
      lvt_7_1_.aK().a(this.b.b().resolve("reports/commands.json").toFile());
   }

   public String a() {
      return "Command Syntax";
   }
public void a(ga p_a_1_) throws IOException {
      YggdrasilAuthenticationService lvt_2_1_ = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
      MinecraftSessionService lvt_3_1_ = lvt_2_1_.createMinecraftSessionService();
      GameProfileRepository lvt_4_1_ = lvt_2_1_.createProfileRepository();
      File lvt_5_1_ = new File(this.b.b().toFile(), "tmp");
      wg lvt_6_1_ = new wg(lvt_4_1_, new File(lvt_5_1_, MinecraftServer.a.getName()));
      MinecraftServer lvt_7_1_ = new to(lvt_5_1_, yu.a(), lvt_2_1_, lvt_3_1_, lvt_4_1_, lvt_6_1_);
      lvt_7_1_.aK().a(this.b.b().resolve("reports/commands.json").toFile());
   }

   public String a() {
      return "Command Syntax";
   }

18w48a

public void a(ga p_a_1_) {
      YggdrasilAuthenticationService lvt_2_1_ = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
      MinecraftSessionService lvt_3_1_ = lvt_2_1_.createMinecraftSessionService();
      GameProfileRepository lvt_4_1_ = lvt_2_1_.createProfileRepository();
      File lvt_5_1_ = new File(this.b.b().toFile(), "tmp");
      wi lvt_6_1_ = new wi(lvt_4_1_, new File(lvt_5_1_, MinecraftServer.a.getName()));
      tp lvt_7_1_ = new tp(Paths.get("server.properties", new String[0]));
      MinecraftServer lvt_8_1_ = new tn(lvt_5_1_, lvt_7_1_, yx.a(), lvt_2_1_, lvt_3_1_, lvt_4_1_, lvt_6_1_);
      lvt_8_1_.aK().a(this.b.b().resolve("reports/commands.json").toFile());
   }

   public String a() {
      return "Command Syntax";
   }
public void a(ga p_a_1_) {
      YggdrasilAuthenticationService lvt_2_1_ = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
      MinecraftSessionService lvt_3_1_ = lvt_2_1_.createMinecraftSessionService();
      GameProfileRepository lvt_4_1_ = lvt_2_1_.createProfileRepository();
      File lvt_5_1_ = new File(this.b.b().toFile(), "tmp");
      wi lvt_6_1_ = new wi(lvt_4_1_, new File(lvt_5_1_, MinecraftServer.a.getName()));
      tp lvt_7_1_ = new tp(Paths.get("server.properties", new String[0]));
      MinecraftServer lvt_8_1_ = new tn(lvt_5_1_, lvt_7_1_, yx.a(), lvt_2_1_, lvt_3_1_, lvt_4_1_, lvt_6_1_);
      lvt_8_1_.aK().a(this.b.b().resolve("reports/commands.json").toFile());
   }

   public String a() {
      return "Command Syntax";
   }

I can't really explain the full process I use, just because it's mostly based on experience (working on projects such as burger that involve a lot of it). But I hope that gives you the general idea...

pokechu22

(Unassigned)

Plausible

(Unassigned)

data-generator, performance

Minecraft 1.13-pre2, Minecraft 1.13-pre3, Minecraft 1.13-pre6, Minecraft 1.13-pre7, Minecraft 1.13-pre8, ..., Minecraft 19w04b, Minecraft 19w05a, 1.14.4, 1.15 Pre-release 6, 1.15.2

20w17a

Retrieved