From 0d38f9b85ba2adf6f7d563ea5221d629298be74a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 8 Dec 2016 21:36:39 +0100 Subject: [PATCH] Made integer data optional https://github.com/TBMCPlugins/DiscordPlugin/issues/19 --- src/main/java/buttondevteam/lib/TBMCPlayer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/buttondevteam/lib/TBMCPlayer.java b/src/main/java/buttondevteam/lib/TBMCPlayer.java index c23a74a..639f53b 100644 --- a/src/main/java/buttondevteam/lib/TBMCPlayer.java +++ b/src/main/java/buttondevteam/lib/TBMCPlayer.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map.Entry; +import java.util.Optional; import java.util.UUID; import org.bukkit.Bukkit; @@ -151,7 +152,7 @@ public class TBMCPlayer implements AutoCloseable { * @return The value or null if not found */ @SuppressWarnings("unchecked") - protected T getIntData(Class cl) { + protected Optional getIntData(Class cl) { StackTraceElement st = new Exception().getStackTrace()[1]; String mname = st.getMethodName(); if (!mname.startsWith("get")) @@ -160,14 +161,14 @@ public class TBMCPlayer implements AutoCloseable { if (obj == null) return null; if (obj instanceof Short) - return (T) obj; + return Optional.of((T) obj); if (!(Integer.class.isAssignableFrom(obj.getClass()))) throw new UnsupportedOperationException("The retrieved object isn't an integer: " + obj); Integer int_ = (Integer) obj; if (Short.class.isAssignableFrom(cl)) - return (T) (Object) int_.shortValue(); + return Optional.of((T) (Object) int_.shortValue()); else - return (T) (Object) int_; + return Optional.of((T) (Object) int_); } /**