From ac54cef2fd122bf1921622c820eee57aa04278f6 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Thu, 5 Feb 2015 16:20:02 -0500 Subject: [PATCH] Add methods to convert NativeGameMode to and from GameMode Fixes #45 --- .../protocol/wrappers/EnumWrappers.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java index 3beae065..d37263a7 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java @@ -46,6 +46,7 @@ public abstract class EnumWrappers { * Represents a native game mode in Minecraft. *

* Not to be confused with {@link GameMode} in Bukkit. + * * @author Kristian */ public enum NativeGameMode { @@ -59,6 +60,49 @@ public abstract class EnumWrappers { * @deprecated Replaced by NOT_SET */ NONE; + + /** + * Gets this NativeGameMode's Bukkit equivalent. + *

+ * Note: There is not a Bukkit equivalent for NOT_SET or NONE + * + * @return The Bukkit equivalent, or null if one does not exist. + */ + public GameMode toBukkit() { + switch (this) { + case ADVENTURE: + return GameMode.ADVENTURE; + case CREATIVE: + return GameMode.CREATIVE; + case SPECTATOR: + return GameMode.SPECTATOR; + case SURVIVAL: + return GameMode.SURVIVAL; + default: + return null; + } + } + + /** + * Obtains the given GameMode's NativeGameMode equivalent. + * + * @param mode Bukkit GameMode + * @return The NativeGameMode equivalent, or null if one does not exist. + */ + public static NativeGameMode fromBukkit(GameMode mode) { + switch (mode) { + case ADVENTURE: + return ADVENTURE; + case CREATIVE: + return CREATIVE; + case SPECTATOR: + return SPECTATOR; + case SURVIVAL: + return SURVIVAL; + default: + return null; + } + } } public enum ResourcePackStatus {