package protocolsupport.protocol.utils.types;

import java.text.MessageFormat;

import protocolsupport.utils.CollectionsUtils;
import protocolsupport.utils.CollectionsUtils.ArrayMap;

public enum GameMode {

	SURVIVAL(0), CREATIVE(1), ADVENTURE(2), SPECTATOR(3);

	private static final ArrayMap<GameMode> byId = CollectionsUtils.makeEnumMappingArrayMap(GameMode.class, GameMode::getId);

	private final int id;
	GameMode(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public static GameMode getById(int id) {
		GameMode gm = byId.get(id);
		if (gm == null) {
			throw new IllegalArgumentException(MessageFormat.format("Unknown gamemode network id {0}", id));
		}
		return gm;
	}

}

package protocolsupport.protocol.utils.types;

import java.text.MessageFormat;

import protocolsupport.utils.CollectionsUtils;
import protocolsupport.utils.CollectionsUtils.ArrayMap;

public enum GameMode {

	NOT_SET(-1), SURVIVAL(0), CREATIVE(1), ADVENTURE(2), SPECTATOR(3);

	private static final ArrayMap<GameMode> byId = CollectionsUtils.makeEnumMappingArrayMap(GameMode.class, GameMode::getId);

	private final int id;
	GameMode(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public static GameMode getById(int id) {
		GameMode gm = byId.get(id);
		if (gm == null) {
			throw new IllegalArgumentException(MessageFormat.format("Unknown gamemode network id {0}", id));
		}
		return gm;
	}

}

Support -1 gamemode (not set), while it's not valid gamemode and should be only used as starting gamemode for server internals, sometimes custom npc plugins do not set it. All supported versions support this gamemode, and no internal logic depends on it, so allowing it shouldn't bring any problems
Support -1 gamemode (not set), while it's not valid gamemode and should
be only used as starting gamemode for server internals, sometimes custom
npc plugins do not set it. All supported versions support this gamemode,
and no internal logic depends on it, so allowing it shouldn't bring any
problems