Why is Java not working?

I was doing Cavern Survival, and I realized that I could change my code to Java, so I decide to try it. After I wrote half of my code, and switched off my computer for the night, and it stoped working.

When every I try to fight anyone nothing loads, and it stops in the load page:

I know that it is a problem with CC’s Java because I assume that my code wouldn’t stop the compile. I also have tried to run some of my other Python codes in CC, and they worked.

Just in case it is my code that is messing my thing up, here is my code (Sorry about the bugs, I haven’t written Java in about a year):

public class AI {
    public static boolean avoid(int x, int y) {
        return !((y < 65 && x > 71 && x < 89) || (y > 72 && x > 71 && x < 89));
    }
    
    public void onSpawn() {
        String[] buildOrder = {"archer", "soldier", "archer", "soldier", "archer"};
        
        while (true) {
            var enemy = hero.findNearestEnemy();
            
            // Commanding Pet
            
            pet.moveXY(110, 69);
            if (enemy && pet.isReady("shape-shift") && pet.distanceTo(enemy) <= 30) {
                pet.shapeShift();
            }
        }
    }
    
    public static void commandFriends() {
        String[] buildOrder = {"archer", "soldier", "archer", "soldier", "archer"};
        
        // Summoning friends
        
        String type = buildOrder[len(hero.built) % len(buildOrder)];
        
        if (enemy && hero.distanceTo(enemy) < 10 && hero.gold >= hero.costOf("soldier")) {
            hero.summon("soldier");
        } else if (hero.gold >= hero.costOf(type)) {
            hero.summon(type);
        }
        
        // Commanding friends
        
        var friends = hero.findFriends();
    
        for (var friend : friends) {
            var enemy = friend.findNearestEnemy();
            door - hero.findByType("door");
            
            if (enemy != null) {
                var distance = friend.distanceTo(enemy);
                
                if (friend.type == "archer") {
                    hero.command(friend, "attack", enemy);
                }
                if ((enemy.type == "soldier" && friend.distanceTo(enemy) < 13) || (enemy.type != "soldier" && friend.distanceTo(enemy) < 20) && enemy.type != "door") {
                    int distancePlusFivePlusFive = Math.pow(((friend.pos.x + 5) - enemy.pos.x), 2) + Math.pow(((friend.pos.y + 5) - enemy.pos.y), 2)
                    int distanceMinusFiveMinusFive = Math.pow(((friend.pos.x - 5) - enemy.pos.x), 2) + Math.pow(((friend.pos.y - 5) - enemy.pos.y), 2)
                    int distancePlusFiveMinusFive = Math.pow(((friend.pos.x + 5) - enemy.pos.x), 2) + Math.pow(((friend.pos.y - 5) - enemy.pos.y), 2)
                    int distanceMinusFivePlusFive = Math.pow(((friend.pos.x - 5) - enemy.pos.x), 2) + Math.pow(((friend.pos.y + 5) - enemy.pos.y), 2)
                    
                    int distanceXPlusFive = Math.pow(((friend.pos.x + 5) - enemy.pos.x), 2) + Math.pow(((friend.pos.y) - enemy.pos.y), 2)
                    int distanceXMinusFive = Math.pow(((friend.pos.x - 5) - enemy.pos.x), 2) + Math.pow(((friend.pos.y) - enemy.pos.y), 2)
                    int distanceYPlusFive = Math.pow(((friend.pos.x) - enemy.pos.x), 2) + Math.pow(((friend.pos.y + 5) - enemy.pos.y), 2)
                    int distanceYMinusFive = Math.pow(((friend.pos.x) - enemy.pos.x), 2) + Math.pow(((friend.pos.y - 5) - enemy.pos.y), 2)
                }
            }
        }
        
        
    }
    
    public static void main(String[] args) {
        pet.on("spawn", AI.onSpawn);
        
        while(true) {
            AI.commandFriends();
        }
    
    }
}

Yeah, Java’s still in an experimental phase, and we are working out some of the kinks with certain language features. Do you need to reset your code to be able to get into the level? You can add ?codeLanguage=python to the URL to force it back into another language if the level isn’t loading, like this:

https://codecombat.com/play/level/cavern-survival?team=humans&codeLanguage=python

@nick Thank You! I also have another question. Since Java compiles then runs while Python doesn’t, does that make Java faster than Python in code combat? Or does Code combat just run all languages at the same time?

We interpret Java like we interpret Python, JavaScript, Lua, CoffeeScript, and Java–it all goes through our custom interpreter, which is written in JavaScript. Because JavaScript needs less extra processing, JavaScript runs the fastest, but in almost all contexts outside of intense multiplayer arena logic or some complicated mountain/glacier levels, code execution shouldn’t take a meaningful amount of time for any of our programming languages.

Java and C++ are parsed server-side, though, so the parsing step (before the code starts to run) is slower for those than it is for the client-side languages. Usually this delay is only a few hundred milliseconds.

Right. Also pet functionality(onSpawn) doesn’t seem to work in Java right now, so that might also contribute to the issue.

Ok, Thanks @nick, just wanted to know! And @Chaboi_3000 that might be the reason my code wasn’t working. Thank You!