Made integer data optional
https://github.com/TBMCPlugins/DiscordPlugin/issues/19
This commit is contained in:
parent
89c707332f
commit
0d38f9b85b
1 changed files with 5 additions and 4 deletions
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -151,7 +152,7 @@ public class TBMCPlayer implements AutoCloseable {
|
||||||
* @return The value or null if not found
|
* @return The value or null if not found
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected <T extends Number> T getIntData(Class<T> cl) {
|
protected <T extends Number> Optional<T> getIntData(Class<T> cl) {
|
||||||
StackTraceElement st = new Exception().getStackTrace()[1];
|
StackTraceElement st = new Exception().getStackTrace()[1];
|
||||||
String mname = st.getMethodName();
|
String mname = st.getMethodName();
|
||||||
if (!mname.startsWith("get"))
|
if (!mname.startsWith("get"))
|
||||||
|
@ -160,14 +161,14 @@ public class TBMCPlayer implements AutoCloseable {
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return null;
|
return null;
|
||||||
if (obj instanceof Short)
|
if (obj instanceof Short)
|
||||||
return (T) obj;
|
return Optional.of((T) obj);
|
||||||
if (!(Integer.class.isAssignableFrom(obj.getClass())))
|
if (!(Integer.class.isAssignableFrom(obj.getClass())))
|
||||||
throw new UnsupportedOperationException("The retrieved object isn't an integer: " + obj);
|
throw new UnsupportedOperationException("The retrieved object isn't an integer: " + obj);
|
||||||
Integer int_ = (Integer) obj;
|
Integer int_ = (Integer) obj;
|
||||||
if (Short.class.isAssignableFrom(cl))
|
if (Short.class.isAssignableFrom(cl))
|
||||||
return (T) (Object) int_.shortValue();
|
return Optional.of((T) (Object) int_.shortValue());
|
||||||
else
|
else
|
||||||
return (T) (Object) int_;
|
return Optional.of((T) (Object) int_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue