From bbf974f348993c8f49d0c4580b79da5d73f807fc Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 16 Dec 2015 12:37:14 +0100 Subject: [PATCH] Fix GameMode integer ids. --- .../type/enumeration/TypeGameMode.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/com/massivecraft/massivecore/command/type/enumeration/TypeGameMode.java b/src/com/massivecraft/massivecore/command/type/enumeration/TypeGameMode.java index cfd64905..116f60a7 100644 --- a/src/com/massivecraft/massivecore/command/type/enumeration/TypeGameMode.java +++ b/src/com/massivecraft/massivecore/command/type/enumeration/TypeGameMode.java @@ -28,10 +28,32 @@ public class TypeGameMode extends TypeEnum { Set ret = new MassiveSet(super.getIdsInner(value)); - String id = String.valueOf(value.ordinal()); - ret.add(id); + int idInt = getIntegerId(value); + String idString = String.valueOf(idInt); + ret.add(idString); return ret; } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + // The reason we can not simply do ".ordinal()" is Survival and Creative has the wrong order. + + public static int getIntegerId(GameMode gameMode) + { + if (gameMode == null) throw new NullPointerException("gameMode"); + + switch (gameMode) + { + case SURVIVAL: return 0; + case CREATIVE: return 1; + case ADVENTURE: return 2; + case SPECTATOR: return 3; + } + + return gameMode.ordinal(); + } + }