package net.minecraft.world.level;

import net.minecraft.world.entity.player.Abilities;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;

public enum GameType {
    NOT_SET(-1, ""), 
    SURVIVAL(0, "survival"), 
    CREATIVE(1, "creative"), 
    ADVENTURE(2, "adventure"), 
    SPECTATOR(3, "spectator");
    
    private final int id;
    private final String name;
    
    private GameType(final int integer3, final String string4) {
        this.id = integer3;
        this.name = string4;
    }
    
    public int getId() {
        return this.id;
    }
    
    public String getName() {
        return this.name;
    }
    
    public Component getDisplayName() {
        return new TranslatableComponent("gameMode." + this.name);
    }
    
    public void updatePlayerAbilities(final Abilities bdz) {
        if (this == GameType.CREATIVE) {
            bdz.mayfly = true;
            bdz.instabuild = true;
            bdz.invulnerable = true;
        }
        else if (this == GameType.SPECTATOR) {
            bdz.mayfly = true;
            bdz.instabuild = false;
            bdz.invulnerable = true;
            bdz.flying = true;
        }
        else {
            bdz.mayfly = false;
            bdz.instabuild = false;
            bdz.invulnerable = false;
            bdz.flying = false;
        }
        bdz.mayBuild = !this.isBlockPlacingRestricted();
    }
    
    public boolean isBlockPlacingRestricted() {
        return this == GameType.ADVENTURE || this == GameType.SPECTATOR;
    }
    
    public boolean isCreative() {
        return this == GameType.CREATIVE;
    }
    
    public boolean isSurvival() {
        return this == GameType.SURVIVAL || this == GameType.ADVENTURE;
    }
    
    public static GameType byId(final int integer) {
        return byId(integer, GameType.SURVIVAL);
    }
    
    public static GameType byId(final int integer, final GameType bpy) {
        for (final GameType bpy2 : values()) {
            if (bpy2.id == integer) {
                return bpy2;
            }
        }
        return bpy;
    }
    
    public static GameType byName(final String string) {
        return byName(string, GameType.SURVIVAL);
    }
    
    public static GameType byName(final String string, final GameType bpy) {
        for (final GameType bpy2 : values()) {
            if (bpy2.name.equals(string)) {
                return bpy2;
            }
        }
        return bpy;
    }
}
